2
0
mirror of https://github.com/edk2-porting/linux-next.git synced 2024-11-28 04:24:34 +08:00

nvme-multipath: convert to blk_alloc_disk/blk_cleanup_disk

Convert the nvme-multipath driver to use the blk_alloc_disk and
blk_cleanup_disk helpers to simplify gendisk and request_queue
allocation.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
Link: https://lore.kernel.org/r/20210521055116.1053587-19-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Christoph Hellwig 2021-05-21 07:51:08 +02:00 committed by Jens Axboe
parent 87eb73b2ca
commit f165fb89b7
2 changed files with 14 additions and 34 deletions

View File

@ -472,7 +472,6 @@ static int pmem_attach_disk(struct device *dev,
blk_queue_flag_set(QUEUE_FLAG_DAX, q); blk_queue_flag_set(QUEUE_FLAG_DAX, q);
disk->fops = &pmem_fops; disk->fops = &pmem_fops;
disk->queue = q;
disk->private_data = pmem; disk->private_data = pmem;
nvdimm_namespace_disk_name(ndns, disk->disk_name); nvdimm_namespace_disk_name(ndns, disk->disk_name);
set_capacity(disk, (pmem->size - pmem->pfn_pad - pmem->data_offset) set_capacity(disk, (pmem->size - pmem->pfn_pad - pmem->data_offset)

View File

@ -427,7 +427,6 @@ static void nvme_requeue_work(struct work_struct *work)
int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl, struct nvme_ns_head *head) int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl, struct nvme_ns_head *head)
{ {
struct request_queue *q;
bool vwc = false; bool vwc = false;
mutex_init(&head->lock); mutex_init(&head->lock);
@ -443,33 +442,24 @@ int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl, struct nvme_ns_head *head)
if (!(ctrl->subsys->cmic & NVME_CTRL_CMIC_MULTI_CTRL) || !multipath) if (!(ctrl->subsys->cmic & NVME_CTRL_CMIC_MULTI_CTRL) || !multipath)
return 0; return 0;
q = blk_alloc_queue(ctrl->numa_node); head->disk = blk_alloc_disk(ctrl->numa_node);
if (!q) if (!head->disk)
goto out; return -ENOMEM;
blk_queue_flag_set(QUEUE_FLAG_NONROT, q); head->disk->fops = &nvme_ns_head_ops;
/* set to a default value for 512 until disk is validated */ head->disk->private_data = head;
blk_queue_logical_block_size(q, 512); sprintf(head->disk->disk_name, "nvme%dn%d",
blk_set_stacking_limits(&q->limits); ctrl->subsys->instance, head->instance);
blk_queue_flag_set(QUEUE_FLAG_NONROT, head->disk->queue);
/* set to a default value of 512 until the disk is validated */
blk_queue_logical_block_size(head->disk->queue, 512);
blk_set_stacking_limits(&head->disk->queue->limits);
/* we need to propagate up the VMC settings */ /* we need to propagate up the VMC settings */
if (ctrl->vwc & NVME_CTRL_VWC_PRESENT) if (ctrl->vwc & NVME_CTRL_VWC_PRESENT)
vwc = true; vwc = true;
blk_queue_write_cache(q, vwc, vwc); blk_queue_write_cache(head->disk->queue, vwc, vwc);
head->disk = alloc_disk(0);
if (!head->disk)
goto out_cleanup_queue;
head->disk->fops = &nvme_ns_head_ops;
head->disk->private_data = head;
head->disk->queue = q;
sprintf(head->disk->disk_name, "nvme%dn%d",
ctrl->subsys->instance, head->instance);
return 0; return 0;
out_cleanup_queue:
blk_cleanup_queue(q);
out:
return -ENOMEM;
} }
static void nvme_mpath_set_live(struct nvme_ns *ns) static void nvme_mpath_set_live(struct nvme_ns *ns)
@ -768,16 +758,7 @@ void nvme_mpath_remove_disk(struct nvme_ns_head *head)
/* make sure all pending bios are cleaned up */ /* make sure all pending bios are cleaned up */
kblockd_schedule_work(&head->requeue_work); kblockd_schedule_work(&head->requeue_work);
flush_work(&head->requeue_work); flush_work(&head->requeue_work);
blk_cleanup_queue(head->disk->queue); blk_cleanup_disk(head->disk);
if (!test_bit(NVME_NSHEAD_DISK_LIVE, &head->flags)) {
/*
* if device_add_disk wasn't called, prevent
* disk release to put a bogus reference on the
* request queue
*/
head->disk->queue = NULL;
}
put_disk(head->disk);
} }
void nvme_mpath_init_ctrl(struct nvme_ctrl *ctrl) void nvme_mpath_init_ctrl(struct nvme_ctrl *ctrl)