All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH DRAFT 0/6] btrfs-progs: partial support for WRITE_INTENT_BITMAP compat RO flag
@ 2022-06-14 22:56 Qu Wenruo
  2022-06-14 22:56 ` [PATCH DRAFT 1/6] btrfs-progs: introduce a new compat RO flag, EXTRA_SUPER_RESERVED Qu Wenruo
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Qu Wenruo @ 2022-06-14 22:56 UTC (permalink / raw)
  To: linux-btrfs

This is the btrfs-progs counter-part to add placeholder for
WRITE_INTENT_BITMAP compat RO flag.

The same as kernel, this will have two compat RO flags:

- EXTRA_SUPER_RESERVED
  To indicate exactly how many bytes are reserved at the beginning of
  each device.

  By default mkfs.btrfs will reserve another 1MiB in addition to the
  existing 1MiB.

  So that later write-intent-bitmap can utilize the extra space.
  (although write-intent-bitmap may only utilize at most 64KiB).

- WRITE_INTENT_BITMAP
  Just to indicate if we have write intent bitmap.

  Currently it doesn't do any real work (aka, just a place holder).

Thus the patchset is mostly for EXTRA_SUPER_RESERVED, including the
following part:

- Add the needed definition
- Add mkfs support
- Add print-tree support
- Add extra warning and solution for btrfsck
  For EXTRA_SUPER_RESERVED only, it's no different than the initial
  1MiB reservation, kernel can handle it without problem.

  The extra check support will just do warning, and at the end, output
  a solution (using balance with drange filter).

Qu Wenruo (6):
  btrfs-progs: introduce a new compat RO flag, EXTRA_SUPER_RESERVED
  btrfs-progs: mkfs: add support for extra-super-reserved runtime flag
  btrfs-progs: print-tree: remove duplicated definition for compat RO
    flags
  btrfs-progs: print-tree: support btrfs_super_block::reserved_bytes
  btrfs-progs: check: add extra warning for dev extents inside the
    reserved range
  btrfs-progs: introduce the experimental compat RO flag,
    WRITE_INTENT_BITMAP

 check/main.c               | 17 ++++++++++++++++
 check/mode-lowmem.c        | 22 +++++++++++++++++++++
 common/fsfeatures.c        | 19 ++++++++++++++++++
 common/fsfeatures.h        |  2 ++
 kernel-shared/ctree.h      | 40 ++++++++++++++++++++++++++++++++++++--
 kernel-shared/disk-io.c    | 18 +++++++++++++++++
 kernel-shared/print-tree.c | 11 ++++++++---
 kernel-shared/volumes.c    |  4 ++++
 mkfs/common.c              | 25 ++++++++++++++++++++++++
 mkfs/main.c                | 14 +++++++++++++
 10 files changed, 167 insertions(+), 5 deletions(-)

-- 
2.36.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH DRAFT 1/6] btrfs-progs: introduce a new compat RO flag, EXTRA_SUPER_RESERVED
  2022-06-14 22:56 [PATCH DRAFT 0/6] btrfs-progs: partial support for WRITE_INTENT_BITMAP compat RO flag Qu Wenruo
@ 2022-06-14 22:56 ` Qu Wenruo
  2022-06-14 22:56 ` [PATCH DRAFT 2/6] btrfs-progs: mkfs: add support for extra-super-reserved runtime flag Qu Wenruo
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Qu Wenruo @ 2022-06-14 22:56 UTC (permalink / raw)
  To: linux-btrfs

This new compat RO flag allows btrfs to reserve extra space other than
the default 1MiB at the beginning of each device.

Currently the new RO flag will enable the new super block member,
reserved_bytes, to be utilized for chunk allocation, to avoid the
specified byte range.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 kernel-shared/ctree.h   | 24 ++++++++++++++++++++++--
 kernel-shared/disk-io.c |  9 +++++++++
 kernel-shared/volumes.c |  4 ++++
 3 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h
index fc8b61eda829..eb49aa8da919 100644
--- a/kernel-shared/ctree.h
+++ b/kernel-shared/ctree.h
@@ -466,8 +466,15 @@ struct btrfs_super_block {
 	__le64 reserved[24];
 	u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
 	struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS];
+
+	/*
+	 * How many bytes are reserved at the beginning of a device.
+	 * Should be >= BTRFS_DEFAULT_RESERVED.
+	 */
+	__le32 reserved_bytes;
+
 	/* Padded to 4096 bytes */
-	u8 padding[565];
+	u8 padding[561];
 } __attribute__ ((__packed__));
 BUILD_ASSERT(sizeof(struct btrfs_super_block) == BTRFS_SUPER_INFO_SIZE);
 
@@ -485,6 +492,16 @@ BUILD_ASSERT(sizeof(struct btrfs_super_block) == BTRFS_SUPER_INFO_SIZE);
  */
 #define BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE_VALID	(1ULL << 1)
 
+/*
+ * Allow btrfs to have extra reserved space (other than the default 1MiB) at
+ * the beginning of each device.
+ *
+ * This feature will enable the usage of btrfs_super_block::reserved_bytes.
+ *
+ * This feature would only be available for non-zoned filesystems.
+ */
+#define BTRFS_FEATURE_COMPAT_RO_EXTRA_SUPER_RESERVED	(1ULL << 3)
+
 #define BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF	(1ULL << 0)
 #define BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL	(1ULL << 1)
 #define BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS	(1ULL << 2)
@@ -514,7 +531,8 @@ BUILD_ASSERT(sizeof(struct btrfs_super_block) == BTRFS_SUPER_INFO_SIZE);
  */
 #define BTRFS_FEATURE_COMPAT_RO_SUPP			\
 	(BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE |	\
-	 BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE_VALID)
+	 BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE_VALID |\
+	 BTRFS_FEATURE_COMPAT_RO_EXTRA_SUPER_RESERVED)
 
 #if EXPERIMENTAL
 #define BTRFS_FEATURE_INCOMPAT_SUPP			\
@@ -2374,6 +2392,8 @@ BTRFS_SETGET_STACK_FUNCS(super_block_group_root_level,
 			 struct btrfs_super_block, block_group_root_level, 8);
 BTRFS_SETGET_STACK_FUNCS(super_nr_global_roots, struct btrfs_super_block,
 			 nr_global_roots, 64);
+BTRFS_SETGET_STACK_FUNCS(super_reserved_bytes, struct btrfs_super_block,
+			 reserved_bytes, 32);
 
 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 26b1c9aa192a..bf3ea5e63165 100644
--- a/kernel-shared/disk-io.c
+++ b/kernel-shared/disk-io.c
@@ -1848,6 +1848,15 @@ int btrfs_check_super(struct btrfs_super_block *sb, unsigned sbflags)
 		}
 	}
 
+	if (btrfs_super_compat_ro_flags(sb) &
+	    BTRFS_FEATURE_COMPAT_RO_EXTRA_SUPER_RESERVED &&
+	    btrfs_super_reserved_bytes(sb) < BTRFS_BLOCK_RESERVED_1M_FOR_SUPER) {
+		error("reserved bytes invalid, has %u expect >= %llu",
+			btrfs_super_reserved_bytes(sb),
+			BTRFS_BLOCK_RESERVED_1M_FOR_SUPER);
+		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/volumes.c b/kernel-shared/volumes.c
index 40032a4b4059..58254c9df5e1 100644
--- a/kernel-shared/volumes.c
+++ b/kernel-shared/volumes.c
@@ -562,10 +562,14 @@ int btrfs_scan_one_device(int fd, const char *path,
 
 static u64 dev_extent_search_start(struct btrfs_device *device, u64 start)
 {
+	struct btrfs_fs_info *fs_info = device->fs_info;
 	u64 zone_size;
 
 	switch (device->fs_devices->chunk_alloc_policy) {
 	case BTRFS_CHUNK_ALLOC_REGULAR:
+		if (btrfs_fs_compat_ro(fs_info, EXTRA_SUPER_RESERVED))
+			return max_t(u64, start,
+				btrfs_super_reserved_bytes(fs_info->super_copy));
 		/*
 		 * We don't want to overwrite the superblock on the drive nor
 		 * any area used by the boot loader (grub for example), so we
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH DRAFT 2/6] btrfs-progs: mkfs: add support for extra-super-reserved runtime flag
  2022-06-14 22:56 [PATCH DRAFT 0/6] btrfs-progs: partial support for WRITE_INTENT_BITMAP compat RO flag Qu Wenruo
  2022-06-14 22:56 ` [PATCH DRAFT 1/6] btrfs-progs: introduce a new compat RO flag, EXTRA_SUPER_RESERVED Qu Wenruo
