[v2,1/2] btrfs: volumes: Use more straightforward way to calculate map length
diff mbox series

Message ID 20191023125648.30840-2-wqu@suse.com
State New
Headers show
Series
  • btrfs: trim: Fix a bug certain range may not be trimmed properly
Related show

Commit Message

Qu Wenruo Oct. 23, 2019, 12:56 p.m. UTC
The old code goes:

 	offset = logical - em->start;
	length = min_t(u64, em->len - offset, length);

Where @length calculate is dependent on offset, it can take reader
several more seconds to find it's just the same code as:

 	offset = logical - em->start;
	length = min_t(u64, em->start + em->len - logical, length);

Use above code to make the length calculate independent from other
variable, thus slightly increase the readability.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/volumes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Nikolay Borisov Oct. 23, 2019, 1:11 p.m. UTC | #1
On 23.10.19 г. 15:56 ч., Qu Wenruo wrote:
> The old code goes:
> 
>  	offset = logical - em->start;
> 	length = min_t(u64, em->len - offset, length);
> 
> Where @length calculate is dependent on offset, it can take reader
> several more seconds to find it's just the same code as:
> 
>  	offset = logical - em->start;
> 	length = min_t(u64, em->start + em->len - logical, length);
> 
> Use above code to make the length calculate independent from other
> variable, thus slightly increase the readability.
> 
> Signed-off-by: Qu Wenruo <wqu@suse.com>

I agree, this calculates whether we need to trim the rest of the BG or
not.

Reviewed-by: Nikolay Borisov <nborisov@suse.com>


> ---
>  fs/btrfs/volumes.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index cdd7af424033..a6db11e821a5 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -5616,7 +5616,7 @@ static int __btrfs_map_block_for_discard(struct btrfs_fs_info *fs_info,
>  	}
>  
>  	offset = logical - em->start;
> -	length = min_t(u64, em->len - offset, length);
> +	length = min_t(u64, em->start + em->len - logical, length);
>  
>  	stripe_len = map->stripe_len;
>  	/*
>

Patch
diff mbox series

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index cdd7af424033..a6db11e821a5 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -5616,7 +5616,7 @@  static int __btrfs_map_block_for_discard(struct btrfs_fs_info *fs_info,
 	}
 
 	offset = logical - em->start;
-	length = min_t(u64, em->len - offset, length);
+	length = min_t(u64, em->start + em->len - logical, length);
 
 	stripe_len = map->stripe_len;
 	/*