Skip to contentSkip to conversation

btrfs: pass fs_info to routines that always take tree_root

PATCH In review [email protected] 2 participants 4 messages Aug 2, 2017 – Aug 21, 2017 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: pass fs_info to routines that always take tree_root

From: Jeff Mahoney <[email protected]>

btrfs_find_root and btrfs_del_root always use the tree_root. Let's pass fs_info instead.

---
 fs/btrfs/ctree.h           |  7 ++++---
 fs/btrfs/disk-io.c         |  2 +-
 fs/btrfs/extent-tree.c     |  4 ++--
 fs/btrfs/free-space-tree.c |  2 +-
 fs/btrfs/qgroup.c          |  3 +--
 fs/btrfs/root-tree.c       | 15 +++++++++------
 6 files changed, 18 insertions(+), 15 deletions(-)
fs/btrfs/ctree.h +4 -3
index 3f3eb7b17cac..eed7cc991a80 100644
@@ -2973,8 +2973,8 @@ int btrfs_del_root_ref(struct btrfs_trans_handle *trans,
 		       struct btrfs_fs_info *fs_info,
 		       u64 root_id, u64 ref_id, u64 dirid, u64 *sequence,
 		       const char *name, int name_len);
-int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
-		   const struct btrfs_key *key);
+int btrfs_del_root(struct btrfs_trans_handle *trans,
+		   struct btrfs_fs_info *fs_info, const struct btrfs_key *key);
 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
 		      const struct btrfs_key *key,
 		      struct btrfs_root_item *item);
@@ -2982,7 +2982,8 @@ int __must_check btrfs_update_root(struct btrfs_trans_handle *trans,
 				   struct btrfs_root *root,
 				   struct btrfs_key *key,
 				   struct btrfs_root_item *item);
