]> git.hungrycats.org Git - linux/commitdiff
btrfs: push grab_fs_root into read_fs_root
authorJosef Bacik <josef@toxicpanda.com>
Wed, 20 Nov 2019 20:02:58 +0000 (12:02 -0800)
committerJosef Bacik <josef@toxicpanda.com>
Fri, 6 Dec 2019 16:34:48 +0000 (08:34 -0800)
All of relocation uses read_fs_root to lookup fs roots, so push the
btrfs_grab_fs_root() up into that helper and remove the individual
calls.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
fs/btrfs/relocation.c

index d40d145588f32008c7540717a1c846abc23a62b3..086c8126ebf2ac5158121c5a10198190613cd95d 100644 (file)
@@ -581,6 +581,7 @@ static struct btrfs_root *read_fs_root(struct btrfs_fs_info *fs_info,
                                        u64 root_objectid)
 {
        struct btrfs_key key;
+       struct btrfs_root *root;
 
        key.objectid = root_objectid;
        key.type = BTRFS_ROOT_ITEM_KEY;
@@ -589,7 +590,12 @@ static struct btrfs_root *read_fs_root(struct btrfs_fs_info *fs_info,
        else
                key.offset = (u64)-1;
 
-       return btrfs_get_fs_root(fs_info, &key, false);
+       root = btrfs_get_fs_root(fs_info, &key, false);
+       if (IS_ERR(root))
+               return root;
+       if (!btrfs_grab_fs_root(root))
+               return ERR_PTR(-ENOENT);
+       return root;
 }
 
 static noinline_for_stack
@@ -861,10 +867,6 @@ again:
                        err = PTR_ERR(root);
                        goto out;
                }
-               if (!btrfs_grab_fs_root(root)) {
-                       err = -ENOENT;
-                       goto out;
-               }
 
                if (!test_bit(BTRFS_ROOT_REF_COWS, &root->state))
                        cur->cowonly = 1;
@@ -2433,8 +2435,6 @@ again:
                list_del_init(&reloc_root->root_list);
 
                root = read_fs_root(fs_info, reloc_root->root_key.offset);
-               if (!btrfs_grab_fs_root(root))
-                       BUG();
                BUG_ON(IS_ERR(root));
                BUG_ON(root->reloc_root != reloc_root);
 
@@ -2505,8 +2505,6 @@ again:
                if (btrfs_root_refs(&reloc_root->root_item) > 0) {
                        root = read_fs_root(fs_info,
                                            reloc_root->root_key.offset);
-                       if (!btrfs_grab_fs_root(root))
-                               BUG();
                        BUG_ON(IS_ERR(root));
                        BUG_ON(root->reloc_root != reloc_root);
 
@@ -2569,8 +2567,6 @@ static int record_reloc_root_in_trans(struct btrfs_trans_handle *trans,
                return 0;
 
        root = read_fs_root(fs_info, reloc_root->root_key.offset);
-       if (!btrfs_grab_fs_root(root))
-               BUG();
        BUG_ON(IS_ERR(root));
        BUG_ON(root->reloc_root != reloc_root);
        ret = btrfs_record_root_in_trans(trans, root);
@@ -3671,10 +3667,6 @@ static int find_data_references(struct reloc_control *rc,
                err = PTR_ERR(root);
                goto out_free;
        }
-       if (!btrfs_grab_fs_root(root)) {
-               err = -ENOENT;
-               goto out_free;
-       }
 
        key.objectid = ref_objectid;
        key.type = BTRFS_EXTENT_DATA_KEY;
@@ -4269,8 +4261,6 @@ struct inode *create_reloc_inode(struct btrfs_fs_info *fs_info,
        root = read_fs_root(fs_info, BTRFS_DATA_RELOC_TREE_OBJECTID);
        if (IS_ERR(root))
                return ERR_CAST(root);
-       if (!btrfs_grab_fs_root(root))
-               return ERR_PTR(-ENOENT);
 
        trans = btrfs_start_transaction(root, 6);
        if (IS_ERR(trans)) {
@@ -4542,10 +4532,6 @@ int btrfs_recover_relocation(struct btrfs_root *root)
                if (btrfs_root_refs(&reloc_root->root_item) > 0) {
                        fs_root = read_fs_root(fs_info,
                                               reloc_root->root_key.offset);
-                       if (!btrfs_grab_fs_root(fs_root)) {
-                               err = -ENOENT;
-                               goto out;
-                       }
                        if (IS_ERR(fs_root)) {
                                ret = PTR_ERR(fs_root);
                                if (ret != -ENOENT) {
@@ -4608,10 +4594,6 @@ int btrfs_recover_relocation(struct btrfs_root *root)
                        list_add_tail(&reloc_root->root_list, &reloc_roots);
                        goto out_free;
                }
-               if (!btrfs_grab_fs_root(fs_root)) {
-                       err = -ENOENT;
-                       goto out_free;
-               }
 
                err = __add_reloc_root(reloc_root);
                BUG_ON(err < 0); /* -ENOMEM or logic error */
@@ -4651,10 +4633,8 @@ out:
                if (IS_ERR(fs_root)) {
                        err = PTR_ERR(fs_root);
                } else {
-                       if (btrfs_grab_fs_root(fs_root)) {
-                               err = btrfs_orphan_cleanup(fs_root);
-                               btrfs_put_fs_root(fs_root);
-                       }
+                       err = btrfs_orphan_cleanup(fs_root);
+                       btrfs_put_fs_root(fs_root);
                }
        }
        return err;