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>
This commit is contained in:
Joel Becker 2008-11-13 14:49:13 -08:00 коммит произвёл Mark Fasheh
Родитель 10995aa245
Коммит 57e3e79711
3 изменённых файлов: 68 добавлений и 66 удалений

Просмотреть файл

@ -396,41 +396,16 @@ static int ocfs2_check_new_group(struct inode *inode,
struct buffer_head *group_bh) struct buffer_head *group_bh)
{ {
int ret; int ret;
struct ocfs2_group_desc *gd; struct ocfs2_group_desc *gd =
(struct ocfs2_group_desc *)group_bh->b_data;
u16 cl_bpc = le16_to_cpu(di->id2.i_chain.cl_bpc); u16 cl_bpc = le16_to_cpu(di->id2.i_chain.cl_bpc);
unsigned int max_bits = le16_to_cpu(di->id2.i_chain.cl_cpg) *
le16_to_cpu(di->id2.i_chain.cl_bpc);
ret = ocfs2_validate_group_descriptor(inode->i_sb, di, gd, 1);
if (ret)
goto out;
gd = (struct ocfs2_group_desc *)group_bh->b_data; ret = -EINVAL;
if (le16_to_cpu(gd->bg_chain) != input->chain)
ret = -EIO;
if (!OCFS2_IS_VALID_GROUP_DESC(gd))
mlog(ML_ERROR, "Group descriptor # %llu isn't valid.\n",
(unsigned long long)le64_to_cpu(gd->bg_blkno));
else if (di->i_blkno != gd->bg_parent_dinode)
mlog(ML_ERROR, "Group descriptor # %llu has bad parent "
"pointer (%llu, expected %llu)\n",
(unsigned long long)le64_to_cpu(gd->bg_blkno),
(unsigned long long)le64_to_cpu(gd->bg_parent_dinode),
(unsigned long long)le64_to_cpu(di->i_blkno));
else if (le16_to_cpu(gd->bg_bits) > max_bits)
mlog(ML_ERROR, "Group descriptor # %llu has bit count of %u\n",
(unsigned long long)le64_to_cpu(gd->bg_blkno),
le16_to_cpu(gd->bg_bits));
else if (le16_to_cpu(gd->bg_free_bits_count) > le16_to_cpu(gd->bg_bits))
mlog(ML_ERROR, "Group descriptor # %llu has bit count %u but "
"claims that %u are free\n",
(unsigned long long)le64_to_cpu(gd->bg_blkno),
le16_to_cpu(gd->bg_bits),
le16_to_cpu(gd->bg_free_bits_count));
else if (le16_to_cpu(gd->bg_bits) > (8 * le16_to_cpu(gd->bg_size)))
mlog(ML_ERROR, "Group descriptor # %llu has bit count %u but "
"max bitmap bits of %u\n",
(unsigned long long)le64_to_cpu(gd->bg_blkno),
le16_to_cpu(gd->bg_bits),
8 * le16_to_cpu(gd->bg_size));
else if (le16_to_cpu(gd->bg_chain) != input->chain)
mlog(ML_ERROR, "Group descriptor # %llu has bad chain %u " mlog(ML_ERROR, "Group descriptor # %llu has bad chain %u "
"while input has %u set.\n", "while input has %u set.\n",
(unsigned long long)le64_to_cpu(gd->bg_blkno), (unsigned long long)le64_to_cpu(gd->bg_blkno),
@ -449,6 +424,7 @@ static int ocfs2_check_new_group(struct inode *inode,
else else
ret = 0; ret = 0;
out:
return ret; return ret;
} }

Просмотреть файл

@ -146,59 +146,71 @@ static u32 ocfs2_bits_per_group(struct ocfs2_chain_list *cl)
} }
/* somewhat more expensive than our other checks, so use sparingly. */ /* somewhat more expensive than our other checks, so use sparingly. */
int ocfs2_check_group_descriptor(struct super_block *sb, int ocfs2_validate_group_descriptor(struct super_block *sb,
struct ocfs2_dinode *di, struct ocfs2_dinode *di,
struct ocfs2_group_desc *gd) struct ocfs2_group_desc *gd,
int clean_error)
{ {
unsigned int max_bits; unsigned int max_bits;
#define do_error(fmt, ...) \
do{ \
if (clean_error) \
mlog(ML_ERROR, fmt "\n", ##__VA_ARGS__); \
else \
ocfs2_error(sb, fmt, ##__VA_ARGS__); \
} while (0)
if (!OCFS2_IS_VALID_GROUP_DESC(gd)) { if (!OCFS2_IS_VALID_GROUP_DESC(gd)) {
OCFS2_RO_ON_INVALID_GROUP_DESC(sb, gd); do_error("Group Descriptor #%llu has bad signature %.*s",
return -EIO; (unsigned long long)le64_to_cpu(gd->bg_blkno), 7,
gd->bg_signature);
return -EINVAL;
} }
if (di->i_blkno != gd->bg_parent_dinode) { if (di->i_blkno != gd->bg_parent_dinode) {
ocfs2_error(sb, "Group descriptor # %llu has bad parent " do_error("Group descriptor # %llu has bad parent "
"pointer (%llu, expected %llu)", "pointer (%llu, expected %llu)",
(unsigned long long)le64_to_cpu(gd->bg_blkno), (unsigned long long)le64_to_cpu(gd->bg_blkno),
(unsigned long long)le64_to_cpu(gd->bg_parent_dinode), (unsigned long long)le64_to_cpu(gd->bg_parent_dinode),
(unsigned long long)le64_to_cpu(di->i_blkno)); (unsigned long long)le64_to_cpu(di->i_blkno));
return -EIO; return -EINVAL;
} }
max_bits = le16_to_cpu(di->id2.i_chain.cl_cpg) * le16_to_cpu(di->id2.i_chain.cl_bpc); max_bits = le16_to_cpu(di->id2.i_chain.cl_cpg) * le16_to_cpu(di->id2.i_chain.cl_bpc);
if (le16_to_cpu(gd->bg_bits) > max_bits) { if (le16_to_cpu(gd->bg_bits) > max_bits) {
ocfs2_error(sb, "Group descriptor # %llu has bit count of %u", do_error("Group descriptor # %llu has bit count of %u",
(unsigned long long)le64_to_cpu(gd->bg_blkno), (unsigned long long)le64_to_cpu(gd->bg_blkno),
le16_to_cpu(gd->bg_bits)); le16_to_cpu(gd->bg_bits));
return -EIO; return -EINVAL;
} }
if (le16_to_cpu(gd->bg_chain) >= if (le16_to_cpu(gd->bg_chain) >=
le16_to_cpu(di->id2.i_chain.cl_next_free_rec)) { le16_to_cpu(di->id2.i_chain.cl_next_free_rec)) {
ocfs2_error(sb, "Group descriptor # %llu has bad chain %u", do_error("Group descriptor # %llu has bad chain %u",
(unsigned long long)le64_to_cpu(gd->bg_blkno), (unsigned long long)le64_to_cpu(gd->bg_blkno),
le16_to_cpu(gd->bg_chain)); le16_to_cpu(gd->bg_chain));
return -EIO; return -EINVAL;
} }
if (le16_to_cpu(gd->bg_free_bits_count) > le16_to_cpu(gd->bg_bits)) { if (le16_to_cpu(gd->bg_free_bits_count) > le16_to_cpu(gd->bg_bits)) {
ocfs2_error(sb, "Group descriptor # %llu has bit count %u but " do_error("Group descriptor # %llu has bit count %u but "
"claims that %u are free", "claims that %u are free",
(unsigned long long)le64_to_cpu(gd->bg_blkno), (unsigned long long)le64_to_cpu(gd->bg_blkno),
le16_to_cpu(gd->bg_bits), le16_to_cpu(gd->bg_bits),
le16_to_cpu(gd->bg_free_bits_count)); le16_to_cpu(gd->bg_free_bits_count));
return -EIO; return -EINVAL;
} }
if (le16_to_cpu(gd->bg_bits) > (8 * le16_to_cpu(gd->bg_size))) { if (le16_to_cpu(gd->bg_bits) > (8 * le16_to_cpu(gd->bg_size))) {
ocfs2_error(sb, "Group descriptor # %llu has bit count %u but " do_error("Group descriptor # %llu has bit count %u but "
"max bitmap bits of %u", "max bitmap bits of %u",
(unsigned long long)le64_to_cpu(gd->bg_blkno), (unsigned long long)le64_to_cpu(gd->bg_blkno),
le16_to_cpu(gd->bg_bits), le16_to_cpu(gd->bg_bits),
8 * le16_to_cpu(gd->bg_size)); 8 * le16_to_cpu(gd->bg_size));
return -EIO; return -EINVAL;
} }
#undef do_error
return 0; return 0;
} }

Просмотреть файл

@ -165,9 +165,23 @@ void ocfs2_free_ac_resource(struct ocfs2_alloc_context *ac);
u64 ocfs2_which_cluster_group(struct inode *inode, u32 cluster); u64 ocfs2_which_cluster_group(struct inode *inode, u32 cluster);
/* somewhat more expensive than our other checks, so use sparingly. */ /* somewhat more expensive than our other checks, so use sparingly. */
int ocfs2_check_group_descriptor(struct super_block *sb, /*
struct ocfs2_dinode *di, * By default, ocfs2_validate_group_descriptor() calls ocfs2_error() when it
struct ocfs2_group_desc *gd); * finds a problem. A caller that wants to check a group descriptor
* without going readonly passes a nonzero clean_error. This is only
* resize, really.
*/
int ocfs2_validate_group_descriptor(struct super_block *sb,
struct ocfs2_dinode *di,
struct ocfs2_group_desc *gd,
int clean_error);
static inline int ocfs2_check_group_descriptor(struct super_block *sb,
struct ocfs2_dinode *di,
struct ocfs2_group_desc *gd)
{
return ocfs2_validate_group_descriptor(sb, di, gd, 0);
}
int ocfs2_lock_allocators(struct inode *inode, struct ocfs2_extent_tree *et, int ocfs2_lock_allocators(struct inode *inode, struct ocfs2_extent_tree *et,
u32 clusters_to_add, u32 extents_to_split, u32 clusters_to_add, u32 extents_to_split,
struct ocfs2_alloc_context **data_ac, struct ocfs2_alloc_context **data_ac,