Skip to content

Commit 241b9b5

Browse files
bvanasscheMikulas Patocka
authored andcommitted
dm-zone: Use bdev_*() helper functions where applicable
Improve code readability by using bdev_is_zone_aligned() and bdev_offset_from_zone_start() where applicable. No functionality has been changed. This patch is a reworked version of a patch from Pankaj Raghav. See also https://lore.kernel.org/linux-block/20220923173618.6899-11-p.raghav@samsung.com/. Cc: Damien Le Moal <dlemoal@kernel.org> Cc: Pankaj Raghav <p.raghav@samsung.com> Signed-off-by: Bart Van Assche <bvanassche@acm.org> Reviewed-by: Damien Le Moal <dlemoal@kernel.org> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
1 parent 3da7326 commit 241b9b5

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

drivers/md/dm-table.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
256256
if (bdev_is_zoned(bdev)) {
257257
unsigned int zone_sectors = bdev_zone_sectors(bdev);
258258

259-
if (start & (zone_sectors - 1)) {
259+
if (!bdev_is_zone_aligned(bdev, start)) {
260260
DMERR("%s: start=%llu not aligned to h/w zone size %u of %pg",
261261
dm_device_name(ti->table->md),
262262
(unsigned long long)start,
@@ -273,7 +273,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
273273
* devices do not end up with a smaller zone in the middle of
274274
* the sector range.
275275
*/
276-
if (len & (zone_sectors - 1)) {
276+
if (!bdev_is_zone_aligned(bdev, len)) {
277277
DMERR("%s: len=%llu not aligned to h/w zone size %u of %pg",
278278
dm_device_name(ti->table->md),
279279
(unsigned long long)len,

drivers/md/dm-zone.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,9 @@ void dm_zone_endio(struct dm_io *io, struct bio *clone)
463463
*/
464464
if (clone->bi_status == BLK_STS_OK &&
465465
bio_op(clone) == REQ_OP_ZONE_APPEND) {
466-
sector_t mask = bdev_zone_sectors(disk->part0) - 1;
467-
468-
orig_bio->bi_iter.bi_sector += clone->bi_iter.bi_sector & mask;
466+
orig_bio->bi_iter.bi_sector +=
467+
bdev_offset_from_zone_start(disk->part0,
468+
clone->bi_iter.bi_sector);
469469
}
470470

471471
return;

include/linux/blkdev.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,13 @@ static inline bool bdev_is_zone_start(struct block_device *bdev,
14191419
return bdev_offset_from_zone_start(bdev, sector) == 0;
14201420
}
14211421

1422+
/* Check whether @sector is a multiple of the zone size. */
1423+
static inline bool bdev_is_zone_aligned(struct block_device *bdev,
1424+
sector_t sector)
1425+
{
1426+
return bdev_is_zone_start(bdev, sector);
1427+
}
1428+
14221429
/**
14231430
* bdev_zone_is_seq - check if a sector belongs to a sequential write zone
14241431
* @bdev: block device to check

0 commit comments

Comments
 (0)