-int btrfs_find_root(struct btrfs_root *root, const struct btrfs_key *search_key,
+int btrfs_find_root(struct btrfs_fs_info *fs_info,
+		    const struct btrfs_key *search_key,
 		    struct btrfs_path *path, struct btrfs_root_item *root_item,
 		    struct btrfs_key *root_key);
 int btrfs_find_orphan_roots(struct btrfs_fs_info *fs_info);
fs/btrfs/disk-io.c +1 -1
index 080e2ebb8aa0..ea1959937875 100644
@@ -1581,7 +1581,7 @@ static struct btrfs_root *btrfs_read_tree_root(struct btrfs_root *tree_root,
 
 	__setup_root(root, fs_info, key->objectid);
 
-	ret = btrfs_find_root(tree_root, key, path,
+	ret = btrfs_find_root(fs_info, key, path,
 			      &root->root_item, &root->root_key);
 	if (ret) {
 		if (ret > 0)
fs/btrfs/extent-tree.c +2 -2
index 82d53a7b6652..12fa33accdcc 100644
@@ -9192,14 +9192,14 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
 	if (err)
 		goto out_end_trans;
 
-	ret = btrfs_del_root(trans, tree_root, &root->root_key);
+	ret = btrfs_del_root(trans, fs_info, &root->root_key);
 	if (ret) {
 		btrfs_abort_transaction(trans, ret);
 		goto out_end_trans;
 	}
 
 	if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID) {
-		ret = btrfs_find_root(tree_root, &root->root_key, path,
+		ret = btrfs_find_root(fs_info, &root->root_key, path,
 				      NULL, NULL);
 		if (ret < 0) {
 			btrfs_abort_transaction(trans, ret);
fs/btrfs/free-space-tree.c +1 -1
index a5e34de06c2f..684f12247db7 100644
@@ -1257,7 +1257,7 @@ int btrfs_clear_free_space_tree(struct btrfs_fs_info *fs_info)
 	if (ret)
 		goto abort;
 
-	ret = btrfs_del_root(trans, tree_root, &free_space_root->root_key);
+	ret = btrfs_del_root(trans, fs_info, &free_space_root->root_key);
 	if (ret)
 		goto abort;
 
fs/btrfs/qgroup.c +1 -2
index 4ce351efe281..ba60523a443c 100644
@@ -946,7 +946,6 @@ int btrfs_quota_enable(struct btrfs_trans_handle *trans,
 int btrfs_quota_disable(struct btrfs_trans_handle *trans,
 			struct btrfs_fs_info *fs_info)
 {
-	struct btrfs_root *tree_root = fs_info->tree_root;
 	struct btrfs_root *quota_root;
 	int ret = 0;
 
@@ -968,7 +967,7 @@ int btrfs_quota_disable(struct btrfs_trans_handle *trans,
 	if (ret)
 		goto out;
 
-	ret = btrfs_del_root(trans, tree_root, &quota_root->root_key);
+	ret = btrfs_del_root(trans, fs_info, &quota_root->root_key);
 	if (ret)
 		goto out;
 
fs/btrfs/root-tree.c +9 -6
index 460db0cb2d07..31c0e7265f44 100644
@@ -62,7 +62,7 @@ static void btrfs_read_root_item(struct extent_buffer *eb, int slot,
 
 /*
  * btrfs_find_root - lookup the root by the key.
- * root: the root of the root tree
+ * fs_info: the fs_info for the file system to search
  * search_key: the key to search
  * path: the path we search
  * root_item: the root item of the tree we look for
@@ -74,7 +74,8 @@ static void btrfs_read_root_item(struct extent_buffer *eb, int slot,
  *
  * If we find something return 0, otherwise > 0, < 0 on error.
  */
-int btrfs_find_root(struct btrfs_root *root, const struct btrfs_key *search_key,
+int btrfs_find_root(struct btrfs_fs_info *fs_info,
+		    const struct btrfs_key *search_key,
 		    struct btrfs_path *path, struct btrfs_root_item *root_item,
 		    struct btrfs_key *root_key)
 {
@@ -83,7 +84,8 @@ int btrfs_find_root(struct btrfs_root *root, const struct btrfs_key *search_key,
 	int ret;
 	int slot;
 
-	ret = btrfs_search_slot(NULL, root, search_key, path, 0, 0);
+	ret = btrfs_search_slot(NULL, fs_info->tree_root, search_key,
+				path, 0, 0);
 	if (ret < 0)
 		return ret;
 
@@ -335,10 +337,11 @@ int btrfs_find_orphan_roots(struct btrfs_fs_info *fs_info)
 	return err;
 }
 
-/* drop the root item for 'key' from 'root' */
-int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
-		   const struct btrfs_key *key)
+/* drop the root item for 'key' from the tree root */
+int btrfs_del_root(struct btrfs_trans_handle *trans,
+		   struct btrfs_fs_info *fs_info, const struct btrfs_key *key)
 {
+	struct btrfs_root *root = fs_info->tree_root;
 	struct btrfs_path *path;
 	int ret;
 
Signature · 1 line
2.11.0
#1 lore raw
Quoted 4 lines · On 8/2/17 3:54 PM, [email protected] wrote:

From: Jeff Mahoney <[email protected]>

btrfs_find_root and btrfs_del_root always use the tree_root. Let's pass fs_info instead.

This one is broken. btrfs_read_fs_root is called during log tree recovery with the log_root_tree. I'll send an updated patch.

-Jeff

Quoted 152 lines
---
 fs/btrfs/ctree.h           |  7 ++++---
 fs/btrfs/disk-io.c         |  2 +-
 fs/btrfs/extent-tree.c     |  4 ++--
 fs/btrfs/free-space-tree.c |  2 +-
 fs/btrfs/qgroup.c          |  3 +--
 fs/btrfs/root-tree.c       | 15 +++++++++------
 6 files changed, 18 insertions(+), 15 deletions(-)
fs/btrfs/ctree.h +4 -3
index 3f3eb7b17cac..eed7cc991a80 100644
@@ -2973,8 +2973,8 @@ int btrfs_del_root_ref(struct btrfs_trans_handle *trans,
 		       struct btrfs_fs_info *fs_info,
 		       u64 root_id, u64 ref_id, u64 dirid, u64 *sequence,
 		       const char *name, int name_len);
-int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
-		   const struct btrfs_key *key);
+int btrfs_del_root(struct btrfs_trans_handle *trans,
+		   struct btrfs_fs_info *fs_info, const struct btrfs_key *key);
 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
 		      const struct btrfs_key *key,
 		      struct btrfs_root_item *item);
@@ -2982,7 +2982,8 @@ int __must_check btrfs_update_root(struct btrfs_trans_handle *trans,
 				   struct btrfs_root *root,
 				   struct btrfs_key *key,
 				   struct btrfs_root_item *item);
-int btrfs_find_root(struct btrfs_root *root, const struct btrfs_key *search_key,
+int btrfs_find_root(struct btrfs_fs_info *fs_info,
+		    const struct btrfs_key *search_key,
 		    struct btrfs_path *path, struct btrfs_root_item *root_item,
 		    struct btrfs_key *root_key);
 int btrfs_find_orphan_roots(struct btrfs_fs_info *fs_info);
fs/btrfs/disk-io.c +1 -1
index 080e2ebb8aa0..ea1959937875 100644
@@ -1581,7 +1581,7 @@ static struct btrfs_root *btrfs_read_tree_root(struct btrfs_root *tree_root,
 
 	__setup_root(root, fs_info, key->objectid);
 
-	ret = btrfs_find_root(tree_root, key, path,
+	ret = btrfs_find_root(fs_info, key, path,
 			      &root->root_item, &root->root_key);
 	if (ret) {
 		if (ret > 0)
fs/btrfs/extent-tree.c +2 -2
index 82d53a7b6652..12fa33accdcc 100644
@@ -9192,14 +9192,14 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
 	if (err)
 		goto out_end_trans;
 
-	ret = btrfs_del_root(trans, tree_root, &root->root_key);
+	ret = btrfs_del_root(trans, fs_info, &root->root_key);
 	if (ret) {
 		btrfs_abort_transaction(trans, ret);
 		goto out_end_trans;
 	}
 
 	if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID) {
-		ret = btrfs_find_root(tree_root, &root->root_key, path,
+		ret = btrfs_find_root(fs_info, &root->root_key, path,
 				      NULL, NULL);
 		if (ret < 0) {
 			btrfs_abort_transaction(trans, ret);
fs/btrfs/free-space-tree.c +1 -1
index a5e34de06c2f..684f12247db7 100644
@@ -1257,7 +1257,7 @@ int btrfs_clear_free_space_tree(struct btrfs_fs_info *fs_info)
 	if (ret)
 		goto abort;
 
-	ret = btrfs_del_root(trans, tree_root, &free_space_root->root_key);
+	ret = btrfs_del_root(trans, fs_info, &free_space_root->root_key);
 	if (ret)
 		goto abort;
 
fs/btrfs/qgroup.c +1 -2
index 4ce351efe281..ba60523a443c 100644
@@ -946,7 +946,6 @@ int btrfs_quota_enable(struct btrfs_trans_handle *trans,
 int btrfs_quota_disable(struct btrfs_trans_handle *trans,
 			struct btrfs_fs_info *fs_info)
 {
-	struct btrfs_root *tree_root = fs_info->tree_root;
 	struct btrfs_root *quota_root;
 	int ret = 0;
 
@@ -968,7 +967,7 @@ int btrfs_quota_disable(struct btrfs_trans_handle *trans,
 	if (ret)
 		goto out;
 
-	ret = btrfs_del_root(trans, tree_root, &quota_root->root_key);
+	ret = btrfs_del_root(trans, fs_info, &quota_root->root_key);
 	if (ret)
 		goto out;
 
fs/btrfs/root-tree.c +9 -6
index 460db0cb2d07..31c0e7265f44 100644
@@ -62,7 +62,7 @@ static void btrfs_read_root_item(struct extent_buffer *eb, int slot,
 
 /*
  * btrfs_find_root - lookup the root by the key.
- * root: the root of the root tree
+ * fs_info: the fs_info for the file system to search
  * search_key: the key to search
  * path: the path we search
  * root_item: the root item of the tree we look for
@@ -74,7 +74,8 @@ static void btrfs_read_root_item(struct extent_buffer *eb, int slot,
  *
  * If we find something return 0, otherwise > 0, < 0 on error.
  */
-int btrfs_find_root(struct btrfs_root *root, const struct btrfs_key *search_key,
+int btrfs_find_root(struct btrfs_fs_info *fs_info,
+		    const struct btrfs_key *search_key,
 		    struct btrfs_path *path, struct btrfs_root_item *root_item,
 		    struct btrfs_key *root_key)
 {
@@ -83,7 +84,8 @@ int btrfs_find_root(struct btrfs_root *root, const struct btrfs_key *search_key,
 	int ret;
 	int slot;
 
-	ret = btrfs_search_slot(NULL, root, search_key, path, 0, 0);
+	ret = btrfs_search_slot(NULL, fs_info->tree_root, search_key,
+				path, 0, 0);
 	if (ret < 0)
 		return ret;
 
@@ -335,10 +337,11 @@ int btrfs_find_orphan_roots(struct btrfs_fs_info *fs_info)
 	return err;
 }
 
-/* drop the root item for 'key' from 'root' */
-int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
-		   const struct btrfs_key *key)
+/* drop the root item for 'key' from the tree root */
+int btrfs_del_root(struct btrfs_trans_handle *trans,
+		   struct btrfs_fs_info *fs_info, const struct btrfs_key *key)
 {
+	struct btrfs_root *root = fs_info->tree_root;
 	struct btrfs_path *path;
 	int ret;
 
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#2 lore raw

PATCH v2 1/1 btrfs: pass fs_info to btrfs_del_root instead of tree_root

In reply to [email protected]

btrfs_del_roots always uses the tree_root. Let's pass fs_info instead.

---
 fs/btrfs/ctree.h           | 4 ++--
 fs/btrfs/extent-tree.c     | 2 +-
 fs/btrfs/free-space-tree.c | 2 +-
 fs/btrfs/qgroup.c          | 3 +--
 fs/btrfs/root-tree.c       | 7 ++++---
 5 files changed, 9 insertions(+), 9 deletions(-)
fs/btrfs/ctree.h +2 -2
index 2ec2b24c0fec..044ca9b65a7b 100644
@@ -2979,8 +2979,8 @@ int btrfs_del_root_ref(struct btrfs_trans_handle *trans,
 		       struct btrfs_fs_info *fs_info,
 		       u64 root_id, u64 ref_id, u64 dirid, u64 *sequence,
 		       const char *name, int name_len);
-int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
-		   const struct btrfs_key *key);
+int btrfs_del_root(struct btrfs_trans_handle *trans,
+		   struct btrfs_fs_info *fs_info, const struct btrfs_key *key);
 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
 		      const struct btrfs_key *key,
 		      struct btrfs_root_item *item);
fs/btrfs/extent-tree.c +1 -1
index 116c5615d6c2..69eee2667720 100644
@@ -9184,7 +9184,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
 	if (err)
 		goto out_end_trans;
 
-	ret = btrfs_del_root(trans, tree_root, &root->root_key);
+	ret = btrfs_del_root(trans, fs_info, &root->root_key);
 	if (ret) {
 		btrfs_abort_transaction(trans, ret);
 		goto out_end_trans;
fs/btrfs/free-space-tree.c +1 -1
index a5e34de06c2f..684f12247db7 100644
@@ -1257,7 +1257,7 @@ int btrfs_clear_free_space_tree(struct btrfs_fs_info *fs_info)
 	if (ret)
 		goto abort;
 
-	ret = btrfs_del_root(trans, tree_root, &free_space_root->root_key);
+	ret = btrfs_del_root(trans, fs_info, &free_space_root->root_key);
 	if (ret)
 		goto abort;
 
fs/btrfs/qgroup.c +1 -2
index ddc37c537058..5c8b61c86e61 100644
@@ -946,7 +946,6 @@ int btrfs_quota_enable(struct btrfs_trans_handle *trans,
 int btrfs_quota_disable(struct btrfs_trans_handle *trans,
 			struct btrfs_fs_info *fs_info)
 {
-	struct btrfs_root *tree_root = fs_info->tree_root;
 	struct btrfs_root *quota_root;
 	int ret = 0;
 
@@ -968,7 +967,7 @@ int btrfs_quota_disable(struct btrfs_trans_handle *trans,
 	if (ret)
 		goto out;
 
-	ret = btrfs_del_root(trans, tree_root, &quota_root->root_key);
+	ret = btrfs_del_root(trans, fs_info, &quota_root->root_key);
 	if (ret)
 		goto out;
 
fs/btrfs/root-tree.c +4 -3
index 5b488af6f25e..9fb9896610e0 100644
@@ -335,10 +335,11 @@ int btrfs_find_orphan_roots(struct btrfs_fs_info *fs_info)
 	return err;
 }
 
-/* drop the root item for 'key' from 'root' */
-int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
-		   const struct btrfs_key *key)
+/* drop the root item for 'key' from the tree root */
+int btrfs_del_root(struct btrfs_trans_handle *trans,
+		   struct btrfs_fs_info *fs_info, const struct btrfs_key *key)
 {
+	struct btrfs_root *root = fs_info->tree_root;
 	struct btrfs_path *path;
 	int ret;