]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
btrfs: uncollapse transaction aborts during renames
authorFilipe Manana <fdmanana@suse.com>
Mon, 6 Jan 2025 12:09:50 +0000 (12:09 +0000)
committerDavid Sterba <dsterba@suse.com>
Mon, 13 Jan 2025 13:53:18 +0000 (14:53 +0100)
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 <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/inode.c

index 8a173a24ac05c64ea2db077520f6d18b741e1f29..a7a3d879f2f2aae711e57efe0a80ba49db1721b2 100644 (file)
@@ -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),
@@ -8281,16 +8295,23 @@ 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) {
@@ -8298,18 +8319,27 @@ static int btrfs_rename(struct mnt_idmap *idmap,
                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;
+                       }
                }
        }