Linux-NVME Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 1/2] nvme-print: list also hostnqn and hostid for verbose
@ 2020-03-24  8:53 Sagi Grimberg
  2020-03-24  8:53 ` [PATCH 2/2] nvmf: use discovery controller host identifiers for persistent controllers Sagi Grimberg
  2020-04-01 19:41 ` [PATCH 1/2] nvme-print: list also hostnqn and hostid for verbose Keith Busch
  0 siblings, 2 replies; 3+ messages in thread
From: Sagi Grimberg @ 2020-03-24  8:53 UTC (permalink / raw)
  To: linux-nvme, Keith Busch

Add it to the json output as the normal display is crowded enough as it is.
Note that we print them only if they exist in sysfs which gives us backward
compatibility (as hostnqn and hostid are still new).

Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
---
 nvme-print.c    | 4 ++++
 nvme-topology.c | 4 ++++
 nvme.h          | 2 ++
 3 files changed, 10 insertions(+)

diff --git a/nvme-print.c b/nvme-print.c
index 579ac100e641..302899ef8b05 100644
--- a/nvme-print.c
+++ b/nvme-print.c
@@ -4497,6 +4497,10 @@ static void json_detail_list(struct nvme_topology *t)
 			json_object_add_value_string(ctrl_attrs, "Transport", c->transport);
 			json_object_add_value_string(ctrl_attrs, "Address", c->address);
 			json_object_add_value_string(ctrl_attrs, "State", c->state);
+			if (c->hostnqn)
+				json_object_add_value_string(ctrl_attrs, "HostNQN", c->hostnqn);
+			if (c->hostid)
+				json_object_add_value_string(ctrl_attrs, "HostID", c->hostid);
 
 			format(formatter, sizeof(formatter), c->id.fr, sizeof(c->id.fr));
 			json_object_add_value_string(ctrl_attrs, "Firmware", formatter);
diff --git a/nvme-topology.c b/nvme-topology.c
index f2d0e7a4e344..30a9eb3c4474 100644
--- a/nvme-topology.c
+++ b/nvme-topology.c
@@ -195,6 +195,8 @@ static int scan_ctrl(struct nvme_ctrl *c, char *p, __u32 ns_instance)
 	c->address = nvme_get_ctrl_attr(path, "address");
 	c->transport = nvme_get_ctrl_attr(path, "transport");
 	c->state = nvme_get_ctrl_attr(path, "state");
+	c->hostnqn = nvme_get_ctrl_attr(path, "hostnqn");
+	c->hostid = nvme_get_ctrl_attr(path, "hostid");
 
 	if (ns_instance)
 		c->ana_state = get_nvme_ctrl_path_ana_state(path, ns_instance);
@@ -406,6 +408,8 @@ static void free_ctrl(struct nvme_ctrl *c)
 	free(c->transport);
 	free(c->address);
 	free(c->state);
+	free(c->hostnqn);
+	free(c->hostid);
 	free(c->ana_state);
 	free(c->namespaces);
 }
diff --git a/nvme.h b/nvme.h
index f6a94e9757c6..017148ae5fb0 100644
--- a/nvme.h
+++ b/nvme.h
@@ -55,6 +55,8 @@ struct nvme_ctrl {
 	char *traddr;
 	char *trsvcid;
 	char *host_traddr;
+	char *hostnqn;
+	char *hostid;
 
 	struct nvme_id_ctrl id;
 
-- 
2.20.1


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

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

* [PATCH 2/2] nvmf: use discovery controller host identifiers for persistent controllers
  2020-03-24  8:53 [PATCH 1/2] nvme-print: list also hostnqn and hostid for verbose Sagi Grimberg
@ 2020-03-24  8:53 ` Sagi Grimberg
  2020-04-01 19:41 ` [PATCH 1/2] nvme-print: list also hostnqn and hostid for verbose Keith Busch
  1 sibling, 0 replies; 3+ messages in thread
From: Sagi Grimberg @ 2020-03-24  8:53 UTC (permalink / raw)
  To: linux-nvme, Keith Busch

It is possible that the user will create a persistent discovery controller
with a specific host identifiers (hostnqn and/or hostid). If we get a discovery
change log event on this discovery controller we need to use the same host
identifiers that otherwise we will may not see what the discovery change log
event intended us to see (as we connect with a different hostnqn for example).

Note that we take these identifiers only if they exist in sysfs which gives us
backward compatibility (as hostnqn and hostid are still new).

Reported-by: Yogev Cohen <yogev@lightbitslabs.com>
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
---
 fabrics.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/fabrics.c b/fabrics.c
index a112f76c146c..e2c9bfb37177 100644
--- a/fabrics.c
+++ b/fabrics.c
@@ -1079,6 +1079,16 @@ static int connect_ctrls(struct nvmf_disc_rsp_page_hdr *log, int numrec)
 	return ret;
 }
 
+static void nvmf_get_host_identifiers(int ctrl_instance)
+{
+	char *path;
+
+	if (asprintf(&path, "%s/nvme%d", SYS_NVME, ctrl_instance) < 0)
+		return;
+	cfg.hostnqn = nvme_get_ctrl_attr(path, "hostnqn");
+	cfg.hostid = nvme_get_ctrl_attr(path, "hostid");
+}
+
 static int do_discover(char *argstr, bool connect)
 {
 	struct nvmf_disc_rsp_page_hdr *log = NULL;
@@ -1117,10 +1127,12 @@ static int do_discover(char *argstr, bool connect)
 		free(cargs.host_traddr);
 	}
 
-	if (!cfg.device)
+	if (!cfg.device) {
 		instance = add_ctrl(argstr);
-	else
+	} else {
 		instance = ctrl_instance(cfg.device);
+		nvmf_get_host_identifiers(instance);
+	}
 	if (instance < 0)
 		return instance;
 
-- 
2.20.1


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

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

* Re: [PATCH 1/2] nvme-print: list also hostnqn and hostid for verbose
  2020-03-24  8:53 [PATCH 1/2] nvme-print: list also hostnqn and hostid for verbose Sagi Grimberg
  2020-03-24  8:53 ` [PATCH 2/2] nvmf: use discovery controller host identifiers for persistent controllers Sagi Grimberg
@ 2020-04-01 19:41 ` Keith Busch
  1 sibling, 0 replies; 3+ messages in thread
From: Keith Busch @ 2020-04-01 19:41 UTC (permalink / raw)
  To: Sagi Grimberg; +Cc: linux-nvme

Thanks for the patches, applied both to nvme-cli

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

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

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-24  8:53 [PATCH 1/2] nvme-print: list also hostnqn and hostid for verbose Sagi Grimberg
2020-03-24  8:53 ` [PATCH 2/2] nvmf: use discovery controller host identifiers for persistent controllers Sagi Grimberg
2020-04-01 19:41 ` [PATCH 1/2] nvme-print: list also hostnqn and hostid for verbose Keith Busch

Linux-NVME Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-nvme/0 linux-nvme/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-nvme linux-nvme/ https://lore.kernel.org/linux-nvme \
		linux-nvme@lists.infradead.org
	public-inbox-index linux-nvme

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-nvme


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git