Skip to contentSkip to conversation

nvme-print: list also hostnqn and hostid for verbose

PATCH In review Sagi Grimberg 2 participants 3 messages Mar 24, 2020 – Apr 1, 2020 NVMe

lore
Share & tools
lore

Sagi Grimberg

author maintainer
#0 lore raw

PATCH 1/2 nvme-print: list also hostnqn and hostid for verbose

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).

---
 nvme-print.c    | 4 ++++
 nvme-topology.c | 4 ++++
 nvme.h          | 2 ++
 3 files changed, 10 insertions(+)
nvme-print.c +4 -0
index 579ac100e641..302899ef8b05 100644
@@ -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);
nvme-topology.c +4 -0
index f2d0e7a4e344..30a9eb3c4474 100644
@@ -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);
 }
nvme.h +2 -0
index f6a94e9757c6..017148ae5fb0 100644
@@ -55,6 +55,8 @@ struct nvme_ctrl {
 	char *traddr;
 	char *trsvcid;
 	char *host_traddr;
+	char *hostnqn;
+	char *hostid;
 
 	struct nvme_id_ctrl id;
 
Signature · 7 lines
2.20.1


_______________________________________________
linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
author maintainer
#1 lore raw

PATCH 2/2 nvmf: use discovery controller host identifiers for persistent controllers

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).

---
 fabrics.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
fabrics.c +14 -2
index a112f76c146c..e2c9bfb37177 100644
@@ -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;
 
Signature · 7 lines
2.20.1


_______________________________________________
linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme