All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH libnvme] Implement 'dhchap_key' host and controller attributes
@ 2021-09-28 12:21 Hannes Reinecke
  0 siblings, 0 replies; 5+ messages in thread
From: Hannes Reinecke @ 2021-09-28 12:21 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Sagi Grimberg, Keith Busch, linux-nvme, Hannes Reinecke

Implement a 'dhchap_key' attribute for the nvme_host structure to
support the 'dhchap_secret' connection argument, and a
'dhchap_key' attribute for the nvme_controller structure to support
the 'dhchap_ctrl_secret' connection argument.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 pynvme/nvme.i      |  2 ++
 src/nvme/fabrics.c |  8 +++++++-
 src/nvme/json.c    | 16 +++++++++++++++-
 src/nvme/private.h |  2 ++
 src/nvme/tree.c    | 43 +++++++++++++++++++++++++++++++++++++++++++
 src/nvme/tree.h    | 32 ++++++++++++++++++++++++++++++++
 6 files changed, 101 insertions(+), 2 deletions(-)

diff --git a/pynvme/nvme.i b/pynvme/nvme.i
index 9193617..eb9e6ef 100644
--- a/pynvme/nvme.i
+++ b/pynvme/nvme.i
@@ -271,6 +271,7 @@ struct nvme_host {
   %immutable hostid;
   char *hostnqn;
   char *hostid;
+  char *dhchap_key;
 };
 
 struct nvme_subsystem {
@@ -302,6 +303,7 @@ struct nvme_ctrl {
   char *traddr;
   char *host_traddr;
   char *trsvcid;
+  char *dhchap_key;
   char *address;
   char *firmware;
   char *model;
diff --git a/src/nvme/fabrics.c b/src/nvme/fabrics.c
index ebfc635..62012a0 100644
--- a/src/nvme/fabrics.c
+++ b/src/nvme/fabrics.c
@@ -276,7 +276,7 @@ static int build_options(nvme_host_t h, nvme_ctrl_t c, char **argstr)
 {
 	struct nvme_fabrics_config *cfg = nvme_ctrl_get_config(c);
 	const char *transport = nvme_ctrl_get_transport(c);
-	const char *hostnqn, *hostid;
+	const char *hostnqn, *hostid, *hostkey, *ctrlkey;
 	bool discover = false;
 
 	if (!transport) {
@@ -306,6 +306,8 @@ static int build_options(nvme_host_t h, nvme_ctrl_t c, char **argstr)
 		discover = true;
 	hostnqn = nvme_host_get_hostnqn(h);
 	hostid = nvme_host_get_hostid(h);
+	hostkey = nvme_host_get_dhchap_key(h);
+	ctrlkey = nvme_ctrl_get_dhchap_key(c);
 	if (add_argument(argstr, "transport", transport) ||
 	    add_argument(argstr, "traddr",
 			 nvme_ctrl_get_traddr(c)) ||
@@ -317,6 +319,10 @@ static int build_options(nvme_host_t h, nvme_ctrl_t c, char **argstr)
 			 nvme_ctrl_get_trsvcid(c)) ||
 	    (hostnqn && add_argument(argstr, "hostnqn", hostnqn)) ||
 	    (hostid && add_argument(argstr, "hostid", hostid)) ||
+	    (!discover && hostkey &&
+	     add_argument(argstr, "dhchap_secret", hostkey)) ||
+	    (!discover && ctrlkey &&
+	     add_argument(argstr, "dhchap_ctrl_secret", ctrlkey)) ||
 	    (!discover &&
 	     add_int_argument(argstr, "nr_io_queues",
 			      cfg->nr_io_queues, false)) ||
diff --git a/src/nvme/json.c b/src/nvme/json.c
index 9d49758..83c91ac 100644
--- a/src/nvme/json.c
+++ b/src/nvme/json.c
@@ -94,6 +94,9 @@ static void json_parse_port(nvme_subsystem_t s, struct json_object *port_obj)
 	c = nvme_lookup_ctrl(s, transport, traddr, host_traddr,
 			     host_iface, trsvcid);
 	if (c) {
+		attr_obj = json_object_object_get(port_obj, "dhchap_key");
+		if (attr_obj)
+			nvme_ctrl_set_dhchap_key(c, json_object_get_string(attr_obj));
 		json_update_attributes(c, port_obj);
 	}
 }
@@ -136,6 +139,9 @@ static void json_parse_host(nvme_root_t r, struct json_object *host_obj)
 	if (attr_obj)
 		hostid = json_object_get_string(attr_obj);
 	h = nvme_lookup_host(r, hostnqn, hostid);
+	attr_obj = json_object_object_get(host_obj, "dhchap_key");
+	if (attr_obj)
+		nvme_host_set_dhchap_key(h, json_object_get_string(attr_obj));
 	subsys_array = json_object_object_get(host_obj, "subsystems");
 	if (!subsys_array)
 		return;
@@ -192,6 +198,10 @@ static void json_update_port(struct json_object *ctrl_array, nvme_ctrl_t c)
 	value = nvme_ctrl_get_trsvcid(c);
 	if (value)
 		json_object_add_value_string(port_obj, "trsvcid", value);
+	value = nvme_ctrl_get_dhchap_key(c);
+	if (value)
+		json_object_add_value_string(port_obj, "dhchap_key",
+					     value);
 	JSON_INT_OPTION(cfg, port_obj, nr_io_queues, 0);
 	JSON_INT_OPTION(cfg, port_obj, nr_write_queues, 0);
 	JSON_INT_OPTION(cfg, port_obj, nr_poll_queues, 0);
@@ -248,7 +258,7 @@ int json_update_config(nvme_root_t r, const char *config_file)
 	json_root = json_object_new_array();
 	nvme_for_each_host(r, h) {
 		nvme_subsystem_t s;
-		const char *hostid;
+		const char *hostid, *dhchap_key;
 
 		host_obj = json_object_new_object();
 		json_object_add_value_string(host_obj, "hostnqn",
@@ -257,6 +267,10 @@ int json_update_config(nvme_root_t r, const char *config_file)
 		if (hostid)
 			json_object_add_value_string(host_obj, "hostid",
 						     hostid);
+		dhchap_key = nvme_host_get_dhchap_key(h);
+		if (dhchap_key)
+			json_object_add_value_string(host_obj, "dhchap_key",
+						     dhchap_key);
 		subsys_array = json_object_new_array();
 		nvme_for_each_subsystem(h, s) {
 			json_update_subsys(subsys_array, s);
diff --git a/src/nvme/private.h b/src/nvme/private.h
index 2a151bf..803d0ce 100644
--- a/src/nvme/private.h
+++ b/src/nvme/private.h
@@ -77,6 +77,7 @@ struct nvme_ctrl {
 	char *trsvcid;
 	char *host_traddr;
 	char *host_iface;
+	char *dhchap_key;
 	bool discovered;
 	bool persistent;
 	struct nvme_fabrics_config cfg;
@@ -103,6 +104,7 @@ struct nvme_host {
 
 	char *hostnqn;
 	char *hostid;
+	char *dhchap_key;
 };
 
 struct nvme_root {
diff --git a/src/nvme/tree.c b/src/nvme/tree.c
index 293b0c0..0910b32 100644
--- a/src/nvme/tree.c
+++ b/src/nvme/tree.c
@@ -147,6 +147,21 @@ const char *nvme_host_get_hostid(nvme_host_t h)
 	return h->hostid;
 }
 
+const char *nvme_host_get_dhchap_key(nvme_host_t h)
+{
+	return h->dhchap_key;
+}
+
+void nvme_host_set_dhchap_key(nvme_host_t h, const char *key)
+{
+	if (h->dhchap_key) {
+		free(h->dhchap_key);
+		h->dhchap_key = NULL;
+	}
+	if (key)
+		h->dhchap_key = strdup(key);
+}
+
 nvme_subsystem_t nvme_first_subsystem(nvme_host_t h)
 {
 	return list_top(&h->subsystems, struct nvme_subsystem, entry);
@@ -310,6 +325,8 @@ static void __nvme_free_host(struct nvme_host *h)
 	free(h->hostnqn);
 	if (h->hostid)
 		free(h->hostid);
+	if (h->dhchap_key)
+		free(h->dhchap_key);
 	h->r->modified = true;
 	free(h);
 }
@@ -415,6 +432,11 @@ static int nvme_scan_subsystem(struct nvme_root *r, char *name,
 		free(hostnqn);
 		if (hostid)
 			free(hostid);
+		if (h) {
+			if (h->dhchap_key)
+				free(h->dhchap_key);
+			h->dhchap_key = nvme_get_attr(path, "dhchap_secret");
+		}
 	}
 	if (!h)
 		h = nvme_default_host(r);
@@ -666,6 +688,21 @@ struct nvme_fabrics_config *nvme_ctrl_get_config(nvme_ctrl_t c)
 	return &c->cfg;
 }
 
+const char *nvme_ctrl_get_dhchap_key(nvme_ctrl_t c)
+{
+	return c->dhchap_key;
+}
+
+void nvme_ctrl_set_dhchap_key(nvme_ctrl_t c, const char *key)
+{
+	if (c->dhchap_key) {
+		free(c->dhchap_key);
+		c->dhchap_key = NULL;
+	}
+	if (key)
+		c->dhchap_key = strdup(key);
+}
+
 void nvme_ctrl_disable_sqflow(nvme_ctrl_t c, bool disable_sqflow)
 {
 	c->cfg.disable_sqflow = disable_sqflow;
@@ -1035,6 +1072,7 @@ static int nvme_configure_ctrl(nvme_ctrl_t c, const char *path,
 	c->queue_count = nvme_get_ctrl_attr(c, "queue_count");
 	c->serial = nvme_get_ctrl_attr(c, "serial");
 	c->sqsize = nvme_get_ctrl_attr(c, "sqsize");
+	c->dhchap_key = nvme_get_ctrl_attr(c, "dhchap_ctrl_secret");
 	return 0;
 }
 
@@ -1173,6 +1211,11 @@ nvme_ctrl_t nvme_scan_ctrl(nvme_root_t r, const char *name)
 		free(hostnqn);
 	if (hostid)
 		free(hostid);
+	if (h) {
+		if (h->dhchap_key)
+			free(h->dhchap_key);
+		h->dhchap_key = nvme_get_attr(path, "dhchap_secret");
+	}
 	if (!h) {
 		h = nvme_default_host(r);
 		if (!h) {
diff --git a/src/nvme/tree.h b/src/nvme/tree.h
index 4974741..48f2ad4 100644
--- a/src/nvme/tree.h
+++ b/src/nvme/tree.h
@@ -105,6 +105,21 @@ const char *nvme_host_get_hostnqn(nvme_host_t h);
  */
 const char *nvme_host_get_hostid(nvme_host_t h);
 
+/**
+ * nvme_host_get_dhchap_key() -
+ * @h:
+ *
+ * Return: 
+ */
+const char *nvme_host_get_dhchap_key(nvme_host_t h);
+
+/**
+ * nvme_host_set_dhchap_key() -
+ * @h: 
+ * @key: 
+ */
+void nvme_host_set_dhchap_key(nvme_host_t h, const char *key);
+
 /**
  * nvme_default_host() -
  * @r:
@@ -787,6 +802,23 @@ const char *nvme_ctrl_get_host_traddr(nvme_ctrl_t c);
  */
 const char *nvme_ctrl_get_host_iface(nvme_ctrl_t c);
 
+/**
+ * nvme_ctrl_set_dhchap_key() -
+ * @c:
+ * @key:
+ *
+ * Return:
+ */
+void nvme_ctrl_set_dhchap_key(nvme_ctrl_t c, const char *key);
+
+/**
+ * nvme_ctrl_get_dhchap_key() -
+ * @c:
+ *
+ * Return:
+ */
+const char *nvme_ctrl_get_dhchap_key(nvme_ctrl_t c);
+
 /**
  * nvme_ctrl_get_config() -
  * @c:
-- 
2.29.2


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

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

* Re: [PATCH libnvme] Implement 'dhchap_key' host and controller attributes
  2021-11-14 13:38   ` Hannes Reinecke
@ 2021-11-14 14:54     ` Sagi Grimberg
  0 siblings, 0 replies; 5+ messages in thread
From: Sagi Grimberg @ 2021-11-14 14:54 UTC (permalink / raw)
  To: Hannes Reinecke; +Cc: Keith Busch, Christoph Hellwig, linux-nvme



On 11/14/21 3:38 PM, Hannes Reinecke wrote:
> On 11/14/21 11:38 AM, Sagi Grimberg wrote:
>>> Implement a 'dhchap_key' attribute for the nvme_host structure to
>>> support the 'dhchap_secret' connection argument, and a
>>> 'dhchap_key' attribute for the nvme_controller structure to support
>>> the 'dhchap_ctrl_secret' connection argument.
>>
>> Hannes, can you add an example of a json entry to the change log?
>> Ideally there is some sort of documentation on what is the
>> format and how to populate the config file?
>>
>> It is unclear to me how the user is supposed to work with it.
>> Is there a dump config functionality like we discussed before?
> 
> I would rather keep the json functionality separate from this.
> Yes, I know that we really need json functionality to make it usable, 
> but then the same could be said for other options, too.

You add this code:
+	attr_obj = json_object_object_get(host_obj, "dhchap_key");
+	if (attr_obj)
+		nvme_host_set_dhchap_key(h, json_object_get_string(attr_obj));

Hence I ask, how is it populated? and how is the json formatted?

> 
> And the problem here is that we'll need to coordinate libnvme and 
> nvme-cli updates to get the whole thing to build, so I'd rather keep the 
> json update separate from this one.

Huh, nvme-cli access this config anywhere?

I ask myself how can someone understand what on earth this json looks
like, how to generate it, and how it is used. Don't get me wrong,
I think its great that a parse-able json config exists, but it is
completely undocumented which makes me wonder who uses it at all.


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

* Re: [PATCH libnvme] Implement 'dhchap_key' host and controller attributes
  2021-11-14 10:38 ` Sagi Grimberg
@ 2021-11-14 13:38   ` Hannes Reinecke
  2021-11-14 14:54     ` Sagi Grimberg
  0 siblings, 1 reply; 5+ messages in thread
From: Hannes Reinecke @ 2021-11-14 13:38 UTC (permalink / raw)
  To: Sagi Grimberg; +Cc: Keith Busch, Christoph Hellwig, linux-nvme

On 11/14/21 11:38 AM, Sagi Grimberg wrote:
>> Implement a 'dhchap_key' attribute for the nvme_host structure to
>> support the 'dhchap_secret' connection argument, and a
>> 'dhchap_key' attribute for the nvme_controller structure to support
>> the 'dhchap_ctrl_secret' connection argument.
> 
> Hannes, can you add an example of a json entry to the change log?
> Ideally there is some sort of documentation on what is the
> format and how to populate the config file?
> 
> It is unclear to me how the user is supposed to work with it.
> Is there a dump config functionality like we discussed before?

I would rather keep the json functionality separate from this.
Yes, I know that we really need json functionality to make it usable, 
but then the same could be said for other options, too.

And the problem here is that we'll need to coordinate libnvme and 
nvme-cli updates to get the whole thing to build, so I'd rather keep the 
json update separate from this one.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer


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

* Re: [PATCH libnvme] Implement 'dhchap_key' host and controller attributes
  2021-11-12 13:00 Hannes Reinecke
@ 2021-11-14 10:38 ` Sagi Grimberg
  2021-11-14 13:38   ` Hannes Reinecke
  0 siblings, 1 reply; 5+ messages in thread
From: Sagi Grimberg @ 2021-11-14 10:38 UTC (permalink / raw)
  To: Hannes Reinecke; +Cc: Keith Busch, Christoph Hellwig, linux-nvme

> Implement a 'dhchap_key' attribute for the nvme_host structure to
> support the 'dhchap_secret' connection argument, and a
> 'dhchap_key' attribute for the nvme_controller structure to support
> the 'dhchap_ctrl_secret' connection argument.

Hannes, can you add an example of a json entry to the change log?
Ideally there is some sort of documentation on what is the
format and how to populate the config file?

It is unclear to me how the user is supposed to work with it.
Is there a dump config functionality like we discussed before?


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

* [PATCH libnvme] Implement 'dhchap_key' host and controller attributes
@ 2021-11-12 13:00 Hannes Reinecke
  2021-11-14 10:38 ` Sagi Grimberg
  0 siblings, 1 reply; 5+ messages in thread
From: Hannes Reinecke @ 2021-11-12 13:00 UTC (permalink / raw)
  To: Sagi Grimberg; +Cc: Keith Busch, Christoph Hellwig, linux-nvme, Hannes Reinecke

Implement a 'dhchap_key' attribute for the nvme_host structure to
support the 'dhchap_secret' connection argument, and a
'dhchap_key' attribute for the nvme_controller structure to support
the 'dhchap_ctrl_secret' connection argument.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 libnvme/nvme.i     |  2 ++
 src/nvme/fabrics.c |  8 +++++++-
 src/nvme/json.c    | 16 +++++++++++++++-
 src/nvme/private.h |  2 ++
 src/nvme/tree.c    | 43 +++++++++++++++++++++++++++++++++++++++++++
 src/nvme/tree.h    | 32 ++++++++++++++++++++++++++++++++
 6 files changed, 101 insertions(+), 2 deletions(-)

diff --git a/libnvme/nvme.i b/libnvme/nvme.i
index cfab8a2..7f1854a 100644
--- a/libnvme/nvme.i
+++ b/libnvme/nvme.i
@@ -265,6 +265,7 @@ struct nvme_host {
   %immutable hostid;
   char *hostnqn;
   char *hostid;
+  char *dhchap_key;
 };
 
 struct nvme_subsystem {
@@ -297,6 +298,7 @@ struct nvme_ctrl {
   char *traddr;
   char *host_traddr;
   char *trsvcid;
+  char *dhchap_key;
   char *address;
   char *firmware;
   char *model;
diff --git a/src/nvme/fabrics.c b/src/nvme/fabrics.c
index 43c4fb1..cfa242e 100644
--- a/src/nvme/fabrics.c
+++ b/src/nvme/fabrics.c
@@ -376,7 +376,7 @@ static int build_options(nvme_host_t h, nvme_ctrl_t c, char **argstr)
 {
 	struct nvme_fabrics_config *cfg = nvme_ctrl_get_config(c);
 	const char *transport = nvme_ctrl_get_transport(c);
-	const char *hostnqn, *hostid;
+	const char *hostnqn, *hostid, *hostkey, *ctrlkey;
 	bool discover = false;
 
 	if (!transport) {
@@ -406,6 +406,8 @@ static int build_options(nvme_host_t h, nvme_ctrl_t c, char **argstr)
 		discover = true;
 	hostnqn = nvme_host_get_hostnqn(h);
 	hostid = nvme_host_get_hostid(h);
+	hostkey = nvme_host_get_dhchap_key(h);
+	ctrlkey = nvme_ctrl_get_dhchap_key(c);
 	if (add_argument(argstr, "transport", transport) ||
 	    add_argument(argstr, "traddr",
 			 nvme_ctrl_get_traddr(c)) ||
@@ -417,6 +419,10 @@ static int build_options(nvme_host_t h, nvme_ctrl_t c, char **argstr)
 			 nvme_ctrl_get_trsvcid(c)) ||
 	    (hostnqn && add_argument(argstr, "hostnqn", hostnqn)) ||
 	    (hostid && add_argument(argstr, "hostid", hostid)) ||
+	    (!discover && hostkey &&
+	     add_argument(argstr, "dhchap_secret", hostkey)) ||
+	    (!discover && ctrlkey &&
+	     add_argument(argstr, "dhchap_ctrl_secret", ctrlkey)) ||
 	    (!discover &&
 	     add_int_argument(argstr, "nr_io_queues",
 			      cfg->nr_io_queues, false)) ||
diff --git a/src/nvme/json.c b/src/nvme/json.c
index 5aa09b0..38930ed 100644
--- a/src/nvme/json.c
+++ b/src/nvme/json.c
@@ -94,6 +94,9 @@ static void json_parse_port(nvme_subsystem_t s, struct json_object *port_obj)
 	c = nvme_lookup_ctrl(s, transport, traddr, host_traddr,
 			     host_iface, trsvcid);
 	if (c) {
+		attr_obj = json_object_object_get(port_obj, "dhchap_key");
+		if (attr_obj)
+			nvme_ctrl_set_dhchap_key(c, json_object_get_string(attr_obj));
 		json_update_attributes(c, port_obj);
 	}
 }
@@ -136,6 +139,9 @@ static void json_parse_host(nvme_root_t r, struct json_object *host_obj)
 	if (attr_obj)
 		hostid = json_object_get_string(attr_obj);
 	h = nvme_lookup_host(r, hostnqn, hostid);
+	attr_obj = json_object_object_get(host_obj, "dhchap_key");
+	if (attr_obj)
+		nvme_host_set_dhchap_key(h, json_object_get_string(attr_obj));
 	subsys_array = json_object_object_get(host_obj, "subsystems");
 	if (!subsys_array)
 		return;
@@ -191,6 +197,10 @@ static void json_update_port(struct json_object *ctrl_array, nvme_ctrl_t c)
 	value = nvme_ctrl_get_trsvcid(c);
 	if (value)
 		json_object_add_value_string(port_obj, "trsvcid", value);
+	value = nvme_ctrl_get_dhchap_key(c);
+	if (value)
+		json_object_add_value_string(port_obj, "dhchap_key",
+					     value);
 	JSON_INT_OPTION(cfg, port_obj, nr_io_queues, 0);
 	JSON_INT_OPTION(cfg, port_obj, nr_write_queues, 0);
 	JSON_INT_OPTION(cfg, port_obj, nr_poll_queues, 0);
@@ -247,7 +257,7 @@ int json_update_config(nvme_root_t r, const char *config_file)
 	json_root = json_object_new_array();
 	nvme_for_each_host(r, h) {
 		nvme_subsystem_t s;
-		const char *hostid;
+		const char *hostid, *dhchap_key;
 
 		host_obj = json_object_new_object();
 		json_object_add_value_string(host_obj, "hostnqn",
@@ -256,6 +266,10 @@ int json_update_config(nvme_root_t r, const char *config_file)
 		if (hostid)
 			json_object_add_value_string(host_obj, "hostid",
 						     hostid);
+		dhchap_key = nvme_host_get_dhchap_key(h);
+		if (dhchap_key)
+			json_object_add_value_string(host_obj, "dhchap_key",
+						     dhchap_key);
 		subsys_array = json_object_new_array();
 		nvme_for_each_subsystem(h, s) {
 			json_update_subsys(subsys_array, s);
diff --git a/src/nvme/private.h b/src/nvme/private.h
index 93770d4..23863b3 100644
--- a/src/nvme/private.h
+++ b/src/nvme/private.h
@@ -86,6 +86,7 @@ struct nvme_ctrl {
 	char *trsvcid;
 	char *host_traddr;
 	char *host_iface;
+	char *dhchap_key;
 	bool discovered;
 	bool persistent;
 	struct nvme_fabrics_config cfg;
@@ -112,6 +113,7 @@ struct nvme_host {
 
 	char *hostnqn;
 	char *hostid;
+	char *dhchap_key;
 };
 
 struct nvme_root {
diff --git a/src/nvme/tree.c b/src/nvme/tree.c
index 0f72320..c39e0c2 100644
--- a/src/nvme/tree.c
+++ b/src/nvme/tree.c
@@ -168,6 +168,21 @@ const char *nvme_host_get_hostid(nvme_host_t h)
 	return h->hostid;
 }
 
+const char *nvme_host_get_dhchap_key(nvme_host_t h)
+{
+	return h->dhchap_key;
+}
+
+void nvme_host_set_dhchap_key(nvme_host_t h, const char *key)
+{
+	if (h->dhchap_key) {
+		free(h->dhchap_key);
+		h->dhchap_key = NULL;
+	}
+	if (key)
+		h->dhchap_key = strdup(key);
+}
+
 nvme_subsystem_t nvme_first_subsystem(nvme_host_t h)
 {
 	return list_top(&h->subsystems, struct nvme_subsystem, entry);
@@ -331,6 +346,8 @@ static void __nvme_free_host(struct nvme_host *h)
 	free(h->hostnqn);
 	if (h->hostid)
 		free(h->hostid);
+	if (h->dhchap_key)
+		free(h->dhchap_key);
 	h->r->modified = true;
 	free(h);
 }
@@ -454,6 +471,11 @@ static int nvme_scan_subsystem(struct nvme_root *r, char *name,
 		free(hostnqn);
 		if (hostid)
 			free(hostid);
+		if (h) {
+			if (h->dhchap_key)
+				free(h->dhchap_key);
+			h->dhchap_key = nvme_get_attr(path, "dhchap_secret");
+		}
 	}
 	if (!h)
 		h = nvme_default_host(r);
@@ -693,6 +715,21 @@ struct nvme_fabrics_config *nvme_ctrl_get_config(nvme_ctrl_t c)
 	return &c->cfg;
 }
 
+const char *nvme_ctrl_get_dhchap_key(nvme_ctrl_t c)
+{
+	return c->dhchap_key;
+}
+
+void nvme_ctrl_set_dhchap_key(nvme_ctrl_t c, const char *key)
+{
+	if (c->dhchap_key) {
+		free(c->dhchap_key);
+		c->dhchap_key = NULL;
+	}
+	if (key)
+		c->dhchap_key = strdup(key);
+}
+
 void nvme_ctrl_disable_sqflow(nvme_ctrl_t c, bool disable_sqflow)
 {
 	c->cfg.disable_sqflow = disable_sqflow;
@@ -1064,6 +1101,7 @@ static int nvme_configure_ctrl(nvme_ctrl_t c, const char *path,
 	c->queue_count = nvme_get_ctrl_attr(c, "queue_count");
 	c->serial = nvme_get_ctrl_attr(c, "serial");
 	c->sqsize = nvme_get_ctrl_attr(c, "sqsize");
+	c->dhchap_key = nvme_get_ctrl_attr(c, "dhchap_ctrl_secret");
 	return 0;
 }
 
@@ -1233,6 +1271,11 @@ nvme_ctrl_t nvme_scan_ctrl(nvme_root_t r, const char *name)
 		free(hostnqn);
 	if (hostid)
 		free(hostid);
+	if (h) {
+		if (h->dhchap_key)
+			free(h->dhchap_key);
+		h->dhchap_key = nvme_get_attr(path, "dhchap_secret");
+	}
 	if (!h) {
 		h = nvme_default_host(r);
 		if (!h) {
diff --git a/src/nvme/tree.h b/src/nvme/tree.h
index fc01b5e..f7b7902 100644
--- a/src/nvme/tree.h
+++ b/src/nvme/tree.h
@@ -105,6 +105,21 @@ const char *nvme_host_get_hostnqn(nvme_host_t h);
  */
 const char *nvme_host_get_hostid(nvme_host_t h);
 
+/**
+ * nvme_host_get_dhchap_key() -
+ * @h:
+ *
+ * Return: 
+ */
+const char *nvme_host_get_dhchap_key(nvme_host_t h);
+
+/**
+ * nvme_host_set_dhchap_key() -
+ * @h: 
+ * @key: 
+ */
+void nvme_host_set_dhchap_key(nvme_host_t h, const char *key);
+
 /**
  * nvme_default_host() -
  * @r:
@@ -771,6 +786,23 @@ const char *nvme_ctrl_get_host_traddr(nvme_ctrl_t c);
  */
 const char *nvme_ctrl_get_host_iface(nvme_ctrl_t c);
 
+/**
+ * nvme_ctrl_set_dhchap_key() -
+ * @c:
+ * @key:
+ *
+ * Return:
+ */
+void nvme_ctrl_set_dhchap_key(nvme_ctrl_t c, const char *key);
+
+/**
+ * nvme_ctrl_get_dhchap_key() -
+ * @c:
+ *
+ * Return:
+ */
+const char *nvme_ctrl_get_dhchap_key(nvme_ctrl_t c);
+
 /**
  * nvme_ctrl_get_config() -
  * @c:
-- 
2.31.1



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

end of thread, other threads:[~2021-11-14 14:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-28 12:21 [PATCH libnvme] Implement 'dhchap_key' host and controller attributes Hannes Reinecke
2021-11-12 13:00 Hannes Reinecke
2021-11-14 10:38 ` Sagi Grimberg
2021-11-14 13:38   ` Hannes Reinecke
2021-11-14 14:54     ` Sagi Grimberg

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.