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

null_blk: Cleanup zoned device initialization

Move all zoned mode related code from null_blk_main.c to
null_blk_zoned.c, avoiding an ugly #ifdef in the process.
Rename null_zone_init() into null_init_zoned_dev(), null_zone_exit()
into null_free_zoned_dev() and add the new function
null_register_zoned_dev() to finalize the zoned dev setup before
add_disk().
Signed-off-by: default avatarDamien Le Moal <damien.lemoal@wdc.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 9dd44c7e
...@@ -90,8 +90,9 @@ blk_status_t null_process_cmd(struct nullb_cmd *cmd, ...@@ -90,8 +90,9 @@ blk_status_t null_process_cmd(struct nullb_cmd *cmd,
unsigned int nr_sectors); unsigned int nr_sectors);
#ifdef CONFIG_BLK_DEV_ZONED #ifdef CONFIG_BLK_DEV_ZONED
int null_zone_init(struct nullb_device *dev); int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q);
void null_zone_exit(struct nullb_device *dev); int null_register_zoned_dev(struct nullb *nullb);
void null_free_zoned_dev(struct nullb_device *dev);
int null_report_zones(struct gendisk *disk, sector_t sector, int null_report_zones(struct gendisk *disk, sector_t sector,
unsigned int nr_zones, report_zones_cb cb, void *data); unsigned int nr_zones, report_zones_cb cb, void *data);
blk_status_t null_process_zoned_cmd(struct nullb_cmd *cmd, blk_status_t null_process_zoned_cmd(struct nullb_cmd *cmd,
...@@ -100,12 +101,17 @@ blk_status_t null_process_zoned_cmd(struct nullb_cmd *cmd, ...@@ -100,12 +101,17 @@ blk_status_t null_process_zoned_cmd(struct nullb_cmd *cmd,
size_t null_zone_valid_read_len(struct nullb *nullb, size_t null_zone_valid_read_len(struct nullb *nullb,
sector_t sector, unsigned int len); sector_t sector, unsigned int len);
#else #else
static inline int null_zone_init(struct nullb_device *dev) static inline int null_init_zoned_dev(struct nullb_device *dev,
struct request_queue *q)
{ {
pr_err("CONFIG_BLK_DEV_ZONED not enabled\n"); pr_err("CONFIG_BLK_DEV_ZONED not enabled\n");
return -EINVAL; return -EINVAL;
} }
static inline void null_zone_exit(struct nullb_device *dev) {} static inline int null_register_zoned_dev(struct nullb *nullb)
{
return -ENODEV;
}
static inline void null_free_zoned_dev(struct nullb_device *dev) {}
static inline blk_status_t null_process_zoned_cmd(struct nullb_cmd *cmd, static inline blk_status_t null_process_zoned_cmd(struct nullb_cmd *cmd,
enum req_opf op, sector_t sector, sector_t nr_sectors) enum req_opf op, sector_t sector, sector_t nr_sectors)
{ {
......
...@@ -580,7 +580,7 @@ static void null_free_dev(struct nullb_device *dev) ...@@ -580,7 +580,7 @@ static void null_free_dev(struct nullb_device *dev)
if (!dev) if (!dev)
return; return;
null_zone_exit(dev); null_free_zoned_dev(dev);
badblocks_exit(&dev->badblocks); badblocks_exit(&dev->badblocks);
kfree(dev); kfree(dev);
} }
...@@ -1618,19 +1618,12 @@ static int null_gendisk_register(struct nullb *nullb) ...@@ -1618,19 +1618,12 @@ static int null_gendisk_register(struct nullb *nullb)
disk->queue = nullb->q; disk->queue = nullb->q;
strncpy(disk->disk_name, nullb->disk_name, DISK_NAME_LEN); strncpy(disk->disk_name, nullb->disk_name, DISK_NAME_LEN);
#ifdef CONFIG_BLK_DEV_ZONED
if (nullb->dev->zoned) { if (nullb->dev->zoned) {
if (queue_is_mq(nullb->q)) { int ret = null_register_zoned_dev(nullb);
int ret = blk_revalidate_disk_zones(disk);
if (ret) if (ret)
return ret; return ret;
} else {
blk_queue_chunk_sectors(nullb->q,
nullb->dev->zone_size_sects);
nullb->q->nr_zones = blkdev_nr_zones(disk);
}
} }
#endif
add_disk(disk); add_disk(disk);
return 0; return 0;
...@@ -1786,14 +1779,9 @@ static int null_add_dev(struct nullb_device *dev) ...@@ -1786,14 +1779,9 @@ static int null_add_dev(struct nullb_device *dev)
} }
if (dev->zoned) { if (dev->zoned) {
rv = null_zone_init(dev); rv = null_init_zoned_dev(dev, nullb->q);
if (rv) if (rv)
goto out_cleanup_blk_queue; goto out_cleanup_blk_queue;
nullb->q->limits.zoned = BLK_ZONED_HM;
blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, nullb->q);
blk_queue_required_elevator_features(nullb->q,
ELEVATOR_F_ZBD_SEQ_WRITE);
} }
nullb->q->queuedata = nullb; nullb->q->queuedata = nullb;
...@@ -1822,8 +1810,7 @@ static int null_add_dev(struct nullb_device *dev) ...@@ -1822,8 +1810,7 @@ static int null_add_dev(struct nullb_device *dev)
return 0; return 0;
out_cleanup_zone: out_cleanup_zone:
if (dev->zoned) null_free_zoned_dev(dev);
null_zone_exit(dev);
out_cleanup_blk_queue: out_cleanup_blk_queue:
blk_cleanup_queue(nullb->q); blk_cleanup_queue(nullb->q);
out_cleanup_tags: out_cleanup_tags:
......
...@@ -13,7 +13,7 @@ static inline unsigned int null_zone_no(struct nullb_device *dev, sector_t sect) ...@@ -13,7 +13,7 @@ static inline unsigned int null_zone_no(struct nullb_device *dev, sector_t sect)
return sect >> ilog2(dev->zone_size_sects); return sect >> ilog2(dev->zone_size_sects);
} }
int null_zone_init(struct nullb_device *dev) int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q)
{ {
sector_t dev_size = (sector_t)dev->size * 1024 * 1024; sector_t dev_size = (sector_t)dev->size * 1024 * 1024;
sector_t sector = 0; sector_t sector = 0;
...@@ -61,10 +61,27 @@ int null_zone_init(struct nullb_device *dev) ...@@ -61,10 +61,27 @@ int null_zone_init(struct nullb_device *dev)
sector += dev->zone_size_sects; sector += dev->zone_size_sects;
} }
q->limits.zoned = BLK_ZONED_HM;
blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, q);
blk_queue_required_elevator_features(q, ELEVATOR_F_ZBD_SEQ_WRITE);
return 0;
}
int null_register_zoned_dev(struct nullb *nullb)
{
struct request_queue *q = nullb->q;
if (queue_is_mq(q))
return blk_revalidate_disk_zones(nullb->disk);
blk_queue_chunk_sectors(q, nullb->dev->zone_size_sects);
q->nr_zones = blkdev_nr_zones(nullb->disk);
return 0; return 0;
} }
void null_zone_exit(struct nullb_device *dev) void null_free_zoned_dev(struct nullb_device *dev)
{ {
kvfree(dev->zones); kvfree(dev->zones);
} }
......
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