@@ -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");
@@ -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)
{
@@ -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
@@ -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;
@@ -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
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(-)