null_blk: convert to blk_alloc_disk/blk_cleanup_disk
Convert the null_blk driver to use the blk_alloc_disk and blk_cleanup_disk helpers to simplify gendisk and request_queue allocation. Note that the blk-mq mode is left with its own allocations scheme, to be handled later. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org> Link: https://lore.kernel.org/r/20210521055116.1053587-26-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
ef35885400
commit
132226b301
|
@ -1597,11 +1597,10 @@ static void null_del_dev(struct nullb *nullb)
|
||||||
null_restart_queue_async(nullb);
|
null_restart_queue_async(nullb);
|
||||||
}
|
}
|
||||||
|
|
||||||
blk_cleanup_queue(nullb->q);
|
blk_cleanup_disk(nullb->disk);
|
||||||
if (dev->queue_mode == NULL_Q_MQ &&
|
if (dev->queue_mode == NULL_Q_MQ &&
|
||||||
nullb->tag_set == &nullb->__tag_set)
|
nullb->tag_set == &nullb->__tag_set)
|
||||||
blk_mq_free_tag_set(nullb->tag_set);
|
blk_mq_free_tag_set(nullb->tag_set);
|
||||||
put_disk(nullb->disk);
|
|
||||||
cleanup_queues(nullb);
|
cleanup_queues(nullb);
|
||||||
if (null_cache_active(nullb))
|
if (null_cache_active(nullb))
|
||||||
null_free_device_storage(nullb->dev, true);
|
null_free_device_storage(nullb->dev, true);
|
||||||
|
@ -1700,22 +1699,19 @@ static int init_driver_queues(struct nullb *nullb)
|
||||||
static int null_gendisk_register(struct nullb *nullb)
|
static int null_gendisk_register(struct nullb *nullb)
|
||||||
{
|
{
|
||||||
sector_t size = ((sector_t)nullb->dev->size * SZ_1M) >> SECTOR_SHIFT;
|
sector_t size = ((sector_t)nullb->dev->size * SZ_1M) >> SECTOR_SHIFT;
|
||||||
struct gendisk *disk;
|
struct gendisk *disk = nullb->disk;
|
||||||
|
|
||||||
disk = nullb->disk = alloc_disk_node(1, nullb->dev->home_node);
|
|
||||||
if (!disk)
|
|
||||||
return -ENOMEM;
|
|
||||||
set_capacity(disk, size);
|
set_capacity(disk, size);
|
||||||
|
|
||||||
disk->flags |= GENHD_FL_EXT_DEVT | GENHD_FL_SUPPRESS_PARTITION_INFO;
|
disk->flags |= GENHD_FL_EXT_DEVT | GENHD_FL_SUPPRESS_PARTITION_INFO;
|
||||||
disk->major = null_major;
|
disk->major = null_major;
|
||||||
disk->first_minor = nullb->index;
|
disk->first_minor = nullb->index;
|
||||||
|
disk->minors = 1;
|
||||||
if (queue_is_mq(nullb->q))
|
if (queue_is_mq(nullb->q))
|
||||||
disk->fops = &null_rq_ops;
|
disk->fops = &null_rq_ops;
|
||||||
else
|
else
|
||||||
disk->fops = &null_bio_ops;
|
disk->fops = &null_bio_ops;
|
||||||
disk->private_data = nullb;
|
disk->private_data = nullb;
|
||||||
disk->queue = nullb->q;
|
|
||||||
strncpy(disk->disk_name, nullb->disk_name, DISK_NAME_LEN);
|
strncpy(disk->disk_name, nullb->disk_name, DISK_NAME_LEN);
|
||||||
|
|
||||||
if (nullb->dev->zoned) {
|
if (nullb->dev->zoned) {
|
||||||
|
@ -1851,23 +1847,27 @@ static int null_add_dev(struct nullb_device *dev)
|
||||||
goto out_cleanup_queues;
|
goto out_cleanup_queues;
|
||||||
|
|
||||||
if (!null_setup_fault())
|
if (!null_setup_fault())
|
||||||
goto out_cleanup_queues;
|
goto out_cleanup_tags;
|
||||||
|
|
||||||
|
rv = -ENOMEM;
|
||||||
nullb->tag_set->timeout = 5 * HZ;
|
nullb->tag_set->timeout = 5 * HZ;
|
||||||
nullb->q = blk_mq_init_queue_data(nullb->tag_set, nullb);
|
nullb->q = blk_mq_init_queue_data(nullb->tag_set, nullb);
|
||||||
if (IS_ERR(nullb->q)) {
|
if (IS_ERR(nullb->q))
|
||||||
rv = -ENOMEM;
|
|
||||||
goto out_cleanup_tags;
|
goto out_cleanup_tags;
|
||||||
}
|
nullb->disk = alloc_disk_node(1, nullb->dev->home_node);
|
||||||
|
if (!nullb->disk)
|
||||||
|
goto out_cleanup_disk;
|
||||||
|
nullb->disk->queue = nullb->q;
|
||||||
} else if (dev->queue_mode == NULL_Q_BIO) {
|
} else if (dev->queue_mode == NULL_Q_BIO) {
|
||||||
nullb->q = blk_alloc_queue(dev->home_node);
|
rv = -ENOMEM;
|
||||||
if (!nullb->q) {
|
nullb->disk = blk_alloc_disk(nullb->dev->home_node);
|
||||||
rv = -ENOMEM;
|
if (!nullb->disk)
|
||||||
goto out_cleanup_queues;
|
goto out_cleanup_queues;
|
||||||
}
|
|
||||||
|
nullb->q = nullb->disk->queue;
|
||||||
rv = init_driver_queues(nullb);
|
rv = init_driver_queues(nullb);
|
||||||
if (rv)
|
if (rv)
|
||||||
goto out_cleanup_blk_queue;
|
goto out_cleanup_disk;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dev->mbps) {
|
if (dev->mbps) {
|
||||||
|
@ -1883,7 +1883,7 @@ static int null_add_dev(struct nullb_device *dev)
|
||||||
if (dev->zoned) {
|
if (dev->zoned) {
|
||||||
rv = null_init_zoned_dev(dev, nullb->q);
|
rv = null_init_zoned_dev(dev, nullb->q);
|
||||||
if (rv)
|
if (rv)
|
||||||
goto out_cleanup_blk_queue;
|
goto out_cleanup_disk;
|
||||||
}
|
}
|
||||||
|
|
||||||
nullb->q->queuedata = nullb;
|
nullb->q->queuedata = nullb;
|
||||||
|
@ -1921,8 +1921,8 @@ static int null_add_dev(struct nullb_device *dev)
|
||||||
return 0;
|
return 0;
|
||||||
out_cleanup_zone:
|
out_cleanup_zone:
|
||||||
null_free_zoned_dev(dev);
|
null_free_zoned_dev(dev);
|
||||||
out_cleanup_blk_queue:
|
out_cleanup_disk:
|
||||||
blk_cleanup_queue(nullb->q);
|
blk_cleanup_disk(nullb->disk);
|
||||||
out_cleanup_tags:
|
out_cleanup_tags:
|
||||||
if (dev->queue_mode == NULL_Q_MQ && nullb->tag_set == &nullb->__tag_set)
|
if (dev->queue_mode == NULL_Q_MQ && nullb->tag_set == &nullb->__tag_set)
|
||||||
blk_mq_free_tag_set(nullb->tag_set);
|
blk_mq_free_tag_set(nullb->tag_set);
|
||||||
|
|
Loading…
Reference in New Issue