All of lore.kernel.org
 help / color / mirror / Atom feed
From: Josef Bacik <josef@toxicpanda.com>
To: linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: [PATCH 21/22] btrfs-progs: mkfs: create the global root's
Date: Fri,  5 Nov 2021 16:40:47 -0400	[thread overview]
Message-ID: <f4448aa8e35dcfb7fe699d03be564529451363b9.1636144276.git.josef@toxicpanda.com> (raw)
In-Reply-To: <cover.1636144275.git.josef@toxicpanda.com>

Now that we have all of the supporting code, add the ability to create
all of the global roots for an extent tree v2 fs.  This will default to
nr_cpu's, but also allow the user to specify how many global roots they
would like.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 mkfs/main.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 67 insertions(+), 1 deletion(-)

diff --git a/mkfs/main.c b/mkfs/main.c
index fd40c70e..8959fd8b 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -810,6 +810,50 @@ out:
 	return ret;
 }
 
+static int create_global_root(struct btrfs_trans_handle *trans, u64 objectid,
+			      int root_id)
+{
+	struct btrfs_fs_info *fs_info = trans->fs_info;
+	struct btrfs_root *root;
+	struct btrfs_key key = {
+		.objectid = objectid,
+		.type = BTRFS_ROOT_ITEM_KEY,
+		.offset = root_id,
+	};
+	int ret = 0;
+
+	root = btrfs_create_tree(trans, fs_info, &key);
+	if (IS_ERR(root)) {
+		ret = PTR_ERR(root);
+		goto out;
+	}
+	ret = btrfs_global_root_insert(fs_info, root);
+out:
+	if (ret)
+		btrfs_abort_transaction(trans, ret);
+	return ret;
+}
+
+static int create_global_roots(struct btrfs_trans_handle *trans,
+			       int nr_global_roots)
+{
+	int ret, i;
+
+	for (i = 1; i < nr_global_roots; i++) {
+		ret = create_global_root(trans, BTRFS_EXTENT_TREE_OBJECTID, i);
+		if (ret)
+			return ret;
+		ret = create_global_root(trans, BTRFS_CSUM_TREE_OBJECTID, i);
+		if (ret)
+			return ret;
+		ret = create_global_root(trans, BTRFS_FREE_SPACE_TREE_OBJECTID, i);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
 static int insert_qgroup_items(struct btrfs_trans_handle *trans,
 			       struct btrfs_fs_info *fs_info,
 			       u64 qgroupid)
@@ -966,13 +1010,18 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
 	struct btrfs_mkfs_config mkfs_cfg;
 	enum btrfs_csum_type csum_type = BTRFS_CSUM_TYPE_CRC32;
 	u64 system_group_size;
+	int nr_global_roots = sysconf(_SC_NPROCESSORS_ONLN);
 
 	crc32c_optimization_init();
 	btrfs_config_init();
 
 	while(1) {
 		int c;
-		enum { GETOPT_VAL_SHRINK = 257, GETOPT_VAL_CHECKSUM };
+		enum {
+			GETOPT_VAL_SHRINK = 257,
+			GETOPT_VAL_CHECKSUM,
+			GETOPT_VAL_GLOBAL_ROOTS,
+		};
 		static const struct option long_options[] = {
 			{ "byte-count", required_argument, NULL, 'b' },
 			{ "csum", required_argument, NULL,
@@ -996,6 +1045,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
 			{ "quiet", 0, NULL, 'q' },
 			{ "verbose", 0, NULL, 'v' },
 			{ "shrink", no_argument, NULL, GETOPT_VAL_SHRINK },
+			{ "num-global-roots", required_argument, NULL, GETOPT_VAL_GLOBAL_ROOTS },
 			{ "help", no_argument, NULL, GETOPT_VAL_HELP },
 			{ NULL, 0, NULL, 0}
 		};
@@ -1100,6 +1150,9 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
 			case GETOPT_VAL_CHECKSUM:
 				csum_type = parse_csum_type(optarg);
 				break;
+			case GETOPT_VAL_GLOBAL_ROOTS:
+				nr_global_roots = (int)arg_strtou64(optarg);
+				break;
 			case GETOPT_VAL_HELP:
 			default:
 				print_usage(c != GETOPT_VAL_HELP);
@@ -1239,6 +1292,11 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
 	if (features & BTRFS_FEATURE_INCOMPAT_EXTENT_TREE_V2) {
 		features |= BTRFS_FEATURE_INCOMPAT_NO_HOLES;
 		runtime_features |= BTRFS_RUNTIME_FEATURE_FREE_SPACE_TREE;
+
+		if (!nr_global_roots) {
+			error("you must set a non-zero num-global-roots value");
+			exit(1);
+		}
 	}
 
 	if (zoned) {
@@ -1466,6 +1524,14 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
 		goto error;
 	}
 
+	if (features & BTRFS_FEATURE_INCOMPAT_EXTENT_TREE_V2) {
+		ret = create_global_roots(trans, nr_global_roots);
+		if (ret) {
+			error("failed to create global roots: %d", ret);
+			goto error;
+		}
+	}
+
 	ret = make_root_dir(trans, root);
 	if (ret) {
 		error("failed to setup the root directory: %d", ret);
-- 
2.26.3


  parent reply	other threads:[~2021-11-05 20:41 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-05 20:40 [PATCH 00/22] btrfs-progs: extent tree v2 support, global roots Josef Bacik
2021-11-05 20:40 ` [PATCH 01/22] btrfs-progs: common: allow users to select extent-tree-v2 option Josef Bacik
2021-11-05 20:40 ` [PATCH 02/22] btrfs-progs: add definitions for the block group tree Josef Bacik
2021-11-05 20:40 ` [PATCH 03/22] btrfs-progs: add on disk pointers to global tree ids Josef Bacik
2021-11-05 20:40 ` [PATCH 04/22] btrfs-progs: add support for loading the block group root Josef Bacik
2021-11-30 18:14   ` David Sterba
2021-11-05 20:40 ` [PATCH 05/22] btrfs-progs: add print support for the block group tree Josef Bacik
2021-11-05 20:40 ` [PATCH 06/22] btrfs-progs: mkfs: use the btrfs_block_group_root helper Josef Bacik
2021-11-05 20:40 ` [PATCH 07/22] btrfs-progs: check-lowmem: " Josef Bacik
2021-11-05 20:40 ` [PATCH 08/22] btrfs-progs: handle no bg item in extent tree for free space tree Josef Bacik
2021-11-05 20:40 ` [PATCH 09/22] btrfs-progs: mkfs: add support for the block group tree Josef Bacik
2021-11-05 20:40 ` [PATCH 10/22] btrfs-progs: check: add block group tree support Josef Bacik
2021-11-05 20:40 ` [PATCH 11/22] btrfs-progs: qgroup-verify: scan extents based on block groups Josef Bacik
2021-11-05 20:40 ` [PATCH 12/22] btrfs-progs: check: make free space tree validation extent tree v2 aware Josef Bacik
2021-11-05 20:40 ` [PATCH 13/22] btrfs-progs: check: add helper to reinit the root based on a key Josef Bacik
2021-11-05 20:40 ` [PATCH 14/22] btrfs-progs: check: handle the block group tree properly Josef Bacik
2021-11-05 20:40 ` [PATCH 15/22] btrfs-progs: load the number of global roots into the fs_info Josef Bacik
2021-11-05 20:40 ` [PATCH 16/22] btrfs-progs: handle the per-block group global root id Josef Bacik
2021-11-05 20:40 ` [PATCH 17/22] btrfs-progs: add a btrfs_delete_and_free_root helper Josef Bacik
2021-11-05 20:40 ` [PATCH 18/22] btrfs-progs: make btrfs_clear_free_space_tree extent tree v2 aware Josef Bacik
2021-11-05 20:40 ` [PATCH 19/22] btrfs-progs: make btrfs_create_tree take a key for the root key Josef Bacik
2021-11-05 20:40 ` [PATCH 20/22] btrfs-progs: mkfs: set chunk_item_objectid properly for extent tree v2 Josef Bacik
2021-11-05 20:40 ` Josef Bacik [this message]
2021-11-05 20:40 ` [PATCH 22/22] btrfs-progs: check: don't do the root item check " 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=f4448aa8e35dcfb7fe699d03be564529451363b9.1636144276.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.