controller deletion consolidation
Subsystems (3)
Christoph Hellwig
maintainerHi all,
this series consolidates a lot of the boilerplate code in controller deletion. I did this when applying the FC patches that finally made it look exactly like RDMA.
This will probably conflict a bit with Sagis consolidation series, but in the end should make it easier.
Two notes:
- do we need the cancellation of reset_work in FC? If so we probably want it in RDMA and loop as well.
- should RDMA really queue delete_work manually in nvme_rdma_reconnect_or_remove instead of going through the state machine? That seems like a bug to me.
Christoph Hellwig
maintainerPATCH 1/5 nvme-fc: avoid workqueue flush stalls
From: James Smart <[email protected]>
There's no need to wait for the full nvme_wq, which is now shared, to flush. flush only the delete_work item.
--- drivers/nvme/host/fc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/host/fc.c +1 -1
@@ -2693,7 +2693,7 @@ nvme_fc_del_nvme_ctrl(struct nvme_ctrl *nctrl)nvme_get_ctrl (&ctrl->ctrl); ret =__nvme_fc_del_ctrl (ctrl);if (!ret) -flush_workqueue (nvme_wq); +flush_work (&ctrl->delete_work);nvme_put_ctrl (&ctrl->ctrl);return ret;
Signature · 1 line
2.14.2
Christoph Hellwig
maintainerPATCH 2/5 nvme-fc: merge __nvme_fc_schedule_delete_work into __nvme_fc_del_ctrl
In reply to Christoph HellwigNo need to have two functions doing the same thing.
--- drivers/nvme/host/fc.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-)
drivers/nvme/host/fc.c +6 -14
@@ -2663,22 +2663,14 @@ nvme_fc_delete_ctrl_work(struct work_struct *work)nvme_put_ctrl (&ctrl->ctrl); } -static bool -__nvme_fc_schedule_delete_work (struct nvme_fc_ctrl *ctrl) -{ -if (!nvme_change_ctrl_state (&ctrl->ctrl,NVME_CTRL_DELETING )) -return true; - -if (!queue_work (nvme_wq, &ctrl->delete_work)) -return true; - -return false; -} -static int __nvme_fc_del_ctrl (struct nvme_fc_ctrl *ctrl) { -return __nvme_fc_schedule_delete_work (ctrl) ? -EBUSY :0 ; +if (!nvme_change_ctrl_state (&ctrl->ctrl,NVME_CTRL_DELETING )) +return -EBUSY ; +if (!queue_work (nvme_wq, &ctrl->delete_work)) +return -EBUSY ; +return 0 ; }/*
@@ -2724,7 +2716,7 @@ nvme_fc_reconnect_or_delete(struct nvme_fc_ctrl *ctrl, int status)"NVME-FC{%d}: Max reconnect attempts (%d) " "reached. Removing controller\n" , ctrl->cnum, ctrl->ctrl.nr_reconnects); -WARN_ON (__nvme_fc_schedule_delete_work (ctrl)); +WARN_ON (__nvme_fc_del_ctrl (ctrl)); } }
Signature · 1 line
2.14.2
PATCH 2/5 nvme-fc: merge __nvme_fc_schedule_delete_work into __nvme_fc_del_ctrl
Quoted 8 lines · Christoph Hellwig
No need to have two functions doing the same thing.
Signed-off-by Christoph Hellwig <hch at lst.de>--- drivers/nvme/host/fc.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-)
Looks fine.
Christoph Hellwig
maintainerPATCH 3/5 nvme: move controller deletion to common code
In reply to Christoph HellwigMove the ->delete_work and the associated helpers to common code instead of duplicating them in every driver. This also adds the missing reference get/put for the loop driver.
--- drivers/nvme/host/core.c | 38 ++++++++++++++++++++++++++++++++++- drivers/nvme/host/fabrics.c | 2 +- drivers/nvme/host/fc.c | 42 +++++---------------------------------- drivers/nvme/host/nvme.h | 5 ++++- drivers/nvme/host/rdma.c | 45 ++++++------------------------------------ drivers/nvme/target/loop.c | 48 +++++++++------------------------------------ 6 files changed, 62 insertions(+), 118 deletions(-)
drivers/nvme/host/core.c +37 -1
@@ -97,6 +97,41 @@ static int nvme_reset_ctrl_sync(struct nvme_ctrl *ctrl)return ret; } +static void nvme_delete_ctrl_work (struct work_struct *work) +{ +struct nvme_ctrl *ctrl = + container_of(work, struct nvme_ctrl, delete_work); + + ctrl->ops->delete_ctrl (ctrl); +} + +int nvme_delete_ctrl (struct nvme_ctrl *ctrl) +{ +if (!nvme_change_ctrl_state (ctrl,NVME_CTRL_DELETING )) +return -EBUSY ; +if (!queue_work (nvme_wq, &ctrl->delete_work)) +return -EBUSY ; +return 0 ; +} +EXPORT_SYMBOL_GPL (nvme_delete_ctrl); + +int nvme_delete_ctrl_sync (struct nvme_ctrl *ctrl) +{ +int ret =0 ; + +/* +* Keep a reference until the work is flushed since ->delete_ctrl +* can free the controller. +*/ +nvme_get_ctrl (ctrl); + ret =nvme_delete_ctrl (ctrl); +if (!ret) +flush_work (&ctrl->delete_work); +nvme_put_ctrl (ctrl); +return ret; +} +EXPORT_SYMBOL_GPL (nvme_delete_ctrl_sync); +static blk_status_t nvme_error_status (struct request *req) {switch (nvme_req (req)->status &0x7ff ) {
@@ -2122,7 +2157,7 @@ static ssize_t nvme_sysfs_delete(struct device *dev,struct nvme_ctrl *ctrl =dev_get_drvdata (dev);if (device_remove_file_self (dev, attr)) - ctrl->ops->delete_ctrl (ctrl); +nvme_delete_ctrl_sync (ctrl);return count; } static DEVICE_ATTR(delete_controller, S_IWUSR, NULL, nvme_sysfs_delete);
@@ -2702,6 +2737,7 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,INIT_WORK (&ctrl->scan_work, nvme_scan_work);INIT_WORK (&ctrl->async_event_work, nvme_async_event_work);INIT_WORK (&ctrl->fw_act_work, nvme_fw_act_work); +INIT_WORK (&ctrl->delete_work, nvme_delete_ctrl_work); ret =ida_simple_get (&nvme_instance_ida,0 ,0 ,GFP_KERNEL );if (ret <0 )
drivers/nvme/host/fabrics.c +1 -1
@@ -887,7 +887,7 @@ nvmf_create_ctrl(struct device *dev, const char *buf, size_t count)"controller returned incorrect NQN: \"%s\".\n" , ctrl->subnqn);up_read (&nvmf_transports_rwsem); - ctrl->ops->delete_ctrl (ctrl); +nvme_delete_ctrl_sync (ctrl);return ERR_PTR (-EINVAL ); }
drivers/nvme/host/fc.c +5 -37
91 lines not on this page · raw message
drivers/nvme/host/nvme.h +4 -1
@@ -138,6 +138,7 @@ struct nvme_ctrl {struct cdev cdev;struct ida ns_ida;struct work_struct reset_work; +struct work_struct delete_work;struct opal_dev *opal_dev;
@@ -236,7 +237,7 @@ struct nvme_ctrl_ops {int (*reg_read64)(struct nvme_ctrl *ctrl,u32 off,u64 *val);void (*free_ctrl)(struct nvme_ctrl *ctrl);void (*submit_async_event)(struct nvme_ctrl *ctrl,int aer_idx); -int (*delete_ctrl)(struct nvme_ctrl *ctrl); +void (*delete_ctrl)(struct nvme_ctrl *ctrl);int (*get_address)(struct nvme_ctrl *ctrl,char *buf,int size);int (*reinit_request)(void *data,struct request *rq); };
@@ -339,6 +340,8 @@ int nvme_set_queue_count(struct nvme_ctrl *ctrl, int *count);void nvme_start_keep_alive (struct nvme_ctrl *ctrl);void nvme_stop_keep_alive (struct nvme_ctrl *ctrl);int nvme_reset_ctrl (struct nvme_ctrl *ctrl); +int nvme_delete_ctrl (struct nvme_ctrl *ctrl); +int nvme_delete_ctrl_sync (struct nvme_ctrl *ctrl);#ifdef CONFIG_NVM int nvme_nvm_register (struct nvme_ns *ns,char *disk_name,int node);
drivers/nvme/host/rdma.c +6 -39
82 lines not on this page · raw message
drivers/nvme/target/loop.c +9 -39
85 lines not on this page · raw message
Signature · 1 line
2.14.2
PATCH 3/5 nvme: move controller deletion to common code
Quoted 7 lines · Christoph Hellwig
Move the ->delete_work and the associated helpers to common code instead of duplicating them in every driver. This also adds the missing reference get/put for the loop driver.
Signed-off-by Christoph Hellwig <hch at lst.de>---
Looks fine.
Christoph Hellwig
maintainerPATCH 4/5 nvme-rdma: remove nvme_rdma_remove_ctrl
In reply to Christoph HellwigIt is only used in two places, and some of the work done by it will be taken into common code soon.
--- drivers/nvme/host/rdma.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
drivers/nvme/host/rdma.c +8 -10
@@ -1755,18 +1755,13 @@ static void nvme_rdma_shutdown_ctrl(struct nvme_rdma_ctrl *ctrl, bool shutdown)nvme_rdma_destroy_admin_queue (ctrl, shutdown); } -static void nvme_rdma_remove_ctrl (struct nvme_rdma_ctrl *ctrl) -{ -nvme_remove_namespaces (&ctrl->ctrl); -nvme_rdma_shutdown_ctrl (ctrl, true); -nvme_uninit_ctrl (&ctrl->ctrl); -nvme_put_ctrl (&ctrl->ctrl); -} -static void nvme_rdma_delete_ctrl (struct nvme_ctrl *ctrl) {nvme_stop_ctrl (ctrl); -nvme_rdma_remove_ctrl (to_rdma_ctrl (ctrl)); +nvme_remove_namespaces (ctrl); +nvme_rdma_shutdown_ctrl (to_rdma_ctrl (ctrl), true); +nvme_uninit_ctrl (ctrl); +nvme_put_ctrl (ctrl); }static void nvme_rdma_reset_ctrl_work (struct work_struct *work)
@@ -1802,7 +1797,10 @@ static void nvme_rdma_reset_ctrl_work(struct work_struct *work) out_fail:dev_warn (ctrl->ctrl.device,"Removing after reset failure\n" ); -nvme_rdma_remove_ctrl (ctrl); +nvme_remove_namespaces (&ctrl->ctrl); +nvme_rdma_shutdown_ctrl (ctrl, true); +nvme_uninit_ctrl (&ctrl->ctrl); +nvme_put_ctrl (&ctrl->ctrl); }static const struct nvme_ctrl_ops nvme_rdma_ctrl_ops = {
Signature · 1 line
2.14.2
Christoph Hellwig
maintainerPATCH 5/5 nvme: consolidate common code from ->reset_work
In reply to Christoph HellwigNo change in behavior except that the FC code cancels two work items a little later now.
--- drivers/nvme/host/core.c | 4 ++++ drivers/nvme/host/fc.c | 13 ------------- drivers/nvme/host/rdma.c | 4 ---- drivers/nvme/target/loop.c | 4 ---- 4 files changed, 4 insertions(+), 21 deletions(-)
drivers/nvme/host/core.c +4 -0
@@ -102,7 +102,11 @@ static void nvme_delete_ctrl_work(struct work_struct *work)struct nvme_ctrl *ctrl = container_of(work, struct nvme_ctrl, delete_work); +nvme_stop_ctrl (ctrl); +nvme_remove_namespaces (ctrl); ctrl->ops->delete_ctrl (ctrl); +nvme_uninit_ctrl (ctrl); +nvme_put_ctrl (ctrl); }int nvme_delete_ctrl (struct nvme_ctrl *ctrl)
drivers/nvme/host/fc.c +0 -13
@@ -2640,24 +2640,11 @@ nvme_fc_delete_ctrl(struct nvme_ctrl *nctrl)cancel_work_sync (&ctrl->ctrl.reset_work);cancel_delayed_work_sync (&ctrl->connect_work); -nvme_stop_ctrl (&ctrl->ctrl); -nvme_remove_namespaces (&ctrl->ctrl);/* * kill the association on the link side. this will block * waiting for io to terminate */ nvme_fc_delete_association (ctrl); - -/* -* tear down the controller -* After the last reference on the nvme ctrl is removed, -* the transport nvme_fc_nvme_ctrl_freed() callback will be -* invoked. From there, the transport will tear down it's -* logical queues and association. -*/ -nvme_uninit_ctrl (&ctrl->ctrl); - -nvme_put_ctrl (&ctrl->ctrl); } static void
drivers/nvme/host/rdma.c +0 -4
@@ -1757,11 +1757,7 @@ static void nvme_rdma_shutdown_ctrl(struct nvme_rdma_ctrl *ctrl, bool shutdown)static void nvme_rdma_delete_ctrl (struct nvme_ctrl *ctrl) { -nvme_stop_ctrl (ctrl); -nvme_remove_namespaces (ctrl);nvme_rdma_shutdown_ctrl (to_rdma_ctrl (ctrl), true); -nvme_uninit_ctrl (ctrl); -nvme_put_ctrl (ctrl); }static void nvme_rdma_reset_ctrl_work (struct work_struct *work)
drivers/nvme/target/loop.c +0 -4
@@ -440,11 +440,7 @@ static void nvme_loop_shutdown_ctrl(struct nvme_loop_ctrl *ctrl)static void nvme_loop_delete_ctrl_host (struct nvme_ctrl *ctrl) { -nvme_stop_ctrl (ctrl); -nvme_remove_namespaces (ctrl);nvme_loop_shutdown_ctrl (to_loop_ctrl (ctrl)); -nvme_uninit_ctrl (ctrl); -nvme_put_ctrl (ctrl); }static void nvme_loop_delete_ctrl (struct nvmet_ctrl *nctrl)
Signature · 1 line
2.14.2
PATCH 5/5 nvme: consolidate common code from ->reset_work
Quoted 6 lines · Christoph Hellwig
No change in behavior except that the FC code cancels two work items a little later now.
Signed-off-by Christoph Hellwig <hch at lst.de>---
Looks fine.
Sagi Grimberg
maintainerQuoted 9 lines
Hi all,
this series consolidates a lot of the boilerplate code in controller deletion. I did this when applying the FC patches that finally made it look exactly like RDMA.
This will probably conflict a bit with Sagis consolidation series, but in the end should make it easier.
Definitely a step in the right direction. Looks good.
Quoted 4 lines
Two notes:
- do we need the cancellation of
reset_workin FC? If so we probably want it in RDMA and loop as well.
We probably do.
Quoted 4 lines
- should RDMA really queue
delete_workmanually innvme_rdma_reconnect_or_removeinstead of going through the state machine? That seems like a bug to me.
I had this fix from the centralization patches, I can easily extract it out and send it asap.