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 v4 15/22] btrfs-progs: load the number of global roots into the fs_info
Date: Wed, 15 Dec 2021 14:59:41 -0500	[thread overview]
Message-ID: <99f0d7bfae36c86db3b063515dbfd1463f40274f.1639598278.git.josef@toxicpanda.com> (raw)
In-Reply-To: <cover.1639598278.git.josef@toxicpanda.com>

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 944bec36..9530db8b 100644
--- a/kernel-shared/ctree.h
+++ b/kernel-shared/ctree.h
@@ -1270,6 +1270,8 @@ struct btrfs_fs_info {
 	u16 csum_type;
 	u16 csum_size;
 
+	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 d6cc7fd3..3283120c 100644
--- a/kernel-shared/disk-io.c
+++ b/kernel-shared/disk-io.c
@@ -1450,6 +1450,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;
@@ -1598,6 +1636,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


  parent reply	other threads:[~2021-12-15 20:00 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-15 19:59 [PATCH v4 00/22] btrfs-progs: extent tree v2 support, global roots Josef Bacik
2021-12-15 19:59 ` [PATCH v4 01/22] btrfs-progs: common: allow users to select extent-tree-v2 option Josef Bacik
2021-12-15 19:59 ` [PATCH v4 02/22] btrfs-progs: add definitions for the block group tree Josef Bacik
2021-12-15 19:59 ` [PATCH v4 03/22] btrfs-progs: add on disk pointers to global tree ids Josef Bacik
2021-12-15 19:59 ` [PATCH v4 04/22] btrfs-progs: add support for loading the block group root Josef Bacik
2021-12-15 19:59 ` [PATCH v4 05/22] btrfs-progs: add print support for the block group tree Josef Bacik
2021-12-15 19:59 ` [PATCH v4 06/22] btrfs-progs: mkfs: use the btrfs_block_group_root helper Josef Bacik
2021-12-15 19:59 ` [PATCH v4 07/22] btrfs-progs: check-lowmem: " Josef Bacik
2021-12-15 19:59 ` [PATCH v4 08/22] btrfs-progs: handle no bg item in extent tree for free space tree Josef Bacik
2021-12-15 19:59 ` [PATCH v4 09/22] btrfs-progs: mkfs: add support for the block group tree Josef Bacik
2021-12-15 19:59 ` [PATCH v4 10/22] btrfs-progs: check: add block group tree support Josef Bacik
2021-12-15 19:59 ` [PATCH v4 11/22] btrfs-progs: qgroup-verify: scan extents based on block groups Josef Bacik
2021-12-15 19:59 ` [PATCH v4 12/22] btrfs-progs: check: make free space tree validation extent tree v2 aware Josef Bacik
2021-12-15 19:59 ` [PATCH v4 13/22] btrfs-progs: check: add helper to reinit the root based on a key Josef Bacik
2021-12-15 19:59 ` [PATCH v4 14/22] btrfs-progs: check: handle the block group tree properly Josef Bacik
2021-12-15 19:59 ` Josef Bacik [this message]
2021-12-15 19:59 ` [PATCH v4 16/22] btrfs-progs: handle the per-block group global root id Josef Bacik
2021-12-15 19:59 ` [PATCH v4 17/22] btrfs-progs: add a btrfs_delete_and_free_root helper Josef Bacik
2021-12-15 19:59 ` [PATCH v4 18/22] btrfs-progs: make btrfs_clear_free_space_tree extent tree v2 aware Josef Bacik
2021-12-15 19:59 ` [PATCH v4 19/22] btrfs-progs: make btrfs_create_tree take a key for the root key Josef Bacik
2021-12-15 19:59 ` [PATCH v4 20/22] btrfs-progs: mkfs: set chunk_item_objectid properly for extent tree v2 Josef Bacik
2021-12-15 19:59 ` [PATCH v4 21/22] btrfs-progs: mkfs: create the global root's Josef Bacik
2021-12-15 19:59 ` [PATCH v4 22/22] btrfs-progs: check: don't do the root item check for extent tree v2 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=99f0d7bfae36c86db3b063515dbfd1463f40274f.1639598278.git.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).