Commit b623e347 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

block: replace blkdev_nr_zones with bdev_nr_zones

Pass a block_device instead of a request_queue as that is what most
callers have at hand.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarChaitanya Kulkarni <kch@nvidia.com>
Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: default avatarDamien Le Moal <damien.lemoal@opensource.wdc.com>
Acked-by: default avatarDamien Le Moal <damien.lemoal@opensource.wdc.com>
Link: https://lore.kernel.org/r/20220706070350.1703384-12-hch@lst.deSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 982977df
...@@ -108,21 +108,22 @@ void __blk_req_zone_write_unlock(struct request *rq) ...@@ -108,21 +108,22 @@ 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);
/** /**
* blkdev_nr_zones - Get number of zones * bdev_nr_zones - Get number of zones
* @disk: Target gendisk * @bdev: Target device
* *
* Return the total number of zones of a zoned block device. For a block * 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. * device without zone capabilities, the number of zones is always 0.
*/ */
unsigned int blkdev_nr_zones(struct gendisk *disk) unsigned int bdev_nr_zones(struct block_device *bdev)
{ {
sector_t zone_sectors = blk_queue_zone_sectors(disk->queue); sector_t zone_sectors = bdev_zone_sectors(bdev);
if (!blk_queue_is_zoned(disk->queue)) if (!bdev_is_zoned(bdev))
return 0; return 0;
return (get_capacity(disk) + zone_sectors - 1) >> ilog2(zone_sectors); return (bdev_nr_sectors(bdev) + zone_sectors - 1) >>
ilog2(zone_sectors);
} }
EXPORT_SYMBOL_GPL(blkdev_nr_zones); EXPORT_SYMBOL_GPL(bdev_nr_zones);
/** /**
* blkdev_report_zones - Get zones information * blkdev_report_zones - Get zones information
......
...@@ -495,7 +495,7 @@ static int blkdev_common_ioctl(struct block_device *bdev, fmode_t mode, ...@@ -495,7 +495,7 @@ static int blkdev_common_ioctl(struct block_device *bdev, fmode_t mode,
case BLKGETZONESZ: case BLKGETZONESZ:
return put_uint(argp, bdev_zone_sectors(bdev)); return put_uint(argp, bdev_zone_sectors(bdev));
case BLKGETNRZONES: case BLKGETNRZONES:
return put_uint(argp, blkdev_nr_zones(bdev->bd_disk)); return put_uint(argp, bdev_nr_zones(bdev));
case BLKROGET: case BLKROGET:
return put_int(argp, bdev_read_only(bdev) != 0); return put_int(argp, bdev_read_only(bdev) != 0);
case BLKSSZGET: /* get block device logical block size */ case BLKSSZGET: /* get block device logical block size */
......
...@@ -170,7 +170,7 @@ int null_register_zoned_dev(struct nullb *nullb) ...@@ -170,7 +170,7 @@ int null_register_zoned_dev(struct nullb *nullb)
return ret; return ret;
} else { } else {
blk_queue_chunk_sectors(q, dev->zone_size_sects); blk_queue_chunk_sectors(q, dev->zone_size_sects);
q->nr_zones = blkdev_nr_zones(nullb->disk); q->nr_zones = bdev_nr_zones(nullb->disk->part0);
} }
blk_queue_max_zone_append_sectors(q, dev->zone_size_sects); blk_queue_max_zone_append_sectors(q, dev->zone_size_sects);
......
...@@ -301,7 +301,7 @@ int dm_set_zones_restrictions(struct dm_table *t, struct request_queue *q) ...@@ -301,7 +301,7 @@ int dm_set_zones_restrictions(struct dm_table *t, struct request_queue *q)
* correct value to be exposed in sysfs queue/nr_zones. * correct value to be exposed in sysfs queue/nr_zones.
*/ */
WARN_ON_ONCE(queue_is_mq(q)); WARN_ON_ONCE(queue_is_mq(q));
q->nr_zones = blkdev_nr_zones(md->disk); q->nr_zones = bdev_nr_zones(md->disk->part0);
/* Check if zone append is natively supported */ /* Check if zone append is natively supported */
if (dm_table_supports_zone_append(t)) { if (dm_table_supports_zone_append(t)) {
......
...@@ -793,8 +793,7 @@ static int dmz_fixup_devices(struct dm_target *ti) ...@@ -793,8 +793,7 @@ static int dmz_fixup_devices(struct dm_target *ti)
} }
zone_nr_sectors = blk_queue_zone_sectors(q); zone_nr_sectors = blk_queue_zone_sectors(q);
zoned_dev->zone_nr_sectors = zone_nr_sectors; zoned_dev->zone_nr_sectors = zone_nr_sectors;
zoned_dev->nr_zones = zoned_dev->nr_zones = bdev_nr_zones(zoned_dev->bdev);
blkdev_nr_zones(zoned_dev->bdev->bd_disk);
} }
} else { } else {
reg_dev = NULL; reg_dev = NULL;
...@@ -805,7 +804,7 @@ static int dmz_fixup_devices(struct dm_target *ti) ...@@ -805,7 +804,7 @@ static int dmz_fixup_devices(struct dm_target *ti)
} }
q = bdev_get_queue(zoned_dev->bdev); q = bdev_get_queue(zoned_dev->bdev);
zoned_dev->zone_nr_sectors = blk_queue_zone_sectors(q); zoned_dev->zone_nr_sectors = blk_queue_zone_sectors(q);
zoned_dev->nr_zones = blkdev_nr_zones(zoned_dev->bdev->bd_disk); zoned_dev->nr_zones = bdev_nr_zones(zoned_dev->bdev);
} }
if (reg_dev) { if (reg_dev) {
......
...@@ -60,7 +60,7 @@ bool nvmet_bdev_zns_enable(struct nvmet_ns *ns) ...@@ -60,7 +60,7 @@ bool nvmet_bdev_zns_enable(struct nvmet_ns *ns)
if (ns->bdev->bd_disk->queue->conv_zones_bitmap) if (ns->bdev->bd_disk->queue->conv_zones_bitmap)
return false; return false;
ret = blkdev_report_zones(ns->bdev, 0, blkdev_nr_zones(bd_disk), ret = blkdev_report_zones(ns->bdev, 0, bdev_nr_zones(ns->bdev),
validate_conv_zones_cb, NULL); validate_conv_zones_cb, NULL);
if (ret < 0) if (ret < 0)
return false; return false;
...@@ -241,7 +241,7 @@ static unsigned long nvmet_req_nr_zones_from_slba(struct nvmet_req *req) ...@@ -241,7 +241,7 @@ static unsigned long nvmet_req_nr_zones_from_slba(struct nvmet_req *req)
{ {
unsigned int sect = nvmet_lba_to_sect(req->ns, req->cmd->zmr.slba); unsigned int sect = nvmet_lba_to_sect(req->ns, req->cmd->zmr.slba);
return blkdev_nr_zones(req->ns->bdev->bd_disk) - return bdev_nr_zones(req->ns->bdev) -
(sect >> ilog2(bdev_zone_sectors(req->ns->bdev))); (sect >> ilog2(bdev_zone_sectors(req->ns->bdev)));
} }
...@@ -386,7 +386,7 @@ static int zmgmt_send_scan_cb(struct blk_zone *z, unsigned i, void *d) ...@@ -386,7 +386,7 @@ static int zmgmt_send_scan_cb(struct blk_zone *z, unsigned i, void *d)
static u16 nvmet_bdev_zone_mgmt_emulate_all(struct nvmet_req *req) static u16 nvmet_bdev_zone_mgmt_emulate_all(struct nvmet_req *req)
{ {
struct block_device *bdev = req->ns->bdev; struct block_device *bdev = req->ns->bdev;
unsigned int nr_zones = blkdev_nr_zones(bdev->bd_disk); unsigned int nr_zones = bdev_nr_zones(bdev);
struct request_queue *q = bdev_get_queue(bdev); struct request_queue *q = bdev_get_queue(bdev);
struct bio *bio = NULL; struct bio *bio = NULL;
sector_t sector = 0; sector_t sector = 0;
......
...@@ -1394,7 +1394,7 @@ static void zonefs_init_dir_inode(struct inode *parent, struct inode *inode, ...@@ -1394,7 +1394,7 @@ static void zonefs_init_dir_inode(struct inode *parent, struct inode *inode,
{ {
struct super_block *sb = parent->i_sb; struct super_block *sb = parent->i_sb;
inode->i_ino = blkdev_nr_zones(sb->s_bdev->bd_disk) + type + 1; inode->i_ino = bdev_nr_zones(sb->s_bdev) + type + 1;
inode_init_owner(&init_user_ns, inode, parent, S_IFDIR | 0555); inode_init_owner(&init_user_ns, inode, parent, S_IFDIR | 0555);
inode->i_op = &zonefs_dir_inode_operations; inode->i_op = &zonefs_dir_inode_operations;
inode->i_fop = &simple_dir_operations; inode->i_fop = &simple_dir_operations;
...@@ -1540,7 +1540,7 @@ static int zonefs_create_zgroup(struct zonefs_zone_data *zd, ...@@ -1540,7 +1540,7 @@ static int zonefs_create_zgroup(struct zonefs_zone_data *zd,
/* /*
* The first zone contains the super block: skip it. * The first zone contains the super block: skip it.
*/ */
end = zd->zones + blkdev_nr_zones(sb->s_bdev->bd_disk); end = zd->zones + bdev_nr_zones(sb->s_bdev);
for (zone = &zd->zones[1]; zone < end; zone = next) { for (zone = &zd->zones[1]; zone < end; zone = next) {
next = zone + 1; next = zone + 1;
...@@ -1635,8 +1635,8 @@ static int zonefs_get_zone_info(struct zonefs_zone_data *zd) ...@@ -1635,8 +1635,8 @@ static int zonefs_get_zone_info(struct zonefs_zone_data *zd)
struct block_device *bdev = zd->sb->s_bdev; struct block_device *bdev = zd->sb->s_bdev;
int ret; int ret;
zd->zones = kvcalloc(blkdev_nr_zones(bdev->bd_disk), zd->zones = kvcalloc(bdev_nr_zones(bdev), sizeof(struct blk_zone),
sizeof(struct blk_zone), GFP_KERNEL); GFP_KERNEL);
if (!zd->zones) if (!zd->zones)
return -ENOMEM; return -ENOMEM;
...@@ -1648,9 +1648,9 @@ static int zonefs_get_zone_info(struct zonefs_zone_data *zd) ...@@ -1648,9 +1648,9 @@ static int zonefs_get_zone_info(struct zonefs_zone_data *zd)
return ret; return ret;
} }
if (ret != blkdev_nr_zones(bdev->bd_disk)) { if (ret != bdev_nr_zones(bdev)) {
zonefs_err(zd->sb, "Invalid zone report (%d/%u zones)\n", zonefs_err(zd->sb, "Invalid zone report (%d/%u zones)\n",
ret, blkdev_nr_zones(bdev->bd_disk)); ret, bdev_nr_zones(bdev));
return -EIO; return -EIO;
} }
...@@ -1816,8 +1816,7 @@ static int zonefs_fill_super(struct super_block *sb, void *data, int silent) ...@@ -1816,8 +1816,7 @@ static int zonefs_fill_super(struct super_block *sb, void *data, int silent)
if (ret) if (ret)
goto cleanup; goto cleanup;
zonefs_info(sb, "Mounting %u zones", zonefs_info(sb, "Mounting %u zones", bdev_nr_zones(sb->s_bdev));
blkdev_nr_zones(sb->s_bdev->bd_disk));
if (!sbi->s_max_wro_seq_files && if (!sbi->s_max_wro_seq_files &&
!sbi->s_max_active_seq_files && !sbi->s_max_active_seq_files &&
...@@ -1833,7 +1832,7 @@ static int zonefs_fill_super(struct super_block *sb, void *data, int silent) ...@@ -1833,7 +1832,7 @@ static int zonefs_fill_super(struct super_block *sb, void *data, int silent)
if (!inode) if (!inode)
goto cleanup; goto cleanup;
inode->i_ino = blkdev_nr_zones(sb->s_bdev->bd_disk); inode->i_ino = bdev_nr_zones(sb->s_bdev);
inode->i_mode = S_IFDIR | 0555; inode->i_mode = S_IFDIR | 0555;
inode->i_ctime = inode->i_mtime = inode->i_atime = current_time(inode); inode->i_ctime = inode->i_mtime = inode->i_atime = current_time(inode);
inode->i_op = &zonefs_dir_inode_operations; inode->i_op = &zonefs_dir_inode_operations;
......
...@@ -298,7 +298,7 @@ void disk_set_zoned(struct gendisk *disk, enum blk_zoned_model model); ...@@ -298,7 +298,7 @@ void disk_set_zoned(struct gendisk *disk, enum blk_zoned_model model);
#define BLK_ALL_ZONES ((unsigned int)-1) #define BLK_ALL_ZONES ((unsigned int)-1)
int blkdev_report_zones(struct block_device *bdev, sector_t sector, int blkdev_report_zones(struct block_device *bdev, sector_t sector,
unsigned int nr_zones, report_zones_cb cb, void *data); unsigned int nr_zones, report_zones_cb cb, void *data);
unsigned int blkdev_nr_zones(struct gendisk *disk); unsigned int bdev_nr_zones(struct block_device *bdev);
extern int blkdev_zone_mgmt(struct block_device *bdev, enum req_opf op, extern int blkdev_zone_mgmt(struct block_device *bdev, enum req_opf op,
sector_t sectors, sector_t nr_sectors, sector_t sectors, sector_t nr_sectors,
gfp_t gfp_mask); gfp_t gfp_mask);
...@@ -312,7 +312,7 @@ extern int blkdev_zone_mgmt_ioctl(struct block_device *bdev, fmode_t mode, ...@@ -312,7 +312,7 @@ extern int blkdev_zone_mgmt_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 gendisk *disk) static inline unsigned int bdev_nr_zones(struct block_device *bdev)
{ {
return 0; return 0;
} }
......
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