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

scm_blk: 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>
Tested-by: default avatarNiklas Schnelle <schnelle@linux.ibm.com>
Reviewed-by: default avatarChaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Link: https://lore.kernel.org/r/20210602065345.355274-28-hch@lst.deSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 77567b25
...@@ -462,12 +462,12 @@ int scm_blk_dev_setup(struct scm_blk_dev *bdev, struct scm_device *scmdev) ...@@ -462,12 +462,12 @@ int scm_blk_dev_setup(struct scm_blk_dev *bdev, struct scm_device *scmdev)
if (ret) if (ret)
goto out; goto out;
rq = blk_mq_init_queue(&bdev->tag_set); bdev->gendisk = blk_mq_alloc_disk(&bdev->tag_set, scmdev);
if (IS_ERR(rq)) { if (IS_ERR(bdev->gendisk)) {
ret = PTR_ERR(rq); ret = PTR_ERR(bdev->gendisk);
goto out_tag; goto out_tag;
} }
bdev->rq = rq; rq = bdev->rq = bdev->gendisk->queue;
nr_max_blk = min(scmdev->nr_max_block, nr_max_blk = min(scmdev->nr_max_block,
(unsigned int) (PAGE_SIZE / sizeof(struct aidaw))); (unsigned int) (PAGE_SIZE / sizeof(struct aidaw)));
...@@ -477,17 +477,11 @@ int scm_blk_dev_setup(struct scm_blk_dev *bdev, struct scm_device *scmdev) ...@@ -477,17 +477,11 @@ int scm_blk_dev_setup(struct scm_blk_dev *bdev, struct scm_device *scmdev)
blk_queue_flag_set(QUEUE_FLAG_NONROT, rq); blk_queue_flag_set(QUEUE_FLAG_NONROT, rq);
blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, rq); blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, rq);
bdev->gendisk = alloc_disk(SCM_NR_PARTS);
if (!bdev->gendisk) {
ret = -ENOMEM;
goto out_queue;
}
rq->queuedata = scmdev;
bdev->gendisk->private_data = scmdev; bdev->gendisk->private_data = scmdev;
bdev->gendisk->fops = &scm_blk_devops; bdev->gendisk->fops = &scm_blk_devops;
bdev->gendisk->queue = rq;
bdev->gendisk->major = scm_major; bdev->gendisk->major = scm_major;
bdev->gendisk->first_minor = devindex * SCM_NR_PARTS; bdev->gendisk->first_minor = devindex * SCM_NR_PARTS;
bdev->gendisk->minors = SCM_NR_PARTS;
len = snprintf(bdev->gendisk->disk_name, DISK_NAME_LEN, "scm"); len = snprintf(bdev->gendisk->disk_name, DISK_NAME_LEN, "scm");
if (devindex > 25) { if (devindex > 25) {
...@@ -504,8 +498,6 @@ int scm_blk_dev_setup(struct scm_blk_dev *bdev, struct scm_device *scmdev) ...@@ -504,8 +498,6 @@ int scm_blk_dev_setup(struct scm_blk_dev *bdev, struct scm_device *scmdev)
device_add_disk(&scmdev->dev, bdev->gendisk, NULL); device_add_disk(&scmdev->dev, bdev->gendisk, NULL);
return 0; return 0;
out_queue:
blk_cleanup_queue(rq);
out_tag: out_tag:
blk_mq_free_tag_set(&bdev->tag_set); blk_mq_free_tag_set(&bdev->tag_set);
out: out:
...@@ -516,9 +508,8 @@ int scm_blk_dev_setup(struct scm_blk_dev *bdev, struct scm_device *scmdev) ...@@ -516,9 +508,8 @@ int scm_blk_dev_setup(struct scm_blk_dev *bdev, struct scm_device *scmdev)
void scm_blk_dev_cleanup(struct scm_blk_dev *bdev) void scm_blk_dev_cleanup(struct scm_blk_dev *bdev)
{ {
del_gendisk(bdev->gendisk); del_gendisk(bdev->gendisk);
blk_cleanup_queue(bdev->gendisk->queue); blk_cleanup_disk(bdev->gendisk);
blk_mq_free_tag_set(&bdev->tag_set); blk_mq_free_tag_set(&bdev->tag_set);
put_disk(bdev->gendisk);
} }
void scm_blk_set_available(struct scm_blk_dev *bdev) void scm_blk_set_available(struct scm_blk_dev *bdev)
......
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