Skip to content

Commit fa4969f

Browse files
committed
tree: preserve dhchap_key to during scan
Commit fe89efa ("tree: do not set dhchap_key to 'none'") and commit a343ed6 ("tree: always set the host key") missed one spot to preserve the existing secret (aka host key). Update nvme_scan_ctrl to only set the secret from sysfs when it's actually there. Reported-by: Puspak Sahu <puspak.sahu@nutanix.com> Signed-off-by: Daniel Wagner <wagi@kernel.org>
1 parent 6634493 commit fa4969f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/nvme/tree.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2245,6 +2245,7 @@ nvme_ctrl_t nvme_scan_ctrl(nvme_root_t r, const char *name)
22452245
_cleanup_free_ char *subsysnqn = NULL, *subsysname = NULL;
22462246
_cleanup_free_ char *hostnqn = NULL, *hostid = NULL;
22472247
_cleanup_free_ char *path = NULL;
2248+
char *host_key;
22482249
nvme_host_t h;
22492250
nvme_subsystem_t s;
22502251
nvme_ctrl_t c;
@@ -2261,12 +2262,13 @@ nvme_ctrl_t nvme_scan_ctrl(nvme_root_t r, const char *name)
22612262
hostid = nvme_get_attr(path, "hostid");
22622263
h = nvme_lookup_host(r, hostnqn, hostid);
22632264
if (h) {
2264-
free(h->dhchap_key);
2265-
h->dhchap_key = nvme_get_attr(path, "dhchap_secret");
2266-
if (h->dhchap_key && !strcmp(h->dhchap_key, "none")) {
2265+
host_key = nvme_get_attr(path, "dhchap_secret");
2266+
if (host_key && strcmp(host_key, "none")) {
22672267
free(h->dhchap_key);
2268-
h->dhchap_key = NULL;
2268+
h->dhchap_key = host_key;
2269+
host_key = NULL;
22692270
}
2271+
free(host_key);
22702272
}
22712273
if (!h) {
22722274
h = nvme_default_host(r);

0 commit comments

Comments
 (0)