From 4e773f9324ea0da5c03e03cc1965be58019ac259 Mon Sep 17 00:00:00 2001 From: Johannes Thumshirn Date: Wed, 10 Jun 2020 21:32:45 +0900 Subject: [PATCH] btrfs-progs: simplify assignment of number of RAID stripes Simplify the assignment of the used number of RAID stripes in chunk allocation. For RAID levels 0, 5, 6 and 10 we first assigned it to the number of devices in the file-system and afterwards capped it to the upper bound of max_stripes. We can just use the max() macro for this. This will help in furhter refactorings. Signed-off-by: Johannes Thumshirn Signed-off-by: David Sterba --- volumes.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/volumes.c b/volumes.c index 089363f6..2a33dc09 100644 --- a/volumes.c +++ b/volumes.c @@ -1079,16 +1079,14 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, min_stripes = 2; } if (type & (BTRFS_BLOCK_GROUP_RAID0)) { - num_stripes = btrfs_super_num_devices(info->super_copy); - if (num_stripes > max_stripes) - num_stripes = max_stripes; + num_stripes = min_t(u64, max_stripes, + btrfs_super_num_devices(info->super_copy)); min_stripes = 2; } if (type & (BTRFS_BLOCK_GROUP_RAID10)) { min_stripes = 4; - num_stripes = btrfs_super_num_devices(info->super_copy); - if (num_stripes > max_stripes) - num_stripes = max_stripes; + num_stripes = min_t(u64, max_stripes, + btrfs_super_num_devices(info->super_copy)); if (num_stripes < min_stripes) return -ENOSPC; num_stripes &= ~(u32)1; @@ -1096,9 +1094,8 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, } if (type & (BTRFS_BLOCK_GROUP_RAID5)) { min_stripes = 2; - num_stripes = btrfs_super_num_devices(info->super_copy); - if (num_stripes > max_stripes) - num_stripes = max_stripes; + num_stripes = min_t(u64, max_stripes, + btrfs_super_num_devices(info->super_copy)); if (num_stripes < min_stripes) return -ENOSPC; stripe_len = find_raid56_stripe_len(num_stripes - 1, @@ -1106,9 +1103,8 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, } if (type & (BTRFS_BLOCK_GROUP_RAID6)) { min_stripes = 3; - num_stripes = btrfs_super_num_devices(info->super_copy); - if (num_stripes > max_stripes) - num_stripes = max_stripes; + num_stripes = min_t(u64, max_stripes, + btrfs_super_num_devices(info->super_copy)); if (num_stripes < min_stripes) return -ENOSPC; stripe_len = find_raid56_stripe_len(num_stripes - 2,