diff mbox series

[12/15] btrfs-progs: compactify num_stripe setting in btrfs_alloc_chunk

Message ID 20200610123258.12382-13-johannes.thumshirn@wdc.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: simplify chunk allocation a bit | expand

Commit Message

Johannes Thumshirn June 10, 2020, 12:32 p.m. UTC
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>
---
 volumes.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/volumes.c b/volumes.c
index 80144a763b72..57d0db5463ef 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;