Skip to content

Commit 6b4c2fb

Browse files
hreineckedwsuse
authored andcommitted
tree: lookup correct subsystem in nvme_scan_ctrl()
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 <[email protected]>
1 parent 3b78629 commit 6b4c2fb

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

src/nvme/tree.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static struct nvme_host *default_host;
3939
static void __nvme_free_host(nvme_host_t h);
4040
static void __nvme_free_ctrl(nvme_ctrl_t c);
4141
static int nvme_subsystem_scan_namespace(struct nvme_subsystem *s, char *name);
42-
static int nvme_scan_subsystem(struct nvme_root *r, char *name,
42+
static int nvme_scan_subsystem(struct nvme_root *r, const char *name,
4343
nvme_scan_filter_t f);
4444
static int nvme_subsystem_scan_ctrl(struct nvme_subsystem *s, char *name);
4545
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)
469469
return 0;
470470
}
471471

472-
static int nvme_scan_subsystem(struct nvme_root *r, char *name,
472+
static int nvme_scan_subsystem(struct nvme_root *r, const char *name,
473473
nvme_scan_filter_t f)
474474
{
475475
struct nvme_subsystem *s;
@@ -1079,7 +1079,7 @@ static int nvme_ctrl_scan_namespaces(struct nvme_ctrl *c)
10791079
return 0;
10801080
}
10811081

1082-
static char *nvme_ctrl_lookup_subsystem_name(char *ctrl_name)
1082+
static char *nvme_ctrl_lookup_subsystem_name(const char *ctrl_name)
10831083
{
10841084
struct dirent **subsys;
10851085
char *subsys_name = NULL;
@@ -1286,7 +1286,7 @@ nvme_ctrl_t nvme_scan_ctrl(nvme_root_t r, const char *name)
12861286
nvme_subsystem_t s;
12871287
nvme_ctrl_t c;
12881288
char *path;
1289-
char *hostnqn, *hostid, *subsysnqn;
1289+
char *hostnqn, *hostid, *subsysnqn, *subsysname;
12901290
int ret;
12911291

12921292
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)
13221322
errno = ENXIO;
13231323
return NULL;
13241324
}
1325-
s = nvme_lookup_subsystem(h, NULL, subsysnqn);
1325+
subsysname = nvme_ctrl_lookup_subsystem_name(name);
1326+
s = nvme_lookup_subsystem(h, subsysname, subsysnqn);
13261327
free(subsysnqn);
13271328
if (!s) {
13281329
free(path);

0 commit comments

Comments
 (0)