btrfs: add raid stripe tree definitions
authorJohannes Thumshirn <johannes.thumshirn@wdc.com>
Thu, 14 Sep 2023 16:06:56 +0000 (09:06 -0700)
committerDavid Sterba <dsterba@suse.com>
Thu, 12 Oct 2023 14:44:09 +0000 (16:44 +0200)
Add definitions for the raid stripe tree. This tree will hold information
about the on-disk layout of the stripes in a RAID set.

Each stripe extent has a 1:1 relationship with an on-disk extent item and
is doing the logical to per-drive physical address translation for the
extent item in question.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/accessors.h
fs/btrfs/locking.c
include/uapi/linux/btrfs_tree.h

index f958eccff4776e82cc10221eb80a7a5eb683bbad..ce18e261c861860b4ebca1f8e1a1936e80494697 100644 (file)
@@ -306,6 +306,14 @@ 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_physical, struct btrfs_raid_stride, physical, 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);
+BTRFS_SETGET_STACK_FUNCS(stack_raid_stride_physical, struct btrfs_raid_stride, physical, 64);
+
 /* struct btrfs_dev_extent */
 BTRFS_SETGET_FUNCS(dev_extent_chunk_tree, struct btrfs_dev_extent, chunk_tree, 64);
 BTRFS_SETGET_FUNCS(dev_extent_chunk_objectid, struct btrfs_dev_extent,
index 6ac4fd8cc8dc8febb82a41e4ff4a4d3c8a18bc67..74d8e2003f58c045606ddb1ab22f727b2dc171a4 100644 (file)
@@ -74,6 +74,7 @@ static struct btrfs_lockdep_keyset {
        { .id = BTRFS_UUID_TREE_OBJECTID,       DEFINE_NAME("uuid")     },
        { .id = BTRFS_FREE_SPACE_TREE_OBJECTID, DEFINE_NAME("free-space") },
        { .id = BTRFS_BLOCK_GROUP_TREE_OBJECTID, DEFINE_NAME("block-group") },
+       { .id = BTRFS_RAID_STRIPE_TREE_OBJECTID, DEFINE_NAME("raid-stripe") },
        { .id = 0,                              DEFINE_NAME("tree")     },
 };
 
index fc3c32186d7eb17ff5b78c8ccf0ac4e373bfe69b..ca65d7b7a6ca19526fd98a81e67a6775a5ec83f8 100644 (file)
@@ -73,6 +73,9 @@
 /* Holds the block group items for extent tree v2. */
 #define BTRFS_BLOCK_GROUP_TREE_OBJECTID 11ULL
 
+/* Tracks RAID stripes in block groups. */
+#define BTRFS_RAID_STRIPE_TREE_OBJECTID 12ULL
+
 /* device stats in the device tree */
 #define BTRFS_DEV_STATS_OBJECTID 0ULL
 
 #define BTRFS_DEV_ITEM_KEY     216
 #define BTRFS_CHUNK_ITEM_KEY   228
 
+#define BTRFS_RAID_STRIPE_KEY  230
+
 /*
  * Records the overall state of the qgroups.
  * There's only one instance of this key present,
@@ -719,6 +724,30 @@ struct btrfs_free_space_header {
        __le64 num_bitmaps;
 } __attribute__ ((__packed__));
 
+struct btrfs_raid_stride {
+       /* The id of device this raid extent lives on. */
+       __le64 devid;
+       /* The physical location on disk. */
+       __le64 physical;
+} __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];
+       /* An array of raid strides this stripe is composed of. */
+       struct btrfs_raid_stride strides[];
+} __attribute__ ((__packed__));
+
 #define BTRFS_HEADER_FLAG_WRITTEN      (1ULL << 0)
 #define BTRFS_HEADER_FLAG_RELOC                (1ULL << 1)