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 02/22] btrfs-progs: add definitions for the block group tree
Date: Wed, 15 Dec 2021 14:59:28 -0500	[thread overview]
Message-ID: <045b7578809fa4fef7c2febd6c0602164b1af2eb.1639598278.git.josef@toxicpanda.com> (raw)
In-Reply-To: <cover.1639598278.git.josef@toxicpanda.com>

Add the on disk definitions for the block group tree.  This will be part
of the super block so we need to add the appropriate helpers to the
super block, as well as adding it to the backup roots.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 cmds/inspect-dump-tree.c   |  7 ++++++-
 kernel-shared/ctree.h      | 29 ++++++++++++++++++++++++++++-
 kernel-shared/disk-io.c    | 14 ++++++++++++++
 kernel-shared/print-tree.c |  3 +++
 libbtrfsutil/btrfs_tree.h  |  3 +++
 5 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/cmds/inspect-dump-tree.c b/cmds/inspect-dump-tree.c
index e1c90be7..6332b46d 100644
--- a/cmds/inspect-dump-tree.c
+++ b/cmds/inspect-dump-tree.c
@@ -155,7 +155,8 @@ static u64 treeid_from_string(const char *str, const char **end)
 		{ "TREE_LOG_FIXUP", BTRFS_TREE_LOG_FIXUP_OBJECTID },
 		{ "TREE_LOG", BTRFS_TREE_LOG_OBJECTID },
 		{ "TREE_RELOC", BTRFS_TREE_RELOC_OBJECTID },
-		{ "DATA_RELOC", BTRFS_DATA_RELOC_TREE_OBJECTID }
+		{ "DATA_RELOC", BTRFS_DATA_RELOC_TREE_OBJECTID },
+		{ "BLOCK_GROUP_TREE", BTRFS_BLOCK_GROUP_TREE_OBJECTID },
 	};
 
 	if (strncasecmp("BTRFS_", str, strlen("BTRFS_")) == 0)
@@ -695,6 +696,10 @@ again:
 					printf("multiple");
 				}
 				break;
