diff mbox series

[2/8] btrfs-progs: mkfs: add support for extra-super-reserved runtime flag

Message ID 4513aea783b695eb55b238ffef4d348b1668dd37.1657006141.git.wqu@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: add support for write-intent bitmaps | expand

Commit Message

Qu Wenruo July 5, 2022, 7:37 a.m. UTC
This allows mkfs to reserved extra 1MiB (2MiB in total).

The extra 1MiB should be large enough for either write-intent bitmap or
full journal.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 common/fsfeatures.c |  8 ++++++++
 common/fsfeatures.h |  1 +
 mkfs/common.c       | 16 ++++++++++++++++
 mkfs/main.c         |  9 +++++++++
 4 files changed, 34 insertions(+)
diff mbox series

Patch

diff --git a/common/fsfeatures.c b/common/fsfeatures.c
index 23a92c21a2cc..057519c50c54 100644
--- a/common/fsfeatures.c
+++ b/common/fsfeatures.c
@@ -172,6 +172,14 @@  static const struct btrfs_feature runtime_features[] = {
 		VERSION_TO_STRING2(safe, 4,9),
 		VERSION_TO_STRING2(default, 5,15),
 		.desc		= "free space tree (space_cache=v2)"
+	}, {
+		.name		= "extra-super-reserved",
+		.flag		= BTRFS_RUNTIME_FEATURE_EXTRA_SUPER_RESERVED,
+		.sysfs_name = "extra_super_reserved",
+		VERSION_TO_STRING2(compat, 6,0),
+		VERSION_NULL(safe),
+		VERSION_NULL(default),
+		.desc		= "extra super block reserved space for each device"
 	},
 	/* Keep this one last */
 	{
diff --git a/common/fsfeatures.h b/common/fsfeatures.h
index 9e39c667b900..565873ec0e4f 100644
--- a/common/fsfeatures.h
+++ b/common/fsfeatures.h
@@ -45,6 +45,7 @@ 
 
 #define BTRFS_RUNTIME_FEATURE_QUOTA		(1ULL << 0)
 #define BTRFS_RUNTIME_FEATURE_FREE_SPACE_TREE	(1ULL << 1)
+#define BTRFS_RUNTIME_FEATURE_EXTRA_SUPER_RESERVED (1ULL << 2)
 
 void btrfs_list_all_fs_features(u64 mask_disallowed);
 void btrfs_list_all_runtime_features(u64 mask_disallowed);
diff --git a/mkfs/common.c b/mkfs/common.c
index 218854491c14..f3c00f08826d 100644
--- a/mkfs/common.c
+++ b/mkfs/common.c
@@ -314,6 +314,8 @@  int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
 				  BTRFS_RUNTIME_FEATURE_FREE_SPACE_TREE);
 	bool extent_tree_v2 = !!(cfg->features &
 				 BTRFS_FEATURE_INCOMPAT_EXTENT_TREE_V2);
+	bool extra_super_reserved = !!(cfg->runtime_features &
+				 BTRFS_RUNTIME_FEATURE_EXTRA_SUPER_RESERVED);
 
 	/* Don't include the free space tree in the blocks to process. */
 	if (!free_space_tree)
@@ -324,6 +326,12 @@  int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
 		blocks_nr = ARRAY_SIZE(extent_tree_v2_blocks);
 		add_block_group = false;
 	}
+	/*
+	 * The extra 1MiB should be enough for either write-intent bitmap or
+	 * future full journal.
+	 */
+	if (extra_super_reserved)
+		system_group_offset += SZ_1M;
 
 	if ((cfg->features & BTRFS_FEATURE_INCOMPAT_ZONED)) {
 		system_group_offset = zoned_system_group_offset(cfg->zone_size);
@@ -641,6 +649,14 @@  int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
 			goto out;
 	}
 
+	if (extra_super_reserved) {
+		u64 ro_flags = btrfs_super_compat_ro_flags(&super) |
+			       BTRFS_FEATURE_COMPAT_RO_EXTRA_SUPER_RESERVED;
+
+		btrfs_set_super_compat_ro_flags(&super, ro_flags);
+		btrfs_set_super_reserved_bytes(&super, system_group_offset);
+	}
+
 	if (extent_tree_v2) {
 		ret = create_block_group_tree(fd, cfg, buf,
 					      system_group_offset,
diff --git a/mkfs/main.c b/mkfs/main.c
index 4e0a46a77aa5..4ccf4e161d06 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -1239,6 +1239,15 @@  int BOX_MAIN(mkfs)(int argc, char **argv)
 		features |= BTRFS_FEATURE_INCOMPAT_ZONED;
 	}
 
+	/*
+	 * Runtime extra-super-reserved feature conflicts with zoned support,
+	 * as it's for regular devices explicitly.
+	 */
+	if (zoned && (runtime_features &
+		      BTRFS_RUNTIME_FEATURE_EXTRA_SUPER_RESERVED)) {
+		error("extra-super-reserved runtime feature conflicts with zoned devices");
+		exit(1);
+	}
 	/*
 	* Set default profiles according to number of added devices.
 	* For mixed groups defaults are single/single.