@ 2022-06-14 22:56 ` Qu Wenruo
  2022-06-14 22:56 ` [PATCH DRAFT 3/6] btrfs-progs: print-tree: remove duplicated definition for compat RO flags Qu Wenruo
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Qu Wenruo @ 2022-06-14 22:56 UTC (permalink / raw)
  To: linux-btrfs

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 --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.
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH DRAFT 3/6] btrfs-progs: print-tree: remove duplicated definition for compat RO flags
  2022-06-14 22:56 [PATCH DRAFT 0/6] btrfs-progs: partial support for WRITE_INTENT_BITMAP compat RO flag Qu Wenruo
  2022-06-14 22:56 ` [PATCH DRAFT 1/6] btrfs-progs: introduce a new compat RO flag, EXTRA_SUPER_RESERVED Qu Wenruo
  2022-06-14 22:56 ` [PATCH DRAFT 2/6] btrfs-progs: mkfs: add support for extra-super-reserved runtime flag Qu Wenruo
@ 2022-06-14 22:56 ` Qu Wenruo
  2022-06-14 22:56 ` [PATCH DRAFT 4/6] btrfs-progs: print-tree: support btrfs_super_block::reserved_bytes Qu Wenruo
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Qu Wenruo @ 2022-06-14 22:56 UTC (permalink / raw)
  To: linux-btrfs

