Commit 1aabd53a authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

lightnvm: convert to blk_alloc_disk/blk_cleanup_disk

Convert the lightnvm driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
Link: https://lore.kernel.org/r/20210521055116.1053587-12-hch@lst.deSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 7681750b
...@@ -305,7 +305,6 @@ static int __nvm_config_extended(struct nvm_dev *dev, ...@@ -305,7 +305,6 @@ static int __nvm_config_extended(struct nvm_dev *dev,
static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create) static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
{ {
struct nvm_ioctl_create_extended e; struct nvm_ioctl_create_extended e;
struct request_queue *tqueue;
struct gendisk *tdisk; struct gendisk *tdisk;
struct nvm_tgt_type *tt; struct nvm_tgt_type *tt;
struct nvm_target *t; struct nvm_target *t;
...@@ -370,23 +369,16 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create) ...@@ -370,23 +369,16 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
goto err_t; goto err_t;
} }
tdisk = alloc_disk(0); tdisk = blk_alloc_disk(dev->q->node);
if (!tdisk) { if (!tdisk) {
ret = -ENOMEM; ret = -ENOMEM;
goto err_dev; goto err_dev;
} }
tqueue = blk_alloc_queue(dev->q->node);
if (!tqueue) {
ret = -ENOMEM;
goto err_disk;
}
strlcpy(tdisk->disk_name, create->tgtname, sizeof(tdisk->disk_name)); strlcpy(tdisk->disk_name, create->tgtname, sizeof(tdisk->disk_name));
tdisk->major = 0; tdisk->major = 0;
tdisk->first_minor = 0; tdisk->first_minor = 0;
tdisk->fops = tt->bops; tdisk->fops = tt->bops;
tdisk->queue = tqueue;
targetdata = tt->init(tgt_dev, tdisk, create->flags); targetdata = tt->init(tgt_dev, tdisk, create->flags);
if (IS_ERR(targetdata)) { if (IS_ERR(targetdata)) {
...@@ -395,14 +387,14 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create) ...@@ -395,14 +387,14 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
} }
tdisk->private_data = targetdata; tdisk->private_data = targetdata;
tqueue->queuedata = targetdata; tdisk->queue->queuedata = targetdata;
mdts = (dev->geo.csecs >> 9) * NVM_MAX_VLBA; mdts = (dev->geo.csecs >> 9) * NVM_MAX_VLBA;
if (dev->geo.mdts) { if (dev->geo.mdts) {
mdts = min_t(u32, dev->geo.mdts, mdts = min_t(u32, dev->geo.mdts,
(dev->geo.csecs >> 9) * NVM_MAX_VLBA); (dev->geo.csecs >> 9) * NVM_MAX_VLBA);
} }
blk_queue_max_hw_sectors(tqueue, mdts); blk_queue_max_hw_sectors(tdisk->queue, mdts);
set_capacity(tdisk, tt->capacity(targetdata)); set_capacity(tdisk, tt->capacity(targetdata));
add_disk(tdisk); add_disk(tdisk);
...@@ -427,10 +419,7 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create) ...@@ -427,10 +419,7 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
if (tt->exit) if (tt->exit)
tt->exit(targetdata, true); tt->exit(targetdata, true);
err_init: err_init:
blk_cleanup_queue(tqueue); blk_cleanup_disk(tdisk);
tdisk->queue = NULL;
err_disk:
put_disk(tdisk);
err_dev: err_dev:
nvm_remove_tgt_dev(tgt_dev, 0); nvm_remove_tgt_dev(tgt_dev, 0);
err_t: err_t:
...@@ -444,10 +433,8 @@ static void __nvm_remove_target(struct nvm_target *t, bool graceful) ...@@ -444,10 +433,8 @@ static void __nvm_remove_target(struct nvm_target *t, bool graceful)
{ {
struct nvm_tgt_type *tt = t->type; struct nvm_tgt_type *tt = t->type;
struct gendisk *tdisk = t->disk; struct gendisk *tdisk = t->disk;
struct request_queue *q = tdisk->queue;
del_gendisk(tdisk); del_gendisk(tdisk);
blk_cleanup_queue(q);
if (tt->sysfs_exit) if (tt->sysfs_exit)
tt->sysfs_exit(tdisk); tt->sysfs_exit(tdisk);
...@@ -456,7 +443,7 @@ static void __nvm_remove_target(struct nvm_target *t, bool graceful) ...@@ -456,7 +443,7 @@ static void __nvm_remove_target(struct nvm_target *t, bool graceful)
tt->exit(tdisk->private_data, graceful); tt->exit(tdisk->private_data, graceful);
nvm_remove_tgt_dev(t->dev, 1); nvm_remove_tgt_dev(t->dev, 1);
put_disk(tdisk); blk_cleanup_disk(tdisk);
module_put(t->type->owner); module_put(t->type->owner);
list_del(&t->list); list_del(&t->list);
......
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