dm-zone: Use bdev_*() helper functions where applicable
authorBart Van Assche <bvanassche@acm.org>
Wed, 14 May 2025 20:50:33 +0000 (13:50 -0700)
committerMikulas Patocka <mpatocka@redhat.com>
Thu, 15 May 2025 13:55:07 +0000 (15:55 +0200)
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>
drivers/md/dm-table.c
drivers/md/dm-zone.c
include/linux/blkdev.h

index 982c8fdd619e9e7088221021a9b6e48700f0efd9..57573e8b5aa97b2865b1b5493c140100a273a45b 100644 (file)
@@ -256,7 +256,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_aligned(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,
@@ -273,7 +273,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_aligned(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,
index 0d989651eb1581a1220ac10e30ec95055a89b764..3d31b82e073043051abf88992ea02d796587b864 100644 (file)
@@ -463,9 +463,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;
index e39c45bc0a97ee18e532b0d2520fa93762fc0fe3..edc941ec8fdd2c6fcfb544f68ac32a2e3a41d6f0 100644 (file)
@@ -1419,6 +1419,13 @@ static inline bool bdev_is_zone_start(struct block_device *bdev,
        return bdev_offset_from_zone_start(bdev, sector) == 0;
 }
 
+/* Check whether @sector is a multiple of the zone size. */
+static inline bool bdev_is_zone_aligned(struct block_device *bdev,
+                                       sector_t sector)
+{
+       return bdev_is_zone_start(bdev, sector);
+}
+
 /**
  * bdev_zone_is_seq - check if a sector belongs to a sequential write zone
  * @bdev:      block device to check