In print_readable_compat_ro_flag(), we provide
BTRFS_FEATURE_COMPAT_RO_SUPP | BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE |
BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE_VALID for supported flags.

However BTRFS_FEATURE_COMPAT_RO_SUPP already includes the latter two
flags.

Just remove the unnecessary flags.

Signed-off-by: Qu Wenruo <wqu@suse.com>

t#
---
 kernel-shared/print-tree.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/kernel-shared/print-tree.c b/kernel-shared/print-tree.c
index a5886ff602ee..db486553f448 100644
--- a/kernel-shared/print-tree.c
+++ b/kernel-shared/print-tree.c
@@ -1754,9 +1754,7 @@ static void print_readable_compat_ro_flag(u64 flag)
 	 */
 	return __print_readable_flag(flag, compat_ro_flags_array,
 				     compat_ro_flags_num,
-				     BTRFS_FEATURE_COMPAT_RO_SUPP |
-				     BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE |
-				     BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE_VALID);
+				     BTRFS_FEATURE_COMPAT_RO_SUPP);
 }
 
 static void print_readable_incompat_flag(u64 flag)
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH DRAFT 4/6] btrfs-progs: print-tree: support btrfs_super_block::reserved_bytes
  2022-06-14 22:56 [PATCH DRAFT 0/6] btrfs-progs: partial support for WRITE_INTENT_BITMAP compat RO flag Qu Wenruo
                   ` (2 preceding siblings ...)
  2022-06-14 22:56 ` [PATCH DRAFT 3/6] btrfs-progs: print-tree: remove duplicated definition for compat RO flags Qu Wenruo
