Skip to content

Commit 4154f98

Browse files
hreineckeigaw
authored andcommitted
fabrics: filter out subsystems with non-matching application string
If the nvme root has an application string set any subsystem lookup should ignore subsystems which either have no application string set or which have a non-matching application string. Signed-off-by: Hannes Reinecke <[email protected]>
1 parent 20a4eaf commit 4154f98

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

src/nvme/fabrics.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,7 @@ int nvmf_add_ctrl(nvme_host_t h, nvme_ctrl_t c,
819819
const struct nvme_fabrics_config *cfg)
820820
{
821821
nvme_subsystem_t s;
822+
const char *root_app, *app;
822823
char *argstr;
823824
int ret;
824825

@@ -855,6 +856,23 @@ int nvmf_add_ctrl(nvme_host_t h, nvme_ctrl_t c,
855856

856857
}
857858

859+
root_app = nvme_root_get_application(h->r);
860+
app = nvme_subsystem_get_application(s);
861+
if (root_app) {
862+
/*
863+
* configuration is managed by an application,
864+
* refuse to act on subsystems which either have
865+
* no application set or which habe a different
866+
* application string.
867+
*/
868+
if (!app || strcmp(app, root_app)) {
869+
nvme_msg(h->r, LOG_INFO, "skip %s, not managed by %s\n",
870+
nvme_subsystem_get_nqn(s), root_app);
871+
errno = ENVME_CONNECT_INVAL;
872+
return -1;
873+
}
874+
}
875+
858876
nvme_ctrl_set_discovered(c, true);
859877
if (traddr_is_hostname(h->r, c)) {
860878
char *traddr = c->traddr;

src/nvme/tree.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,12 @@ struct nvme_subsystem *nvme_lookup_subsystem(struct nvme_host *h,
466466
if (name && s->name &&
467467
strcmp(s->name, name))
468468
continue;
469+
if (h->r->application) {
470+
if (!s->application)
471+
continue;
472+
if (strcmp(h->r->application, s->application))
473+
continue;
474+
}
469475
return s;
470476
}
471477
return nvme_alloc_subsystem(h, name, subsysnqn);
@@ -572,6 +578,8 @@ static int nvme_init_subsystem(nvme_subsystem_t s, const char *name)
572578
}
573579
s->name = strdup(name);
574580
s->sysfs_dir = (char *)path;
581+
if (s->h->r->application)
582+
s->application = strdup(s->h->r->application);
575583

576584
return 0;
577585
}

0 commit comments

Comments
 (0)