Skip to content

Commit 5b5acce

Browse files
committed
tree: simplifiy nvme_subsystem_lookup_namespace()
The list of namespaces needs to be considered static, and should only be changed on a full rescan. So simplify the function to just return the corresponding namespace entry from the topology tree. Signed-off-by: Hannes Reinecke <[email protected]>
1 parent f603510 commit 5b5acce

1 file changed

Lines changed: 4 additions & 15 deletions

File tree

src/nvme/tree.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,22 +1913,11 @@ static int nvme_subsystem_scan_namespace(nvme_root_t r, nvme_subsystem_t s,
19131913
struct nvme_ns *nvme_subsystem_lookup_namespace(struct nvme_subsystem *s,
19141914
__u32 nsid)
19151915
{
1916-
nvme_root_t r = s->h ? s->h->r : NULL;
19171916
struct nvme_ns *n;
1918-
char *name;
1919-
int ret;
19201917

1921-
ret = asprintf(&name, "%sn%u", s->name, nsid);
1922-
if (ret < 0)
1923-
return NULL;
1924-
n = __nvme_scan_namespace(s->sysfs_dir, name);
1925-
free(name);
1926-
if (!n) {
1927-
nvme_msg(r, LOG_DEBUG, "failed to scan namespace %d\n", nsid);
1928-
return NULL;
1918+
nvme_subsystem_for_each_ns(s, n) {
1919+
if (nvme_ns_get_nsid(n) == nsid)
1920+
return n;
19291921
}
1930-
1931-
n->s = s;
1932-
list_add(&s->namespaces, &n->entry);
1933-
return n;
1922+
return NULL;
19341923
}

0 commit comments

Comments
 (0)