btrfs-progs: compactify num_stripe setting in btrfs_alloc_chunk

Now that most of the RAID profile dependent chunk allocation parameters
have been converted to table lookus and moved out of the if-statement
maze, all that remains is the actual calculation of the number of stripes.

Compact the 5 if statements into a single switch statemnt to make the code
a bit more compact and more intuitive to follow.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Johannes Thumshirn 2020-06-10 21:32:55 +09:00 committed by David Sterba
parent 408264be2c
commit ed9964895f
1 changed files with 15 additions and 12 deletions

View File

@ -1129,28 +1129,31 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
ctl.max_stripes = BTRFS_MAX_DEVS(info);
}
}
if (ctl.type == BTRFS_RAID_RAID1 ||
ctl.type == BTRFS_RAID_RAID1C3 ||
ctl.type == BTRFS_RAID_RAID1C4) {
switch (ctl.type) {
case BTRFS_RAID_RAID1:
case BTRFS_RAID_RAID1C3:
case BTRFS_RAID_RAID1C4:
ctl.num_stripes = min(ctl.min_stripes, ctl.total_devs);
}
if (ctl.type == BTRFS_RAID_RAID0) {
break;
case BTRFS_RAID_RAID0:
ctl.num_stripes = min(ctl.max_stripes, ctl.total_devs);
ctl.min_stripes = btrfs_raid_profile_table[ctl.type].min_stripes;
}
if (ctl.type == BTRFS_RAID_RAID10) {
break;
case BTRFS_RAID_RAID10:
ctl.num_stripes = min(ctl.max_stripes, ctl.total_devs);
ctl.num_stripes &= ~(u32)1;
}
if (ctl.type == BTRFS_RAID_RAID5) {
break;
case BTRFS_RAID_RAID5:
ctl.num_stripes = min(ctl.max_stripes, ctl.total_devs);
ctl.stripe_len = find_raid56_stripe_len(ctl.num_stripes - 1,
btrfs_super_stripesize(info->super_copy));
}
if (ctl.type == BTRFS_RAID_RAID6) {
break;
case BTRFS_RAID_RAID6:
ctl.num_stripes = min(ctl.max_stripes, ctl.total_devs);
ctl.stripe_len = find_raid56_stripe_len(ctl.num_stripes - 2,
btrfs_super_stripesize(info->super_copy));
break;
default:
break;
}
if (ctl.num_stripes < ctl.min_stripes)
return -ENOSPC;