btrfs-progs: use raid table for devs_min and replace local helper

Another duplication of the raid table, in this case missing the changes
to raid10 and raid0 minimum devices changed in a177ef7dd4
("btrfs-progs: mkfs: allow degenerate raid0/raid10").

Define and use a helper using the table value.

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2021-10-06 23:15:08 +02:00
parent e9696b06f0
commit b29f1603b0
3 changed files with 10 additions and 23 deletions

View File

@ -576,27 +576,6 @@ int get_fsid(const char *path, u8 *fsid, int silent)
return ret;
}
static int group_profile_devs_min(u64 flag)
{
switch (flag & BTRFS_BLOCK_GROUP_PROFILE_MASK) {
case 0: /* single */
case BTRFS_BLOCK_GROUP_DUP:
return 1;
case BTRFS_BLOCK_GROUP_RAID0:
case BTRFS_BLOCK_GROUP_RAID1:
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;
}
}
int test_num_disk_vs_raid(u64 metadata_profile, u64 data_profile,
u64 dev_cnt, int mixed, int ssd)
{
@ -628,7 +607,7 @@ int test_num_disk_vs_raid(u64 metadata_profile, u64 data_profile,
"ERROR: unable to create FS with metadata profile %s "
"(have %llu devices but %d devices are required)\n",
btrfs_group_profile_str(metadata_profile), dev_cnt,
group_profile_devs_min(metadata_profile));
btrfs_bg_type_to_devs_min(metadata_profile));
return 1;
}
if (data_profile & ~allowed) {
@ -636,7 +615,7 @@ int test_num_disk_vs_raid(u64 metadata_profile, u64 data_profile,
"ERROR: unable to create FS with data profile %s "
"(have %llu devices but %d devices are required)\n",
btrfs_group_profile_str(data_profile), dev_cnt,
group_profile_devs_min(data_profile));
btrfs_bg_type_to_devs_min(data_profile));
return 1;
}

View File

@ -217,6 +217,13 @@ int btrfs_bg_type_to_tolerated_failures(u64 flags)
return btrfs_raid_array[index].tolerated_failures;
}
int btrfs_bg_type_to_devs_min(u64 flags)
{
const int index = btrfs_bg_flags_to_raid_index(flags);
return btrfs_raid_array[index].devs_min;
}
static inline int nr_parity_stripes(struct map_lookup *map)
{
if (map->type & BTRFS_BLOCK_GROUP_RAID5)

View File

@ -310,5 +310,6 @@ enum btrfs_raid_types btrfs_bg_flags_to_raid_index(u64 flags);
int btrfs_bg_type_to_factor(u64 flags);
const char *btrfs_bg_type_to_raid_name(u64 flags);
int btrfs_bg_type_to_tolerated_failures(u64 flags);
int btrfs_bg_type_to_devs_min(u64 flags);
#endif