BACKPORT: FROMLIST: block: introduce bdev_zone_no helper

Add a generic bdev_zone_no() helper to calculate zone number for a
given sector in a block device. This helper internally uses disk_zone_no()
to find the zone number.

Use the helper bdev_zone_no() to calculate nr of zones. This lets us
make modifications to the math if needed in one place.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
Bug: 197782466
Bug: 269471019
Link: https://lore.kernel.org/linux-block/20230110143635.77300-4-p.raghav@samsung.com/
Change-Id: I86d97c0a64db5ebe1be725710accdaf6e8346d9e
Signed-off-by: Bart Van Assche <bvanassche@google.com>
This commit is contained in:
Pankaj Raghav
2023-01-10 11:41:03 -08:00
committed by Treehugger Robot
parent 610058c970
commit c5c1ebb7cf
2 changed files with 6 additions and 1 deletions

View File

@@ -251,7 +251,7 @@ static unsigned long nvmet_req_nr_zones_from_slba(struct nvmet_req *req)
unsigned int sect = nvmet_lba_to_sect(req->ns, req->cmd->zmr.slba);
return blkdev_nr_zones(req->ns->bdev->bd_disk) -
(sect >> ilog2(bdev_zone_sectors(req->ns->bdev)));
bdev_zone_no(req->ns->bdev, sect);
}
static unsigned long get_nr_zones_from_buf(struct nvmet_req *req, u32 bufsize)

View File

@@ -1638,6 +1638,11 @@ static inline bool bdev_is_zoned(struct block_device *bdev)
return blk_queue_is_zoned(bdev_get_queue(bdev));
}
static inline unsigned int bdev_zone_no(struct block_device *bdev, sector_t sec)
{
return blk_queue_zone_no(bdev->bd_disk->queue, sec);
}
static inline sector_t bdev_zone_sectors(struct block_device *bdev)
{
struct request_queue *q = bdev_get_queue(bdev);