Skip to content

Commit

Permalink
btrfs: raid56: use in_range where applicable
Browse files Browse the repository at this point in the history
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.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
  • Loading branch information
Nikolay Borisov authored and David Sterba committed Jul 27, 2020
1 parent bf28a60 commit 8302586
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions fs/btrfs/raid56.c
Original file line number Diff line number Diff line change
Expand Up @@ -1349,17 +1349,14 @@ 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;

physical <<= 9;

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) {
Expand All @@ -1377,18 +1374,14 @@ 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 = (u64)bio->bi_iter.bi_sector << 9;
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;
}
Expand Down

0 comments on commit 8302586

Please sign in to comment.