Skip to content

Commit dc1c466

Browse files
LiBaokun96tytso
authored andcommitted
ext4: propagate errors from ext4_sb_bread() in ext4_xattr_block_cache_find()
In ext4_xattr_block_cache_find(), when ext4_sb_bread() returns an error, we will either continue to find the next ea block or return NULL to try to insert a new ea block. But whether ext4_sb_bread() returns -EIO or -ENOMEM, the next operation is most likely to fail with the same error. So propagate the error returned by ext4_sb_bread() to make ext4_xattr_block_set() fail to reduce pointless operations. Signed-off-by: Baokun Li <libaokun1@huawei.com> Reviewed-by: Jan Kara <jack@suse.cz> Link: https://lore.kernel.org/r/20240504075526.2254349-3-libaokun@huaweicloud.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent 0c0b4a4 commit dc1c466

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

fs/ext4/xattr.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2028,8 +2028,13 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,
20282028

20292029
inserted:
20302030
if (!IS_LAST_ENTRY(s->first)) {
2031-
new_bh = ext4_xattr_block_cache_find(inode, header(s->base),
2032-
&ce);
2031+
new_bh = ext4_xattr_block_cache_find(inode, header(s->base), &ce);
2032+
if (IS_ERR(new_bh)) {
2033+
error = PTR_ERR(new_bh);
2034+
new_bh = NULL;
2035+
goto cleanup;
2036+
}
2037+
20332038
if (new_bh) {
20342039
/* We found an identical block in the cache. */
20352040
if (new_bh == bs->bh)
@@ -3094,8 +3099,8 @@ ext4_xattr_cmp(struct ext4_xattr_header *header1,
30943099
*
30953100
* Find an identical extended attribute block.
30963101
*
3097-
* Returns a pointer to the block found, or NULL if such a block was
3098-
* not found or an error occurred.
3102+
* Returns a pointer to the block found, or NULL if such a block was not
3103+
* found, or an error pointer if an error occurred while reading ea block.
30993104
*/
31003105
static struct buffer_head *
31013106
ext4_xattr_block_cache_find(struct inode *inode,
@@ -3117,13 +3122,11 @@ ext4_xattr_block_cache_find(struct inode *inode,
31173122

31183123
bh = ext4_sb_bread(inode->i_sb, ce->e_value, REQ_PRIO);
31193124
if (IS_ERR(bh)) {
3120-
if (PTR_ERR(bh) == -ENOMEM) {
3121-
mb_cache_entry_put(ea_block_cache, ce);
3122-
return NULL;
3123-
}
3124-
bh = NULL;
3125-
EXT4_ERROR_INODE(inode, "block %lu read error",
3126-
(unsigned long)ce->e_value);
3125+
if (PTR_ERR(bh) != -ENOMEM)
3126+
EXT4_ERROR_INODE(inode, "block %lu read error",
3127+
(unsigned long)ce->e_value);
3128+
mb_cache_entry_put(ea_block_cache, ce);
3129+
return bh;
31273130
} else if (ext4_xattr_cmp(header, BHDR(bh)) == 0) {
31283131
*pce = ce;
31293132
return bh;

0 commit comments

Comments
 (0)