dm-zone: Use bdev_*() helper functions where applicable
PATCH 1/1 dm-zone: Use bdev_*() helper functions where applicable
Improve code readability by using bdev_is_zone_start() and bdev_offset_from_zone_start() where applicable. No functionality has been changed.
This patch includes a subset of a patch from Pankaj Raghav.
See also https://lore.kernel.org/linux-block/[email protected]/.
--- drivers/md/dm-table.c | 4 ++-- drivers/md/dm-zone.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/md/dm-table.c +2 -2
@@ -257,7 +257,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,if (bdev_is_zoned (bdev)) {unsigned int zone_sectors =bdev_zone_sectors (bdev); -if (start & (zone_sectors -1 )) { +if (!bdev_is_zone_start (bdev, start)) { DMERR("%s: start=%llu not aligned to h/w zone size %u of %pg", dm_device_name(ti->table->md), (unsigned long long)start,
@@ -274,7 +274,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,* devices do not end up with a smaller zone in the middle of * the sector range. */ -if (len & (zone_sectors -1 )) { +if (!bdev_is_zone_start (bdev, len)) { DMERR("%s: len=%llu not aligned to h/w zone size %u of %pg", dm_device_name(ti->table->md), (unsigned long long)len,
drivers/md/dm-zone.c +3 -3
@@ -423,9 +423,9 @@ void dm_zone_endio(struct dm_io *io, struct bio *clone)*/ if (clone->bi_status ==BLK_STS_OK &&bio_op (clone) ==REQ_OP_ZONE_APPEND ) { -sector_t mask =bdev_zone_sectors (disk->part0) -1 ; - - orig_bio->bi_iter.bi_sector += clone->bi_iter.bi_sector & mask; + orig_bio->bi_iter.bi_sector += +bdev_offset_from_zone_start (disk->part0, + clone->bi_iter.bi_sector); }return ;
Quoted 30 lines · Bart Van Assche
Improve code readability by using
bdev_is_zone_start()andbdev_offset_from_zone_start()where applicable. No functionality has been changed.This patch includes a subset of a patch from Pankaj Raghav.
See also https://lore.kernel.org/linux-block/[email protected]/.
Cc Damien Le Moal <[email protected]>Cc Pankaj Raghav <[email protected]>Signed-off-by Bart Van Assche <[email protected]>--- drivers/md/dm-table.c | 4 ++-- drivers/md/dm-zone.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-)drivers/md/dm-table.c +1
-1@@ -257,7 +257,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,if (bdev_is_zoned (bdev)) {unsigned int zone_sectors =bdev_zone_sectors (bdev); -if (start & (zone_sectors -1 )) { +if (!bdev_is_zone_start (bdev, start)) { DMERR("%s: start=%llu not aligned to h/w zone size %u of %pg", dm_device_name(ti->table->md), (unsigned long long)start,
drivers/md/dm-table.c static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev, · line 277
Quoted 5 lines
drivers/md/dm-table.c +1
-1@@ -274,7 +274,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,* devices do not end up with a smaller zone in the middle of * the sector range. */ -if (len & (zone_sectors -1 )) { +if (!bdev_is_zone_start (bdev, len)) {
This is odd. While the calculation is the same, this checks that the length is zone aligned. Changing this to testing if length is a zone start sector makes it hard to understand. So maybe add a synonym helper for that to avoid such odd naming/code ? E.g.:
/*
* Check if val is aligned to the device zone size.
*/
static inline bool bdev_is_zone_aligned(struct block_device *bdev, sector_t val)
{
return bdev_is_zone_start(bdev, val);
}Other than this, this looks good to me.
Quoted 21 lines
drivers/md/dm-table.c +0
-0DMERR("%s: len=%llu not aligned to h/w zone size %u of %pg", dm_device_name(ti->table->md), (unsigned long long)len,drivers/md/dm-zone.c +3
-3@@ -423,9 +423,9 @@ void dm_zone_endio(struct dm_io *io, struct bio *clone)*/ if (clone->bi_status ==BLK_STS_OK &&bio_op (clone) ==REQ_OP_ZONE_APPEND ) { -sector_t mask =bdev_zone_sectors (disk->part0) -1 ; - - orig_bio->bi_iter.bi_sector += clone->bi_iter.bi_sector & mask; + orig_bio->bi_iter.bi_sector += +bdev_offset_from_zone_start (disk->part0, + clone->bi_iter.bi_sector); }return ;
Signature · 2 lines
Damien Le Moal Western Digital Research