Skip to content

Commit 193b4e8

Browse files
fdmananakdave
authored andcommitted
btrfs: do not BUG_ON() on failure to update inode when setting xattr
We are doing a BUG_ON() if we fail to update an inode after setting (or clearing) a xattr, but there's really no reason to not instead simply abort the transaction and return the error to the caller. This should be a rare error because we have previously reserved enough metadata space to update the inode and the delayed inode should have already been setup, so an -ENOSPC or -ENOMEM, which are the possible errors, are very unlikely to happen. So replace the BUG_ON()s with a transaction abort. CC: [email protected] # 4.9+ Reviewed-by: Qu Wenruo <[email protected]> Reviewed-by: Anand Jain <[email protected]> Signed-off-by: Filipe Manana <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent d0e64a9 commit 193b4e8

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

fs/btrfs/xattr.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ int btrfs_setxattr_trans(struct inode *inode, const char *name,
262262
inode_inc_iversion(inode);
263263
inode->i_ctime = current_time(inode);
264264
ret = btrfs_update_inode(trans, root, BTRFS_I(inode));
265-
BUG_ON(ret);
265+
if (ret)
266+
btrfs_abort_transaction(trans, ret);
266267
out:
267268
if (start_trans)
268269
btrfs_end_transaction(trans);
@@ -416,7 +417,8 @@ static int btrfs_xattr_handler_set_prop(const struct xattr_handler *handler,
416417
inode_inc_iversion(inode);
417418
inode->i_ctime = current_time(inode);
418419
ret = btrfs_update_inode(trans, root, BTRFS_I(inode));
419-
BUG_ON(ret);
420+
if (ret)
421+
btrfs_abort_transaction(trans, ret);
420422
}
421423

422424
btrfs_end_transaction(trans);

0 commit comments

Comments
 (0)