linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] nvmet: make ctrl-id configurable
@ 2019-11-03 18:13 Chaitanya Kulkarni
  2019-11-03 18:15 ` Chaitanya Kulkarni
  2019-11-04  9:36 ` Max Gurtovoy
  0 siblings, 2 replies; 16+ messages in thread
From: Chaitanya Kulkarni @ 2019-11-03 18:13 UTC (permalink / raw)
  To: linux-nvme; +Cc: Chaitanya Kulkarni

This patch adds a new target subsys attribute which allows user to
optionally specify target controller which then used in the
nvmet_execute_identify_ctrl() to fill up the nvme_id_ctrl structure.

When new attribute is not specified target will fall back to original
cntlid calculation method.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
Hi Mark,

This patch allows user to set the contoller ID through configfs
which is target susbsy attribute.

Can you please take a look and provide feedback ? so that we can get
it to upstream ? I'm planning to send this on Sunday.

-Regards,
Chaitanya
---
 drivers/nvme/target/configfs.c | 23 +++++++++++++++++++++++
 drivers/nvme/target/core.c     | 23 +++++++++++++++--------
 drivers/nvme/target/nvmet.h    |  1 +
 3 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c
index 98613a45bd3b..83391e54ed12 100644
--- a/drivers/nvme/target/configfs.c
+++ b/drivers/nvme/target/configfs.c
@@ -862,10 +862,33 @@ static ssize_t nvmet_subsys_attr_serial_store(struct config_item *item,
 }
 CONFIGFS_ATTR(nvmet_subsys_, attr_serial);
 
+static ssize_t nvmet_subsys_attr_id_show(struct config_item *item,
+					     char *page)
+{
+	struct nvmet_subsys *subsys = to_subsys(item);
+
+	return snprintf(page, PAGE_SIZE, "%d\n", subsys->id);
+}
+
+static ssize_t nvmet_subsys_attr_id_store(struct config_item *item,
+					  const char *page, size_t count)
+{
+	struct nvmet_subsys *subsys = to_subsys(item);
+
+	down_write(&nvmet_config_sem);
+	/* should this be %x ? */
+	sscanf(page, "%hu\n", &subsys->id);
+	up_write(&nvmet_config_sem);
+
+	return count;
+}
+CONFIGFS_ATTR(nvmet_subsys_, attr_id);
+
 static struct configfs_attribute *nvmet_subsys_attrs[] = {
 	&nvmet_subsys_attr_attr_allow_any_host,
 	&nvmet_subsys_attr_attr_version,
 	&nvmet_subsys_attr_attr_serial,
+	&nvmet_subsys_attr_attr_id,
 	NULL,
 };
 
diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index 28438b833c1b..2396215a23c9 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -1267,13 +1267,18 @@ u16 nvmet_alloc_ctrl(const char *subsysnqn, const char *hostnqn,
 	if (!ctrl->sqs)
 		goto out_free_cqs;
 
-	ret = ida_simple_get(&cntlid_ida,
-			     NVME_CNTLID_MIN, NVME_CNTLID_MAX,
-			     GFP_KERNEL);
-	if (ret < 0) {
-		status = NVME_SC_CONNECT_CTRL_BUSY | NVME_SC_DNR;
-		goto out_free_sqs;
-	}
+	if (!subsys->id) {
+		ret = ida_simple_get(&cntlid_ida,
+				NVME_CNTLID_MIN, NVME_CNTLID_MAX,
+				GFP_KERNEL);
+		if (ret < 0) {
+			status = NVME_SC_CONNECT_CTRL_BUSY | NVME_SC_DNR;
+			goto out_free_sqs;
+		}
+		ctrl->cntlid = ret;
+	} else
+		ret = subsys->id;
+
 	ctrl->cntlid = ret;
 
 	ctrl->ops = req->ops;
@@ -1330,7 +1335,8 @@ static void nvmet_ctrl_free(struct kref *ref)
 	flush_work(&ctrl->async_event_work);
 	cancel_work_sync(&ctrl->fatal_err_work);
 
-	ida_simple_remove(&cntlid_ida, ctrl->cntlid);
+	if (!subsys->id)
+		ida_simple_remove(&cntlid_ida, ctrl->cntlid);
 
 	kfree(ctrl->sqs);
 	kfree(ctrl->cqs);
@@ -1416,6 +1422,7 @@ struct nvmet_subsys *nvmet_subsys_alloc(const char *subsysnqn,
 		kfree(subsys);
 		return ERR_PTR(-ENOMEM);
 	}
+	subsys->id = 0;
 
 	kref_init(&subsys->ref);
 
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index 46df45e837c9..a3d3471bdf2d 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -211,6 +211,7 @@ struct nvmet_subsys {
 	struct list_head	namespaces;
 	unsigned int		nr_namespaces;
 	unsigned int		max_nsid;
+	u16			id;
 
 	struct list_head	ctrls;
 
-- 
2.22.1


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2019-11-20 18:51 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-03 18:13 [PATCH] nvmet: make ctrl-id configurable Chaitanya Kulkarni
2019-11-03 18:15 ` Chaitanya Kulkarni
2019-11-04  9:36 ` Max Gurtovoy
2019-11-04 10:45   ` Mark Ruijter
2019-11-04 14:04     ` Max Gurtovoy
2019-11-04 16:36       ` Mark Ruijter
2019-11-05 22:38         ` James Smart
2019-11-06 16:51           ` Sagi Grimberg
2019-11-08 16:15             ` Mark Ruijter
2019-11-12 19:01               ` Sagi Grimberg
2019-11-12 21:19                 ` Mark Ruijter
2019-11-13  0:44                   ` James Smart
2019-11-13 23:40                 ` Chaitanya Kulkarni
2019-11-14 15:55                   ` Mark Ruijter
2019-11-20 18:51                   ` Christoph Hellwig
2019-11-05 21:15     ` Chaitanya Kulkarni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).