All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guixin Liu <kanie@linux.alibaba.com>
To: hch@lst.de, sagi@grimberg.me, kch@nvidia.com
Cc: linux-nvme@lists.infradead.org
Subject: [PATCH 4/5] nvmet: relocate the cntlid_ida to the internal of subsystem
Date: Wed, 13 Dec 2023 14:32:51 +0800	[thread overview]
Message-ID: <1702449172-8920-5-git-send-email-kanie@linux.alibaba.com> (raw)
In-Reply-To: <1702449172-8920-1-git-send-email-kanie@linux.alibaba.com>

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@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



  parent reply	other threads:[~2023-12-13  6:33 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-13  6:32 [PATCH 0/5] *** bugfixes and code refactoring for nvme target *** Guixin Liu
2023-12-13  6:32 ` [PATCH 1/5] nvmet: fix wrong error handling approach in nvmet_install_queue Guixin Liu
2023-12-13  8:43   ` Christoph Hellwig
2023-12-13 12:49     ` Guixin Liu
2023-12-13 13:45       ` Sagi Grimberg
2023-12-13  6:32 ` [PATCH 2/5] nvmet: allow identical cntlid_min and cntlid_max settings Guixin Liu
2023-12-13  8:43   ` Christoph Hellwig
2023-12-13 13:46   ` Sagi Grimberg
2023-12-13  6:32 ` [PATCH 3/5] nvmet: remove cntlid_min and cntlid_max check in nvmet_alloc_ctrl Guixin Liu
2023-12-13  8:43   ` Christoph Hellwig
2023-12-13 13:47   ` Sagi Grimberg
2023-12-13  6:32 ` Guixin Liu [this message]
2023-12-13  8:46   ` [PATCH 4/5] nvmet: relocate the cntlid_ida to the internal of subsystem Christoph Hellwig
2023-12-13 12:59     ` Guixin Liu
2023-12-13 15:37       ` Christoph Hellwig
2023-12-13  6:32 ` [PATCH 5/5] nvmet: return invalid filed when check fctype fails Guixin Liu
2023-12-13  8:48   ` Christoph Hellwig
2023-12-13 13:05     ` Guixin Liu
2023-12-13 13:52       ` Sagi Grimberg
2023-12-13 23:05 ` [PATCH 0/5] *** bugfixes and code refactoring for nvme target *** Keith Busch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1702449172-8920-5-git-send-email-kanie@linux.alibaba.com \
    --to=kanie@linux.alibaba.com \
    --cc=hch@lst.de \
    --cc=kch@nvidia.com \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sagi@grimberg.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.