@ 2022-06-14 22:56 ` Qu Wenruo
  2022-06-14 22:56 ` [PATCH DRAFT 5/6] btrfs-progs: check: add extra warning for dev extents inside the reserved range Qu Wenruo
  2022-06-14 22:56 ` [PATCH DRAFT 6/6] btrfs-progs: introduce the experimental compat RO flag, WRITE_INTENT_BITMAP Qu Wenruo
  5 siblings, 0 replies; 7+ messages in thread
From: Qu Wenruo @ 2022-06-14 22:56 UTC (permalink / raw)
  To: linux-btrfs

This only needs two things:

- Add readable flags for EXTRA_SUPER_RESERVED flag

- Add optional output for reserved_bytes

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 kernel-shared/print-tree.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/kernel-shared/print-tree.c b/kernel-shared/print-tree.c
index db486553f448..918ebe02144a 100644
--- a/kernel-shared/print-tree.c
+++ b/kernel-shared/print-tree.c
@@ -1668,6 +1668,7 @@ struct readable_flag_entry {
 static struct readable_flag_entry compat_ro_flags_array[] = {
 	DEF_COMPAT_RO_FLAG_ENTRY(FREE_SPACE_TREE),
 	DEF_COMPAT_RO_FLAG_ENTRY(FREE_SPACE_TREE_VALID),
+	DEF_COMPAT_RO_FLAG_ENTRY(EXTRA_SUPER_RESERVED),
 };
 static const int compat_ro_flags_num = sizeof(compat_ro_flags_array) /
 				       sizeof(struct readable_flag_entry);
@@ -2051,6 +2052,11 @@ void btrfs_print_superblock(struct btrfs_super_block *sb, int full)
 	printf("block_group_root_level\t%llu\n",
 	       (unsigned long long)btrfs_super_block_group_root_level(sb));
 
+	if (btrfs_super_compat_ro_flags(sb) &
+	    BTRFS_FEATURE_COMPAT_RO_EXTRA_SUPER_RESERVED)
+		printf("reserved_bytes\t\t%u\n",
+			btrfs_super_reserved_bytes(sb));
+
 	uuid_unparse(sb->dev_item.uuid, buf);
 	printf("dev_item.uuid\t\t%s\n", buf);
 
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH DRAFT 5/6] btrfs-progs: check: add extra warning for dev extents inside the reserved range
  2022-06-14 22:56 [PATCH DRAFT 0/6] btrfs-progs: partial support for WRITE_INTENT_BITMAP compat RO flag Qu Wenruo
                   ` (3 preceding siblings ...)
  2022-06-14 22:56 ` [PATCH DRAFT 4/6] btrfs-progs: print-tree: support btrfs_super_block::reserved_bytes Qu Wenruo
@ 2022-06-14 22:56 ` Qu Wenruo
  2022-06-14 22:56 ` [PATCH DRAFT 6/6] btrfs-progs: introduce the experimental compat RO flag, WRITE_INTENT_BITMAP Qu Wenruo
  5 siblings, 0 replies; 7+ messages in thread
From: Qu Wenruo @ 2022-06-14 22:56 UTC (permalink / raw)
  To: linux-btrfs

Since kernel can handle it without problem, and we rely on balance to
relocate those offending dev extents, we only need to output warning
when such dev extents are detected.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 check/main.c          | 17 +++++++++++++++++
 check/mode-lowmem.c   | 22 ++++++++++++++++++++++
 kernel-shared/ctree.h |  1 +
 3 files changed, 40 insertions(+)

diff --git a/check/main.c b/check/main.c
index 6b2be57a1505..6c230cf05acb 100644
--- a/check/main.c
+++ b/check/main.c
@@ -8918,6 +8918,7 @@ static int check_dev_extents(void)
 	struct btrfs_key key;
 	struct btrfs_root *dev_root = gfs_info->dev_root;
 	int ret;
+	u32 super_reserved = BTRFS_BLOCK_RESERVED_1M_FOR_SUPER;
 	u64 prev_devid = 0;
 	u64 prev_dev_ext_end = 0;
 
@@ -8927,6 +8928,10 @@ static int check_dev_extents(void)
 	key.type = BTRFS_DEV_EXTENT_KEY;
 	key.offset = 0;
 
+	if (btrfs_fs_compat_ro(gfs_info, EXTRA_SUPER_RESERVED) &&
+	    btrfs_super_reserved_bytes(gfs_info->super_copy) >= super_reserved)
+		super_reserved = btrfs_super_reserved_bytes(gfs_info->super_copy);
+
 	ret = btrfs_search_slot(NULL, dev_root, &key, &path, 0, 0);
 	if (ret < 0) {
 		errno = -ret;
@@ -8983,6 +8988,13 @@ static int check_dev_extents(void)
 			ret = -EUCLEAN;
 			goto out;
 		}
+		if (physical_offset < super_reserved) {
+			warning(
+"dev extent devid %llu physical offset %llu is inside the reserved range (%u)",
+				devid, physical_offset,
+				super_reserved);
+			gfs_info->found_dev_extents_in_reserved = 1;
+		}
 		prev_devid = devid;
 		prev_dev_ext_end = physical_offset + physical_len;
 
@@ -8998,6 +9010,11 @@ static int check_dev_extents(void)
 		}
 	}
 out:
+	if (gfs_info->found_dev_extents_in_reserved) {
+		warning("to relocate the dev extents in reserved range, mount the fs and run:");
+		warning("\tbtrfs balance start -mdrange=0..%u -ddrange=0..%u -sdrange=0..%u",
+			super_reserved, super_reserved, super_reserved);
+	}
 	btrfs_release_path(&path);
 	return ret;
 }
diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
index fa324506dd5d..103c27c6d0bf 100644
--- a/check/mode-lowmem.c
+++ b/check/mode-lowmem.c
@@ -4433,12 +4433,17 @@ static int check_dev_extent_item(struct extent_buffer *eb, int slot)
 	struct btrfs_key devext_key;
 	struct btrfs_chunk *chunk;
 	struct extent_buffer *l;
+	u32 super_reserved = BTRFS_BLOCK_RESERVED_1M_FOR_SUPER;
 	int num_stripes;
 	u64 length;
 	int i;
 	int found_chunk = 0;
 	int ret;
 
+	if (btrfs_fs_compat_ro(gfs_info, EXTRA_SUPER_RESERVED) &&
+	    btrfs_super_reserved_bytes(gfs_info->super_copy) >= super_reserved)
+		super_reserved = btrfs_super_reserved_bytes(gfs_info->super_copy);
+
 	btrfs_item_key_to_cpu(eb, &devext_key, slot);
 	ptr = btrfs_item_ptr(eb, slot, struct btrfs_dev_extent);
 	length = btrfs_dev_extent_length(eb, ptr);
@@ -4447,6 +4452,13 @@ static int check_dev_extent_item(struct extent_buffer *eb, int slot)
 	chunk_key.type = BTRFS_CHUNK_ITEM_KEY;
 	chunk_key.offset = btrfs_dev_extent_chunk_offset(eb, ptr);
 
+	if (devext_key.offset < super_reserved) {
+		warning(
+"dev extent devid %llu physical offset %llu is inside the reserved range (%u)",
+			devext_key.objectid, devext_key.offset,
+			super_reserved);
+		gfs_info->found_dev_extents_in_reserved = 1;
+	}
 	btrfs_init_path(&path);
 	ret = btrfs_search_slot(NULL, chunk_root, &chunk_key, &path, 0, 0);
 	if (ret)
@@ -5526,9 +5538,14 @@ int check_chunks_and_extents_lowmem(void)
 	struct btrfs_key key;
 	struct btrfs_root *root;
 	struct btrfs_root *cur_root;
+	u32 super_reserved = BTRFS_BLOCK_RESERVED_1M_FOR_SUPER;
 	int err = 0;
 	int ret;
 
+	if (btrfs_fs_compat_ro(gfs_info, EXTRA_SUPER_RESERVED) &&
+	    btrfs_super_reserved_bytes(gfs_info->super_copy) >= super_reserved)
+		super_reserved = btrfs_super_reserved_bytes(gfs_info->super_copy);
+
 	root = gfs_info->chunk_root;
 	ret = check_btrfs_root(root, 1);
 	err |= ret;
@@ -5590,6 +5607,11 @@ out:
 			total_used);
 		err |= SUPER_BYTES_USED_ERROR;
 	}
+	if (gfs_info->found_dev_extents_in_reserved) {
+		warning("to relocate the dev extents in reserved range, mount the fs and run:");
+		warning("\tbtrfs balance start -mdrange=0..%u -ddrange=0..%u -sdrange=0..%u",
+			super_reserved, super_reserved, super_reserved);
+	}
 
 	if (repair) {
 		ret = end_avoid_extents_overwrite();
diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h
index eb49aa8da919..0b4a8d60ceb4 100644
--- a/kernel-shared/ctree.h
+++ b/kernel-shared/ctree.h
@@ -1271,6 +1271,7 @@ struct btrfs_fs_info {
 	unsigned int finalize_on_close:1;
 	unsigned int hide_names:1;
 	unsigned int allow_transid_mismatch:1;
+	unsigned int found_dev_extents_in_reserved:1;
 
 	int transaction_aborted;
 	int force_csum_type;
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH DRAFT 6/6] btrfs-progs: introduce the experimental compat RO flag, WRITE_INTENT_BITMAP
  2022-06-14 22:56 [PATCH DRAFT 0/6] btrfs-progs: partial support for WRITE_INTENT_BITMAP compat RO flag Qu Wenruo
                   ` (4 preceding siblings ...)
  2022-06-14 22:56 ` [PATCH DRAFT 5/6] btrfs-progs: check: add extra warning for dev extents inside the reserved range Qu Wenruo
@ 2022-06-14 22:56 ` Qu Wenruo
  5 siblings, 0 replies; 7+ messages in thread
