[PATCH v2 3/3] block: introduce bdev_zone_no helper
Pankaj Raghav
p.raghav at samsung.com
Tue Jan 10 06:36:35 PST 2023
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 at lst.de>
Reviewed-by: Chaitanya Kulkarni <kch at nvidia.com>
Reviewed-by: Bart Van Assche <bvanassche at acm.org>
Reviewed-by: Damien Le Moal <damien.lemoal at opensource.wdc.com>
Signed-off-by: Pankaj Raghav <p.raghav at samsung.com>
---
drivers/nvme/target/zns.c | 3 +--
include/linux/blkdev.h | 5 +++++
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/nvme/target/zns.c b/drivers/nvme/target/zns.c
index 1254cf57e008..7e4292d88016 100644
--- a/drivers/nvme/target/zns.c
+++ b/drivers/nvme/target/zns.c
@@ -254,8 +254,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 bdev_nr_zones(req->ns->bdev) -
- (sect >> ilog2(bdev_zone_sectors(req->ns->bdev)));
+ return bdev_nr_zones(req->ns->bdev) - bdev_zone_no(req->ns->bdev, sect);
}
static unsigned long get_nr_zones_from_buf(struct nvmet_req *req, u32 bufsize)
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 7822c6f4c7bd..89f51d68c68a 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1288,6 +1288,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 disk_zone_no(bdev->bd_disk, sec);
+}
+
static inline bool bdev_op_is_zoned_write(struct block_device *bdev,
blk_opf_t op)
{
--
2.25.1
More information about the Linux-nvme
mailing list