]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
tree: lookup correct subsystem in nvme_scan_ctrl()
authorHannes Reinecke <hare@suse.de>
Tue, 28 Sep 2021 12:14:49 +0000 (14:14 +0200)
committerDaniel Wagner <dwagner@suse.de>
Tue, 11 Jan 2022 15:31:18 +0000 (16:31 +0100)
Looking subsystems by subsys NQN only might yield wrong results
(eg for discovery controllers), as there might be several subsystem
instances all having the same subsystem NQN.

Signed-off-by: Hannes Reinecke <hare@suse.de>
src/nvme/tree.c

index 1c44478893cd150c501610579cfbe9e7aac050cc..bee373995ad9d4ccabeedecfe27a4c22a131cba5 100644 (file)
@@ -39,7 +39,7 @@ static struct nvme_host *default_host;
 static void __nvme_free_host(nvme_host_t h);
 static void __nvme_free_ctrl(nvme_ctrl_t c);
 static int nvme_subsystem_scan_namespace(struct nvme_subsystem *s, char *name);
-static int nvme_scan_subsystem(struct nvme_root *r, char *name,
+static int nvme_scan_subsystem(struct nvme_root *r, const char *name,
                               nvme_scan_filter_t f);
 static int nvme_subsystem_scan_ctrl(struct nvme_subsystem *s, char *name);
 static int nvme_ctrl_scan_namespace(struct nvme_ctrl *c, char *name);
@@ -469,7 +469,7 @@ static int nvme_init_subsystem(nvme_subsystem_t s, const char *name)
        return 0;
 }
 
-static int nvme_scan_subsystem(struct nvme_root *r, char *name,
+static int nvme_scan_subsystem(struct nvme_root *r, const char *name,
                               nvme_scan_filter_t f)
 {
        struct nvme_subsystem *s;
@@ -1079,7 +1079,7 @@ static int nvme_ctrl_scan_namespaces(struct nvme_ctrl *c)
        return 0;
 }
 
-static char *nvme_ctrl_lookup_subsystem_name(char *ctrl_name)
+static char *nvme_ctrl_lookup_subsystem_name(const char *ctrl_name)
 {
        struct dirent **subsys;
        char *subsys_name = NULL;
@@ -1286,7 +1286,7 @@ nvme_ctrl_t nvme_scan_ctrl(nvme_root_t r, const char *name)
        nvme_subsystem_t s;
        nvme_ctrl_t c;
        char *path;
-       char *hostnqn, *hostid, *subsysnqn;
+       char *hostnqn, *hostid, *subsysnqn, *subsysname;
        int ret;
 
        ret = asprintf(&path, "%s/%s", nvme_ctrl_sysfs_dir, name);
@@ -1322,7 +1322,8 @@ nvme_ctrl_t nvme_scan_ctrl(nvme_root_t r, const char *name)
                errno = ENXIO;
                return NULL;
        }
-       s = nvme_lookup_subsystem(h, NULL, subsysnqn);
+       subsysname = nvme_ctrl_lookup_subsystem_name(name);
+       s = nvme_lookup_subsystem(h, subsysname, subsysnqn);
        free(subsysnqn);
        if (!s) {
                free(path);