Skip to content

Commit 9393455

Browse files
committed
tree: make nvme_ctrl_scan_namespace() idempotent
When issuing a rescan the list of namespaces is not cleared, so just blindly adding new entries might not yield the expected result. This patch clears out old entries from the controller namespace list before adding new ones, ensuring that we only ever have one namespace with a given name in the list of controller namespaces. Signed-off-by: Hannes Reinecke <[email protected]>
1 parent 70946ce commit 9393455

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/nvme/tree.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,7 +1840,7 @@ nvme_ns_t nvme_scan_namespace(const char *name)
18401840
static int nvme_ctrl_scan_namespace(nvme_root_t r, struct nvme_ctrl *c,
18411841
char *name)
18421842
{
1843-
struct nvme_ns *n;
1843+
struct nvme_ns *n, *_n, *__n;
18441844

18451845
nvme_msg(r, LOG_DEBUG, "scan controller %s namespace %s\n",
18461846
c->name, name);
@@ -1854,7 +1854,11 @@ static int nvme_ctrl_scan_namespace(nvme_root_t r, struct nvme_ctrl *c,
18541854
nvme_msg(r, LOG_DEBUG, "failed to scan namespace %s\n", name);
18551855
return -1;
18561856
}
1857-
1857+
nvme_ctrl_for_each_ns_safe(c, _n, __n) {
1858+
if (strcmp(n->name, _n->name))
1859+
continue;
1860+
__nvme_free_ns(_n);
1861+
}
18581862
n->s = c->s;
18591863
n->c = c;
18601864
list_add(&c->namespaces, &n->entry);

0 commit comments

Comments
 (0)