btrfs-progs: use raid table for min devs in btrfs_check_chunk_valid

Replace the hard coded values with the raid table reference.

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2021-10-07 00:36:14 +02:00
parent 3d05b20435
commit e3355b43b4

View File

@ -2054,6 +2054,7 @@ int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info,
u64 type; u64 type;
u32 chunk_ondisk_size; u32 chunk_ondisk_size;
u32 sectorsize = fs_info->sectorsize; u32 sectorsize = fs_info->sectorsize;
int min_devs;
/* /*
* Basic chunk item size check. Note that btrfs_chunk already contains * Basic chunk item size check. Note that btrfs_chunk already contains
@ -2148,13 +2149,14 @@ int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info,
/* /*
* Device number check against profile * Device number check against profile
*/ */
min_devs = btrfs_bg_type_to_devs_min(type);
if ((type & BTRFS_BLOCK_GROUP_RAID10 && (sub_stripes != 2 || if ((type & BTRFS_BLOCK_GROUP_RAID10 && (sub_stripes != 2 ||
!IS_ALIGNED(num_stripes, sub_stripes))) || !IS_ALIGNED(num_stripes, sub_stripes))) ||
(type & BTRFS_BLOCK_GROUP_RAID1 && num_stripes < 1) || (type & BTRFS_BLOCK_GROUP_RAID1 && num_stripes < min_devs) ||
(type & BTRFS_BLOCK_GROUP_RAID1C3 && num_stripes < 3) || (type & BTRFS_BLOCK_GROUP_RAID1C3 && num_stripes < min_devs) ||
(type & BTRFS_BLOCK_GROUP_RAID1C4 && num_stripes < 4) || (type & BTRFS_BLOCK_GROUP_RAID1C4 && num_stripes < min_devs) ||
(type & BTRFS_BLOCK_GROUP_RAID5 && num_stripes < 2) || (type & BTRFS_BLOCK_GROUP_RAID5 && num_stripes < min_devs) ||
(type & BTRFS_BLOCK_GROUP_RAID6 && num_stripes < 3) || (type & BTRFS_BLOCK_GROUP_RAID6 && num_stripes < min_devs) ||
(type & BTRFS_BLOCK_GROUP_DUP && num_stripes > 2) || (type & BTRFS_BLOCK_GROUP_DUP && num_stripes > 2) ||
((type & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0 && ((type & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0 &&
num_stripes != 1)) { num_stripes != 1)) {