Skip to contentSkip to conversation

btrfs-progs: remove raid stripe encoding

PATCH In review Johannes Thumshirn 2 participants 4 messages Jun 20, 2024 – Jun 24, 2024 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs-progs: remove raid stripe encoding

From: Johannes Thumshirn <[email protected]>

Remove the not needed encoding and reserved fields in struct raid_stripe_extent.

This saves 8 bytes per stripe extent.

---
 kernel-shared/accessors.h       |  3 ---
 kernel-shared/print-tree.c      | 33 +--------------------------------
 kernel-shared/uapi/btrfs_tree.h | 14 +-------------
 3 files changed, 2 insertions(+), 48 deletions(-)
kernel-shared/accessors.h +0 -3
index b17c675c1807..c2681698b3cc 100644
@@ -322,11 +322,8 @@ BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32);
 BTRFS_SETGET_STACK_FUNCS(stack_timespec_sec, struct btrfs_timespec, sec, 64);
 BTRFS_SETGET_STACK_FUNCS(stack_timespec_nsec, struct btrfs_timespec, nsec, 32);
 
-BTRFS_SETGET_FUNCS(stripe_extent_encoding, struct btrfs_stripe_extent, encoding, 8);
 BTRFS_SETGET_FUNCS(raid_stride_devid, struct btrfs_raid_stride, devid, 64);
 BTRFS_SETGET_FUNCS(raid_stride_offset, struct btrfs_raid_stride, offset, 64);
-BTRFS_SETGET_STACK_FUNCS(stack_stripe_extent_encoding,
-			 struct btrfs_stripe_extent, encoding, 8);
 BTRFS_SETGET_STACK_FUNCS(stack_raid_stride_devid, struct btrfs_raid_stride, devid, 64);
 
 static inline struct btrfs_raid_stride *btrfs_raid_stride_nr(
kernel-shared/print-tree.c +1 -32
index 6f78ec3512de..1692e6475865 100644
@@ -669,42 +669,11 @@ static void print_free_space_header(struct extent_buffer *leaf, int slot)
 	       (unsigned long long)btrfs_free_space_bitmaps(leaf, header));
 }
 
