Commit 83025863 authored by Nikolay Borisov's avatar Nikolay Borisov Committed by David Sterba

btrfs: raid56: use in_range where applicable

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: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: default avatarNikolay Borisov <nborisov@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent bf28a605
...@@ -1349,7 +1349,6 @@ static int find_bio_stripe(struct btrfs_raid_bio *rbio, ...@@ -1349,7 +1349,6 @@ static int find_bio_stripe(struct btrfs_raid_bio *rbio,
struct bio *bio) struct bio *bio)
{ {
u64 physical = bio->bi_iter.bi_sector; u64 physical = bio->bi_iter.bi_sector;
u64 stripe_start;
int i; int i;
struct btrfs_bio_stripe *stripe; struct btrfs_bio_stripe *stripe;
...@@ -1357,9 +1356,7 @@ static int find_bio_stripe(struct btrfs_raid_bio *rbio, ...@@ -1357,9 +1356,7 @@ static int find_bio_stripe(struct btrfs_raid_bio *rbio,
for (i = 0; i < rbio->bbio->num_stripes; i++) { for (i = 0; i < rbio->bbio->num_stripes; i++) {
stripe = &rbio->bbio->stripes[i]; stripe = &rbio->bbio->stripes[i];
stripe_start = stripe->physical; if (in_range(physical, stripe->physical, rbio->stripe_len) &&
if (physical >= stripe_start &&
physical < stripe_start + rbio->stripe_len &&
stripe->dev->bdev && stripe->dev->bdev &&
bio->bi_disk == stripe->dev->bdev->bd_disk && bio->bi_disk == stripe->dev->bdev->bd_disk &&
bio->bi_partno == stripe->dev->bdev->bd_partno) { bio->bi_partno == stripe->dev->bdev->bd_partno) {
...@@ -1377,19 +1374,15 @@ static int find_bio_stripe(struct btrfs_raid_bio *rbio, ...@@ -1377,19 +1374,15 @@ static int find_bio_stripe(struct btrfs_raid_bio *rbio,
static int find_logical_bio_stripe(struct btrfs_raid_bio *rbio, static int find_logical_bio_stripe(struct btrfs_raid_bio *rbio,
struct bio *bio) struct bio *bio)
{ {
u64 logical = bio->bi_iter.bi_sector; u64 logical = (u64)bio->bi_iter.bi_sector << 9;
u64 stripe_start;
int i; int i;
logical <<= 9;
for (i = 0; i < rbio->nr_data; i++) { for (i = 0; i < rbio->nr_data; i++) {
stripe_start = rbio->bbio->raid_map[i]; u64 stripe_start = rbio->bbio->raid_map[i];
if (logical >= stripe_start &&
logical < stripe_start + rbio->stripe_len) { if (in_range(logical, stripe_start, rbio->stripe_len))
return i; return i;
} }
}
return -1; return -1;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment