Commit d67ea690 authored by Pankaj Raghav's avatar Pankaj Raghav Committed by Jens Axboe

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: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarChaitanya Kulkarni <kch@nvidia.com>
Reviewed-by: default avatarBart Van Assche <bvanassche@acm.org>
Reviewed-by: default avatarDamien Le Moal <damien.lemoal@opensource.wdc.com>
Signed-off-by: default avatarPankaj Raghav <p.raghav@samsung.com>
Link: https://lore.kernel.org/r/20230110143635.77300-4-p.raghav@samsung.comSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent e29b2100
...@@ -254,8 +254,7 @@ static unsigned long nvmet_req_nr_zones_from_slba(struct nvmet_req *req) ...@@ -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); unsigned int sect = nvmet_lba_to_sect(req->ns, req->cmd->zmr.slba);
return bdev_nr_zones(req->ns->bdev) - return bdev_nr_zones(req->ns->bdev) - bdev_zone_no(req->ns->bdev, sect);
(sect >> ilog2(bdev_zone_sectors(req->ns->bdev)));
} }
static unsigned long get_nr_zones_from_buf(struct nvmet_req *req, u32 bufsize) static unsigned long get_nr_zones_from_buf(struct nvmet_req *req, u32 bufsize)
......
...@@ -1288,6 +1288,11 @@ static inline bool bdev_is_zoned(struct block_device *bdev) ...@@ -1288,6 +1288,11 @@ static inline bool bdev_is_zoned(struct block_device *bdev)
return blk_queue_is_zoned(bdev_get_queue(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, static inline bool bdev_op_is_zoned_write(struct block_device *bdev,
blk_opf_t op) blk_opf_t op)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment