summaryrefslogtreecommitdiffstats
path: root/src/nvme/tree.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/nvme/tree.c42
1 files changed, 34 insertions, 8 deletions
diff --git a/src/nvme/tree.c b/src/nvme/tree.c
index e3b41e7..b992824 100644
--- a/src/nvme/tree.c
+++ b/src/nvme/tree.c
@@ -810,12 +810,12 @@ 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)
+const char *nvme_ctrl_get_dhchap_host_key(nvme_ctrl_t c)
{
return c->dhchap_key;
}
-void nvme_ctrl_set_dhchap_key(nvme_ctrl_t c, const char *key)
+void nvme_ctrl_set_dhchap_host_key(nvme_ctrl_t c, const char *key)
{
if (c->dhchap_key) {
free(c->dhchap_key);
@@ -825,6 +825,21 @@ void nvme_ctrl_set_dhchap_key(nvme_ctrl_t c, const char *key)
c->dhchap_key = strdup(key);
}
+const char *nvme_ctrl_get_dhchap_key(nvme_ctrl_t c)
+{
+ return c->dhchap_ctrl_key;
+}
+
+void nvme_ctrl_set_dhchap_key(nvme_ctrl_t c, const char *key)
+{
+ if (c->dhchap_ctrl_key) {
+ free(c->dhchap_ctrl_key);
+ c->dhchap_ctrl_key = NULL;
+ }
+ if (key)
+ c->dhchap_ctrl_key = strdup(key);
+}
+
void nvme_ctrl_set_discovered(nvme_ctrl_t c, bool discovered)
{
c->discovered = discovered;
@@ -898,6 +913,7 @@ void nvme_deconfigure_ctrl(nvme_ctrl_t c)
FREE_CTRL_ATTR(c->serial);
FREE_CTRL_ATTR(c->sqsize);
FREE_CTRL_ATTR(c->dhchap_key);
+ FREE_CTRL_ATTR(c->dhchap_ctrl_key);
FREE_CTRL_ATTR(c->address);
FREE_CTRL_ATTR(c->dctype);
FREE_CTRL_ATTR(c->cntrltype);
@@ -1146,6 +1162,7 @@ static int nvme_configure_ctrl(nvme_root_t r, nvme_ctrl_t c, const char *path,
const char *name)
{
DIR *d;
+ char *host_key;
d = opendir(path);
if (!d) {
@@ -1166,10 +1183,19 @@ static int nvme_configure_ctrl(nvme_root_t r, 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");
- if (c->dhchap_key && !strcmp(c->dhchap_key, "none")) {
- free(c->dhchap_key);
- c->dhchap_key = NULL;
+ host_key = nvme_get_ctrl_attr(c, "dhchap_secret");
+ if (host_key && c->s && c->s->h && c->s->h->dhchap_key &&
+ (!strcmp(c->s->h->dhchap_key, host_key) ||
+ !strcmp("none", host_key))) {
+ free(host_key);
+ host_key = NULL;
+ }
+ if (host_key)
+ c->dhchap_key = host_key;
+ c->dhchap_ctrl_key = nvme_get_ctrl_attr(c, "dhchap_ctrl_secret");
+ if (c->dhchap_ctrl_key && !strcmp(c->dhchap_ctrl_key, "none")) {
+ free(c->dhchap_ctrl_key);
+ c->dhchap_ctrl_key = NULL;
}
c->cntrltype = nvme_get_ctrl_attr(c, "cntrltype");
c->dctype = nvme_get_ctrl_attr(c, "dctype");
@@ -1525,9 +1551,9 @@ const uint8_t *nvme_ns_get_nguid(nvme_ns_t n)
return n->nguid;
}
-void nvme_ns_get_uuid(nvme_ns_t n, uuid_t out)
+void nvme_ns_get_uuid(nvme_ns_t n, unsigned char out[NVME_UUID_LEN])
{
- uuid_copy(out, n->uuid);
+ memcpy(out, n->uuid, NVME_UUID_LEN);
}
int nvme_ns_identify(nvme_ns_t n, struct nvme_id_ns *ns)