[PATCH 10/10] nvme-fabrics: set common attributes during nvmf_init_ctrl

Max Gurtovoy mgurtovoy at nvidia.com
Wed Oct 20 03:38:44 PDT 2021


Move common logic for setting opts, queue_count, sqsize and kato from
RDMA/TCP drivers to the fabrics driver.

Signed-off-by: Max Gurtovoy <mgurtovoy at nvidia.com>
---
 drivers/nvme/host/fabrics.c |  8 +++++++-
 drivers/nvme/host/fabrics.h |  2 +-
 drivers/nvme/host/rdma.c    | 10 ++--------
 drivers/nvme/host/tcp.c     |  8 +-------
 4 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
index e13891619de0..335fef227baf 100644
--- a/drivers/nvme/host/fabrics.c
+++ b/drivers/nvme/host/fabrics.c
@@ -572,8 +572,14 @@ void nvmf_reset_ctrl_work(struct work_struct *work)
 	nvmf_reconnect_or_remove(ctrl);
 }
 
-void nvmf_init_ctrl(struct nvme_ctrl *ctrl)
+void nvmf_init_ctrl(struct nvme_ctrl *ctrl, struct nvmf_ctrl_options *opts)
 {
+	ctrl->opts = opts;
+	ctrl->queue_count = opts->nr_io_queues + opts->nr_write_queues +
+			    opts->nr_poll_queues + 1;
+	ctrl->sqsize = opts->queue_size - 1;
+	ctrl->kato = opts->kato;
+
 	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);
diff --git a/drivers/nvme/host/fabrics.h b/drivers/nvme/host/fabrics.h
index ca405ecf90dc..0a694fd3b01e 100644
--- a/drivers/nvme/host/fabrics.h
+++ b/drivers/nvme/host/fabrics.h
@@ -189,7 +189,7 @@ 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_error_recovery(struct nvme_ctrl *ctrl);
-void nvmf_init_ctrl(struct nvme_ctrl *ctrl);
+void nvmf_init_ctrl(struct nvme_ctrl *ctrl, struct nvmf_ctrl_options *opts);
 void nvmf_uninit_ctrl(struct nvme_ctrl *ctrl);
 bool nvmf_ip_options_match(struct nvme_ctrl *ctrl,
 		struct nvmf_ctrl_options *opts);
diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c
index c49ad0b3ffdf..04d741075376 100644
--- a/drivers/nvme/host/rdma.c
+++ b/drivers/nvme/host/rdma.c
@@ -2231,8 +2231,9 @@ static struct nvme_ctrl *nvme_rdma_create_ctrl(struct device *dev,
 	ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL);
 	if (!ctrl)
 		return ERR_PTR(-ENOMEM);
-	ctrl->ctrl.opts = opts;
+
 	INIT_LIST_HEAD(&ctrl->list);
+	nvmf_init_ctrl(&ctrl->ctrl, opts);
 
 	if (!(opts->mask & NVMF_OPT_TRSVCID)) {
 		opts->trsvcid =
@@ -2267,13 +2268,6 @@ static struct nvme_ctrl *nvme_rdma_create_ctrl(struct device *dev,
 		goto out_free_ctrl;
 	}
 
-	nvmf_init_ctrl(&ctrl->ctrl);
-
-	ctrl->ctrl.queue_count = opts->nr_io_queues + opts->nr_write_queues +
-				opts->nr_poll_queues + 1;
-	ctrl->ctrl.sqsize = opts->queue_size - 1;
-	ctrl->ctrl.kato = opts->kato;
-
 	ret = -ENOMEM;
 	ctrl->queues = kcalloc(ctrl->ctrl.queue_count, sizeof(*ctrl->queues),
 				GFP_KERNEL);
diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
index e65bdd0db4d5..5b9a876291f4 100644
--- a/drivers/nvme/host/tcp.c
+++ b/drivers/nvme/host/tcp.c
@@ -2406,13 +2406,7 @@ static struct nvme_ctrl *nvme_tcp_create_ctrl(struct device *dev,
 		return ERR_PTR(-ENOMEM);
 
 	INIT_LIST_HEAD(&ctrl->list);
-	ctrl->ctrl.opts = opts;
-	ctrl->ctrl.queue_count = opts->nr_io_queues + opts->nr_write_queues +
-				opts->nr_poll_queues + 1;
-	ctrl->ctrl.sqsize = opts->queue_size - 1;
-	ctrl->ctrl.kato = opts->kato;
-
-	nvmf_init_ctrl(&ctrl->ctrl);
+	nvmf_init_ctrl(&ctrl->ctrl, opts);
 
 	if (!(opts->mask & NVMF_OPT_TRSVCID)) {
 		opts->trsvcid =
-- 
2.18.1




More information about the Linux-nvme mailing list