]> git.dujemihanovic.xyz Git - linux.git/commitdiff
btrfs: always clear PERTRANS metadata during commit
authorBoris Burkov <boris@bur.io>
Tue, 26 Mar 2024 19:01:28 +0000 (12:01 -0700)
committerDavid Sterba <dsterba@suse.com>
Tue, 2 Apr 2024 17:19:13 +0000 (19:19 +0200)
It is possible to clear a root's IN_TRANS tag from the radix tree, but
not clear its PERTRANS, if there is some error in between. Eliminate
that possibility by moving the free up to where we clear the tag.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Boris Burkov <boris@bur.io>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/transaction.c

index 1f10082d35d928d5a6d3952d6eb0a24f45327e0b..85f359e0e0a7f2ea078157c85a1f78b0ea2bcadd 100644 (file)
@@ -1494,6 +1494,7 @@ static noinline int commit_fs_roots(struct btrfs_trans_handle *trans)
                        radix_tree_tag_clear(&fs_info->fs_roots_radix,
                                        (unsigned long)root->root_key.objectid,
                                        BTRFS_ROOT_TRANS_TAG);
+                       btrfs_qgroup_free_meta_all_pertrans(root);
                        spin_unlock(&fs_info->fs_roots_radix_lock);
 
                        btrfs_free_log(trans, root);
@@ -1518,7 +1519,6 @@ static noinline int commit_fs_roots(struct btrfs_trans_handle *trans)
                        if (ret2)
                                return ret2;
                        spin_lock(&fs_info->fs_roots_radix_lock);
-                       btrfs_qgroup_free_meta_all_pertrans(root);
                }
        }
        spin_unlock(&fs_info->fs_roots_radix_lock);