-struct raid_encoding_map {
-	u8 encoding;
-	char name[16];
-};
-
-static const struct raid_encoding_map raid_map[] = {
-	{ BTRFS_STRIPE_DUP,	"DUP" },
-	{ BTRFS_STRIPE_RAID0,	"RAID0" },
-	{ BTRFS_STRIPE_RAID1,	"RAID1" },
-	{ BTRFS_STRIPE_RAID1C3,	"RAID1C3" },
-	{ BTRFS_STRIPE_RAID1C4, "RAID1C4" },
-	{ BTRFS_STRIPE_RAID5,	"RAID5" },
-	{ BTRFS_STRIPE_RAID6,	"RAID6" },
-	{ BTRFS_STRIPE_RAID10,	"RAID10" }
-};
-
-static const char *stripe_encoding_name(u8 encoding)
-{
-	for (int i = 0; i < ARRAY_SIZE(raid_map); i++) {
-		if (raid_map[i].encoding == encoding)
-			return raid_map[i].name;
-	}
-
-	return "UNKNOWN";
-}
-
 static void print_raid_stripe_key(struct extent_buffer *eb,
 				  u32 item_size, struct btrfs_stripe_extent *stripe)
 {
-	int num_stripes;
-	u8 encoding = btrfs_stripe_extent_encoding(eb, stripe);
-
-	num_stripes = (item_size - offsetof(struct btrfs_stripe_extent, strides)) /
-		      sizeof(struct btrfs_raid_stride);
+	int num_stripes = item_size / sizeof(struct btrfs_raid_stride);
 
-	printf("\t\t\tencoding: %s\n", stripe_encoding_name(encoding));
 	for (int i = 0; i < num_stripes; i++)
 		printf("\t\t\tstripe %d devid %llu physical %llu\n", i,
 		       (unsigned long long)btrfs_raid_stride_devid_nr(eb, stripe, i),
kernel-shared/uapi/btrfs_tree.h +1 -13
index 271346258d1d..5720a03c939b 100644
@@ -712,21 +712,9 @@ struct btrfs_raid_stride {
 	__le64 offset;
 } __attribute__ ((__packed__));
 
-/* The stripe_extent::encoding, 1:1 mapping of enum btrfs_raid_types */
-#define BTRFS_STRIPE_RAID0	1
-#define BTRFS_STRIPE_RAID1	2
-#define BTRFS_STRIPE_DUP	3
-#define BTRFS_STRIPE_RAID10	4
-#define BTRFS_STRIPE_RAID5	5
-#define BTRFS_STRIPE_RAID6	6
-#define BTRFS_STRIPE_RAID1C3	7
-#define BTRFS_STRIPE_RAID1C4	8
-
 struct btrfs_stripe_extent {
-	u8 encoding;
-	u8 reserved[7];
 	/* Array of raid strides this stripe is comprised of. */
-	struct btrfs_raid_stride strides;
+	__DECLARE_FLEX_ARRAY(struct btrfs_raid_stride, strides);
 } __attribute__ ((__packed__));
 
 #define BTRFS_FREE_SPACE_EXTENT	1
Signature · 1 line
2.43.0
#1 lore raw
Quoted 5 lines · Johannes Thumshirn

From: Johannes Thumshirn <[email protected]>

Remove the not needed encoding and reserved fields in struct raid_stripe_extent.

Quoted 8 lines

This saves 8 bytes per stripe extent.

---
 kernel-shared/accessors.h       |  3 ---
 kernel-shared/print-tree.c      | 33 +--------------------------------
 kernel-shared/uapi/btrfs_tree.h | 14 +-------------
 3 files changed, 2 insertions(+), 48 deletions(-)

This fails to compiler because the tree-checker.c code still references the removed functions:

kernel-shared/tree-checker.c: In function ‘check_raid_stripe_extent’:
kernel-shared/tree-checker.c:1740:17: warning: implicit declaration of function ‘btrfs_stripe_extent_encoding’; did you mean ‘btrfs_file_extent_end’? [-Wimplicit-function-declaration]

 1740 |         switch (btrfs_stripe_extent_encoding(leaf, stripe_extent)) {
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#2 lore raw
Quoted 15 lines · David Sterba
Quoted 5 lines · Johannes Thumshirn

From: Johannes Thumshirn <[email protected]>

Remove the not needed encoding and reserved fields in struct raid_stripe_extent.

Quoted 8 lines

This saves 8 bytes per stripe extent.

---
 kernel-shared/accessors.h       |  3 ---
 kernel-shared/print-tree.c      | 33 +--------------------------------
 kernel-shared/uapi/btrfs_tree.h | 14 +-------------
 3 files changed, 2 insertions(+), 48 deletions(-)
Quoted 7 lines

This fails to compiler because the tree-checker.c code still references the removed functions:

kernel-shared/tree-checker.c: In function ‘check_raid_stripe_extent’:
kernel-shared/tree-checker.c:1740:17: warning: implicit declaration of function ‘btrfs_stripe_extent_encoding’; did you mean ‘btrfs_file_extent_end’? [-Wimplicit-function-declaration]

 1740 |         switch (btrfs_stripe_extent_encoding(leaf, stripe_extent)) {
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fixed in devel.

#3 lore raw
In reply to Johannes Thumshirn

kernel-shared/uapi/btrfs_tree.h struct btrfs_raid_stride { · line 717

Quoted 1 line · Johannes Thumshirn
kernel-shared/uapi/btrfs_tree.h +1 -0
+	__DECLARE_FLEX_ARRAY(struct btrfs_raid_stride, strides);

This is too new for LTS distros, I added a copy of the definition to kernecompat.h.