FROMLIST: 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/.

Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Cc: Pankaj Raghav <p.raghav@samsung.com>
Change-Id: Iddeca794a7b695a414cffdaf7442e5595523792f
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Bug: 415836627
Link: https://lore.kernel.org/dm-devel/20250514205033.2108129-1-bvanassche@acm.org/
Signed-off-by: Bart Van Assche <bvanassche@google.com>
This commit is contained in:
Bart Van Assche
2025-05-14 13:50:33 -07:00
committed by Bart Van Assche
parent 1d1b2e8d63
commit 996a35040a
3 changed files with 12 additions and 5 deletions

View File

@@ -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_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,
@@ -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_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,

View File

@@ -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;

View File

@@ -1547,6 +1547,13 @@ unsigned long bio_start_io_acct(struct bio *bio);
void bio_end_io_acct_remapped(struct bio *bio, unsigned long start_time,
struct block_device *orig_bdev);
/* 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);
}
/**
* bio_end_io_acct - end I/O accounting for bio based drivers
* @bio: bio to end account for