Skip to content

Commit 1690dd4

Browse files
Johannes Thumshirnkdave
authored andcommitted
btrfs: improve error handling of btrfs_add_link
In the error handling block, err holds the return value of either btrfs_del_root_ref() or btrfs_del_inode_ref() but it hasn't been checked since it's introduction with commit fe66a05 (Btrfs: improve error handling for btrfs_insert_dir_item callers) in 2012. If the error handling in the error handling fails, there's not much left to do and the abort either happened earlier in the callees or is necessary here. So if one of btrfs_del_root_ref() or btrfs_del_inode_ref() failed, abort the transaction, but still return the original code of the failure stored in 'ret' as this will be reported to the user. Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 34a28e3 commit 1690dd4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

fs/btrfs/inode.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6359,14 +6359,19 @@ int btrfs_add_link(struct btrfs_trans_handle *trans,
63596359
err = btrfs_del_root_ref(trans, key.objectid,
63606360
root->root_key.objectid, parent_ino,
63616361
&local_index, name, name_len);
6362-
6362+
if (err)
6363+
btrfs_abort_transaction(trans, err);
63636364
} else if (add_backref) {
63646365
u64 local_index;
63656366
int err;
63666367

63676368
err = btrfs_del_inode_ref(trans, root, name, name_len,
63686369
ino, parent_ino, &local_index);
6370+
if (err)
6371+
btrfs_abort_transaction(trans, err);
63696372
}
6373+
6374+
/* Return the original error code */
63706375
return ret;
63716376
}
63726377

0 commit comments

Comments
 (0)