[PATCH 09/10] nvme/nvme-fabrics: move reset ctrl flow to common code
From: Max Gurtovoy <mgurtovoy@nvidia.com>
Date: 2021-10-20 10:44:02
Subsystem:
nvm express driver, the rest · Maintainers:
Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg, Linus Torvalds
Reset work is duplicated in RDMA and TCP transports. Move this logic to common code. For that, introduce a new ctrl op to teardown a ctrl. Also update the RDMA/TCP transport drivers to use this API and remove the duplicated code. Make nvmf_reconnect_or_remove function static since it's only used inside the fabrics driver now. Signed-off-by: Max Gurtovoy <mgurtovoy@nvidia.com> --- drivers/nvme/host/fabrics.c | 29 +++++++++++++++++++++++-- drivers/nvme/host/fabrics.h | 1 - drivers/nvme/host/nvme.h | 1 + drivers/nvme/host/rdma.c | 43 ++++++++----------------------------- drivers/nvme/host/tcp.c | 27 +---------------------- 5 files changed, 38 insertions(+), 63 deletions(-)
diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
index e50f6b32a286..e13891619de0 100644
--- a/drivers/nvme/host/fabrics.c
+++ b/drivers/nvme/host/fabrics.c@@ -472,7 +472,7 @@ bool nvmf_should_reconnect(struct nvme_ctrl *ctrl) } EXPORT_SYMBOL_GPL(nvmf_should_reconnect); -void nvmf_reconnect_or_remove(struct nvme_ctrl *ctrl) +static void nvmf_reconnect_or_remove(struct nvme_ctrl *ctrl) { /* If we are resetting/deleting then do nothing */ if (ctrl->state != NVME_CTRL_CONNECTING) {
@@ -491,7 +491,6 @@ void nvmf_reconnect_or_remove(struct nvme_ctrl *ctrl) nvme_delete_ctrl(ctrl); } } -EXPORT_SYMBOL_GPL(nvmf_reconnect_or_remove); static void nvmf_error_recovery_work(struct work_struct *work) {
@@ -548,10 +547,36 @@ static void nvmf_reconnect_ctrl_work(struct work_struct *work) nvmf_reconnect_or_remove(ctrl); } +void nvmf_reset_ctrl_work(struct work_struct *work) +{ + struct nvme_ctrl *ctrl = + container_of(work, struct nvme_ctrl, reset_work); + + nvme_stop_ctrl(ctrl); + ctrl->ops->teardown_ctrl(ctrl, false); + + if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_CONNECTING)) { + /* state change failure is ok if we started ctrl delete */ + WARN_ON_ONCE(ctrl->state != NVME_CTRL_DELETING && + ctrl->state != NVME_CTRL_DELETING_NOIO); + return; + } + + if (ctrl->ops->setup_ctrl(ctrl, false)) + goto out_fail; + + return; + +out_fail: + ++ctrl->nr_reconnects; + nvmf_reconnect_or_remove(ctrl); +} + void nvmf_init_ctrl(struct nvme_ctrl *ctrl) { INIT_DELAYED_WORK(&ctrl->connect_work, nvmf_reconnect_ctrl_work); INIT_WORK(&ctrl->err_work, nvmf_error_recovery_work); + INIT_WORK(&ctrl->reset_work, nvmf_reset_ctrl_work); } EXPORT_SYMBOL_GPL(nvmf_init_ctrl);
diff --git a/drivers/nvme/host/fabrics.h b/drivers/nvme/host/fabrics.h
index 06933e7a4ff4..ca405ecf90dc 100644
--- a/drivers/nvme/host/fabrics.h
+++ b/drivers/nvme/host/fabrics.h@@ -188,7 +188,6 @@ void nvmf_unregister_transport(struct nvmf_transport_ops *ops); void nvmf_free_options(struct nvmf_ctrl_options *opts); int nvmf_get_address(struct nvme_ctrl *ctrl, char *buf, int size); bool nvmf_should_reconnect(struct nvme_ctrl *ctrl); -void nvmf_reconnect_or_remove(struct nvme_ctrl *ctrl); void nvmf_error_recovery(struct nvme_ctrl *ctrl); void nvmf_init_ctrl(struct nvme_ctrl *ctrl); void nvmf_uninit_ctrl(struct nvme_ctrl *ctrl);
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index e137db2760d8..c654da7e45c4 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h@@ -498,6 +498,7 @@ struct nvme_ctrl_ops { void (*teardown_ctrl_io_queues)(struct nvme_ctrl *ctrl, bool remove); void (*teardown_ctrl_admin_queue)(struct nvme_ctrl *ctrl, bool remove); int (*setup_ctrl)(struct nvme_ctrl *ctrl, bool new); + void (*teardown_ctrl)(struct nvme_ctrl *ctrl, bool shutdown); }; /*
diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c
index f4eeafee05e5..c49ad0b3ffdf 100644
--- a/drivers/nvme/host/rdma.c
+++ b/drivers/nvme/host/rdma.c@@ -2157,46 +2157,21 @@ static const struct blk_mq_ops nvme_rdma_admin_mq_ops = { .timeout = nvme_rdma_timeout, }; -static void nvme_rdma_shutdown_ctrl(struct nvme_rdma_ctrl *ctrl, bool shutdown) +static void nvme_rdma_teardown_ctrl(struct nvme_ctrl *nctrl, bool shutdown) { - nvmf_uninit_ctrl(&ctrl->ctrl); - nvme_rdma_teardown_io_queues(&ctrl->ctrl, shutdown); - blk_mq_quiesce_queue(ctrl->ctrl.admin_q); + nvmf_uninit_ctrl(nctrl); + nvme_rdma_teardown_io_queues(nctrl, shutdown); + blk_mq_quiesce_queue(nctrl->admin_q); if (shutdown) - nvme_shutdown_ctrl(&ctrl->ctrl); + nvme_shutdown_ctrl(nctrl); else - nvme_disable_ctrl(&ctrl->ctrl); - nvme_rdma_teardown_admin_queue(&ctrl->ctrl, shutdown); + nvme_disable_ctrl(nctrl); + nvme_rdma_teardown_admin_queue(nctrl, shutdown); } static void nvme_rdma_delete_ctrl(struct nvme_ctrl *ctrl) { - nvme_rdma_shutdown_ctrl(to_rdma_ctrl(ctrl), true); -} - -static void nvme_rdma_reset_ctrl_work(struct work_struct *work) -{ - struct nvme_rdma_ctrl *ctrl = - container_of(work, struct nvme_rdma_ctrl, ctrl.reset_work); - - nvme_stop_ctrl(&ctrl->ctrl); - nvme_rdma_shutdown_ctrl(ctrl, false); - - if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_CONNECTING)) { - /* state change failure is ok if we started ctrl delete */ - WARN_ON_ONCE(ctrl->ctrl.state != NVME_CTRL_DELETING && - ctrl->ctrl.state != NVME_CTRL_DELETING_NOIO); - return; - } - - if (nvme_rdma_setup_ctrl(&ctrl->ctrl, false)) - goto out_fail; - - return; - -out_fail: - ++ctrl->ctrl.nr_reconnects; - nvmf_reconnect_or_remove(&ctrl->ctrl); + nvme_rdma_teardown_ctrl(ctrl, true); } static const struct nvme_ctrl_ops nvme_rdma_ctrl_ops = {
@@ -2214,6 +2189,7 @@ static const struct nvme_ctrl_ops nvme_rdma_ctrl_ops = { .teardown_ctrl_io_queues = nvme_rdma_teardown_io_queues, .teardown_ctrl_admin_queue = nvme_rdma_teardown_admin_queue, .setup_ctrl = nvme_rdma_setup_ctrl, + .teardown_ctrl = nvme_rdma_teardown_ctrl, }; /*
@@ -2292,7 +2268,6 @@ static struct nvme_ctrl *nvme_rdma_create_ctrl(struct device *dev, } nvmf_init_ctrl(&ctrl->ctrl); - INIT_WORK(&ctrl->ctrl.reset_work, nvme_rdma_reset_ctrl_work); ctrl->ctrl.queue_count = opts->nr_io_queues + opts->nr_write_queues + opts->nr_poll_queues + 1;
diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
index 7f50b423388f..e65bdd0db4d5 100644
--- a/drivers/nvme/host/tcp.c
+++ b/drivers/nvme/host/tcp.c@@ -2049,31 +2049,6 @@ static void nvme_tcp_delete_ctrl(struct nvme_ctrl *ctrl) nvme_tcp_teardown_ctrl(ctrl, true); } -static void nvme_reset_ctrl_work(struct work_struct *work) -{ - struct nvme_ctrl *ctrl = - container_of(work, struct nvme_ctrl, reset_work); - - nvme_stop_ctrl(ctrl); - nvme_tcp_teardown_ctrl(ctrl, false); - - if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_CONNECTING)) { - /* state change failure is ok if we started ctrl delete */ - WARN_ON_ONCE(ctrl->state != NVME_CTRL_DELETING && - ctrl->state != NVME_CTRL_DELETING_NOIO); - return; - } - - if (nvme_tcp_setup_ctrl(ctrl, false)) - goto out_fail; - - return; - -out_fail: - ++ctrl->nr_reconnects; - nvmf_reconnect_or_remove(ctrl); -} - static void nvme_tcp_free_ctrl(struct nvme_ctrl *nctrl) { struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(nctrl);
@@ -2400,6 +2375,7 @@ static const struct nvme_ctrl_ops nvme_tcp_ctrl_ops = { .teardown_ctrl_io_queues = nvme_tcp_teardown_io_queues, .teardown_ctrl_admin_queue = nvme_tcp_teardown_admin_queue, .setup_ctrl = nvme_tcp_setup_ctrl, + .teardown_ctrl = nvme_tcp_teardown_ctrl, }; static bool
@@ -2437,7 +2413,6 @@ static struct nvme_ctrl *nvme_tcp_create_ctrl(struct device *dev, ctrl->ctrl.kato = opts->kato; nvmf_init_ctrl(&ctrl->ctrl); - INIT_WORK(&ctrl->ctrl.reset_work, nvme_reset_ctrl_work); if (!(opts->mask & NVMF_OPT_TRSVCID)) { opts->trsvcid =
--
2.18.1