Commit 4af5f2e0 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

nbd: use blk_mq_alloc_disk and blk_cleanup_disk

Use blk_mq_alloc_disk and blk_cleanup_disk to simplify the gendisk and
request_queue allocation.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarChaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Link: https://lore.kernel.org/r/20210602065345.355274-20-hch@lst.deSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 1c99502f
...@@ -219,15 +219,11 @@ static const struct device_attribute pid_attr = { ...@@ -219,15 +219,11 @@ static const struct device_attribute pid_attr = {
static void nbd_dev_remove(struct nbd_device *nbd) static void nbd_dev_remove(struct nbd_device *nbd)
{ {
struct gendisk *disk = nbd->disk; struct gendisk *disk = nbd->disk;
struct request_queue *q;
if (disk) { if (disk) {
q = disk->queue;
del_gendisk(disk); del_gendisk(disk);
blk_cleanup_queue(q);
blk_mq_free_tag_set(&nbd->tag_set); blk_mq_free_tag_set(&nbd->tag_set);
disk->private_data = NULL; blk_cleanup_disk(disk);
put_disk(disk);
} }
/* /*
...@@ -1646,15 +1642,24 @@ static int nbd_dev_add(int index) ...@@ -1646,15 +1642,24 @@ static int nbd_dev_add(int index)
{ {
struct nbd_device *nbd; struct nbd_device *nbd;
struct gendisk *disk; struct gendisk *disk;
struct request_queue *q;
int err = -ENOMEM; int err = -ENOMEM;
nbd = kzalloc(sizeof(struct nbd_device), GFP_KERNEL); nbd = kzalloc(sizeof(struct nbd_device), GFP_KERNEL);
if (!nbd) if (!nbd)
goto out; goto out;
disk = alloc_disk(1 << part_shift); nbd->tag_set.ops = &nbd_mq_ops;
if (!disk) nbd->tag_set.nr_hw_queues = 1;
nbd->tag_set.queue_depth = 128;
nbd->tag_set.numa_node = NUMA_NO_NODE;
nbd->tag_set.cmd_size = sizeof(struct nbd_cmd);
nbd->tag_set.flags = BLK_MQ_F_SHOULD_MERGE |
BLK_MQ_F_BLOCKING;
nbd->tag_set.driver_data = nbd;
nbd->destroy_complete = NULL;
err = blk_mq_alloc_tag_set(&nbd->tag_set);
if (err)
goto out_free_nbd; goto out_free_nbd;
if (index >= 0) { if (index >= 0) {
...@@ -1668,30 +1673,15 @@ static int nbd_dev_add(int index) ...@@ -1668,30 +1673,15 @@ static int nbd_dev_add(int index)
index = err; index = err;
} }
if (err < 0) if (err < 0)
goto out_free_disk; goto out_free_tags;
nbd->index = index; nbd->index = index;
nbd->disk = disk;
nbd->tag_set.ops = &nbd_mq_ops;
nbd->tag_set.nr_hw_queues = 1;
nbd->tag_set.queue_depth = 128;
nbd->tag_set.numa_node = NUMA_NO_NODE;
nbd->tag_set.cmd_size = sizeof(struct nbd_cmd);
nbd->tag_set.flags = BLK_MQ_F_SHOULD_MERGE |
BLK_MQ_F_BLOCKING;
nbd->tag_set.driver_data = nbd;
nbd->destroy_complete = NULL;
err = blk_mq_alloc_tag_set(&nbd->tag_set); disk = blk_mq_alloc_disk(&nbd->tag_set, NULL);
if (err) if (IS_ERR(disk)) {
err = PTR_ERR(disk);
goto out_free_idr; goto out_free_idr;
q = blk_mq_init_queue(&nbd->tag_set);
if (IS_ERR(q)) {
err = PTR_ERR(q);
goto out_free_tags;
} }
disk->queue = q; nbd->disk = disk;
/* /*
* Tell the block layer that we are not a rotational device * Tell the block layer that we are not a rotational device
...@@ -1712,6 +1702,7 @@ static int nbd_dev_add(int index) ...@@ -1712,6 +1702,7 @@ static int nbd_dev_add(int index)
INIT_LIST_HEAD(&nbd->list); INIT_LIST_HEAD(&nbd->list);
disk->major = NBD_MAJOR; disk->major = NBD_MAJOR;
disk->first_minor = index << part_shift; disk->first_minor = index << part_shift;
disk->minors = 1 << part_shift;
disk->fops = &nbd_fops; disk->fops = &nbd_fops;
disk->private_data = nbd; disk->private_data = nbd;
sprintf(disk->disk_name, "nbd%d", index); sprintf(disk->disk_name, "nbd%d", index);
...@@ -1719,12 +1710,10 @@ static int nbd_dev_add(int index) ...@@ -1719,12 +1710,10 @@ static int nbd_dev_add(int index)
nbd_total_devices++; nbd_total_devices++;
return index; return index;
out_free_tags:
blk_mq_free_tag_set(&nbd->tag_set);
out_free_idr: out_free_idr:
idr_remove(&nbd_index_idr, index); idr_remove(&nbd_index_idr, index);
out_free_disk: out_free_tags:
put_disk(disk); blk_mq_free_tag_set(&nbd->tag_set);
out_free_nbd: out_free_nbd:
kfree(nbd); kfree(nbd);
out: out:
......
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