Commit a91e1380 authored by Damien Le Moal's avatar Damien Le Moal Committed by Jens Axboe

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: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarHannes Reinecke <hare@suse.com>
Signed-off-by: default avatarDamien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 5f832a39
...@@ -63,6 +63,33 @@ void __blk_req_zone_write_unlock(struct request *rq) ...@@ -63,6 +63,33 @@ void __blk_req_zone_write_unlock(struct request *rq)
} }
EXPORT_SYMBOL_GPL(__blk_req_zone_write_unlock); 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. * Check that a zone report belongs to the partition.
* If yes, fix its start sector and write pointer, copy it in the * If yes, fix its start sector and write pointer, copy it in the
......
...@@ -702,8 +702,7 @@ static int dmz_get_zoned_device(struct dm_target *ti, char *path) ...@@ -702,8 +702,7 @@ static int dmz_get_zoned_device(struct dm_target *ti, char *path)
dev->zone_nr_blocks = dmz_sect2blk(dev->zone_nr_sectors); dev->zone_nr_blocks = dmz_sect2blk(dev->zone_nr_sectors);
dev->zone_nr_blocks_shift = ilog2(dev->zone_nr_blocks); dev->zone_nr_blocks_shift = ilog2(dev->zone_nr_blocks);
dev->nr_zones = (dev->capacity + dev->zone_nr_sectors - 1) dev->nr_zones = blkdev_nr_zones(dev->bdev);
>> dev->zone_nr_sectors_shift;
dmz->dev = dev; dmz->dev = dev;
......
...@@ -401,6 +401,7 @@ struct blk_zone_report_hdr { ...@@ -401,6 +401,7 @@ struct blk_zone_report_hdr {
u8 padding[60]; u8 padding[60];
}; };
extern unsigned int blkdev_nr_zones(struct block_device *bdev);
extern int blkdev_report_zones(struct block_device *bdev, extern int blkdev_report_zones(struct block_device *bdev,
sector_t sector, struct blk_zone *zones, sector_t sector, struct blk_zone *zones,
unsigned int *nr_zones, gfp_t gfp_mask); unsigned int *nr_zones, gfp_t gfp_mask);
...@@ -414,6 +415,10 @@ extern int blkdev_reset_zones_ioctl(struct block_device *bdev, fmode_t mode, ...@@ -414,6 +415,10 @@ extern int blkdev_reset_zones_ioctl(struct block_device *bdev, fmode_t mode,
#else /* CONFIG_BLK_DEV_ZONED */ #else /* CONFIG_BLK_DEV_ZONED */
static inline unsigned int blkdev_nr_zones(struct block_device *bdev)
{
return 0;
}
static inline int blkdev_report_zones_ioctl(struct block_device *bdev, static inline int blkdev_report_zones_ioctl(struct block_device *bdev,
fmode_t mode, unsigned int cmd, fmode_t mode, unsigned int cmd,
unsigned long arg) unsigned long arg)
......
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