Linux-NVME Archive mirror
 help / color / mirror / Atom feed
From: Nilay Shroff <nilay@linux.ibm.com>
To: linux-nvme@lists.infradead.org
Cc: kbusch@kernel.org, dwagner@suse.de, gjoyce@ibm.com, nilay@linux.ibm.com
Subject: [PATCH] tree: Add NVM subsystem controller identifier
Date: Tue, 26 Mar 2024 12:27:23 +0530	[thread overview]
Message-ID: <20240326065752.164286-1-nilay@linux.ibm.com> (raw)

This commit introduces a field "cntlid" for controller,
that contains the NVM subsystem unique identifier assigned
to each controller device in an NVM subsystem.

While attaching a namespace, typically user needs to specify the
controller identifier (cntlid). The cntlid could be referenced from
sysfs (/sys/class/nvme/nvmeX/cntlid) but it would be nice to have
a direct option.

Signed-off-by: Nilay Shroff <nilay@linux.ibm.com>
---
Hi all,

While attaching an NVMe namespace using nvme-cli command 
"nvme attach-ns", we need to specifiy controller identifier 
(cntlid) against which the namespace is being attached. 

Not specifying cntlid while attaching namespace would result in 
no actual change in namespace attachment. For instance,

# nvme create-ns /dev/nvme0 --nsze=0x156d56 --ncap=0x156d56  --block-size=4096 
create-ns: Success, created nsid:1

# nvme attach-ns /dev/nvme0 -n 1
warning: empty controller-id list will result in no actual change in namespace attachment
attach-ns: Success, nsid:1

# nvme list -o json
{
  "Devices":[
  ]
}

Though it's possible to find the cntlid looking at the sysfs file, 
it'd be convenient to have it readily avaliable under nvme list 
verbose output. 

This patch adds support for retrieving the cntlid in libnvme, 
the subsequent nvme-cli patch shall use this information to 
print the cntlid field in nvme list verbose output.

Thanks,
--Nilay

---
 src/libnvme.map    | 1 +
 src/nvme/private.h | 1 +
 src/nvme/tree.c    | 7 +++++++
 src/nvme/tree.h    | 7 +++++++
 4 files changed, 16 insertions(+)

diff --git a/src/libnvme.map b/src/libnvme.map
index c03a99d1..8710c41f 100644
--- a/src/libnvme.map
+++ b/src/libnvme.map
@@ -9,6 +9,7 @@ LIBNVME_1.9 {
 		nvme_submit_passthru;
 		nvme_submit_passthru64;
 		nvme_update_key;
+		nvme_ctrl_get_cntlid;
 };
 
 LIBNVME_1_8 {
diff --git a/src/nvme/private.h b/src/nvme/private.h
index 11744c25..723740be 100644
--- a/src/nvme/private.h
+++ b/src/nvme/private.h
@@ -86,6 +86,7 @@ struct nvme_ctrl {
 	char *dhchap_key;
 	char *dhchap_ctrl_key;
 	char *cntrltype;
+	char *cntlid;
 	char *dctype;
 	char *phy_slot;
 	bool discovery_ctrl;
diff --git a/src/nvme/tree.c b/src/nvme/tree.c
index 584e3f6a..6efdf992 100644
--- a/src/nvme/tree.c
+++ b/src/nvme/tree.c
@@ -1008,6 +1008,11 @@ const char *nvme_ctrl_get_dhchap_host_key(nvme_ctrl_t c)
 	return c->dhchap_key;
 }
 
+const char *nvme_ctrl_get_cntlid(nvme_ctrl_t c)
+{
+	return c->cntlid;
+}
+
 void nvme_ctrl_set_dhchap_host_key(nvme_ctrl_t c, const char *key)
 {
 	if (c->dhchap_key) {
@@ -1117,6 +1122,7 @@ void nvme_deconfigure_ctrl(nvme_ctrl_t c)
 	FREE_CTRL_ATTR(c->address);
 	FREE_CTRL_ATTR(c->dctype);
 	FREE_CTRL_ATTR(c->cntrltype);
+	FREE_CTRL_ATTR(c->cntlid);
 	FREE_CTRL_ATTR(c->phy_slot);
 }
 
@@ -1800,6 +1806,7 @@ static int nvme_configure_ctrl(nvme_root_t r, nvme_ctrl_t c, const char *path,
 		}
 	}
 	c->cntrltype = nvme_get_ctrl_attr(c, "cntrltype");
+	c->cntlid = nvme_get_ctrl_attr(c, "cntlid");
 	c->dctype = nvme_get_ctrl_attr(c, "dctype");
 	c->phy_slot = nvme_ctrl_lookup_phy_slot(r, c->address);
 
diff --git a/src/nvme/tree.h b/src/nvme/tree.h
index a30e8eb7..1d635baa 100644
--- a/src/nvme/tree.h
+++ b/src/nvme/tree.h
@@ -1025,6 +1025,13 @@ const char *nvme_ctrl_get_host_iface(nvme_ctrl_t c);
  */
 const char *nvme_ctrl_get_dhchap_host_key(nvme_ctrl_t c);
 
+/**
+ *  nvme_ctrl_get_cntlid() - Controller id
+ *  @c:	Controller to be checked
+ *
+ *  Return : Controller id of @c
+ */
+const char *nvme_ctrl_get_cntlid(nvme_ctrl_t c);
 /**
  * nvme_ctrl_set_dhchap_host_key() - Set host key
  * @c:		Host for which the key should be set
-- 
2.44.0



             reply	other threads:[~2024-03-26  6:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-26  6:57 Nilay Shroff [this message]
2024-03-26  7:03 ` [PATCH] tree: Add NVM subsystem controller identifier Nilay Shroff
2024-03-26  7:10 ` Hannes Reinecke
2024-03-26  8:50   ` Nilay Shroff
2024-04-02 13:32     ` Nilay Shroff
2024-04-03  9:57 ` Daniel Wagner

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=20240326065752.164286-1-nilay@linux.ibm.com \
    --to=nilay@linux.ibm.com \
    --cc=dwagner@suse.de \
    --cc=gjoyce@ibm.com \
    --cc=kbusch@kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    /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 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 read-only IMAP folder(s) and NNTP newsgroup(s).