linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Josef Bacik <josef@toxicpanda.com>
To: linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: [PATCH 30/44] btrfs: push grab_fs_root into read_fs_root
Date: Fri,  6 Dec 2019 09:45:24 -0500	[thread overview]
Message-ID: <20191206144538.168112-31-josef@toxicpanda.com> (raw)
In-Reply-To: <20191206144538.168112-1-josef@toxicpanda.com>

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 | 38 +++++++++-----------------------------
 1 file changed, 9 insertions(+), 29 deletions(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index d40d145588f3..086c8126ebf2 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -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 @@ struct backref_node *build_backref_tree(struct reloc_control *rc,
 			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 @@ int prepare_to_merge(struct reloc_control *rc, int err)
 		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 @@ void merge_reloc_roots(struct reloc_control *rc)
 		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 @@ int btrfs_recover_relocation(struct btrfs_root *root)
 		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;
-- 
2.23.0


  parent reply	other threads:[~2019-12-06 14:46 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-06 14:44 [PATCH 0/44] Cleanup how we handle root refs, part 1 Josef Bacik
2019-12-06 14:44 ` [PATCH 01/44] btrfs: push __setup_root into btrfs_alloc_root Josef Bacik
2019-12-06 14:44 ` [PATCH 02/44] btrfs: move fs root init stuff into btrfs_init_fs_root Josef Bacik
2019-12-06 14:44 ` [PATCH 03/44] btrfs: make btrfs_find_orphan_roots use btrfs_get_fs_root Josef Bacik
2019-12-06 14:44 ` [PATCH 04/44] btrfs: export and use btrfs_read_tree_root Josef Bacik
2019-12-06 14:44 ` [PATCH 05/44] btrfs: make relocation use btrfs_read_tree_root() Josef Bacik
2019-12-06 14:45 ` [PATCH 06/44] btrfs: kill btrfs_read_fs_root Josef Bacik
2019-12-06 14:45 ` [PATCH 07/44] btrfs: kill the btrfs_read_fs_root_no_name helper Josef Bacik
2019-12-06 14:45 ` [PATCH 08/44] btrfs: make the fs root init functions static Josef Bacik
2019-12-06 14:45 ` [PATCH 09/44] btrfs: handle NULL roots in btrfs_put_fs_root() Josef Bacik
2019-12-06 14:45 ` [PATCH 10/44] btrfs: hold a ref on fs roots while they're in the radix tree Josef Bacik
2019-12-06 14:45 ` [PATCH 11/44] btrfs: hold a ref on the root in resolve_indirect_ref Josef Bacik
2019-12-06 14:45 ` [PATCH 12/44] btrfs: hold a root ref in btrfs_get_dentry Josef Bacik
2019-12-06 14:45 ` [PATCH 13/44] btrfs: hold a ref on the root in __btrfs_run_defrag_inode Josef Bacik
2019-12-06 14:45 ` [PATCH 14/44] btrfs: hold a ref for the root in record_one_backref Josef Bacik
2019-12-06 14:45 ` [PATCH 15/44] btrfs: grab a ref on the root in relink_extent_backref Josef Bacik
2019-12-06 14:45 ` [PATCH 16/44] btrfs: hold a ref on the root in fixup_tree_root_location Josef Bacik
2019-12-06 14:45 ` [PATCH 17/44] btrfs: hold a ref on the root in create_subvol Josef Bacik
2019-12-06 14:45 ` [PATCH 18/44] btrfs: hold a ref on the root in search_ioctl Josef Bacik
2019-12-06 14:45 ` [PATCH 19/44] btrfs: hold a ref on the root in btrfs_search_path_in_tree Josef Bacik
2019-12-06 14:45 ` [PATCH 20/44] btrfs: hold a ref on the root in btrfs_search_path_in_tree_user Josef Bacik
2019-12-06 14:45 ` [PATCH 21/44] btrfs: hold a ref on the root in btrfs_ioctl_get_subvol_info Josef Bacik
2019-12-06 14:45 ` [PATCH 22/44] btrfs: hold ref on root in btrfs_ioctl_default_subvol Josef Bacik
2019-12-06 14:45 ` [PATCH 23/44] btrfs: hold a ref on the root in build_backref_tree Josef Bacik
2019-12-06 14:45 ` [PATCH 24/44] btrfs: hold a ref on the root in prepare_to_merge Josef Bacik
2019-12-06 14:45 ` [PATCH 25/44] btrfs: hold a ref on the root in merge_reloc_roots Josef Bacik
2019-12-06 14:45 ` [PATCH 26/44] btrfs: hold a ref on the root in record_reloc_root_in_trans Josef Bacik
2019-12-06 14:45 ` [PATCH 27/44] btrfs: hold a ref on the root in find_data_references Josef Bacik
2019-12-06 14:45 ` [PATCH 28/44] btrfs: hold a ref on the root in create_reloc_inode Josef Bacik
2019-12-06 14:45 ` [PATCH 29/44] btrfs: hold a ref on the root in btrfs_recover_relocation Josef Bacik
2019-12-06 14:45 ` Josef Bacik [this message]
2019-12-06 14:45 ` [PATCH 31/44] btrfs: hold a ref for the root in btrfs_find_orphan_roots Josef Bacik
2019-12-06 14:45 ` [PATCH 32/44] btrfs: hold a ref on the root in scrub_print_warning_inode Josef Bacik
2019-12-06 14:45 ` [PATCH 33/44] btrfs: hold a ref on the root in btrfs_ioctl_send Josef Bacik
2019-12-06 14:45 ` [PATCH 34/44] btrfs: hold a ref on the root in get_subvol_name_from_objectid Josef Bacik
2019-12-06 14:45 ` [PATCH 35/44] btrfs: hold a ref on the root in create_pending_snapshot Josef Bacik
2019-12-06 14:45 ` [PATCH 36/44] btrfs: hold a ref on the root in btrfs_recover_log_trees Josef Bacik
2019-12-06 14:45 ` [PATCH 37/44] btrfs: hold a ref on the root in btrfs_check_uuid_tree_entry Josef Bacik
2019-12-06 14:45 ` [PATCH 38/44] btrfs: hold a ref on the root in open_ctree Josef Bacik
2019-12-06 14:45 ` [PATCH 39/44] btrfs: use btrfs_put_fs_root to free roots always Josef Bacik
2019-12-06 14:45 ` [PATCH 40/44] btrfs: push btrfs_grab_fs_root into btrfs_get_fs_root Josef Bacik
2019-12-06 14:45 ` [PATCH 41/44] btrfs: free more things in btrfs_free_fs_info Josef Bacik
2019-12-06 14:45 ` [PATCH 42/44] btrfs: move fs_info init work into it's own helper function Josef Bacik
2019-12-06 14:45 ` [PATCH 43/44] btrfs: add a leak check for roots Josef Bacik
2019-12-06 14:45 ` [PATCH 44/44] btrfs: rename btrfs_put_fs_root and btrfs_grab_fs_root Josef Bacik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191206144538.168112-31-josef@toxicpanda.com \
    --to=josef@toxicpanda.com \
    --cc=kernel-team@fb.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).