btrfs-progs: introduce helper to get allowed profiles for a given device number

Use the raid table helper to avoid hard coding profiles for the given
number of devices in test_num_disk_vs_raid.

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2021-10-07 01:03:50 +02:00
parent 86f7cc0ee1
commit 11fcdbc35e
3 changed files with 16 additions and 17 deletions

View File

@ -579,25 +579,10 @@ int get_fsid(const char *path, u8 *fsid, int silent)
int test_num_disk_vs_raid(u64 metadata_profile, u64 data_profile,
u64 dev_cnt, int mixed, int ssd)
{
u64 allowed = 0;
u64 allowed;
u64 profile = metadata_profile | data_profile;
switch (dev_cnt) {
default:
case 4:
allowed |= BTRFS_BLOCK_GROUP_RAID10;
allowed |= BTRFS_BLOCK_GROUP_RAID10 | BTRFS_BLOCK_GROUP_RAID1C4;
/* fallthrough */
case 3:
allowed |= BTRFS_BLOCK_GROUP_RAID6 | BTRFS_BLOCK_GROUP_RAID1C3;
/* fallthrough */
case 2:
allowed |= BTRFS_BLOCK_GROUP_RAID0 | BTRFS_BLOCK_GROUP_RAID1 |
BTRFS_BLOCK_GROUP_RAID5 | BTRFS_BLOCK_GROUP_RAID10;
/* fallthrough */
case 1:
allowed |= BTRFS_BLOCK_GROUP_DUP | BTRFS_BLOCK_GROUP_RAID0;
}
allowed = btrfs_bg_flags_for_device_num(dev_cnt);
if (dev_cnt > 1 && profile & BTRFS_BLOCK_GROUP_DUP) {
warning("DUP is not recommended on filesystem with multiple devices");

View File

@ -245,6 +245,19 @@ int btrfs_bg_type_to_sub_stripes(u64 flags)
return btrfs_raid_array[index].sub_stripes;
}
u64 btrfs_bg_flags_for_device_num(int number)
{
int i;
u64 ret = 0;
for (i = 0; i < ARRAY_SIZE(btrfs_raid_array); i++) {
if (number >= btrfs_raid_array[i].devs_min)
ret |= btrfs_raid_array[i].bg_flag;
}
return ret;
}
static inline int nr_data_stripes(struct map_lookup *map)
{
return map->num_stripes - btrfs_bg_type_to_nparity(map->type);

View File

@ -312,5 +312,6 @@ int btrfs_bg_type_to_devs_min(u64 flags);
int btrfs_bg_type_to_ncopies(u64 flags);
int btrfs_bg_type_to_nparity(u64 flags);
int btrfs_bg_type_to_sub_stripes(u64 flags);
u64 btrfs_bg_flags_for_device_num(int number);
#endif