Skip to content

Commit d213466

Browse files
committed
tree: filter out namespaces
As the scan filter accepts a namespace as argument use it to filter out namespaces, too. Signed-off-by: Hannes Reinecke <[email protected]>
1 parent 9f0f169 commit d213466

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

src/nvme/tree.c

Lines changed: 14 additions & 8 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(nvme_root_t r,
42-
struct nvme_subsystem *s, char *name);
42+
struct nvme_subsystem *s, char *name, nvme_scan_filter_t f);
4343
static int nvme_init_subsystem(nvme_subsystem_t s, const char *name);
4444
static int nvme_scan_subsystem(nvme_root_t r, const char *name,
4545
nvme_scan_filter_t f);
@@ -465,7 +465,8 @@ struct nvme_host *nvme_lookup_host(nvme_root_t r, const char *hostnqn,
465465
return h;
466466
}
467467

468-
static int nvme_subsystem_scan_namespaces(nvme_root_t r, nvme_subsystem_t s)
468+
static int nvme_subsystem_scan_namespaces(nvme_root_t r, nvme_subsystem_t s,
469+
nvme_scan_filter_t f)
469470
{
470471
struct dirent **namespaces;
471472
int i, num_ns, ret;
@@ -480,7 +481,7 @@ static int nvme_subsystem_scan_namespaces(nvme_root_t r, nvme_subsystem_t s)
480481

481482
for (i = 0; i < num_ns; i++) {
482483
ret = nvme_subsystem_scan_namespace(r, s,
483-
namespaces[i]->d_name);
484+
namespaces[i]->d_name, f);
484485
if (ret < 0)
485486
nvme_msg(r, LOG_DEBUG,
486487
"failed to scan namespace %s: %s\n",
@@ -573,13 +574,14 @@ static int nvme_scan_subsystem(struct nvme_root *r, const char *name,
573574
if (!s)
574575
return -1;
575576

576-
nvme_subsystem_scan_namespaces(r, s);
577-
578577
if (f && !f(s, NULL, NULL)) {
579578
nvme_msg(r, LOG_DEBUG, "filter out subsystem %s\n", name);
580579
__nvme_free_subsystem(s);
580+
return 0;
581581
}
582582

583+
nvme_subsystem_scan_namespaces(r, s, f);
584+
583585
return 0;
584586
}
585587

@@ -1411,7 +1413,7 @@ void nvme_rescan_ctrl(struct nvme_ctrl *c)
14111413
nvme_root_t r = c->s && c->s->h ? c->s->h->r : NULL;
14121414
if (!c->s)
14131415
return;
1414-
nvme_subsystem_scan_namespaces(r, c->s);
1416+
nvme_subsystem_scan_namespaces(r, c->s, NULL);
14151417
nvme_ctrl_scan_namespaces(r, c);
14161418
nvme_ctrl_scan_paths(r, c);
14171419
}
@@ -1884,7 +1886,7 @@ static void nvme_subsystem_set_ns_path(nvme_subsystem_t s, nvme_ns_t n)
18841886
}
18851887

18861888
static int nvme_subsystem_scan_namespace(nvme_root_t r, nvme_subsystem_t s,
1887-
char *name)
1889+
char *name, nvme_scan_filter_t f)
18881890
{
18891891
struct nvme_ns *n;
18901892

@@ -1895,7 +1897,11 @@ static int nvme_subsystem_scan_namespace(nvme_root_t r, nvme_subsystem_t s,
18951897
nvme_msg(r, LOG_DEBUG, "failed to scan namespace %s\n", name);
18961898
return -1;
18971899
}
1898-
1900+
if (f && !f(NULL, NULL, n)) {
1901+
nvme_msg(r, LOG_DEBUG, "filter out namespace %s\n", name);
1902+
__nvme_free_ns(n);
1903+
return 0;
1904+
}
18991905
n->s = s;
19001906
list_add(&s->namespaces, &n->entry);
19011907
nvme_subsystem_set_ns_path(s, n);

0 commit comments

Comments
 (0)