From ed9964895ff95fb3fc165a3c431607f86684fca5 Mon Sep 17 00:00:00 2001 From: Johannes Thumshirn Date: Wed, 10 Jun 2020 21:32:55 +0900 Subject: [PATCH] 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 Signed-off-by: David Sterba --- volumes.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/volumes.c b/volumes.c index 80144a76..57d0db54 100644 --- a/volumes.c +++ b/volumes.c @@ -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;