diff options
Diffstat (limited to 'fs/ocfs2/suballoc.c')
-rw-r--r-- | fs/ocfs2/suballoc.c | 74 |
1 files changed, 43 insertions, 31 deletions
diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c index 95d432b694e4..ddba97dc06a0 100644 --- a/fs/ocfs2/suballoc.c +++ b/fs/ocfs2/suballoc.c | |||
@@ -146,59 +146,71 @@ static u32 ocfs2_bits_per_group(struct ocfs2_chain_list *cl) | |||
146 | } | 146 | } |
147 | 147 | ||
148 | /* somewhat more expensive than our other checks, so use sparingly. */ | 148 | /* somewhat more expensive than our other checks, so use sparingly. */ |
149 | int ocfs2_check_group_descriptor(struct super_block *sb, | 149 | int ocfs2_validate_group_descriptor(struct super_block *sb, |
150 | struct ocfs2_dinode *di, | 150 | struct ocfs2_dinode *di, |
151 | struct ocfs2_group_desc *gd) | 151 | struct ocfs2_group_desc *gd, |
152 | int clean_error) | ||
152 | { | 153 | { |
153 | unsigned int max_bits; | 154 | unsigned int max_bits; |
154 | 155 | ||
156 | #define do_error(fmt, ...) \ | ||
157 | do{ \ | ||
158 | if (clean_error) \ | ||
159 | mlog(ML_ERROR, fmt "\n", ##__VA_ARGS__); \ | ||
160 | else \ | ||
161 | ocfs2_error(sb, fmt, ##__VA_ARGS__); \ | ||
162 | } while (0) | ||
163 | |||
155 | if (!OCFS2_IS_VALID_GROUP_DESC(gd)) { | 164 | if (!OCFS2_IS_VALID_GROUP_DESC(gd)) { |
156 | OCFS2_RO_ON_INVALID_GROUP_DESC(sb, gd); | 165 | do_error("Group Descriptor #%llu has bad signature %.*s", |
157 | return -EIO; | 166 | (unsigned long long)le64_to_cpu(gd->bg_blkno), 7, |
167 | gd->bg_signature); | ||
168 | return -EINVAL; | ||
158 | } | 169 | } |
159 | 170 | ||
160 | if (di->i_blkno != gd->bg_parent_dinode) { | 171 | if (di->i_blkno != gd->bg_parent_dinode) { |
161 | ocfs2_error(sb, "Group descriptor # %llu has bad parent " | 172 | do_error("Group descriptor # %llu has bad parent " |
162 | "pointer (%llu, expected %llu)", | 173 | "pointer (%llu, expected %llu)", |
163 | (unsigned long long)le64_to_cpu(gd->bg_blkno), | 174 | (unsigned long long)le64_to_cpu(gd->bg_blkno), |
164 | (unsigned long long)le64_to_cpu(gd->bg_parent_dinode), | 175 | (unsigned long long)le64_to_cpu(gd->bg_parent_dinode), |
165 | (unsigned long long)le64_to_cpu(di->i_blkno)); | 176 | (unsigned long long)le64_to_cpu(di->i_blkno)); |
166 | return -EIO; | 177 | return -EINVAL; |
167 | } | 178 | } |
168 | 179 | ||
169 | max_bits = le16_to_cpu(di->id2.i_chain.cl_cpg) * le16_to_cpu(di->id2.i_chain.cl_bpc); | 180 | max_bits = le16_to_cpu(di->id2.i_chain.cl_cpg) * le16_to_cpu(di->id2.i_chain.cl_bpc); |
170 | if (le16_to_cpu(gd->bg_bits) > max_bits) { | 181 | if (le16_to_cpu(gd->bg_bits) > max_bits) { |
171 | ocfs2_error(sb, "Group descriptor # %llu has bit count of %u", | 182 | do_error("Group descriptor # %llu has bit count of %u", |
172 | (unsigned long long)le64_to_cpu(gd->bg_blkno), | 183 | (unsigned long long)le64_to_cpu(gd->bg_blkno), |
173 | le16_to_cpu(gd->bg_bits)); | 184 | le16_to_cpu(gd->bg_bits)); |
174 | return -EIO; | 185 | return -EINVAL; |
175 | } | 186 | } |
176 | 187 | ||
177 | if (le16_to_cpu(gd->bg_chain) >= | 188 | if (le16_to_cpu(gd->bg_chain) >= |
178 | le16_to_cpu(di->id2.i_chain.cl_next_free_rec)) { | 189 | le16_to_cpu(di->id2.i_chain.cl_next_free_rec)) { |
179 | ocfs2_error(sb, "Group descriptor # %llu has bad chain %u", | 190 | do_error("Group descriptor # %llu has bad chain %u", |
180 | (unsigned long long)le64_to_cpu(gd->bg_blkno), | 191 | (unsigned long long)le64_to_cpu(gd->bg_blkno), |
181 | le16_to_cpu(gd->bg_chain)); | 192 | le16_to_cpu(gd->bg_chain)); |
182 | return -EIO; | 193 | return -EINVAL; |
183 | } | 194 | } |
184 | 195 | ||
185 | if (le16_to_cpu(gd->bg_free_bits_count) > le16_to_cpu(gd->bg_bits)) { | 196 | if (le16_to_cpu(gd->bg_free_bits_count) > le16_to_cpu(gd->bg_bits)) { |
186 | ocfs2_error(sb, "Group descriptor # %llu has bit count %u but " | 197 | do_error("Group descriptor # %llu has bit count %u but " |
187 | "claims that %u are free", | 198 | "claims that %u are free", |
188 | (unsigned long long)le64_to_cpu(gd->bg_blkno), | 199 | (unsigned long long)le64_to_cpu(gd->bg_blkno), |
189 | le16_to_cpu(gd->bg_bits), | 200 | le16_to_cpu(gd->bg_bits), |
190 | le16_to_cpu(gd->bg_free_bits_count)); | 201 | le16_to_cpu(gd->bg_free_bits_count)); |
191 | return -EIO; | 202 | return -EINVAL; |
192 | } | 203 | } |
193 | 204 | ||
194 | if (le16_to_cpu(gd->bg_bits) > (8 * le16_to_cpu(gd->bg_size))) { | 205 | if (le16_to_cpu(gd->bg_bits) > (8 * le16_to_cpu(gd->bg_size))) { |
195 | ocfs2_error(sb, "Group descriptor # %llu has bit count %u but " | 206 | do_error("Group descriptor # %llu has bit count %u but " |
196 | "max bitmap bits of %u", | 207 | "max bitmap bits of %u", |
197 | (unsigned long long)le64_to_cpu(gd->bg_blkno), | 208 | (unsigned long long)le64_to_cpu(gd->bg_blkno), |
198 | le16_to_cpu(gd->bg_bits), | 209 | le16_to_cpu(gd->bg_bits), |
199 | 8 * le16_to_cpu(gd->bg_size)); | 210 | 8 * le16_to_cpu(gd->bg_size)); |
200 | return -EIO; | 211 | return -EINVAL; |
201 | } | 212 | } |
213 | #undef do_error | ||
202 | 214 | ||
203 | return 0; | 215 | return 0; |
204 | } | 216 | } |