diff options
author | Damien Le Moal <damien.lemoal@wdc.com> | 2018-10-12 06:08:43 -0400 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2018-10-25 13:17:40 -0400 |
commit | a91e138022bc29b5d2bbc56b41de3e0db6261e28 (patch) | |
tree | 858cb365d8459eed119c9e51371ee25d99d53e2a | |
parent | 5f832a395859de7191e638e3777ae57f37d46d08 (diff) |
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>
-rw-r--r-- | block/blk-zoned.c | 27 | ||||
-rw-r--r-- | drivers/md/dm-zoned-target.c | 3 | ||||
-rw-r--r-- | include/linux/blkdev.h | 5 |
3 files changed, 33 insertions, 2 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) | |||
63 | } | 63 | } |
64 | EXPORT_SYMBOL_GPL(__blk_req_zone_write_unlock); | 64 | EXPORT_SYMBOL_GPL(__blk_req_zone_write_unlock); |
65 | 65 | ||
66 | static inline unsigned int __blkdev_nr_zones(struct request_queue *q, | ||
67 | sector_t nr_sectors) | ||
68 | { | ||
69 | unsigned long zone_sectors = blk_queue_zone_sectors(q); | ||
70 | |||
71 | return (nr_sectors + zone_sectors - 1) >> ilog2(zone_sectors); | ||
72 | } | ||
73 | |||
74 | /** | ||
75 | * blkdev_nr_zones - Get number of zones | ||
76 | * @bdev: Target block device | ||
77 | * | ||
78 | * Description: | ||
79 | * Return the total number of zones of a zoned block device. | ||
80 | * For a regular block device, the number of zones is always 0. | ||
81 | */ | ||
82 | unsigned int blkdev_nr_zones(struct block_device *bdev) | ||
83 | { | ||
84 | struct request_queue *q = bdev_get_queue(bdev); | ||
85 | |||
86 | if (!blk_queue_is_zoned(q)) | ||
87 | return 0; | ||
88 | |||
89 | return __blkdev_nr_zones(q, bdev->bd_part->nr_sects); | ||
90 | } | ||
91 | EXPORT_SYMBOL_GPL(blkdev_nr_zones); | ||
92 | |||
66 | /* | 93 | /* |
67 | * Check that a zone report belongs to the partition. | 94 | * Check that a zone report belongs to the partition. |
68 | * If yes, fix its start sector and write pointer, copy it in the | 95 | * If yes, fix its start sector and write pointer, copy it in the |
diff --git a/drivers/md/dm-zoned-target.c b/drivers/md/dm-zoned-target.c index a44183ff4be0..12d96a263623 100644 --- a/drivers/md/dm-zoned-target.c +++ b/drivers/md/dm-zoned-target.c | |||
@@ -702,8 +702,7 @@ static int dmz_get_zoned_device(struct dm_target *ti, char *path) | |||
702 | dev->zone_nr_blocks = dmz_sect2blk(dev->zone_nr_sectors); | 702 | dev->zone_nr_blocks = dmz_sect2blk(dev->zone_nr_sectors); |
703 | dev->zone_nr_blocks_shift = ilog2(dev->zone_nr_blocks); | 703 | dev->zone_nr_blocks_shift = ilog2(dev->zone_nr_blocks); |
704 | 704 | ||
705 | dev->nr_zones = (dev->capacity + dev->zone_nr_sectors - 1) | 705 | dev->nr_zones = blkdev_nr_zones(dev->bdev); |
706 | >> dev->zone_nr_sectors_shift; | ||
707 | 706 | ||
708 | dmz->dev = dev; | 707 | dmz->dev = dev; |
709 | 708 | ||
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 7d423721b327..ca5fdc1b7745 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h | |||
@@ -401,6 +401,7 @@ struct blk_zone_report_hdr { | |||
401 | u8 padding[60]; | 401 | u8 padding[60]; |
402 | }; | 402 | }; |
403 | 403 | ||
404 | extern unsigned int blkdev_nr_zones(struct block_device *bdev); | ||
404 | extern int blkdev_report_zones(struct block_device *bdev, | 405 | extern int blkdev_report_zones(struct block_device *bdev, |
405 | sector_t sector, struct blk_zone *zones, | 406 | sector_t sector, struct blk_zone *zones, |
406 | unsigned int *nr_zones, gfp_t gfp_mask); | 407 | 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 | 415 | ||
415 | #else /* CONFIG_BLK_DEV_ZONED */ | 416 | #else /* CONFIG_BLK_DEV_ZONED */ |
416 | 417 | ||
418 | static inline unsigned int blkdev_nr_zones(struct block_device *bdev) | ||
419 | { | ||
420 | return 0; | ||
421 | } | ||
417 | static inline int blkdev_report_zones_ioctl(struct block_device *bdev, | 422 | static inline int blkdev_report_zones_ioctl(struct block_device *bdev, |
418 | fmode_t mode, unsigned int cmd, | 423 | fmode_t mode, unsigned int cmd, |
419 | unsigned long arg) | 424 | unsigned long arg) |