Skip to content

Commit

Permalink
btrfs: uncollapse transaction aborts during renames
Browse files Browse the repository at this point in the history
During renames we are grouping transaction aborts that can be due to a
failure of one of several function calls. While this makes the code less
verbose, it makes it harder to debug as we end up not knowing from which
function call we got an error.

So change this to trigger a transaction abort after each function call
failure, so that when we get a transaction abort message we know exactly
which function call failed, helping us to debug issues.

Signed-off-by: Filipe Manana <[email protected]>
Reviewed-by: David Sterba <[email protected]>
Signed-off-by: David Sterba <[email protected]>
  • Loading branch information
fdmanana authored and kdave committed Jan 13, 2025
1 parent 2a9bb78 commit 097a7ee
Showing 1 changed file with 52 additions and 22 deletions.
74 changes: 52 additions & 22 deletions fs/btrfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -8021,31 +8021,45 @@ static int btrfs_rename_exchange(struct inode *old_dir,
/* src is a subvolume */
if (old_ino == BTRFS_FIRST_FREE_OBJECTID) {
ret = btrfs_unlink_subvol(trans, BTRFS_I(old_dir), old_dentry);
if (ret) {
btrfs_abort_transaction(trans, ret);
goto out_fail;
}
} else { /* src is an inode */
ret = __btrfs_unlink_inode(trans, BTRFS_I(old_dir),
BTRFS_I(old_dentry->d_inode),
old_name, &old_rename_ctx);
if (!ret)
ret = btrfs_update_inode(trans, BTRFS_I(old_inode));
}
if (ret) {
btrfs_abort_transaction(trans, ret);
goto out_fail;
if (ret) {
btrfs_abort_transaction(trans, ret);
goto out_fail;
}
ret = btrfs_update_inode(trans, BTRFS_I(old_inode));
if (ret) {
btrfs_abort_transaction(trans, ret);
goto out_fail;
}
}

/* dest is a subvolume */
if (new_ino == BTRFS_FIRST_FREE_OBJECTID) {
ret = btrfs_unlink_subvol(trans, BTRFS_I(new_dir), new_dentry);
if (ret) {
btrfs_abort_transaction(trans, ret);
goto out_fail;
}
} else { /* dest is an inode */
ret = __btrfs_unlink_inode(trans, BTRFS_I(new_dir),
BTRFS_I(new_dentry->d_inode),
new_name, &new_rename_ctx);
if (!ret)
ret = btrfs_update_inode(trans, BTRFS_I(new_inode));
}
if (ret) {
btrfs_abort_transaction(trans, ret);
goto out_fail;
if (ret) {
btrfs_abort_transaction(trans, ret);
goto out_fail;
}
ret = btrfs_update_inode(trans, BTRFS_I(new_inode));
if (ret) {
btrfs_abort_transaction(trans, ret);
goto out_fail;
}
}

ret = btrfs_add_link(trans, BTRFS_I(new_dir), BTRFS_I(old_inode),
Expand Down Expand Up @@ -8281,35 +8295,51 @@ static int btrfs_rename(struct mnt_idmap *idmap,

if (unlikely(old_ino == BTRFS_FIRST_FREE_OBJECTID)) {
ret = btrfs_unlink_subvol(trans, BTRFS_I(old_dir), old_dentry);
if (ret) {
btrfs_abort_transaction(trans, ret);
goto out_fail;
}
} else {
ret = __btrfs_unlink_inode(trans, BTRFS_I(old_dir),
BTRFS_I(d_inode(old_dentry)),
&old_fname.disk_name, &rename_ctx);
if (!ret)
ret = btrfs_update_inode(trans, BTRFS_I(old_inode));
}
if (ret) {
btrfs_abort_transaction(trans, ret);
goto out_fail;
if (ret) {
btrfs_abort_transaction(trans, ret);
goto out_fail;
}
ret = btrfs_update_inode(trans, BTRFS_I(old_inode));
if (ret) {
btrfs_abort_transaction(trans, ret);
goto out_fail;
}
}

if (new_inode) {
inode_inc_iversion(new_inode);
if (unlikely(btrfs_ino(BTRFS_I(new_inode)) ==
BTRFS_EMPTY_SUBVOL_DIR_OBJECTID)) {
ret = btrfs_unlink_subvol(trans, BTRFS_I(new_dir), new_dentry);
if (ret) {
btrfs_abort_transaction(trans, ret);
goto out_fail;
}
BUG_ON(new_inode->i_nlink == 0);
} else {
ret = btrfs_unlink_inode(trans, BTRFS_I(new_dir),
BTRFS_I(d_inode(new_dentry)),
&new_fname.disk_name);
if (ret) {
btrfs_abort_transaction(trans, ret);
goto out_fail;
}
}
if (!ret && new_inode->i_nlink == 0)
if (new_inode->i_nlink == 0) {
ret = btrfs_orphan_add(trans,
BTRFS_I(d_inode(new_dentry)));
if (ret) {
btrfs_abort_transaction(trans, ret);
goto out_fail;
if (ret) {
btrfs_abort_transaction(trans, ret);
goto out_fail;
}
}
}

Expand Down

0 comments on commit 097a7ee

Please sign in to comment.