From: Qu Wenruo @ 2022-06-14 22:56 UTC (permalink / raw)
  To: linux-btrfs

This new compat RO flag will only be enabled through experimental
features.

Since this feature has no real code implementation yet, only the
following code changes are added:

- New super block check
  To ensure WRITE_INTENT_BITMAP is enabled along with
  EXTRA_SUPER_RESERVED

- New compat RO flag readable string output

- New mkfs runtime features

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 common/fsfeatures.c        | 11 +++++++++++
 common/fsfeatures.h        |  1 +
 kernel-shared/ctree.h      | 15 +++++++++++++++
 kernel-shared/disk-io.c    |  9 +++++++++
 kernel-shared/print-tree.c |  1 +
 mkfs/common.c              |  9 +++++++++
 mkfs/main.c                |  5 +++++
 7 files changed, 51 insertions(+)

diff --git a/common/fsfeatures.c b/common/fsfeatures.c
index 057519c50c54..63258262437d 100644
--- a/common/fsfeatures.c
+++ b/common/fsfeatures.c
@@ -181,6 +181,17 @@ static const struct btrfs_feature runtime_features[] = {
 		VERSION_NULL(default),
 		.desc		= "extra super block reserved space for each device"
 	},
+#if EXPERIMENTAL
+	{
+		.name		= "write-intent-bitmap",
+		.flag		= BTRFS_RUNTIME_FEATURE_WRITE_INTENT_BITMAP,
+		.sysfs_name = "write_intent_bitmap",
+		VERSION_NULL(compat),
+		VERSION_NULL(safe),
+		VERSION_NULL(default),
+		.desc		= "write intent bitmap"
+	},
+#endif
 	/* Keep this one last */
 	{
 		.name = "list-all",
diff --git a/common/fsfeatures.h b/common/fsfeatures.h
index 565873ec0e4f..c48aa5d05ac0 100644
--- a/common/fsfeatures.h
+++ b/common/fsfeatures.h
@@ -46,6 +46,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)
+#define BTRFS_RUNTIME_FEATURE_WRITE_INTENT_BITMAP  (1ULL << 3)
 
 void btrfs_list_all_fs_features(u64 mask_disallowed);
 void btrfs_list_all_runtime_features(u64 mask_disallowed);
diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h
index 0b4a8d60ceb4..c746c0d3ab89 100644
--- a/kernel-shared/ctree.h
+++ b/kernel-shared/ctree.h
@@ -502,6 +502,13 @@ BUILD_ASSERT(sizeof(struct btrfs_super_block) == BTRFS_SUPER_INFO_SIZE);
  */
 #define BTRFS_FEATURE_COMPAT_RO_EXTRA_SUPER_RESERVED	(1ULL << 3)
 
+/*
+ * Allow btrfs to have per-device write-intent bitmap.
+ * Will be utilized to close the RAID56 write-hole (by forced scrub for dirty
+ * partial written stripes at mount time).
+ */
+#define BTRFS_FEATURE_COMPAT_RO_WRITE_INTENT_BITMAP	(1ULL << 4)
+
 #define BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF	(1ULL << 0)
 #define BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL	(1ULL << 1)
 #define BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS	(1ULL << 2)
@@ -524,6 +531,13 @@ BUILD_ASSERT(sizeof(struct btrfs_super_block) == BTRFS_SUPER_INFO_SIZE);
 
 #define BTRFS_FEATURE_COMPAT_SUPP		0ULL
 
+#if EXPERIMENTAL
+#define BTRFS_FEATURE_COMPAT_RO_SUPP			\
+	(BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE |	\
+	 BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE_VALID |\
+	 BTRFS_FEATURE_COMPAT_RO_EXTRA_SUPER_RESERVED |	\
+	 BTRFS_FEATURE_COMPAT_RO_WRITE_INTENT_BITMAP)
+#else
 /*
  * The FREE_SPACE_TREE and FREE_SPACE_TREE_VALID compat_ro bits must not be
  * added here until read-write support for the free space tree is implemented in
@@ -533,6 +547,7 @@ BUILD_ASSERT(sizeof(struct btrfs_super_block) == BTRFS_SUPER_INFO_SIZE);
 	(BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE |	\
 	 BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE_VALID |\
 	 BTRFS_FEATURE_COMPAT_RO_EXTRA_SUPER_RESERVED)
+#endif
 
 #if EXPERIMENTAL
 #define BTRFS_FEATURE_INCOMPAT_SUPP			\
diff --git a/kernel-shared/disk-io.c b/kernel-shared/disk-io.c
index bf3ea5e63165..843fe0e73940 100644
--- a/kernel-shared/disk-io.c
+++ b/kernel-shared/disk-io.c
@@ -1848,6 +1848,15 @@ int btrfs_check_super(struct btrfs_super_block *sb, unsigned sbflags)
 		}
 	}
 
+	if (btrfs_super_compat_ro_flags(sb) &
+	    BTRFS_FEATURE_COMPAT_RO_WRITE_INTENT_BITMAP &&
+	    !(btrfs_super_compat_ro_flags(sb) &
+	      BTRFS_FEATURE_COMPAT_RO_EXTRA_SUPER_RESERVED)) {
+		error(
+"write intent bitmap feature enabled without extra super reserved feature");
+		goto error_out;
+	}
+
 	if (btrfs_super_compat_ro_flags(sb) &
 	    BTRFS_FEATURE_COMPAT_RO_EXTRA_SUPER_RESERVED &&
 	    btrfs_super_reserved_bytes(sb) < BTRFS_BLOCK_RESERVED_1M_FOR_SUPER) {
diff --git a/kernel-shared/print-tree.c b/kernel-shared/print-tree.c
index 918ebe02144a..55875a7bc2d3 100644
--- a/kernel-shared/print-tree.c
+++ b/kernel-shared/print-tree.c
@@ -1669,6 +1669,7 @@ static struct readable_flag_entry compat_ro_flags_array[] = {
 	DEF_COMPAT_RO_FLAG_ENTRY(FREE_SPACE_TREE),
 	DEF_COMPAT_RO_FLAG_ENTRY(FREE_SPACE_TREE_VALID),
 	DEF_COMPAT_RO_FLAG_ENTRY(EXTRA_SUPER_RESERVED),
+	DEF_COMPAT_RO_FLAG_ENTRY(WRITE_INTENT_BITMAP),
 };
 static const int compat_ro_flags_num = sizeof(compat_ro_flags_array) /
 				       sizeof(struct readable_flag_entry);
diff --git a/mkfs/common.c b/mkfs/common.c
index f3c00f08826d..98da10718e7b 100644
--- a/mkfs/common.c
+++ b/mkfs/common.c
@@ -316,6 +316,8 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
 				 BTRFS_FEATURE_INCOMPAT_EXTENT_TREE_V2);
 	bool extra_super_reserved = !!(cfg->runtime_features &
 				 BTRFS_RUNTIME_FEATURE_EXTRA_SUPER_RESERVED);
+	bool write_intent_bitmap = !!(cfg->runtime_features &
+				 BTRFS_RUNTIME_FEATURE_WRITE_INTENT_BITMAP);
 
 	/* Don't include the free space tree in the blocks to process. */
 	if (!free_space_tree)
