diff mbox series

[4/9] btrfs: scrub: factor out common scrub_stripe constraints

Message ID d175e98023012390c53755ba85f93606376f51a4.1621961965.git.dsterba@suse.com (mailing list archive)
State New, archived
Headers show
Series Misc fixups and cleanups | expand

Commit Message

David Sterba May 25, 2021, 5:08 p.m. UTC
There are common values set for the stripe constraints, some of them
are already factored out. Do that for increment and mirror_num as well.

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

Comments

Qu Wenruo May 25, 2021, 11:51 p.m. UTC | #1
On 2021/5/26 上午1:08, David Sterba wrote:
> There are common values set for the stripe constraints, some of them
> are already factored out. Do that for increment and mirror_num as well.
>
> Signed-off-by: David Sterba <dsterba@suse.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu
> ---
>   fs/btrfs/scrub.c | 9 ++-------
>   1 file changed, 2 insertions(+), 7 deletions(-)
>
> diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
> index 518415d0c122..5839ad1e25a2 100644
> --- a/fs/btrfs/scrub.c
> +++ b/fs/btrfs/scrub.c
> @@ -3204,28 +3204,23 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
>   	physical = map->stripes[num].physical;
>   	offset = 0;
>   	nstripes = div64_u64(length, map->stripe_len);
> +	mirror_num = 1;
> +	increment = map->stripe_len;
>   	if (map->type & BTRFS_BLOCK_GROUP_RAID0) {
>   		offset = map->stripe_len * num;
>   		increment = map->stripe_len * map->num_stripes;
> -		mirror_num = 1;
>   	} else if (map->type & BTRFS_BLOCK_GROUP_RAID10) {
>   		int factor = map->num_stripes / map->sub_stripes;
>   		offset = map->stripe_len * (num / map->sub_stripes);
>   		increment = map->stripe_len * factor;
>   		mirror_num = num % map->sub_stripes + 1;
>   	} else if (map->type & BTRFS_BLOCK_GROUP_RAID1_MASK) {
> -		increment = map->stripe_len;
>   		mirror_num = num % map->num_stripes + 1;
>   	} else if (map->type & BTRFS_BLOCK_GROUP_DUP) {
> -		increment = map->stripe_len;
>   		mirror_num = num % map->num_stripes + 1;
>   	} else if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) {
>   		get_raid56_logic_offset(physical, num, map, &offset, NULL);
>   		increment = map->stripe_len * nr_data_stripes(map);
> -		mirror_num = 1;
> -	} else {
> -		increment = map->stripe_len;
> -		mirror_num = 1;
>   	}
>
>   	path = btrfs_alloc_path();
>
Anand Jain May 26, 2021, 7:16 a.m. UTC | #2
On 26/05/2021 01:08, David Sterba wrote:
> There are common values set for the stripe constraints, some of them
> are already factored out. Do that for increment and mirror_num as well.
> 
> Signed-off-by: David Sterba <dsterba@suse.com>

  Reviewed-by: Anand Jain <anand.jain@oracle.com>

Thanks.

> ---
>   fs/btrfs/scrub.c | 9 ++-------
>   1 file changed, 2 insertions(+), 7 deletions(-)
> 
> diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
> index 518415d0c122..5839ad1e25a2 100644
> --- a/fs/btrfs/scrub.c
> +++ b/fs/btrfs/scrub.c
> @@ -3204,28 +3204,23 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
>   	physical = map->stripes[num].physical;
>   	offset = 0;
>   	nstripes = div64_u64(length, map->stripe_len);
> +	mirror_num = 1;
> +	increment = map->stripe_len;
>   	if (map->type & BTRFS_BLOCK_GROUP_RAID0) {
>   		offset = map->stripe_len * num;
>   		increment = map->stripe_len * map->num_stripes;
> -		mirror_num = 1;
>   	} else if (map->type & BTRFS_BLOCK_GROUP_RAID10) {
>   		int factor = map->num_stripes / map->sub_stripes;
>   		offset = map->stripe_len * (num / map->sub_stripes);
>   		increment = map->stripe_len * factor;
>   		mirror_num = num % map->sub_stripes + 1;
>   	} else if (map->type & BTRFS_BLOCK_GROUP_RAID1_MASK) {
> -		increment = map->stripe_len;
>   		mirror_num = num % map->num_stripes + 1;
>   	} else if (map->type & BTRFS_BLOCK_GROUP_DUP) {
> -		increment = map->stripe_len;
>   		mirror_num = num % map->num_stripes + 1;
>   	} else if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) {
>   		get_raid56_logic_offset(physical, num, map, &offset, NULL);
>   		increment = map->stripe_len * nr_data_stripes(map);
> -		mirror_num = 1;
> -	} else {
> -		increment = map->stripe_len;
> -		mirror_num = 1;
>   	}
>   
>   	path = btrfs_alloc_path();
>
diff mbox series

Patch

diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 518415d0c122..5839ad1e25a2 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -3204,28 +3204,23 @@  static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
 	physical = map->stripes[num].physical;
 	offset = 0;
 	nstripes = div64_u64(length, map->stripe_len);
+	mirror_num = 1;
+	increment = map->stripe_len;
 	if (map->type & BTRFS_BLOCK_GROUP_RAID0) {
 		offset = map->stripe_len * num;
 		increment = map->stripe_len * map->num_stripes;
-		mirror_num = 1;
 	} else if (map->type & BTRFS_BLOCK_GROUP_RAID10) {
 		int factor = map->num_stripes / map->sub_stripes;
 		offset = map->stripe_len * (num / map->sub_stripes);
 		increment = map->stripe_len * factor;
 		mirror_num = num % map->sub_stripes + 1;
 	} else if (map->type & BTRFS_BLOCK_GROUP_RAID1_MASK) {
-		increment = map->stripe_len;
 		mirror_num = num % map->num_stripes + 1;
 	} else if (map->type & BTRFS_BLOCK_GROUP_DUP) {
-		increment = map->stripe_len;
 		mirror_num = num % map->num_stripes + 1;
 	} else if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) {
 		get_raid56_logic_offset(physical, num, map, &offset, NULL);
 		increment = map->stripe_len * nr_data_stripes(map);
-		mirror_num = 1;
-	} else {
-		increment = map->stripe_len;
-		mirror_num = 1;
 	}
 
 	path = btrfs_alloc_path();