+			case BTRFS_BLOCK_GROUP_TREE_OBJECTID:
+				if (!skip)
+					printf("block group");
+				break;
 			default:
 				if (!skip) {
 					printf("file");
diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h
index 9f7ccd38..eb815b2d 100644
--- a/kernel-shared/ctree.h
+++ b/kernel-shared/ctree.h
@@ -85,6 +85,9 @@ struct btrfs_free_space_ctl;
 /* tracks free space in block groups. */
 #define BTRFS_FREE_SPACE_TREE_OBJECTID 10ULL
 
+/* hold the block group items. */
+#define BTRFS_BLOCK_GROUP_TREE_OBJECTID 11ULL
+
 /* device stats in the device tree */
 #define BTRFS_DEV_STATS_OBJECTID 0ULL
 
@@ -459,8 +462,14 @@ struct btrfs_super_block {
 	__le64 uuid_tree_generation;
 
 	u8 metadata_uuid[BTRFS_FSID_SIZE];
+
+	__le64 block_group_root;
+	__le64 block_group_root_generation;
+	u8 block_group_root_level;
+
 	/* future expansion */
-	__le64 reserved[28];
+	u8 reserved8[7];
+	__le64 reserved[25];
 	u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
 	struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS];
 	/* Padded to 4096 bytes */
@@ -2289,6 +2298,17 @@ BTRFS_SETGET_STACK_FUNCS(backup_bytes_used, struct btrfs_root_backup,
 BTRFS_SETGET_STACK_FUNCS(backup_num_devices, struct btrfs_root_backup,
 		   num_devices, 64);
 
+/*
+ * Extent tree v2 doesn't have a global csum or extent root, so we use the
+ * extent root slot for the block group root.
+ */
+BTRFS_SETGET_STACK_FUNCS(backup_block_group_root, struct btrfs_root_backup,
+		   extent_root, 64);
+BTRFS_SETGET_STACK_FUNCS(backup_block_group_root_gen, struct btrfs_root_backup,
+		   extent_root_gen, 64);
+BTRFS_SETGET_STACK_FUNCS(backup_block_group_root_level, struct btrfs_root_backup,
+		   extent_root_level, 8);
+
 /* struct btrfs_super_block */
 
 BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64);
@@ -2339,6 +2359,13 @@ BTRFS_SETGET_STACK_FUNCS(super_cache_generation, struct btrfs_super_block,
 BTRFS_SETGET_STACK_FUNCS(super_uuid_tree_generation, struct btrfs_super_block,
 			 uuid_tree_generation, 64);
 BTRFS_SETGET_STACK_FUNCS(super_magic, struct btrfs_super_block, magic, 64);
+BTRFS_SETGET_STACK_FUNCS(super_block_group_root, struct btrfs_super_block,
+			 block_group_root, 64);
+BTRFS_SETGET_STACK_FUNCS(super_block_group_root_generation,
+			 struct btrfs_super_block,
+			 block_group_root_generation, 64);
+BTRFS_SETGET_STACK_FUNCS(super_block_group_root_level,
+			 struct btrfs_super_block, block_group_root_level, 8);
 
 static inline unsigned long btrfs_leaf_data(struct extent_buffer *l)
 {
diff --git a/kernel-shared/disk-io.c b/kernel-shared/disk-io.c
index 8100748a..364a0bd8 100644
--- a/kernel-shared/disk-io.c
+++ b/kernel-shared/disk-io.c
@@ -1723,6 +1723,20 @@ int btrfs_check_super(struct btrfs_super_block *sb, unsigned sbflags)
 		goto error_out;
 	}
 
+	if (btrfs_super_incompat_flags(sb) & BTRFS_FEATURE_INCOMPAT_EXTENT_TREE_V2) {
+		if (btrfs_super_block_group_root_level(sb) >= BTRFS_MAX_LEVEL) {
+			error("block_group_root level too big: %d >= %d",
+			      btrfs_super_block_group_root_level(sb),
+			      BTRFS_MAX_LEVEL);
+			goto error_out;
+		}
+		if (!IS_ALIGNED(btrfs_super_block_group_root(sb), 4096)) {
+			error("block_group_root block unaligned: %llu",
+			      btrfs_super_block_group_root(sb));
+			goto error_out;
+		}
+	}
+
 	if (btrfs_super_incompat_flags(sb) & BTRFS_FEATURE_INCOMPAT_METADATA_UUID)
 		metadata_uuid = sb->metadata_uuid;
 	else
diff --git a/kernel-shared/print-tree.c b/kernel-shared/print-tree.c
index c7748f15..73f969c3 100644
--- a/kernel-shared/print-tree.c
+++ b/kernel-shared/print-tree.c
@@ -784,6 +784,9 @@ void print_objectid(FILE *stream, u64 objectid, u8 type)
 	case BTRFS_MULTIPLE_OBJECTIDS:
 		fprintf(stream, "MULTIPLE");
 		break;
+	case BTRFS_BLOCK_GROUP_TREE_OBJECTID:
+		fprintf(stream, "BLOCK_GROUP_TREE");
+		break;
 	case (u64)-1:
 		fprintf(stream, "-1");
 		break;
diff --git a/libbtrfsutil/btrfs_tree.h b/libbtrfsutil/btrfs_tree.h
index d3b752ee..1df9efd6 100644
--- a/libbtrfsutil/btrfs_tree.h
+++ b/libbtrfsutil/btrfs_tree.h
@@ -48,6 +48,9 @@
 /* tracks free space in block groups. */
 #define BTRFS_FREE_SPACE_TREE_OBJECTID 10ULL
 
+/* hold the block group items. */
+#define BTRFS_BLOCK_GROUP_TREE_OBJECTID 11ULL
+
 /* device stats in the device tree */
 #define BTRFS_DEV_STATS_OBJECTID 0ULL
 
-- 
2.26.3


  parent reply	other threads:[~2021-12-15 19:59 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 ` Josef Bacik [this message]
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 ` [PATCH v4 15/22] btrfs-progs: load the number of global roots into the fs_info Josef Bacik
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=045b7578809fa4fef7c2febd6c0602164b1af2eb.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).