Skip to content

Commit

Permalink
block: simplify blkdev_nr_zones
Browse files Browse the repository at this point in the history
Simplify the arguments to blkdev_nr_zones by passing a gendisk instead
of the block_device and capacity.  This also removes the need for
__blkdev_nr_zones as all callers are outside the fast path and can
deal with the additional branch.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Christoph Hellwig authored and Jens Axboe committed Dec 3, 2019
1 parent bb55628 commit 9b38bb4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 23 deletions.
26 changes: 8 additions & 18 deletions block/blk-zoned.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,20 @@ 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)
{
sector_t 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
* @disk: Target gendisk
*
* Description:
* Return the total number of zones of a zoned block device.
* For a regular block device, the number of zones is always 0.
* Return the total number of zones of a zoned block device. For a block
* device without zone capabilities, the number of zones is always 0.
*/
unsigned int blkdev_nr_zones(struct block_device *bdev)
unsigned int blkdev_nr_zones(struct gendisk *disk)
{
struct request_queue *q = bdev_get_queue(bdev);
sector_t zone_sectors = blk_queue_zone_sectors(disk->queue);

if (!blk_queue_is_zoned(q))
if (!blk_queue_is_zoned(disk->queue))
return 0;

return __blkdev_nr_zones(q, get_capacity(bdev->bd_disk));
return (get_capacity(disk) + zone_sectors - 1) >> ilog2(zone_sectors);
}
EXPORT_SYMBOL_GPL(blkdev_nr_zones);

Expand Down Expand Up @@ -447,7 +437,7 @@ static int blk_update_zone_info(struct gendisk *disk, unsigned int nr_zones,
int blk_revalidate_disk_zones(struct gendisk *disk)
{
struct request_queue *q = disk->queue;
unsigned int nr_zones = __blkdev_nr_zones(q, get_capacity(disk));
unsigned int nr_zones = blkdev_nr_zones(disk);
struct blk_revalidate_zone_args args = { .disk = disk };
int ret = 0;

Expand Down
2 changes: 1 addition & 1 deletion block/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
case BLKGETZONESZ:
return put_uint(arg, bdev_zone_sectors(bdev));
case BLKGETNRZONES:
return put_uint(arg, blkdev_nr_zones(bdev));
return put_uint(arg, blkdev_nr_zones(bdev->bd_disk));
case HDIO_GETGEO:
return blkdev_getgeo(bdev, argp);
case BLKRAGET:
Expand Down
2 changes: 1 addition & 1 deletion drivers/md/dm-zoned-target.c
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,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_shift = ilog2(dev->zone_nr_blocks);

dev->nr_zones = blkdev_nr_zones(dev->bdev);
dev->nr_zones = blkdev_nr_zones(dev->bdev->bd_disk);

dmz->dev = dev;

Expand Down
5 changes: 2 additions & 3 deletions include/linux/blkdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,7 @@ typedef int (*report_zones_cb)(struct blk_zone *zone, unsigned int idx,
#define BLK_ALL_ZONES ((unsigned int)-1)
int blkdev_report_zones(struct block_device *bdev, sector_t sector,
unsigned int nr_zones, report_zones_cb cb, void *data);

extern unsigned int blkdev_nr_zones(struct block_device *bdev);
unsigned int blkdev_nr_zones(struct gendisk *disk);
extern int blkdev_zone_mgmt(struct block_device *bdev, enum req_opf op,
sector_t sectors, sector_t nr_sectors,
gfp_t gfp_mask);
Expand All @@ -371,7 +370,7 @@ extern int blkdev_zone_mgmt_ioctl(struct block_device *bdev, fmode_t mode,

#else /* CONFIG_BLK_DEV_ZONED */

static inline unsigned int blkdev_nr_zones(struct block_device *bdev)
static inline unsigned int blkdev_nr_zones(struct gendisk *disk)
{
return 0;
}
Expand Down

0 comments on commit 9b38bb4

Please sign in to comment.