[PATCH 4/5] nvmet: relocate the cntlid_ida to the internal of subsystem

Guixin Liu kanie at linux.alibaba.com
Tue Dec 12 22:32:51 PST 2023


As per the NVMe specification, the cntlid must be unique within an NVM
subsystem. Therefore, the cntlid_ida should be moved internally within
the subsystem.

Signed-off-by: Guixin Liu <kanie at linux.alibaba.com>
---
 drivers/nvme/target/core.c  | 8 ++++----
 drivers/nvme/target/nvmet.h | 2 ++
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index d26aa30..c4cff43 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -21,7 +21,6 @@
 struct workqueue_struct *buffered_io_wq;
 struct workqueue_struct *zbd_wq;
 static const struct nvmet_fabrics_ops *nvmet_transports[NVMF_TRTYPE_MAX];
-static DEFINE_IDA(cntlid_ida);
 
 struct workqueue_struct *nvmet_wq;
 EXPORT_SYMBOL_GPL(nvmet_wq);
@@ -1425,7 +1424,7 @@ u16 nvmet_alloc_ctrl(const char *subsysnqn, const char *hostnqn,
 	if (!ctrl->sqs)
 		goto out_free_changed_ns_list;
 
-	ret = ida_alloc_range(&cntlid_ida,
+	ret = ida_alloc_range(&subsys->cntlid_ida,
 			     subsys->cntlid_min, subsys->cntlid_max,
 			     GFP_KERNEL);
 	if (ret < 0) {
@@ -1486,7 +1485,7 @@ static void nvmet_ctrl_free(struct kref *ref)
 
 	nvmet_destroy_auth(ctrl);
 
-	ida_free(&cntlid_ida, ctrl->cntlid);
+	ida_free(&subsys->cntlid_ida, ctrl->cntlid);
 
 	nvmet_async_events_free(ctrl);
 	kfree(ctrl->sqs);
@@ -1598,6 +1597,7 @@ struct nvmet_subsys *nvmet_subsys_alloc(const char *subsysnqn,
 	xa_init(&subsys->namespaces);
 	INIT_LIST_HEAD(&subsys->ctrls);
 	INIT_LIST_HEAD(&subsys->hosts);
+	ida_init(&subsys->cntlid_ida);
 
 	return subsys;
 
@@ -1619,6 +1619,7 @@ static void nvmet_subsys_free(struct kref *ref)
 
 	xa_destroy(&subsys->namespaces);
 	nvmet_passthru_subsys_free(subsys);
+	ida_destroy(&subsys->cntlid_ida);
 
 	kfree(subsys->subsysnqn);
 	kfree(subsys->model_number);
@@ -1692,7 +1693,6 @@ static void __exit nvmet_exit(void)
 {
 	nvmet_exit_configfs();
 	nvmet_exit_discovery();
-	ida_destroy(&cntlid_ida);
 	destroy_workqueue(nvmet_wq);
 	destroy_workqueue(buffered_io_wq);
 	destroy_workqueue(zbd_wq);
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index 6c8aceb..af27243 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -291,6 +291,8 @@ struct nvmet_subsys {
 #ifdef CONFIG_BLK_DEV_ZONED
 	u8			zasl;
 #endif /* CONFIG_BLK_DEV_ZONED */
+
+	struct ida		cntlid_ida;
 };
 
 static inline struct nvmet_subsys *to_subsys(struct config_item *item)
-- 
1.8.3.1




More information about the Linux-nvme mailing list