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.
Unified · Split
| @@ -254,8 +254,7 @@ static unsigned long nvmet_req_nr_zones_from_slba(struct nvmet_req *req) · 253 unmodified lines | |||
| 254 | { | 254 | { |
| 255 | unsigned int sect = nvmet_lba_to_sect(req->ns, req->cmd->zmr.slba); | 255 | unsigned int sect = nvmet_lba_to_sect(req->ns, req->cmd->zmr.slba); |
| 256 | 256 | ||
| 257 | return bdev_nr_zones(req->ns->bdev) - | 257 | return bdev_nr_zones(req->ns->bdev) - bdev_zone_no(req->ns->bdev, sect); |
| 258 | (sect >> ilog2(bdev_zone_sectors(req->ns->bdev))); | ||
| 259 | } | 258 | } |
| 260 | 259 | ||
| 261 | static unsigned long get_nr_zones_from_buf(struct nvmet_req *req, u32 bufsize) | 260 | 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) · 1287 unmodified lines | |||
| 1288 | return blk_queue_is_zoned(bdev_get_queue(bdev)); | 1288 | return blk_queue_is_zoned(bdev_get_queue(bdev)); |
| 1289 | } | 1289 | } |
| 1290 | 1290 | ||
| 1291 | static inline unsigned int bdev_zone_no(struct block_device *bdev, sector_t sec) | ||
| 1292 | { | ||
| 1293 | return disk_zone_no(bdev->bd_disk, sec); | ||
| 1294 | } | ||
| 1295 | |||
| 1291 | static inline bool bdev_op_is_zoned_write(struct block_device *bdev, | 1296 | static inline bool bdev_op_is_zoned_write(struct block_device *bdev, |
| 1292 | blk_opf_t op) | 1297 | blk_opf_t op) |
| 1293 | { | 1298 | { |