@@ -1228,7 +1228,7 @@ static int do_convert(const char *devname, u32 convert_flags, u32 nodesize,
mkfs_cfg.sectorsize = blocksize;
mkfs_cfg.stripesize = blocksize;
mkfs_cfg.features = features;
- mkfs_cfg.leaf_data_size = __BTRFS_LEAF_DATA_SIZE(nodesize);
+ mkfs_cfg.leaf_data_size = __BTRFS_LEAF_DATA_SIZE(nodesize, false);
printf("Create initial btrfs filesystem\n");
ret = make_convert_btrfs(fd, &mkfs_cfg, &cctx);
@@ -367,8 +367,10 @@ struct btrfs_header_v2 {
__le64 snapshot_id;
} __attribute__ ((__packed__));
-static inline u32 __BTRFS_LEAF_DATA_SIZE(u32 nodesize)
+static inline u32 __BTRFS_LEAF_DATA_SIZE(u32 nodesize, bool v2)
{
+ if (v2)
+ return nodesize - sizeof(struct btrfs_header_v2);
return nodesize - sizeof(struct btrfs_header);
}
@@ -1642,15 +1642,20 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, struct open_ctree_flags *oc
fs_info->stripesize = btrfs_super_stripesize(disk_super);
fs_info->csum_type = btrfs_super_csum_type(disk_super);
fs_info->csum_size = btrfs_super_csum_size(disk_super);
- fs_info->leaf_data_size = __BTRFS_LEAF_DATA_SIZE(fs_info->nodesize);
ret = btrfs_check_fs_compatibility(fs_info->super_copy, flags);
if (ret)
goto out_devices;
- if (btrfs_fs_incompat(fs_info, EXTENT_TREE_V2))
+ if (btrfs_fs_incompat(fs_info, EXTENT_TREE_V2)) {
+ fs_info->leaf_data_size =
+ __BTRFS_LEAF_DATA_SIZE(fs_info->nodesize, true);
fs_info->nr_global_roots =
btrfs_super_nr_global_roots(fs_info->super_copy);
+ } else {
+ fs_info->leaf_data_size =
+ __BTRFS_LEAF_DATA_SIZE(fs_info->nodesize, false);
+ }
/*
* fs_info->zone_size (and zoned) are not known before reading the
@@ -1025,6 +1025,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
enum btrfs_csum_type csum_type = BTRFS_CSUM_TYPE_CRC32;
u64 system_group_size;
int nr_global_roots = sysconf(_SC_NPROCESSORS_ONLN);
+ bool extent_tree_v2 = false;
crc32c_optimization_init();
btrfs_config_init();
@@ -1195,6 +1196,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
print_usage(1);
zoned = !!(features & BTRFS_FEATURE_INCOMPAT_ZONED);
+ extent_tree_v2 = !!(features & BTRFS_FEATURE_INCOMPAT_EXTENT_TREE_V2);
if (source_dir_set && dev_cnt > 1) {
error("the option -r is limited to a single device");
@@ -1305,7 +1307,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
}
/* Extent tree v2 comes with a set of mandatory features. */
- if (features & BTRFS_FEATURE_INCOMPAT_EXTENT_TREE_V2) {
+ if (extent_tree_v2) {
features |= BTRFS_FEATURE_INCOMPAT_NO_HOLES;
runtime_features |= BTRFS_RUNTIME_FEATURE_FREE_SPACE_TREE;
@@ -1499,7 +1501,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
mkfs_cfg.features = features;
mkfs_cfg.runtime_features = runtime_features;
mkfs_cfg.csum_type = csum_type;
- mkfs_cfg.leaf_data_size = __BTRFS_LEAF_DATA_SIZE(nodesize);
+ mkfs_cfg.leaf_data_size = __BTRFS_LEAF_DATA_SIZE(nodesize, extent_tree_v2);
if (zoned)
mkfs_cfg.zone_size = zone_size(file);
else
@@ -1541,7 +1543,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
goto error;
}
- if (features & BTRFS_FEATURE_INCOMPAT_EXTENT_TREE_V2) {
+ if (extent_tree_v2) {
ret = create_global_roots(trans, nr_global_roots);
if (ret) {
error("failed to create global roots: %d", ret);
Now that we have a larger header we need __BTRFS_LEAF_DATA_SIZE to take this into account if we have extent tree v2 set. Add a bool to this helper and adjust all of the callers. Signed-off-by: Josef Bacik <josef@toxicpanda.com> --- convert/main.c | 2 +- kernel-shared/ctree.h | 4 +++- kernel-shared/disk-io.c | 9 +++++++-- mkfs/main.c | 8 +++++--- 4 files changed, 16 insertions(+), 7 deletions(-)