Skip to content

Commit 8d6fac0

Browse files
committed
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. Signed-off-by: David Sterba <[email protected]>
1 parent 47e6f74 commit 8d6fac0

File tree

6 files changed

+24
-3
lines changed

6 files changed

+24
-3
lines changed

fs/btrfs/ctree.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ struct btrfs_ref;
5757
* filesystem data as well that can be used to read data in order to repair
5858
* read errors on other disks.
5959
*
60-
* Current value is derived from RAID1C3 with 3 copies.
60+
* Current value is derived from RAID1C4 with 4 copies.
6161
*/
62-
#define BTRFS_MAX_MIRRORS (3 + 1)
62+
#define BTRFS_MAX_MIRRORS (4 + 1)
6363

6464
#define BTRFS_MAX_LEVEL 8
6565

fs/btrfs/super.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,6 +1937,8 @@ static inline int btrfs_calc_avail_data_space(struct btrfs_fs_info *fs_info,
19371937
num_stripes = 2;
19381938
else if (type & BTRFS_BLOCK_GROUP_RAID1C3)
19391939
num_stripes = 3;
1940+
else if (type & BTRFS_BLOCK_GROUP_RAID1C4)
1941+
num_stripes = 4;
19401942
else if (type & BTRFS_BLOCK_GROUP_RAID10)
19411943
num_stripes = 4;
19421944

fs/btrfs/volumes.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
7070
.bg_flag = BTRFS_BLOCK_GROUP_RAID1C3,
7171
.mindev_error = BTRFS_ERROR_DEV_RAID1C3_MIN_NOT_MET,
7272
},
73+
[BTRFS_RAID_RAID1C4] = {
74+
.sub_stripes = 1,
75+
.dev_stripes = 1,
76+
.devs_max = 0,
77+
.devs_min = 4,
78+
.tolerated_failures = 3,
79+
.devs_increment = 4,
80+
.ncopies = 4,
81+
.raid_name = "raid1c4",
82+
.bg_flag = BTRFS_BLOCK_GROUP_RAID1C4,
83+
.mindev_error = BTRFS_ERROR_DEV_RAID1C4_MIN_NOT_MET,
84+
},
7385
[BTRFS_RAID_DUP] = {
7486
.sub_stripes = 1,
7587
.dev_stripes = 2,

fs/btrfs/volumes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,8 @@ static inline enum btrfs_raid_types btrfs_bg_flags_to_raid_index(u64 flags)
547547
return BTRFS_RAID_RAID1;
548548
else if (flags & BTRFS_BLOCK_GROUP_RAID1C3)
549549
return BTRFS_RAID_RAID1C3;
550+
else if (flags & BTRFS_BLOCK_GROUP_RAID1C4)
551+
return BTRFS_RAID_RAID1C4;
550552
else if (flags & BTRFS_BLOCK_GROUP_DUP)
551553
return BTRFS_RAID_DUP;
552554
else if (flags & BTRFS_BLOCK_GROUP_RAID0)

include/uapi/linux/btrfs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,7 @@ enum btrfs_err_code {
833833
BTRFS_ERROR_DEV_ONLY_WRITABLE,
834834
BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS,
835835
BTRFS_ERROR_DEV_RAID1C3_MIN_NOT_MET,
836+
BTRFS_ERROR_DEV_RAID1C4_MIN_NOT_MET,
836837
};
837838

838839
#define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \

include/uapi/linux/btrfs_tree.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,7 @@ struct btrfs_dev_replace_item {
842842
#define BTRFS_BLOCK_GROUP_RAID5 (1ULL << 7)
843843
#define BTRFS_BLOCK_GROUP_RAID6 (1ULL << 8)
844844
#define BTRFS_BLOCK_GROUP_RAID1C3 (1ULL << 9)
845+
#define BTRFS_BLOCK_GROUP_RAID1C4 (1ULL << 10)
845846
#define BTRFS_BLOCK_GROUP_RESERVED (BTRFS_AVAIL_ALLOC_BIT_SINGLE | \
846847
BTRFS_SPACE_INFO_GLOBAL_RSV)
847848

@@ -854,6 +855,7 @@ enum btrfs_raid_types {
854855
BTRFS_RAID_RAID5,
855856
BTRFS_RAID_RAID6,
856857
BTRFS_RAID_RAID1C3,
858+
BTRFS_RAID_RAID1C4,
857859
BTRFS_NR_RAID_TYPES
858860
};
859861

@@ -864,6 +866,7 @@ enum btrfs_raid_types {
864866
#define BTRFS_BLOCK_GROUP_PROFILE_MASK (BTRFS_BLOCK_GROUP_RAID0 | \
865867
BTRFS_BLOCK_GROUP_RAID1 | \
866868
BTRFS_BLOCK_GROUP_RAID1C3 | \
869+
BTRFS_BLOCK_GROUP_RAID1C4 | \
867870
BTRFS_BLOCK_GROUP_RAID5 | \
868871
BTRFS_BLOCK_GROUP_RAID6 | \
869872
BTRFS_BLOCK_GROUP_DUP | \
@@ -872,7 +875,8 @@ enum btrfs_raid_types {
872875
BTRFS_BLOCK_GROUP_RAID6)
873876

874877
#define BTRFS_BLOCK_GROUP_RAID1_MASK (BTRFS_BLOCK_GROUP_RAID1 | \
875-
BTRFS_BLOCK_GROUP_RAID1C3)
878+
BTRFS_BLOCK_GROUP_RAID1C3 | \
879+
BTRFS_BLOCK_GROUP_RAID1C4)
876880

877881
/*
878882
* We need a bit for restriper to be able to tell when chunks of type

0 commit comments

Comments
 (0)