diff --git a/src/nvme/tree.c b/src/nvme/tree.c index 37224614..bdb527d2 100644 --- a/src/nvme/tree.c +++ b/src/nvme/tree.c @@ -1887,7 +1887,9 @@ static int nvme_configure_ctrl(nvme_root_t r, nvme_ctrl_t c, const char *path, const char *name) { DIR *d; - char *host_key, *tls_psk; + char *host_key, *ctrl_key; + + _cleanup_free_ char *tls_psk = NULL; d = opendir(path); if (!d) { @@ -1908,6 +1910,7 @@ 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"); + 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) || @@ -1915,13 +1918,21 @@ static int nvme_configure_ctrl(nvme_root_t r, nvme_ctrl_t c, const char *path, free(host_key); host_key = NULL; } - if (host_key) + if (host_key) { + nvme_ctrl_set_dhchap_host_key(c, NULL); 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; } + + ctrl_key = nvme_get_ctrl_attr(c, "dhchap_ctrl_secret"); + if (ctrl_key && !strcmp(ctrl_key, "none")) { + free(ctrl_key); + ctrl_key = NULL; + } + if (ctrl_key) { + nvme_ctrl_set_dhchap_key(c, NULL); + c->dhchap_ctrl_key = ctrl_key; + } + tls_psk = nvme_get_ctrl_attr(c, "tls_key"); if (tls_psk) { char *endptr; @@ -1932,6 +1943,7 @@ static int nvme_configure_ctrl(nvme_root_t r, nvme_ctrl_t c, const char *path, c->cfg.tls = true; } } + c->cntrltype = nvme_get_ctrl_attr(c, "cntrltype"); c->cntlid = nvme_get_ctrl_attr(c, "cntlid"); c->dctype = nvme_get_ctrl_attr(c, "dctype");