Thread (24 messages) 24 messages, 2 authors, 2021-11-30
STALE1669d
Revisions (5)
  1. v1 current
  2. v2 [diff vs current]
  3. v2 [diff vs current]
  4. v4 [diff vs current]
  5. v5 [diff vs current]

[PATCH 15/22] btrfs-progs: load the number of global roots into the fs_info

From: Josef Bacik <josef@toxicpanda.com>
Date: 2021-11-05 20:41:14
Subsystem: the rest · Maintainer: Linus Torvalds

We need to know how many global roots we have in order to round robin
assign block groups to their specific global root.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 kernel-shared/ctree.h   |  2 ++
 kernel-shared/disk-io.c | 42 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)
diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h
index 27e31e03..c7346fee 100644
--- a/kernel-shared/ctree.h
+++ b/kernel-shared/ctree.h
@@ -1262,6 +1262,8 @@ struct btrfs_fs_info {
 	u32 sectorsize;
 	u32 stripesize;
 
+	u64 num_global_roots;
+
 	/*
 	 * Zone size > 0 when in ZONED mode, otherwise it's used for a check
 	 * if the mode is enabled
diff --git a/kernel-shared/disk-io.c b/kernel-shared/disk-io.c
index 38741819..4c613b52 100644
--- a/kernel-shared/disk-io.c
+++ b/kernel-shared/disk-io.c
@@ -1432,6 +1432,44 @@ int btrfs_setup_chunk_tree_and_device_map(struct btrfs_fs_info *fs_info,
 	return 0;
 }
 
+static int btrfs_get_global_roots_count(struct btrfs_fs_info *fs_info)
+{
+	struct btrfs_key key = {
+		.objectid = BTRFS_EXTENT_TREE_OBJECTID,
+		.type = BTRFS_ROOT_ITEM_KEY,
+		.offset = (u64)-1,
+	};
+	struct btrfs_path *path;
+	int ret;
+
+	if (!btrfs_fs_incompat(fs_info, EXTENT_TREE_V2))
+		return 0;
+
+	path = btrfs_alloc_path();
+	if (!path)
+		return -ENOMEM;
+	ret = btrfs_search_slot(NULL, fs_info->tree_root, &key, path, 0, 0);
+	if (ret < 0)
+		goto out;
+	if (ret == 0) {
+		ret = -EINVAL;
+		error("Found a corrupt root item looking for global roots count");
+		goto out;
+	}
+	ret = btrfs_previous_item(fs_info->tree_root, path, key.objectid,
+				  key.type);
+	if (ret) {
+		ret = -EINVAL;
+		error("Didn't find a extent root looking for global roots count");
+		goto out;
+	}
+	btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
+	fs_info->num_global_roots = key.offset + 1;
+out:
+	btrfs_free_path(path);
+	return ret;
+}
+
 static struct btrfs_fs_info *__open_ctree_fd(int fp, struct open_ctree_flags *ocf)
 {
 	struct btrfs_fs_info *fs_info;
@@ -1578,6 +1616,10 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, struct open_ctree_flags *oc
 	    !fs_info->ignore_chunk_tree_error)
 		goto out_chunk;
 
+	ret = btrfs_get_global_roots_count(fs_info);
+	if (ret && !(flags & OPEN_CTREE_PARTIAL))
+		goto out_chunk;
+
 	return fs_info;
 
 out_chunk:
-- 
2.26.3
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help