[4/6] btrfs: use raid_attr to adjust minimal stripe size in btrfs_calc_avail_data_space
diff mbox series

Message ID 353ead8638fbac0abe61e1647110bcd795662b27.1560880630.git.dsterba@suse.com
State New
Headers show
Series
  • Minor cleanups
Related show

Commit Message

David Sterba June 18, 2019, 6 p.m. UTC
Special case for DUP can be replaced by lookup to the attribute table,
where the dev_stripes is the right coefficient.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/super.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

Nikolay Borisov June 19, 2019, 6:57 a.m. UTC | #1
On 18.06.19 г. 21:00 ч., David Sterba wrote:
> Special case for DUP can be replaced by lookup to the attribute table,
> where the dev_stripes is the right coefficient.
> 
> Signed-off-by: David Sterba <dsterba@suse.com>
> ---
>  fs/btrfs/super.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
> index 6e196b8a0820..a813b582fa72 100644
> --- a/fs/btrfs/super.c
> +++ b/fs/btrfs/super.c
> @@ -1904,6 +1904,7 @@ static inline int btrfs_calc_avail_data_space(struct btrfs_fs_info *fs_info,
>  	u64 min_stripe_size;
>  	int min_stripes = 1, num_stripes = 1;
>  	int i = 0, nr_devices;
> +	const struct btrfs_raid_attr *rattr;
>  
>  	/*
>  	 * We aren't under the device list lock, so this is racy-ish, but good
> @@ -1927,6 +1928,8 @@ static inline int btrfs_calc_avail_data_space(struct btrfs_fs_info *fs_info,
>  
>  	/* calc min stripe number for data space allocation */
>  	type = btrfs_data_alloc_profile(fs_info);
> +	rattr = &btrfs_raid_array[btrfs_bg_flags_to_raid_index(type)];
> +	ASSERT(rattr);

That ASSERT is a noop since btrfs_bg_flags_to_raid_index always returns
a valid index.

>  	if (type & BTRFS_BLOCK_GROUP_RAID0) {
>  		min_stripes = 2;
>  		num_stripes = nr_devices;
> @@ -1938,10 +1941,8 @@ static inline int btrfs_calc_avail_data_space(struct btrfs_fs_info *fs_info,
>  		num_stripes = 4;
>  	}
>  
> -	if (type & BTRFS_BLOCK_GROUP_DUP)
> -		min_stripe_size = 2 * BTRFS_STRIPE_LEN;
> -	else
> -		min_stripe_size = BTRFS_STRIPE_LEN;
> +	/* Adjust for more than 1 stripe per device */
> +	min_stripe_size = rattr->dev_stripes * BTRFS_STRIPE_LEN;
>  
>  	rcu_read_lock();
>  	list_for_each_entry_rcu(device, &fs_devices->devices, dev_list) {
>

Patch
diff mbox series

diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 6e196b8a0820..a813b582fa72 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -1904,6 +1904,7 @@  static inline int btrfs_calc_avail_data_space(struct btrfs_fs_info *fs_info,
 	u64 min_stripe_size;
 	int min_stripes = 1, num_stripes = 1;
 	int i = 0, nr_devices;
+	const struct btrfs_raid_attr *rattr;
 
 	/*
 	 * We aren't under the device list lock, so this is racy-ish, but good
@@ -1927,6 +1928,8 @@  static inline int btrfs_calc_avail_data_space(struct btrfs_fs_info *fs_info,
 
 	/* calc min stripe number for data space allocation */
 	type = btrfs_data_alloc_profile(fs_info);
+	rattr = &btrfs_raid_array[btrfs_bg_flags_to_raid_index(type)];
+	ASSERT(rattr);
 	if (type & BTRFS_BLOCK_GROUP_RAID0) {
 		min_stripes = 2;
 		num_stripes = nr_devices;
@@ -1938,10 +1941,8 @@  static inline int btrfs_calc_avail_data_space(struct btrfs_fs_info *fs_info,
 		num_stripes = 4;
 	}
 
-	if (type & BTRFS_BLOCK_GROUP_DUP)
-		min_stripe_size = 2 * BTRFS_STRIPE_LEN;
-	else
-		min_stripe_size = BTRFS_STRIPE_LEN;
+	/* Adjust for more than 1 stripe per device */
+	min_stripe_size = rattr->dev_stripes * BTRFS_STRIPE_LEN;
 
 	rcu_read_lock();
 	list_for_each_entry_rcu(device, &fs_devices->devices, dev_list) {