BACKPORT: FROMLIST: block: add a new helper bdev_{is_zone_start, offset_from_zone_start}

Instead of open coding to check for zone start, add a helper to improve
readability and store the logic in one place.

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
Bug: 197782466
Bug: 269471019
Link: https://lore.kernel.org/linux-block/20230110143635.77300-3-p.raghav@samsung.com/
Change-Id: Ieb3ec909589fe087f49a61c48ba85f0e612b6d1d
Signed-off-by: Bart Van Assche <bvanassche@google.com>
This commit is contained in:
Pankaj Raghav
2023-01-10 15:36:34 +01:00
committed by Treehugger Robot
parent 5d1853d5f4
commit 610058c970
2 changed files with 14 additions and 2 deletions

View File

@@ -274,10 +274,10 @@ int blkdev_zone_mgmt(struct block_device *bdev, enum req_opf op,
return -EINVAL;
/* Check alignment (handle eventual smaller last zone) */
if (sector & (zone_sectors - 1))
if (!bdev_is_zone_start(bdev, sector))
return -EINVAL;
if ((nr_sectors & (zone_sectors - 1)) && end_sector != capacity)
if (!bdev_is_zone_start(bdev, nr_sectors) && end_sector != capacity)
return -EINVAL;
/*

View File

@@ -1665,6 +1665,18 @@ static inline unsigned int bdev_max_active_zones(struct block_device *bdev)
return 0;
}
static inline sector_t bdev_offset_from_zone_start(struct block_device *bdev,
sector_t sector)
{
return sector & (bdev_zone_sectors(bdev) - 1);
}
static inline bool bdev_is_zone_start(struct block_device *bdev,
sector_t sector)
{
return bdev_offset_from_zone_start(bdev, sector) == 0;
}
static inline int queue_dma_alignment(const struct request_queue *q)
{
return q ? q->dma_alignment : 511;