@@ -657,6 +659,13 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
 		btrfs_set_super_reserved_bytes(&super, system_group_offset);
 	}
 
+	if (write_intent_bitmap) {
+		u64 ro_flags = btrfs_super_compat_ro_flags(&super) |
+			       BTRFS_FEATURE_COMPAT_RO_WRITE_INTENT_BITMAP;
+
+		btrfs_set_super_compat_ro_flags(&super, ro_flags);
+	}
+
 	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 4ccf4e161d06..049d6f1dae2a 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -1248,6 +1248,11 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
 		error("extra-super-reserved runtime feature conflicts with zoned devices");
 		exit(1);
 	}
+
+	/* Write intent bitmap must has extra reserved space. */
+	if (runtime_features & BTRFS_RUNTIME_FEATURE_WRITE_INTENT_BITMAP)
+		runtime_features |= BTRFS_RUNTIME_FEATURE_EXTRA_SUPER_RESERVED;
+
 	/*
 	* Set default profiles according to number of added devices.
 	* For mixed groups defaults are single/single.
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-06-14 22:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-14 22:56 [PATCH DRAFT 0/6] btrfs-progs: partial support for WRITE_INTENT_BITMAP compat RO flag Qu Wenruo
2022-06-14 22:56 ` [PATCH DRAFT 1/6] btrfs-progs: introduce a new compat RO flag, EXTRA_SUPER_RESERVED Qu Wenruo
2022-06-14 22:56 ` [PATCH DRAFT 2/6] btrfs-progs: mkfs: add support for extra-super-reserved runtime flag Qu Wenruo
2022-06-14 22:56 ` [PATCH DRAFT 3/6] btrfs-progs: print-tree: remove duplicated definition for compat RO flags Qu Wenruo
2022-06-14 22:56 ` [PATCH DRAFT 4/6] btrfs-progs: print-tree: support btrfs_super_block::reserved_bytes Qu Wenruo
2022-06-14 22:56 ` [PATCH DRAFT 5/6] btrfs-progs: check: add extra warning for dev extents inside the reserved range Qu Wenruo
2022-06-14 22:56 ` [PATCH DRAFT 6/6] btrfs-progs: introduce the experimental compat RO flag, WRITE_INTENT_BITMAP Qu Wenruo

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.