Skip to content

Commit 7aaed6e

Browse files
committed
tree: link paths to namespaces in nvme_subsystem_scan_namespace()
Depending on the order of scanning nvme_subsystem_scan_namespace() might be called after nvme_scan_ctrl(), causing the links from paths to namespaces to be missing. Signed-off-by: Hannes Reinecke <[email protected]>
1 parent 38a150f commit 7aaed6e

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

src/nvme/tree.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,8 @@ static int nvme_subsystem_scan_namespaces(nvme_root_t r, nvme_subsystem_t s)
462462
}
463463

464464
for (i = 0; i < num_ns; i++) {
465-
ret = nvme_subsystem_scan_namespace(r, s, namespaces[i]->d_name);
465+
ret = nvme_subsystem_scan_namespace(r, s,
466+
namespaces[i]->d_name);
466467
if (ret < 0)
467468
nvme_msg(r, LOG_DEBUG,
468469
"failed to scan namespace %s: %s\n",
@@ -1367,6 +1368,7 @@ nvme_ctrl_t nvme_scan_ctrl(nvme_root_t r, const char *name)
13671368
errno = ENOMEM;
13681369
return NULL;
13691370
}
1371+
13701372
c = nvme_ctrl_alloc(r, s, path, name);
13711373
if (!c) {
13721374
free(path);
@@ -1827,6 +1829,32 @@ static int nvme_ctrl_scan_namespace(nvme_root_t r, struct nvme_ctrl *c,
18271829
return 0;
18281830
}
18291831

1832+
static void nvme_subsystem_set_ns_path(nvme_subsystem_t s, nvme_ns_t n)
1833+
{
1834+
nvme_ctrl_t c;
1835+
nvme_path_t p;
1836+
int ns_ctrl, ns_nsid, ret;
1837+
1838+
ret = sscanf(nvme_ns_get_name(n), "nvme%dn%d", &ns_ctrl, &ns_nsid);
1839+
if (ret != 2)
1840+
return;
1841+
1842+
nvme_subsystem_for_each_ctrl(s, c) {
1843+
nvme_ctrl_for_each_path(c, p) {
1844+
int p_subsys, p_ctrl, p_nsid;
1845+
1846+
ret = sscanf(nvme_path_get_name(p), "nvme%dc%dn%d",
1847+
&p_subsys, &p_ctrl, &p_nsid);
1848+
if (ret != 3)
1849+
continue;
1850+
if (ns_ctrl == p_subsys && ns_nsid == p_nsid) {
1851+
list_add(&n->paths, &p->nentry);
1852+
p->n = n;
1853+
}
1854+
}
1855+
}
1856+
}
1857+
18301858
static int nvme_subsystem_scan_namespace(nvme_root_t r, nvme_subsystem_t s,
18311859
char *name)
18321860
{
@@ -1840,6 +1868,7 @@ static int nvme_subsystem_scan_namespace(nvme_root_t r, nvme_subsystem_t s,
18401868

18411869
n->s = s;
18421870
list_add(&s->namespaces, &n->entry);
1871+
nvme_subsystem_set_ns_path(s, n);
18431872
return 0;
18441873
}
18451874

0 commit comments

Comments
 (0)