RAID1 with 3- and 4- copies
David Sterba
maintainerPATCH v2 1/4 btrfs: add support for 3-copy replication (raid1c3)
In reply to David SterbaAdd new block group profile to store 3 copies in a simliar way that current RAID1 does. The profile attributes and constraints are defined in the raid table and used by the same code that already handles the 2-copy RAID1.
The minimum number of devices is 3, the maximum number of devices/chunks that can be lost/damaged is 2. Like RAID6 but with 33% space utilization.
--- fs/btrfs/ctree.h | 4 ++-- fs/btrfs/super.c | 2 ++ fs/btrfs/volumes.c | 19 +++++++++++++++++-- fs/btrfs/volumes.h | 2 ++ include/uapi/linux/btrfs.h | 3 ++- include/uapi/linux/btrfs_tree.h | 6 +++++- 6 files changed, 30 insertions(+), 6 deletions(-)
fs/btrfs/ctree.h +2 -2
@@ -57,9 +57,9 @@ struct btrfs_ref;* filesystem data as well that can be used to read data in order to repair * read errors on other disks. * -* Current value is derived from RAID1 with 2 copies. +* Current value is derived from RAID1C3 with 3 copies. */ -#define BTRFS_MAX_MIRRORS (2 + 1) +#define BTRFS_MAX_MIRRORS (3 + 1)#define BTRFS_MAX_LEVEL 8
fs/btrfs/super.c +2 -0
@@ -1935,6 +1935,8 @@ static inline int btrfs_calc_avail_data_space(struct btrfs_fs_info *fs_info, num_stripes = nr_devices; else if (type & BTRFS_BLOCK_GROUP_RAID1) num_stripes =2 ; + else if (type & BTRFS_BLOCK_GROUP_RAID1C3) + num_stripes =3 ; else if (type & BTRFS_BLOCK_GROUP_RAID10) num_stripes =4 ;
fs/btrfs/volumes.c +17 -2
@@ -58,6 +58,18 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = { .bg_flag = BTRFS_BLOCK_GROUP_RAID1, .mindev_error = BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET, }, + [BTRFS_RAID_RAID1C3] = { + .sub_stripes = 1, + .dev_stripes = 1, + .devs_max = 0, + .devs_min = 3, + .tolerated_failures = 2, + .devs_increment = 3, + .ncopies = 3, + .raid_name = "raid1c3", + .bg_flag = BTRFS_BLOCK_GROUP_RAID1C3, + .mindev_error = BTRFS_ERROR_DEV_RAID1C3_MIN_NOT_MET, + }, [BTRFS_RAID_DUP] = { .sub_stripes = 1, .dev_stripes = 2,
@@ -4839,8 +4851,11 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,sort (devices_info, ndevs,sizeof (struct btrfs_device_info ), btrfs_cmp_device_info,NULL ); -/* round down to number of usable stripes */ - ndevs =round_down (ndevs, devs_increment); +/* +* Round down to number of usable stripes, devs_increment can be any +* number so we can't use round_down() +*/ + ndevs -= ndevs % devs_increment;if (ndevs < devs_min) { ret = -ENOSPC ;
fs/btrfs/volumes.h +2 -0
@@ -545,6 +545,8 @@ static inline enum btrfs_raid_types btrfs_bg_flags_to_raid_index(u64 flags)return BTRFS_RAID_RAID10 ; else if (flags & BTRFS_BLOCK_GROUP_RAID1) return BTRFS_RAID_RAID1; + else if (flags & BTRFS_BLOCK_GROUP_RAID1C3) + return BTRFS_RAID_RAID1C3; else if (flags & BTRFS_BLOCK_GROUP_DUP) return BTRFS_RAID_DUP; else if (flags & BTRFS_BLOCK_GROUP_RAID0)
include/uapi/linux/btrfs.h +2 -1
@@ -831,7 +831,8 @@ enum btrfs_err_code {BTRFS_ERROR_DEV_TGT_REPLACE ,BTRFS_ERROR_DEV_MISSING_NOT_FOUND ,BTRFS_ERROR_DEV_ONLY_WRITABLE , - BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS +BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS , + BTRFS_ERROR_DEV_RAID1C3_MIN_NOT_MET, };#define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \
include/uapi/linux/btrfs_tree.h +5 -1
@@ -841,6 +841,7 @@ struct btrfs_dev_replace_item {#define BTRFS_BLOCK_GROUP_RAID10 (1ULL << 6)#define BTRFS_BLOCK_GROUP_RAID5 (1ULL << 7)#define BTRFS_BLOCK_GROUP_RAID6 (1ULL << 8) +#define BTRFS_BLOCK_GROUP_RAID1C3 (1ULL << 9)#define BTRFS_BLOCK_GROUP_RESERVED (BTRFS_AVAIL_ALLOC_BIT_SINGLE | \ BTRFS_SPACE_INFO_GLOBAL_RSV)
@@ -852,6 +853,7 @@ enum btrfs_raid_types {BTRFS_RAID_SINGLE ,BTRFS_RAID_RAID5 ,BTRFS_RAID_RAID6 , +BTRFS_RAID_RAID1C3 , BTRFS_NR_RAID_TYPES };
@@ -861,6 +863,7 @@ enum btrfs_raid_types {#define BTRFS_BLOCK_GROUP_PROFILE_MASK (BTRFS_BLOCK_GROUP_RAID0 | \ BTRFS_BLOCK_GROUP_RAID1 | \ + BTRFS_BLOCK_GROUP_RAID1C3 | \ BTRFS_BLOCK_GROUP_RAID5 | \ BTRFS_BLOCK_GROUP_RAID6 | \ BTRFS_BLOCK_GROUP_DUP | \
@@ -868,7 +871,8 @@ enum btrfs_raid_types {#define BTRFS_BLOCK_GROUP_RAID56_MASK (BTRFS_BLOCK_GROUP_RAID5 | \ BTRFS_BLOCK_GROUP_RAID6) -#define BTRFS_BLOCK_GROUP_RAID1_MASK (BTRFS_BLOCK_GROUP_RAID1) +#define BTRFS_BLOCK_GROUP_RAID1_MASK (BTRFS_BLOCK_GROUP_RAID1 | \ + BTRFS_BLOCK_GROUP_RAID1C3)/* * We need a bit for restriper to be able to tell when chunks of type
Signature · 1 line
2.23.0
David Sterba
maintainerv3 cover RAID1 with 3- and 4- copies
Here it goes again, RAID1 with 3- and 4- copies. I found the bug that stopped it from inclusion last time, it was in the test itself, so the kernel code is effectively unchanged.
So, with 1 or 2 missing devices, replace by device id works. There's one annoying thing but not new: regarding replace of a missing device, some extra single/dup block groups are created during the replace process. Example below. This can happen on plain raid1 with degraded read-write mount as well.
Now what's the merge target.
The patches almost made it to 5.3, the changes build on existing code so the actual addition of new profiles is namely in the definitions and additional cases. So it should be safe.
I'm for adding it to 5.5 queue, though we're at rc5 and this can be seen as a late time for a feature. The user benefits are noticeable, raid1c3 can replace raid6 of metadata which is the most problematic part and much more complicated to fix (write ahead journal or something like that). The feedback regarding the plain 3-copy as a replacement was positive, on IRC and there are mails about that too.
Further information can be found in the 5.3-time submission:
https://lore.kernel.org/linux-btrfs/[email protected]/
--
Example of 2 devices gone missing and replaced
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- mkfs -d raid1c3 -m raidc3 /dev/sda10 /dev/sda11 /dev/sda12
- delete devices 2 and 3 from the system
Data Metadata System Id Path RAID1C3 RAID1C3 RAID1C3 Unallocated -- ---------- --------- --------- -------- ----------- 1 /dev/sda10 1.00GiB 256.00MiB 8.00MiB 8.74GiB 2 missing 1.00GiB 256.00MiB 8.00MiB -1.26GiB 3 missing 1.00GiB 256.00MiB 8.00MiB -1.26GiB
-- ---------- --------- --------- -------- -----------
Total 1.00GiB 256.00MiB 8.00MiB 6.23GiB
Used 200.31MiB 320.00KiB 16.00KiB
- mount -o degraded
- btrfs replace 2 /dev/sda13
Data Metadata Metadata System System Id Path RAID1C3 single RAID1C3 single RAID1C3 Unallocated -- ---------- --------- --------- --------- -------- ------- ----------- 1 /dev/sda10 1.00GiB 256.00MiB 256.00MiB 32.00MiB 8.00MiB 8.46GiB 2 /dev/sda13 1.00GiB - 256.00MiB - 8.00MiB 8.74GiB 3 missing 1.00GiB - 256.00MiB - 8.00MiB -1.26GiB
-- ---------- --------- --------- --------- -------- ------- -----------
Total 1.00GiB 256.00MiB 256.00MiB 32.00MiB 8.00MiB 15.95GiB
Used 200.31MiB 0.00B 320.00KiB 16.00KiB 0.00B
- btrfs replace 3 /dev/sda14
Data Metadata Metadata System System Id Path RAID1C3 single RAID1C3 single RAID1C3 Unallocated -- ---------- --------- --------- --------- -------- ------- ----------- 1 /dev/sda10 1.00GiB 256.00MiB 256.00MiB 32.00MiB 8.00MiB 8.46GiB 2 /dev/sda13 1.00GiB - 256.00MiB - 8.00MiB 8.74GiB 3 /dev/sda14 1.00GiB - 256.00MiB - 8.00MiB 8.74GiB
-- ---------- --------- --------- --------- -------- ------- -----------
Total 1.00GiB 256.00MiB 256.00MiB 32.00MiB 8.00MiB 25.95GiB
Used 200.31MiB 0.00B 320.00KiB 16.00KiB 0.00B
There you can see the metadata/single and system/single chunks, that are otherwise unused if there are no other writes happening during replace. Running 'balance start -mconvert=raid1c3,profiles=single' should get rid of them.
This is an annoyance, we have a plan to avoid that but it needs to change behaviour with degraded mount and enabled writes.
Implementation details: The new profiles are reduced from the expected ones
(raid1 -> single or dup) to allow writes without breaking the raid constraints. To relax that condition, allow writing to "half" of the raid with a missing device will skip creating the block groups.
This is similar to MD-RAID that allows writing to just one of the RAID1 devices, and then sync to the other when it's available again.
With the btrfs style raid1 we can do better in case there are enough other devices that would satify the raid1 constraint (yet with a missing device).
--
David Sterba (4):
btrfs: add support for 3-copy replication (raid1c3)
btrfs: add support for 4-copy replication (raid1c4)
btrfs: add incompat for raid1 with 3, 4 copies
btrfs: drop incompat bit for raid1c34 after last block group is gone
fs/btrfs/block-group.c | 27 ++++++++++++++-------- fs/btrfs/ctree.h | 7 +++--- fs/btrfs/super.c | 4 ++++ fs/btrfs/sysfs.c | 2 ++ fs/btrfs/volumes.c | 40 +++++++++++++++++++++++++++++++-- fs/btrfs/volumes.h | 4 ++++ include/uapi/linux/btrfs.h | 5 ++++- include/uapi/linux/btrfs_tree.h | 10 ++++++++- 8 files changed, 83 insertions(+), 16 deletions(-)
Signature · 1 line
2.23.0
David Sterba
maintainerPATCH v2 2/4 btrfs: add support for 4-copy replication (raid1c4)
Add new block group profile to store 4 copies in a simliar way that current RAID1 does. The profile attributes and constraints are defined in the raid table and used by the same code that already handles the 2- and 3-copy RAID1.
The minimum number of devices is 4, the maximum number of devices/chunks that can be lost/damaged is 3. There is no comparable traditional RAID level, the profile is added for future needs to accompany triple-parity and beyond.
--- fs/btrfs/ctree.h | 4 ++-- fs/btrfs/super.c | 2 ++ fs/btrfs/volumes.c | 12 ++++++++++++ fs/btrfs/volumes.h | 2 ++ include/uapi/linux/btrfs.h | 1 + include/uapi/linux/btrfs_tree.h | 6 +++++- 6 files changed, 24 insertions(+), 3 deletions(-)
fs/btrfs/ctree.h +2 -2
@@ -57,9 +57,9 @@ struct btrfs_ref;* filesystem data as well that can be used to read data in order to repair * read errors on other disks. * -* Current value is derived from RAID1C3 with 3 copies. +* Current value is derived from RAID1C4 with 4 copies. */ -#define BTRFS_MAX_MIRRORS (3 + 1) +#define BTRFS_MAX_MIRRORS (4 + 1)#define BTRFS_MAX_LEVEL 8
fs/btrfs/super.c +2 -0
@@ -1937,6 +1937,8 @@ static inline int btrfs_calc_avail_data_space(struct btrfs_fs_info *fs_info, num_stripes =2 ; else if (type & BTRFS_BLOCK_GROUP_RAID1C3) num_stripes =3 ; + else if (type & BTRFS_BLOCK_GROUP_RAID1C4) + num_stripes =4 ; else if (type & BTRFS_BLOCK_GROUP_RAID10) num_stripes =4 ;
fs/btrfs/volumes.c +12 -0
@@ -70,6 +70,18 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = { .bg_flag = BTRFS_BLOCK_GROUP_RAID1C3, .mindev_error = BTRFS_ERROR_DEV_RAID1C3_MIN_NOT_MET, }, + [BTRFS_RAID_RAID1C4] = { + .sub_stripes = 1, + .dev_stripes = 1, + .devs_max = 0, + .devs_min = 4, + .tolerated_failures = 3, + .devs_increment = 4, + .ncopies = 4, + .raid_name = "raid1c4", + .bg_flag = BTRFS_BLOCK_GROUP_RAID1C4, + .mindev_error = BTRFS_ERROR_DEV_RAID1C4_MIN_NOT_MET, + }, [BTRFS_RAID_DUP] = { .sub_stripes = 1, .dev_stripes = 2,
fs/btrfs/volumes.h +2 -0
@@ -547,6 +547,8 @@ static inline enum btrfs_raid_types btrfs_bg_flags_to_raid_index(u64 flags)return BTRFS_RAID_RAID1 ; else if (flags & BTRFS_BLOCK_GROUP_RAID1C3) return BTRFS_RAID_RAID1C3; + else if (flags & BTRFS_BLOCK_GROUP_RAID1C4) + return BTRFS_RAID_RAID1C4; else if (flags & BTRFS_BLOCK_GROUP_DUP) return BTRFS_RAID_DUP; else if (flags & BTRFS_BLOCK_GROUP_RAID0)
include/uapi/linux/btrfs.h +1 -0
@@ -833,6 +833,7 @@ enum btrfs_err_code {BTRFS_ERROR_DEV_ONLY_WRITABLE ,BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS ,BTRFS_ERROR_DEV_RAID1C3_MIN_NOT_MET , + BTRFS_ERROR_DEV_RAID1C4_MIN_NOT_MET, };#define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \
include/uapi/linux/btrfs_tree.h +5 -1
@@ -842,6 +842,7 @@ struct btrfs_dev_replace_item {#define BTRFS_BLOCK_GROUP_RAID5 (1ULL << 7)#define BTRFS_BLOCK_GROUP_RAID6 (1ULL << 8)#define BTRFS_BLOCK_GROUP_RAID1C3 (1ULL << 9) +#define BTRFS_BLOCK_GROUP_RAID1C4 (1ULL << 10)#define BTRFS_BLOCK_GROUP_RESERVED (BTRFS_AVAIL_ALLOC_BIT_SINGLE | \ BTRFS_SPACE_INFO_GLOBAL_RSV)
@@ -854,6 +855,7 @@ enum btrfs_raid_types {BTRFS_RAID_RAID5 ,BTRFS_RAID_RAID6 ,BTRFS_RAID_RAID1C3 , +BTRFS_RAID_RAID1C4 , BTRFS_NR_RAID_TYPES };
@@ -864,6 +866,7 @@ enum btrfs_raid_types {#define BTRFS_BLOCK_GROUP_PROFILE_MASK (BTRFS_BLOCK_GROUP_RAID0 | \ BTRFS_BLOCK_GROUP_RAID1 | \ BTRFS_BLOCK_GROUP_RAID1C3 | \ + BTRFS_BLOCK_GROUP_RAID1C4 | \ BTRFS_BLOCK_GROUP_RAID5 | \ BTRFS_BLOCK_GROUP_RAID6 | \ BTRFS_BLOCK_GROUP_DUP | \
@@ -872,7 +875,8 @@ enum btrfs_raid_types { BTRFS_BLOCK_GROUP_RAID6)#define BTRFS_BLOCK_GROUP_RAID1_MASK (BTRFS_BLOCK_GROUP_RAID1 | \ - BTRFS_BLOCK_GROUP_RAID1C3) + BTRFS_BLOCK_GROUP_RAID1C3 | \ + BTRFS_BLOCK_GROUP_RAID1C4)/* * We need a bit for restriper to be able to tell when chunks of type
Signature · 1 line
2.23.0
David Sterba
maintainerPATCH v2 3/4 btrfs: add incompat for raid1 with 3, 4 copies
In reply to David SterbaThe new raid1c3 and raid1c4 profiles are backward incompatible and the name shall be 'raid1c34', the status can be found in the global supported features in /sys/fs/btrfs/features or in the per-filesystem directory.
--- fs/btrfs/ctree.h | 3 ++- fs/btrfs/sysfs.c | 2 ++ fs/btrfs/volumes.c | 9 +++++++++ include/uapi/linux/btrfs.h | 1 + 4 files changed, 14 insertions(+), 1 deletion(-)
fs/btrfs/ctree.h +2 -1
@@ -292,7 +292,8 @@ struct btrfs_super_block {BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF | \BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA | \BTRFS_FEATURE_INCOMPAT_NO_HOLES | \ - BTRFS_FEATURE_INCOMPAT_METADATA_UUID) +BTRFS_FEATURE_INCOMPAT_METADATA_UUID | \ + BTRFS_FEATURE_INCOMPAT_RAID1C34) #define BTRFS_FEATURE_INCOMPAT_SAFE_SET \ (BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF )
fs/btrfs/sysfs.c +2 -0
@@ -259,6 +259,7 @@ BTRFS_FEAT_ATTR_INCOMPAT(skinny_metadata, SKINNY_METADATA);BTRFS_FEAT_ATTR_INCOMPAT (no_holes,NO_HOLES );BTRFS_FEAT_ATTR_INCOMPAT (metadata_uuid,METADATA_UUID );BTRFS_FEAT_ATTR_COMPAT_RO (free_space_tree,FREE_SPACE_TREE ); +BTRFS_FEAT_ATTR_INCOMPAT (raid1c34,RAID1C34 );/* static struct btrfs_feature_attr btrfs_attr_features_checksums_name = {
@@ -283,6 +284,7 @@ static struct attribute *btrfs_supported_feature_attrs[] = {BTRFS_FEAT_ATTR_PTR (no_holes),BTRFS_FEAT_ATTR_PTR (metadata_uuid),BTRFS_FEAT_ATTR_PTR (free_space_tree), +BTRFS_FEAT_ATTR_PTR (raid1c34), NULL };
fs/btrfs/volumes.c +9 -0
@@ -4717,6 +4717,14 @@ static void check_raid56_incompat_flag(struct btrfs_fs_info *info, u64 type)btrfs_set_fs_incompat (info,RAID56 ); } +static void check_raid1c34_incompat_flag (struct btrfs_fs_info *info,u64 type) +{ +if (!(type & (BTRFS_BLOCK_GROUP_RAID1C3 |BTRFS_BLOCK_GROUP_RAID1C4 ))) +return ; + +btrfs_set_fs_incompat (info,RAID1C34 ); +} +static int __btrfs_alloc_chunk (struct btrfs_trans_handle *trans,u64 start,u64 type) {
@@ -4983,6 +4991,7 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,free_extent_map (em);check_raid56_incompat_flag (info, type); +check_raid1c34_incompat_flag (info, type);kfree (devices_info);return 0 ;
include/uapi/linux/btrfs.h +1 -0
@@ -270,6 +270,7 @@ struct btrfs_ioctl_fs_info_args {#define BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA (1ULL << 8)#define BTRFS_FEATURE_INCOMPAT_NO_HOLES (1ULL << 9)#define BTRFS_FEATURE_INCOMPAT_METADATA_UUID (1ULL << 10) +#define BTRFS_FEATURE_INCOMPAT_RAID1C34 (1ULL << 11)struct btrfs_ioctl_feature_flags {__u64 compat_flags;
Signature · 1 line
2.23.0
David Sterba
maintainerPATCH v2 4/4 btrfs: drop incompat bit for raid1c34 after last block group is gone
In reply to David SterbaWhen there are no raid1c3 or raid1c4 block groups left after balance (either convert or with other filters applied), remove the incompat bit. This is already done for RAID56, do the same for RAID1C34.
--- fs/btrfs/block-group.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-)
fs/btrfs/block-group.c +18 -9
@@ -828,27 +828,36 @@ static void clear_avail_alloc_bits(struct btrfs_fs_info *fs_info, u64 flags)* * - RAID56 - in case there's neither RAID5 nor RAID6 profile block group * in the whole filesystem +* +* - RAID1C34 - same as above for RAID1C3 and RAID1C4 block groups */ static void clear_incompat_bg_bits (struct btrfs_fs_info *fs_info,u64 flags) { -if (flags &BTRFS_BLOCK_GROUP_RAID56_MASK ) { +bool found_raid56 = false; +bool found_raid1c34 = false; + +if ((flags &BTRFS_BLOCK_GROUP_RAID56_MASK ) || + (flags &BTRFS_BLOCK_GROUP_RAID1C3 ) || + (flags &BTRFS_BLOCK_GROUP_RAID1C4 )) {struct list_head *head = &fs_info->space_info;struct btrfs_space_info *sinfo;list_for_each_entry_rcu (sinfo, head, list) { -bool found = false; -down_read (&sinfo->groups_sem);if (!list_empty (&sinfo->block_groups[BTRFS_RAID_RAID5 ])) - found = true; + found_raid56 = true;if (!list_empty (&sinfo->block_groups[BTRFS_RAID_RAID6 ])) - found = true; + found_raid56 = true; +if (!list_empty (&sinfo->block_groups[BTRFS_RAID_RAID1C3 ])) + found_raid1c34 = true; +if (!list_empty (&sinfo->block_groups[BTRFS_RAID_RAID1C4 ])) + found_raid1c34 = true;up_read (&sinfo->groups_sem); - -if (found) -return ; } -btrfs_clear_fs_incompat (fs_info,RAID56 ); +if (found_raid56) +btrfs_clear_fs_incompat (fs_info,RAID56 ); +if (found_raid1c34) +btrfs_clear_fs_incompat (fs_info,RAID1C34 ); } }
Signature · 1 line
2.23.0
David Sterba
maintainerPATCH 1/1 btrfs-progs: add support for raid1c3 and raid1c4
In reply to David SterbaAdd support for 3- and 4- copy variants of RAID1. This adds resiliency against 2 or resp. 3 devices lost or damaged.
$ ./mkfs.btrfs -m raid1c4 -d raid1c3 /dev/sd[abcd]
Label: (null)
UUID: f1f988ab-6750-4bc2-957b-98a4ebe98631
Node size: 16384
Sector size: 4096
Filesystem size: 8.00GiB
Block group profiles:
Data: RAID1C3 273.06MiB
Metadata: RAID1C4 204.75MiB
System: RAID1C4 8.00MiB
SSD detected: no
Incompat features: extref, skinny-metadata, raid1c34
Number of devices: 4
Devices:
ID SIZE PATH
1 2.00GiB /dev/sda
2 2.00GiB /dev/sdb
3 2.00GiB /dev/sdc
4 2.00GiB /dev/sdd--- cmds/balance.c | 4 ++++ cmds/filesystem-usage.c | 8 +++++++ cmds/inspect-dump-super.c | 3 ++- cmds/rescue-chunk-recover.c | 4 ++++ common/fsfeatures.c | 6 +++++ common/utils.c | 12 +++++++++- ctree.h | 8 +++++++ extent-tree.c | 4 ++++ ioctl.h | 4 +++- mkfs/main.c | 11 ++++++++- print-tree.c | 6 +++++ volumes.c | 48 +++++++++++++++++++++++++++++++++++-- volumes.h | 4 ++++ 13 files changed, 116 insertions(+), 6 deletions(-)
cmds/balance.c +4 -0
@@ -46,6 +46,10 @@ static int parse_one_profile(const char *profile, u64 *flags) *flags |=BTRFS_BLOCK_GROUP_RAID0 ; }else if (!strcmp (profile,"raid1" )) { *flags |=BTRFS_BLOCK_GROUP_RAID1 ; + }else if (!strcmp (profile,"raid1c3" )) { + *flags |=BTRFS_BLOCK_GROUP_RAID1C3 ; + }else if (!strcmp (profile,"raid1c4" )) { + *flags |=BTRFS_BLOCK_GROUP_RAID1C4 ; }else if (!strcmp (profile,"raid10" )) { *flags |=BTRFS_BLOCK_GROUP_RAID10 ; }else if (!strcmp (profile,"raid5" )) {
cmds/filesystem-usage.c +8 -0
@@ -374,6 +374,10 @@ static int print_filesystem_usage_overall(int fd, struct chunk_info *chunkinfo, ratio =1 ; else if (flags & BTRFS_BLOCK_GROUP_RAID1) ratio =2 ; + else if (flags & BTRFS_BLOCK_GROUP_RAID1C3) + ratio =3 ; + else if (flags & BTRFS_BLOCK_GROUP_RAID1C4) + ratio =4 ; else if (flags & BTRFS_BLOCK_GROUP_RAID5) ratio =0 ; else if (flags & BTRFS_BLOCK_GROUP_RAID6)
@@ -654,6 +658,10 @@ static u64 calc_chunk_size(struct chunk_info *ci)return ci->size / ci->num_stripes; else if (ci->type & BTRFS_BLOCK_GROUP_RAID1) return ci->size ; + else if (ci->type & BTRFS_BLOCK_GROUP_RAID1C3) + return ci->size; + else if (ci->type & BTRFS_BLOCK_GROUP_RAID1C4) + return ci->size; else if (ci->type & BTRFS_BLOCK_GROUP_DUP) return ci->size ; else if (ci->type & BTRFS_BLOCK_GROUP_RAID5)
cmds/inspect-dump-super.c +2 -1
@@ -227,7 +227,8 @@ static struct readable_flag_entry incompat_flags_array[] = {DEF_INCOMPAT_FLAG_ENTRY (RAID56 ),DEF_INCOMPAT_FLAG_ENTRY (SKINNY_METADATA ),DEF_INCOMPAT_FLAG_ENTRY (NO_HOLES ), - DEF_INCOMPAT_FLAG_ENTRY(METADATA_UUID) +DEF_INCOMPAT_FLAG_ENTRY (METADATA_UUID ), + DEF_INCOMPAT_FLAG_ENTRY(RAID1C34), };static const int incompat_flags_num =sizeof (incompat_flags_array) /sizeof (struct readable_flag_entry );
cmds/rescue-chunk-recover.c +4 -0
@@ -1582,6 +1582,10 @@ static int calc_num_stripes(u64 type)else if (type & (BTRFS_BLOCK_GROUP_RAID1 |BTRFS_BLOCK_GROUP_DUP ))return 2 ; +else if (type & (BTRFS_BLOCK_GROUP_RAID1C3 )) +return 3 ; +else if (type & (BTRFS_BLOCK_GROUP_RAID1C4 )) +return 4 ;else return 1 ; }
common/fsfeatures.c +6 -0
@@ -86,6 +86,12 @@ static const struct btrfs_fs_feature { VERSION_TO_STRING2(4,0), NULL, 0, "no explicit hole extents for files" }, + {"raid1c34" ,BTRFS_FEATURE_INCOMPAT_RAID1C34 , +"raid1c34" , +VERSION_TO_STRING2 (5 ,5 ), +NULL ,0 , +NULL ,0 , + "RAID1 with 3 or 4 copies" },/* Keep this one last */ { "list-all", BTRFS_FEATURE_LIST_ALL, NULL } };
common/utils.c +11 -1
@@ -1117,8 +1117,10 @@ static int group_profile_devs_min(u64 flag)case BTRFS_BLOCK_GROUP_RAID5 :return 2 ;case BTRFS_BLOCK_GROUP_RAID6 : +case BTRFS_BLOCK_GROUP_RAID1C3 :return 3 ;case BTRFS_BLOCK_GROUP_RAID10 : +case BTRFS_BLOCK_GROUP_RAID1C4 :return 4 ;default :return -1 ;
@@ -1135,9 +1137,10 @@ int test_num_disk_vs_raid(u64 metadata_profile, u64 data_profile,default :case 4 : allowed |=BTRFS_BLOCK_GROUP_RAID10 ; + allowed |=BTRFS_BLOCK_GROUP_RAID10 |BTRFS_BLOCK_GROUP_RAID1C4 ; __attribute__ ((fallthrough));case 3 : - allowed |=BTRFS_BLOCK_GROUP_RAID6 ; + allowed |=BTRFS_BLOCK_GROUP_RAID6 |BTRFS_BLOCK_GROUP_RAID1C3 ; __attribute__ ((fallthrough));case 2 : allowed |= BTRFS_BLOCK_GROUP_RAID0 | BTRFS_BLOCK_GROUP_RAID1 |
@@ -1191,7 +1194,10 @@ int group_profile_max_safe_loss(u64 flags)case BTRFS_BLOCK_GROUP_RAID10 :return 1 ;case BTRFS_BLOCK_GROUP_RAID6 : +case BTRFS_BLOCK_GROUP_RAID1C3 :return 2 ; +case BTRFS_BLOCK_GROUP_RAID1C4 : +return 3 ;default :return -1 ; }
@@ -1341,6 +1347,10 @@ const char* btrfs_group_profile_str(u64 flag)return "RAID0" ;case BTRFS_BLOCK_GROUP_RAID1 :return "RAID1" ; +case BTRFS_BLOCK_GROUP_RAID1C3 : +return "RAID1C3" ; +case BTRFS_BLOCK_GROUP_RAID1C4 : +return "RAID1C4" ;case BTRFS_BLOCK_GROUP_RAID5 :return "RAID5" ;case BTRFS_BLOCK_GROUP_RAID6 :
ctree.h +8 -0
@@ -489,6 +489,7 @@ struct btrfs_super_block {#define BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA (1ULL << 8)#define BTRFS_FEATURE_INCOMPAT_NO_HOLES (1ULL << 9)#define BTRFS_FEATURE_INCOMPAT_METADATA_UUID (1ULL << 10) +#define BTRFS_FEATURE_INCOMPAT_RAID1C34 (1ULL << 11)#define BTRFS_FEATURE_COMPAT_SUPP 0ULL
@@ -512,6 +513,7 @@ struct btrfs_super_block {BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS | \BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA | \BTRFS_FEATURE_INCOMPAT_NO_HOLES | \ +BTRFS_FEATURE_INCOMPAT_RAID1C34 | \ BTRFS_FEATURE_INCOMPAT_METADATA_UUID)/*
@@ -961,6 +963,8 @@ struct btrfs_csum_item {#define BTRFS_BLOCK_GROUP_RAID10 (1ULL << 6)#define BTRFS_BLOCK_GROUP_RAID5 (1ULL << 7)#define BTRFS_BLOCK_GROUP_RAID6 (1ULL << 8) +#define BTRFS_BLOCK_GROUP_RAID1C3 (1ULL << 9) +#define BTRFS_BLOCK_GROUP_RAID1C4 (1ULL << 10)#define BTRFS_BLOCK_GROUP_RESERVED BTRFS_AVAIL_ALLOC_BIT_SINGLEenum btrfs_raid_types {
@@ -971,6 +975,8 @@ enum btrfs_raid_types {BTRFS_RAID_SINGLE ,BTRFS_RAID_RAID5 ,BTRFS_RAID_RAID6 , +BTRFS_RAID_RAID1C3 , +BTRFS_RAID_RAID1C4 , BTRFS_NR_RAID_TYPES };
@@ -982,6 +988,8 @@ enum btrfs_raid_types {BTRFS_BLOCK_GROUP_RAID1 | \BTRFS_BLOCK_GROUP_RAID5 | \BTRFS_BLOCK_GROUP_RAID6 | \ +BTRFS_BLOCK_GROUP_RAID1C3 | \ +BTRFS_BLOCK_GROUP_RAID1C4 | \BTRFS_BLOCK_GROUP_DUP | \ BTRFS_BLOCK_GROUP_RAID10)
extent-tree.c +4 -0
@@ -1669,6 +1669,8 @@ static void set_avail_alloc_bits(struct btrfs_fs_info *fs_info, u64 flags) { u64 extra_flags = flags & (BTRFS_BLOCK_GROUP_RAID0 | BTRFS_BLOCK_GROUP_RAID1 | + BTRFS_BLOCK_GROUP_RAID1C3 | + BTRFS_BLOCK_GROUP_RAID1C4 | BTRFS_BLOCK_GROUP_RAID10 | BTRFS_BLOCK_GROUP_RAID5 | BTRFS_BLOCK_GROUP_RAID6 |
@@ -3104,6 +3106,8 @@ static u64 get_dev_extent_len(struct map_lookup *map)case 0 :/* Single */ case BTRFS_BLOCK_GROUP_DUP :case BTRFS_BLOCK_GROUP_RAID1 : +case BTRFS_BLOCK_GROUP_RAID1C3 : +case BTRFS_BLOCK_GROUP_RAID1C4 : div =1 ;break ;case BTRFS_BLOCK_GROUP_RAID5 :
ioctl.h +3 -1
@@ -775,7 +775,9 @@ enum btrfs_err_code {BTRFS_ERROR_DEV_TGT_REPLACE ,BTRFS_ERROR_DEV_MISSING_NOT_FOUND ,BTRFS_ERROR_DEV_ONLY_WRITABLE , - BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS +BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS , +BTRFS_ERROR_DEV_RAID1C3_MIN_NOT_MET , + BTRFS_ERROR_DEV_RAID1C4_MIN_NOT_MET, };/* An error code to error string mapping for the kernel
mkfs/main.c +10 -1
@@ -337,7 +337,7 @@ static void print_usage(int ret)printf ("Usage: mkfs.btrfs [options] dev [ dev ... ]\n" );printf ("Options:\n" );printf (" allocation profiles:\n" ); -printf ("\t-d|--data PROFILE data profile, raid0, raid1, raid5, raid6, raid10, dup or single\n" ); +printf ("\t-d|--data PROFILE data profile, raid0, raid1, raid1c3, raid1c4, raid5, raid6, raid10, dup or single\n" );printf ("\t-m|--metadata PROFILE metadata profile, values like for data profile\n" );printf ("\t-M|--mixed mix metadata and data together\n" );printf (" features:\n" );
@@ -370,6 +370,10 @@ static u64 parse_profile(const char *s)return BTRFS_BLOCK_GROUP_RAID0 ; }else if (strcasecmp (s,"raid1" ) ==0 ) {return BTRFS_BLOCK_GROUP_RAID1 ; + }else if (strcasecmp (s,"raid1c3" ) ==0 ) { +return BTRFS_BLOCK_GROUP_RAID1C3 ; + }else if (strcasecmp (s,"raid1c4" ) ==0 ) { +return BTRFS_BLOCK_GROUP_RAID1C4 ; }else if (strcasecmp (s,"raid5" ) ==0 ) {return BTRFS_BLOCK_GROUP_RAID5 ; }else if (strcasecmp (s,"raid6" ) ==0 ) {
@@ -1065,6 +1069,11 @@ int BOX_MAIN(mkfs)(int argc, char **argv) features |=BTRFS_FEATURE_INCOMPAT_RAID56 ; } +if ((data_profile | metadata_profile) & + (BTRFS_BLOCK_GROUP_RAID1C3 |BTRFS_BLOCK_GROUP_RAID1C4 )) { + features |=BTRFS_FEATURE_INCOMPAT_RAID1C34 ; + } +if (btrfs_check_nodesize (nodesize, sectorsize, features)) goto error;
print-tree.c +6 -0
@@ -162,6 +162,12 @@ static void bg_flags_to_str(u64 flags, char *ret)case BTRFS_BLOCK_GROUP_RAID1 :strcat (ret,"|RAID1" );break ; +case BTRFS_BLOCK_GROUP_RAID1C3 : +strcat (ret,"|RAID1C3" ); +break ; +case BTRFS_BLOCK_GROUP_RAID1C4 : +strcat (ret,"|RAID1C4" ); +break ;case BTRFS_BLOCK_GROUP_DUP :strcat (ret,"|DUP" );break ;
volumes.c +46 -2
102 lines not on this page · raw message
volumes.h +4 -0
@@ -135,6 +135,10 @@ static inline enum btrfs_raid_types btrfs_bg_flags_to_raid_index(u64 flags)return BTRFS_RAID_RAID10 ; else if (flags & BTRFS_BLOCK_GROUP_RAID1) return BTRFS_RAID_RAID1; + else if (flags & BTRFS_BLOCK_GROUP_RAID1C3) + return BTRFS_RAID_RAID1C3; + else if (flags & BTRFS_BLOCK_GROUP_RAID1C4) + return BTRFS_RAID_RAID1C4; else if (flags & BTRFS_BLOCK_GROUP_DUP) return BTRFS_RAID_DUP; else if (flags & BTRFS_BLOCK_GROUP_RAID0)
Signature · 1 line
2.23.0
The kernel code can be pulled from (based on misc-next)
git://github.com/kdave/btrfs-devel.git dev/raid1c3-5.5-final
and for btrfs-progs (based on 5.3.1)
git://github.com/kdave/btrfs-progs.git dev/raid1c34
Quoted 17 lines · David Sterba
Here it goes again, RAID1 with 3- and 4- copies. I found the bug that stopped it from inclusion last time, it was in the test itself, so the kernel code is effectively unchanged.
So, with 1 or 2 missing devices, replace by device id works. There's one annoying thing but not new: regarding replace of a missing device, some extra single/dup block groups are created during the replace process. Example below. This can happen on plain raid1 with degraded read-write mount as well.
Now what's the merge target.
The patches almost made it to 5.3, the changes build on existing code so the actual addition of new profiles is namely in the definitions and additional cases. So it should be safe.
Quoted 7 lines
I'm for adding it to 5.5 queue, though we're at rc5 and this can be seen as a late time for a feature. The user benefits are noticeable, raid1c3 can replace raid6 of metadata which is the most problematic part and much more complicated to fix (write ahead journal or something like that). The feedback regarding the plain 3-copy as a replacement was positive, on IRC and there are mails about that too.
What's the reasoning for not submitting this for 5.4? I think the improvements here are definitely worth pulling into the 5.4 kernel release...
Signature · 1 line
真実はいつも一つ!/ Always, there's only one truth!
Quoted 3 lines · Neal Gompa
What's the reasoning for not submitting this for 5.4? I think the improvements here are definitely worth pulling into the 5.4 kernel release...
Because 5.4 is at rc5, new features are allowed to be merged only during the merge window, ie. before 5.4-rc1. Thats more than a month ago. From rc1-rcX only regressions or fixes can be applied, so you can see pull requests but the subject lines almost always contain 'fix'.
A new feature has to be in the develoment branch at least 2 weeks before the merge window opens (for testing), so right now it's the last opportunity to get it to 5.5, 5.4 is out of question. No matter how much I or users want to get it merged. This is how the linux development process works.
The raid1c34 patches are not intrusive and could be backported on top of 5.3 because all the preparatory work has been merged already.
Would GRUB be able to boot from RAID1c34 by treating it as "regular" RAID1?! If not I think a warning could be useful.
Quoted 19 lines · David Sterba
Quoted 3 lines · Neal Gompa
What's the reasoning for not submitting this for 5.4? I think the improvements here are definitely worth pulling into the 5.4 kernel release...
Because 5.4 is at rc5, new features are allowed to be merged only during the merge window, ie. before 5.4-rc1. Thats more than a month ago. From rc1-rcX only regressions or fixes can be applied, so you can see pull requests but the subject lines almost always contain 'fix'.
A new feature has to be in the develoment branch at least 2 weeks before the merge window opens (for testing), so right now it's the last opportunity to get it to 5.5, 5.4 is out of question. No matter how much I or users want to get it merged. This is how the linux development process works.
The raid1c34 patches are not intrusive and could be backported on top of 5.3 because all the preparatory work has been merged already.
Quoted 2 lines · waxhead
Would GRUB be able to boot from RAID1c34 by treating it as "regular" RAID1?! If not I think a warning could be useful.
Currently grub will refuse to boot from that with 'unknown profile' message. Adding the support seems to be fairly easi, I'll send the patches.
Quoted 2 lines · David Sterba
The raid1c34 patches are not intrusive and could be backported on top of 5.3 because all the preparatory work has been merged already.
Indeed, that's how I ended up testing them. I couldn't get the 5.4-rc kernels to run long enough to do meaningful testing before they locked up. I tested with 5.3.8 + patches.
I left out the last patch that removes the raid1c3 incompat flag because 5.3 didn't have the block group tree code to apply it to.
I ran my raid1 and raid56 corruption recovery tests modified for raid1c3. The first test is roughly:
mkfs.btrfs -draid1c3 -mraid1c3 /dev/vd[bcdef] mount /dev/vdb /test
cp -a 9GB_data /test
sync
sysctl vm.drop_caches=3
diff -r 9GB_data /test
head -c 9g /dev/urandom > /dev/vdb head -c 9g /dev/urandom > /dev/vdc sync
sysctl vm.drop_caches=3
diff -r 9GB_data /test
btrfs scrub start -Bd /test
sysctl vm.drop_caches=3
diff -r 9GB_data /test
btrfs scrub start -Bd /test
sysctl vm.drop_caches=3
diff -r 9GB_data /test
First scrub reported a lot of corruption on /dev/vdb and /dev/vdc. Second scrub reported no errors. diff (all instances) reported no differences.
Second test is:
mkfs.btrfs -draid6 -mraid1c3 /dev/vd[bcdef] # rest as above...
Similar results: first scrub reported many errors as expected. Second scrub reported no errors. No diffs.
Quoted 35 lines · Zygo Blaxell
Quoted 2 lines · David Sterba
The raid1c34 patches are not intrusive and could be backported on top of 5.3 because all the preparatory work has been merged already.
Indeed, that's how I ended up testing them. I couldn't get the 5.4-rc kernels to run long enough to do meaningful testing before they locked up. I tested with 5.3.8 + patches.
I left out the last patch that removes the raid1c3 incompat flag because 5.3 didn't have the block group tree code to apply it to.
I ran my raid1 and raid56 corruption recovery tests modified for raid1c3. The first test is roughly:
mkfs.btrfs -draid1c3 -mraid1c3 /dev/vd[bcdef] mount
/dev/vdb/test
cp -a 9GB_data /test
sync
sysctl vm.drop_caches=3
diff -r 9GB_data /test
head -c 9g/dev/urandom>/dev/vdbhead -c 9g/dev/urandom>/dev/vdcsync
sysctl vm.drop_caches=3
diff -r 9GB_data /test
btrfs scrub start -Bd /test
sysctl vm.drop_caches=3
diff -r 9GB_data /test
btrfs scrub start -Bd /test
sysctl vm.drop_caches=3
diff -r 9GB_data /testFirst scrub reported a lot of corruption on
/dev/vdband/dev/vdc. Second scrub reported no errors. diff (all instances) reported no differences.
Quoted 7 lines
Second test is:
mkfs.btrfs -draid6 -mraid1c3 /dev/vd[bcdef] # rest as above...
Similar results: first scrub reported many errors as expected. Second scrub reported no errors. No diffs.
Thanks for the tests.