Commit 9f583209 authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba

btrfs: push grab_fs_root into read_fs_root

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: default avatarJosef Bacik <josef@toxicpanda.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 932fd26d
...@@ -659,6 +659,7 @@ static struct btrfs_root *read_fs_root(struct btrfs_fs_info *fs_info, ...@@ -659,6 +659,7 @@ static struct btrfs_root *read_fs_root(struct btrfs_fs_info *fs_info,
u64 root_objectid) u64 root_objectid)
{ {
struct btrfs_key key; struct btrfs_key key;
struct btrfs_root *root;
key.objectid = root_objectid; key.objectid = root_objectid;
key.type = BTRFS_ROOT_ITEM_KEY; key.type = BTRFS_ROOT_ITEM_KEY;
...@@ -667,7 +668,12 @@ static struct btrfs_root *read_fs_root(struct btrfs_fs_info *fs_info, ...@@ -667,7 +668,12 @@ static struct btrfs_root *read_fs_root(struct btrfs_fs_info *fs_info,
else else
key.offset = (u64)-1; 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 static noinline_for_stack
...@@ -939,10 +945,6 @@ struct backref_node *build_backref_tree(struct reloc_control *rc, ...@@ -939,10 +945,6 @@ struct backref_node *build_backref_tree(struct reloc_control *rc,
err = PTR_ERR(root); err = PTR_ERR(root);
goto out; goto out;
} }
if (!btrfs_grab_fs_root(root)) {
err = -ENOENT;
goto out;
}
if (!test_bit(BTRFS_ROOT_REF_COWS, &root->state)) if (!test_bit(BTRFS_ROOT_REF_COWS, &root->state))
cur->cowonly = 1; cur->cowonly = 1;
...@@ -2521,7 +2523,6 @@ int prepare_to_merge(struct reloc_control *rc, int err) ...@@ -2521,7 +2523,6 @@ int prepare_to_merge(struct reloc_control *rc, int err)
root = read_fs_root(fs_info, reloc_root->root_key.offset); root = read_fs_root(fs_info, reloc_root->root_key.offset);
BUG_ON(IS_ERR(root)); BUG_ON(IS_ERR(root));
BUG_ON(!btrfs_grab_fs_root(root));
BUG_ON(root->reloc_root != reloc_root); BUG_ON(root->reloc_root != reloc_root);
/* /*
...@@ -2592,7 +2593,6 @@ void merge_reloc_roots(struct reloc_control *rc) ...@@ -2592,7 +2593,6 @@ void merge_reloc_roots(struct reloc_control *rc)
root = read_fs_root(fs_info, root = read_fs_root(fs_info,
reloc_root->root_key.offset); reloc_root->root_key.offset);
BUG_ON(IS_ERR(root)); BUG_ON(IS_ERR(root));
BUG_ON(!btrfs_grab_fs_root(root));
BUG_ON(root->reloc_root != reloc_root); BUG_ON(root->reloc_root != reloc_root);
ret = merge_reloc_root(rc, root); ret = merge_reloc_root(rc, root);
...@@ -2655,7 +2655,6 @@ static int record_reloc_root_in_trans(struct btrfs_trans_handle *trans, ...@@ -2655,7 +2655,6 @@ static int record_reloc_root_in_trans(struct btrfs_trans_handle *trans,
root = read_fs_root(fs_info, reloc_root->root_key.offset); root = read_fs_root(fs_info, reloc_root->root_key.offset);
BUG_ON(IS_ERR(root)); BUG_ON(IS_ERR(root));
BUG_ON(!btrfs_grab_fs_root(root));
BUG_ON(root->reloc_root != reloc_root); BUG_ON(root->reloc_root != reloc_root);
ret = btrfs_record_root_in_trans(trans, root); ret = btrfs_record_root_in_trans(trans, root);
btrfs_put_fs_root(root); btrfs_put_fs_root(root);
...@@ -3753,10 +3752,6 @@ static int find_data_references(struct reloc_control *rc, ...@@ -3753,10 +3752,6 @@ static int find_data_references(struct reloc_control *rc,
err = PTR_ERR(root); err = PTR_ERR(root);
goto out_free; goto out_free;
} }
if (!btrfs_grab_fs_root(root)) {
err = -ENOENT;
goto out_free;
}
key.objectid = ref_objectid; key.objectid = ref_objectid;
key.type = BTRFS_EXTENT_DATA_KEY; key.type = BTRFS_EXTENT_DATA_KEY;
...@@ -4351,8 +4346,6 @@ struct inode *create_reloc_inode(struct btrfs_fs_info *fs_info, ...@@ -4351,8 +4346,6 @@ struct inode *create_reloc_inode(struct btrfs_fs_info *fs_info,
root = read_fs_root(fs_info, BTRFS_DATA_RELOC_TREE_OBJECTID); root = read_fs_root(fs_info, BTRFS_DATA_RELOC_TREE_OBJECTID);
if (IS_ERR(root)) if (IS_ERR(root))
return ERR_CAST(root); return ERR_CAST(root);
if (!btrfs_grab_fs_root(root))
return ERR_PTR(-ENOENT);
trans = btrfs_start_transaction(root, 6); trans = btrfs_start_transaction(root, 6);
if (IS_ERR(trans)) { if (IS_ERR(trans)) {
...@@ -4648,10 +4641,6 @@ int btrfs_recover_relocation(struct btrfs_root *root) ...@@ -4648,10 +4641,6 @@ int btrfs_recover_relocation(struct btrfs_root *root)
goto out; goto out;
} }
} else { } else {
if (!btrfs_grab_fs_root(fs_root)) {
err = -ENOENT;
goto out;
}
btrfs_put_fs_root(fs_root); btrfs_put_fs_root(fs_root);
} }
} }
...@@ -4702,10 +4691,6 @@ int btrfs_recover_relocation(struct btrfs_root *root) ...@@ -4702,10 +4691,6 @@ int btrfs_recover_relocation(struct btrfs_root *root)
list_add_tail(&reloc_root->root_list, &reloc_roots); list_add_tail(&reloc_root->root_list, &reloc_roots);
goto out_free; goto out_free;
} }
if (!btrfs_grab_fs_root(fs_root)) {
err = -ENOENT;
goto out_free;
}
err = __add_reloc_root(reloc_root); err = __add_reloc_root(reloc_root);
BUG_ON(err < 0); /* -ENOMEM or logic error */ BUG_ON(err < 0); /* -ENOMEM or logic error */
...@@ -4745,10 +4730,8 @@ int btrfs_recover_relocation(struct btrfs_root *root) ...@@ -4745,10 +4730,8 @@ int btrfs_recover_relocation(struct btrfs_root *root)
if (IS_ERR(fs_root)) { if (IS_ERR(fs_root)) {
err = PTR_ERR(fs_root); err = PTR_ERR(fs_root);
} else { } else {
if (btrfs_grab_fs_root(fs_root)) { err = btrfs_orphan_cleanup(fs_root);
err = btrfs_orphan_cleanup(fs_root); btrfs_put_fs_root(fs_root);
btrfs_put_fs_root(fs_root);
}
} }
} }
return err; return err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment