Skip to content

Commit de05ca8

Browse files
committed
ext4: move call to ext4_error() into ext4_xattr_check_block()
Refactor the call to EXT4_ERROR_INODE() into ext4_xattr_check_block(). This simplifies the code, and fixes a problem where not all callers of ext4_xattr_check_block() were not resulting in ext4_error() getting called when the xattr block is corrupted. Signed-off-by: Theodore Ts'o <[email protected]> Cc: [email protected]
1 parent 27f394a commit de05ca8

File tree

1 file changed

+27
-33
lines changed

1 file changed

+27
-33
lines changed

fs/ext4/xattr.c

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -225,25 +225,36 @@ ext4_xattr_check_entries(struct ext4_xattr_entry *entry, void *end,
225225
}
226226

227227
static inline int
228-
ext4_xattr_check_block(struct inode *inode, struct buffer_head *bh)
228+
__ext4_xattr_check_block(struct inode *inode, struct buffer_head *bh,
229+
const char *function, unsigned int line)
229230
{
230-
int error;
231+
int error = -EFSCORRUPTED;
231232

232233
if (buffer_verified(bh))
233234
return 0;
234235

235236
if (BHDR(bh)->h_magic != cpu_to_le32(EXT4_XATTR_MAGIC) ||
236237
BHDR(bh)->h_blocks != cpu_to_le32(1))
237-
return -EFSCORRUPTED;
238+
goto errout;
239+
error = -EFSBADCRC;
238240
if (!ext4_xattr_block_csum_verify(inode, bh))
239-
return -EFSBADCRC;
241+
goto errout;
240242
error = ext4_xattr_check_entries(BFIRST(bh), bh->b_data + bh->b_size,
241243
bh->b_data);
242-
if (!error)
244+
errout:
245+
if (error)
246+
__ext4_error_inode(inode, function, line, 0,
247+
"corrupted xattr block %llu",
248+
(unsigned long long) bh->b_blocknr);
249+
else
243250
set_buffer_verified(bh);
244251
return error;
245252
}
246253

254+
#define ext4_xattr_check_block(inode, bh) \
255+
__ext4_xattr_check_block((inode), (bh), __func__, __LINE__)
256+
257+
247258
static int
248259
__xattr_check_inode(struct inode *inode, struct ext4_xattr_ibody_header *header,
249260
void *end, const char *function, unsigned int line)
@@ -514,12 +525,9 @@ ext4_xattr_block_get(struct inode *inode, int name_index, const char *name,
514525
goto cleanup;
515526
ea_bdebug(bh, "b_count=%d, refcount=%d",
516527
atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount));
517-
if (ext4_xattr_check_block(inode, bh)) {
518-
EXT4_ERROR_INODE(inode, "bad block %llu",
519-
EXT4_I(inode)->i_file_acl);
520-
error = -EFSCORRUPTED;
528+
error = ext4_xattr_check_block(inode, bh);
529+
if (error)
521530
goto cleanup;
522-
}
523531
ext4_xattr_block_cache_insert(ea_block_cache, bh);
524532
entry = BFIRST(bh);
525533
error = ext4_xattr_find_entry(&entry, name_index, name, 1);
@@ -679,12 +687,9 @@ ext4_xattr_block_list(struct dentry *dentry, char *buffer, size_t buffer_size)
679687
goto cleanup;
680688
ea_bdebug(bh, "b_count=%d, refcount=%d",
681689
atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount));
682-
if (ext4_xattr_check_block(inode, bh)) {
683-
EXT4_ERROR_INODE(inode, "bad block %llu",
684-
EXT4_I(inode)->i_file_acl);
685-
error = -EFSCORRUPTED;
690+
error = ext4_xattr_check_block(inode, bh);
691+
if (error)
686692
goto cleanup;
687-
}
688693
ext4_xattr_block_cache_insert(EA_BLOCK_CACHE(inode), bh);
689694
error = ext4_xattr_list_entries(dentry, BFIRST(bh), buffer, buffer_size);
690695

@@ -811,10 +816,9 @@ int ext4_get_inode_usage(struct inode *inode, qsize_t *usage)
811816
goto out;
812817
}
813818

814-
if (ext4_xattr_check_block(inode, bh)) {
815-
ret = -EFSCORRUPTED;
819+
ret = ext4_xattr_check_block(inode, bh);
820+
if (ret)
816821
goto out;
817-
}
818822

819823
for (entry = BFIRST(bh); !IS_LAST_ENTRY(entry);
820824
entry = EXT4_XATTR_NEXT(entry))
@@ -1796,12 +1800,9 @@ ext4_xattr_block_find(struct inode *inode, struct ext4_xattr_info *i,
17961800
ea_bdebug(bs->bh, "b_count=%d, refcount=%d",
17971801
atomic_read(&(bs->bh->b_count)),
17981802
le32_to_cpu(BHDR(bs->bh)->h_refcount));
1799-
if (ext4_xattr_check_block(inode, bs->bh)) {
1800-
EXT4_ERROR_INODE(inode, "bad block %llu",
1801-
EXT4_I(inode)->i_file_acl);
1802-
error = -EFSCORRUPTED;
1803+
error = ext4_xattr_check_block(inode, bs->bh);
1804+
if (error)
18031805
goto cleanup;
1804-
}
18051806
/* Find the named attribute. */
18061807
bs->s.base = BHDR(bs->bh);
18071808
bs->s.first = BFIRST(bs->bh);
@@ -2724,13 +2725,9 @@ int ext4_expand_extra_isize_ea(struct inode *inode, int new_extra_isize,
27242725
error = -EIO;
27252726
if (!bh)
27262727
goto cleanup;
2727-
if (ext4_xattr_check_block(inode, bh)) {
2728-
EXT4_ERROR_INODE(inode, "bad block %llu",
2729-
EXT4_I(inode)->i_file_acl);
2730-
error = -EFSCORRUPTED;
2731-
brelse(bh);
2728+
error = ext4_xattr_check_block(inode, bh);
2729+
if (error)
27322730
goto cleanup;
2733-
}
27342731
base = BHDR(bh);
27352732
end = bh->b_data + bh->b_size;
27362733
min_offs = end - base;
@@ -2887,11 +2884,8 @@ int ext4_xattr_delete_inode(handle_t *handle, struct inode *inode,
28872884
goto cleanup;
28882885
}
28892886
error = ext4_xattr_check_block(inode, bh);
2890-
if (error) {
2891-
EXT4_ERROR_INODE(inode, "bad block %llu (error %d)",
2892-
EXT4_I(inode)->i_file_acl, error);
2887+
if (error)
28932888
goto cleanup;
2894-
}
28952889

28962890
if (ext4_has_feature_ea_inode(inode->i_sb)) {
28972891
for (entry = BFIRST(bh); !IS_LAST_ENTRY(entry);

0 commit comments

Comments
 (0)