diff options
author | Joel Becker <joel.becker@oracle.com> | 2008-11-13 17:49:13 -0500 |
---|---|---|
committer | Mark Fasheh <mfasheh@suse.com> | 2009-01-05 11:36:53 -0500 |
commit | 57e3e7971136003c96766346049aa73b82cab079 (patch) | |
tree | 4ba192d7507c77bc1bebd20ba6d82fbbe3da5428 /fs | |
parent | 10995aa2451afa20b721cc7de856cae1a13dba57 (diff) |
ocfs2: Consolidate validation of group descriptors.
Currently the validation of group descriptors is directly duplicated so
that one version can error the filesystem and the other (resize) can
just report the problem. Consolidate to one function that takes a
boolean. Wrap that function with the old call for the old users.
This is in preparation for lifting the read+validate step into a
single function.
Signed-off-by: Joel Becker <joel.becker@oracle.com>
Signed-off-by: Mark Fasheh <mfasheh@suse.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/ocfs2/resize.c | 40 | ||||
-rw-r--r-- | fs/ocfs2/suballoc.c | 74 | ||||
-rw-r--r-- | fs/ocfs2/suballoc.h | 20 |
3 files changed, 68 insertions, 66 deletions
diff --git a/fs/ocfs2/resize.c b/fs/ocfs2/resize.c index 739d452f6174..a2de32a317ad 100644 --- a/fs/ocfs2/resize.c +++ b/fs/ocfs2/resize.c | |||
@@ -396,41 +396,16 @@ static int ocfs2_check_new_group(struct inode *inode, | |||
396 | struct buffer_head *group_bh) | 396 | struct buffer_head *group_bh) |
397 | { | 397 | { |
398 | int ret; | 398 | int ret; |
399 | struct ocfs2_group_desc *gd; | 399 | struct ocfs2_group_desc *gd = |
400 | (struct ocfs2_group_desc *)group_bh->b_data; | ||
400 | u16 cl_bpc = le16_to_cpu(di->id2.i_chain.cl_bpc); | 401 | u16 cl_bpc = le16_to_cpu(di->id2.i_chain.cl_bpc); |
401 | unsigned int max_bits = le16_to_cpu(di->id2.i_chain.cl_cpg) * | ||
402 | le16_to_cpu(di->id2.i_chain.cl_bpc); | ||
403 | 402 | ||
403 | ret = ocfs2_validate_group_descriptor(inode->i_sb, di, gd, 1); | ||
404 | if (ret) | ||
405 | goto out; | ||
404 | 406 | ||
405 | gd = (struct ocfs2_group_desc *)group_bh->b_data; | 407 | ret = -EINVAL; |
406 | 408 | if (le16_to_cpu(gd->bg_chain) != input->chain) | |
407 | ret = -EIO; | ||
408 | if (!OCFS2_IS_VALID_GROUP_DESC(gd)) | ||
409 | mlog(ML_ERROR, "Group descriptor # %llu isn't valid.\n", | ||
410 | (unsigned long long)le64_to_cpu(gd->bg_blkno)); | ||
411 | else if (di->i_blkno != gd->bg_parent_dinode) | ||
412 | mlog(ML_ERROR, "Group descriptor # %llu has bad parent " | ||
413 | "pointer (%llu, expected %llu)\n", | ||
414 | (unsigned long long)le64_to_cpu(gd->bg_blkno), | ||
415 | (unsigned long long)le64_to_cpu(gd->bg_parent_dinode), | ||
416 | (unsigned long long)le64_to_cpu(di->i_blkno)); | ||
417 | else if (le16_to_cpu(gd->bg_bits) > max_bits) | ||
418 | mlog(ML_ERROR, "Group descriptor # %llu has bit count of %u\n", | ||
419 | (unsigned long long)le64_to_cpu(gd->bg_blkno), | ||
420 | le16_to_cpu(gd->bg_bits)); | ||
421 | else if (le16_to_cpu(gd->bg_free_bits_count) > le16_to_cpu(gd->bg_bits)) | ||
422 | mlog(ML_ERROR, "Group descriptor # %llu has bit count %u but " | ||
423 | "claims that %u are free\n", | ||
424 | (unsigned long long)le64_to_cpu(gd->bg_blkno), | ||
425 | le16_to_cpu(gd->bg_bits), | ||
426 | le16_to_cpu(gd->bg_free_bits_count)); | ||
427 | else if (le16_to_cpu(gd->bg_bits) > (8 * le16_to_cpu(gd->bg_size))) | ||
428 | mlog(ML_ERROR, "Group descriptor # %llu has bit count %u but " | ||
429 | "max bitmap bits of %u\n", | ||
430 | (unsigned long long)le64_to_cpu(gd->bg_blkno), | ||
431 | le16_to_cpu(gd->bg_bits), | ||
432 | 8 * le16_to_cpu(gd->bg_size)); | ||
433 | else if (le16_to_cpu(gd->bg_chain) != input->chain) | ||
434 | mlog(ML_ERROR, "Group descriptor # %llu has bad chain %u " | 409 | mlog(ML_ERROR, "Group descriptor # %llu has bad chain %u " |
435 | "while input has %u set.\n", | 410 | "while input has %u set.\n", |
436 | (unsigned long long)le64_to_cpu(gd->bg_blkno), | 411 | (unsigned long long)le64_to_cpu(gd->bg_blkno), |
@@ -449,6 +424,7 @@ static int ocfs2_check_new_group(struct inode *inode, | |||
449 | else | 424 | else |
450 | ret = 0; | 425 | ret = 0; |
451 | 426 | ||
427 | out: | ||
452 | return ret; | 428 | return ret; |
453 | } | 429 | } |
454 | 430 | ||
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 | } |
diff --git a/fs/ocfs2/suballoc.h b/fs/ocfs2/suballoc.h index 4df159d8f450..7adfcc478bdb 100644 --- a/fs/ocfs2/suballoc.h +++ b/fs/ocfs2/suballoc.h | |||
@@ -165,9 +165,23 @@ void ocfs2_free_ac_resource(struct ocfs2_alloc_context *ac); | |||
165 | u64 ocfs2_which_cluster_group(struct inode *inode, u32 cluster); | 165 | u64 ocfs2_which_cluster_group(struct inode *inode, u32 cluster); |
166 | 166 | ||
167 | /* somewhat more expensive than our other checks, so use sparingly. */ | 167 | /* somewhat more expensive than our other checks, so use sparingly. */ |
168 | int ocfs2_check_group_descriptor(struct super_block *sb, | 168 | /* |
169 | struct ocfs2_dinode *di, | 169 | * By default, ocfs2_validate_group_descriptor() calls ocfs2_error() when it |
170 | struct ocfs2_group_desc *gd); | 170 | * finds a problem. A caller that wants to check a group descriptor |
171 | * without going readonly passes a nonzero clean_error. This is only | ||
172 | * resize, really. | ||
173 | */ | ||
174 | int ocfs2_validate_group_descriptor(struct super_block *sb, | ||
175 | struct ocfs2_dinode *di, | ||
176 | struct ocfs2_group_desc *gd, | ||
177 | int clean_error); | ||
178 | static inline int ocfs2_check_group_descriptor(struct super_block *sb, | ||
179 | struct ocfs2_dinode *di, | ||
180 | struct ocfs2_group_desc *gd) | ||
181 | { | ||
182 | return ocfs2_validate_group_descriptor(sb, di, gd, 0); | ||
183 | } | ||
184 | |||
171 | int ocfs2_lock_allocators(struct inode *inode, struct ocfs2_extent_tree *et, | 185 | int ocfs2_lock_allocators(struct inode *inode, struct ocfs2_extent_tree *et, |
172 | u32 clusters_to_add, u32 extents_to_split, | 186 | u32 clusters_to_add, u32 extents_to_split, |
173 | struct ocfs2_alloc_context **data_ac, | 187 | struct ocfs2_alloc_context **data_ac, |