public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Nikolay Borisov <nborisov@suse.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 05/10] btrfs: raid56: Use in_range where applicable
Date: Fri, 3 Jul 2020 17:45:06 +0200	[thread overview]
Message-ID: <20200703154506.GD27795@twin.jikos.cz> (raw)
In-Reply-To: <20200702134650.16550-6-nborisov@suse.com>

On Thu, Jul 02, 2020 at 04:46:45PM +0300, Nikolay Borisov wrote:
> While at it use the opportunity to simplify find_logical_bio_stripe by
> reducing the scope of 'stripe_start' variable and squash the
> sector-to-bytes conversion on one line.
> 
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>
> ---
>  fs/btrfs/raid56.c | 16 ++++------------
>  1 file changed, 4 insertions(+), 12 deletions(-)
> 
> diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
> index d9415a22617b..d89dd3030bba 100644
> --- a/fs/btrfs/raid56.c
> +++ b/fs/btrfs/raid56.c
> @@ -1349,7 +1349,6 @@ static int find_bio_stripe(struct btrfs_raid_bio *rbio,
>  			   struct bio *bio)
>  {
>  	u64 physical = bio->bi_iter.bi_sector;
> -	u64 stripe_start;
>  	int i;
>  	struct btrfs_bio_stripe *stripe;
>  
> @@ -1357,9 +1356,7 @@ static int find_bio_stripe(struct btrfs_raid_bio *rbio,
>  
>  	for (i = 0; i < rbio->bbio->num_stripes; i++) {
>  		stripe = &rbio->bbio->stripes[i];
> -		stripe_start = stripe->physical;
> -		if (physical >= stripe_start &&
> -		    physical < stripe_start + rbio->stripe_len &&
> +		if (in_range(physical, stripe->physical, rbio->stripe_len) &&
>  		    stripe->dev->bdev &&
>  		    bio->bi_disk == stripe->dev->bdev->bd_disk &&
>  		    bio->bi_partno == stripe->dev->bdev->bd_partno) {
> @@ -1377,18 +1374,13 @@ static int find_bio_stripe(struct btrfs_raid_bio *rbio,
>  static int find_logical_bio_stripe(struct btrfs_raid_bio *rbio,
>  				   struct bio *bio)
>  {
> -	u64 logical = bio->bi_iter.bi_sector;
> -	u64 stripe_start;
> +	u64 logical = bio->bi_iter.bi_sector << 9;

FYI, if bi_iter::bi_sector is shifted left or right, it needs the u64
cast because the type sector_t is not always 64bit for some reasons.
We've had bugs with the conversion on 32bit arches, for consistency it
needs to be there.

>  	int i;
>  
> -	logical <<= 9;
> -
>  	for (i = 0; i < rbio->nr_data; i++) {
> -		stripe_start = rbio->bbio->raid_map[i];
> -		if (logical >= stripe_start &&
> -		    logical < stripe_start + rbio->stripe_len) {
> +		u64 stripe_start = rbio->bbio->raid_map[i];
> +		if (in_range(logical, stripe_start, rbio->stripe_len))
>  			return i;
> -		}
>  	}
>  	return -1;
>  }
> -- 
> 2.17.1

  parent reply	other threads:[~2020-07-03 15:45 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-02 13:46 [PATCH 00/10] A bunch of misc cleanups Nikolay Borisov
2020-07-02 13:46 ` [PATCH 01/10] btrfs: Always initialize btrfs_bio::tgtdev_map/raid_map pointers Nikolay Borisov
2020-07-02 14:04   ` Johannes Thumshirn
2020-07-03  8:31     ` Nikolay Borisov
2020-07-03 15:57       ` David Sterba
2020-07-06  6:38         ` Johannes Thumshirn
2020-07-02 13:46 ` [PATCH 02/10] btrfs: raid56: Remove redundant check in rbio_add_io_page Nikolay Borisov
2020-07-02 14:12   ` Johannes Thumshirn
2020-07-02 13:46 ` [PATCH 03/10] btrfs: raid56: Assign bio in while() Nikolay Borisov
2020-07-02 14:14   ` Johannes Thumshirn
2020-07-02 13:46 ` [PATCH 04/10] btrfs: raid56: Remove out label in __raid56_parity_recover Nikolay Borisov
2020-07-02 14:02   ` David Sterba
2020-07-02 14:51     ` Nikolay Borisov
2020-07-02 13:46 ` [PATCH 05/10] btrfs: raid56: Use in_range where applicable Nikolay Borisov
2020-07-02 14:19   ` Johannes Thumshirn
2020-07-03 15:45   ` David Sterba [this message]
2020-07-02 13:46 ` [PATCH 06/10] btrfs: raid56: Don't opencode swap() Nikolay Borisov
2020-07-02 14:20   ` Johannes Thumshirn
2020-07-02 13:46 ` [PATCH 07/10] btrfs: Remove fail label in check_compressed_csum Nikolay Borisov
2020-07-02 14:10   ` David Sterba
2020-07-02 13:46 ` [PATCH 08/10] btrfs: Remove fail1 label in btrfs_submit_compressed_read Nikolay Borisov
2020-07-02 14:03   ` David Sterba
2020-07-02 13:46 ` [PATCH 09/10] btrfs: Remove fail2 label from btrfs_submit_compressed_read Nikolay Borisov
2020-07-02 14:14   ` David Sterba
2020-07-02 13:46 ` [PATCH 10/10] btrfs: Remove out label in btrfs_submit_compressed_read Nikolay Borisov
2020-07-02 14:23   ` Johannes Thumshirn
2020-07-03 16:21 ` [PATCH 00/10] A bunch of misc cleanups David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200703154506.GD27795@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=nborisov@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox