diff options
author | Damien Le Moal <damien.lemoal@wdc.com> | 2018-10-12 12:08:43 +0200 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2018-10-25 19:17:40 +0200 |
commit | a91e138022bc29b5d2bbc56b41de3e0db6261e28 (patch) | |
tree | 858cb365d8459eed119c9e51371ee25d99d53e2a /block | |
parent | scsi: sd_zbc: Fix sd_zbc_check_zones() error checks (diff) | |
download | linux-a91e138022bc29b5d2bbc56b41de3e0db6261e28.tar.xz linux-a91e138022bc29b5d2bbc56b41de3e0db6261e28.zip |
block: Introduce blkdev_nr_zones() helper
Introduce the blkdev_nr_zones() helper function to get the total
number of zones of a zoned block device. This number is always 0 for a
regular block device (q->limits.zoned == BLK_ZONED_NONE case).
Replace hard-coded number of zones calculation in dmz_get_zoned_device()
with a call to this helper.
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block')
-rw-r--r-- | block/blk-zoned.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/block/blk-zoned.c b/block/blk-zoned.c index c461cf63f1f4..32e377f755d8 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -63,6 +63,33 @@ void __blk_req_zone_write_unlock(struct request *rq) } EXPORT_SYMBOL_GPL(__blk_req_zone_write_unlock); +static inline unsigned int __blkdev_nr_zones(struct request_queue *q, + sector_t nr_sectors) +{ + unsigned long zone_sectors = blk_queue_zone_sectors(q); + + return (nr_sectors + zone_sectors - 1) >> ilog2(zone_sectors); +} + +/** + * blkdev_nr_zones - Get number of zones + * @bdev: Target block device + * + * Description: + * Return the total number of zones of a zoned block device. + * For a regular block device, the number of zones is always 0. + */ +unsigned int blkdev_nr_zones(struct block_device *bdev) +{ + struct request_queue *q = bdev_get_queue(bdev); + + if (!blk_queue_is_zoned(q)) + return 0; + + return __blkdev_nr_zones(q, bdev->bd_part->nr_sects); +} +EXPORT_SYMBOL_GPL(blkdev_nr_zones); + /* * Check that a zone report belongs to the partition. * If yes, fix its start sector and write pointer, copy it in the |