From: Hannes Reinecke Date: Thu, 20 Apr 2023 10:38:10 +0000 (+0200) Subject: fabrics: filter out subsystems with non-matching application string X-Git-Tag: v1.5~19 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=4154f98aa170410f3129560775a138b0d5c59d52;p=users%2Fsagi%2Flibnvme.git 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 --- diff --git a/src/nvme/fabrics.c b/src/nvme/fabrics.c index eaee29bb..bfc8cd3c 100644 --- a/src/nvme/fabrics.c +++ b/src/nvme/fabrics.c @@ -819,6 +819,7 @@ int nvmf_add_ctrl(nvme_host_t h, nvme_ctrl_t c, const struct nvme_fabrics_config *cfg) { nvme_subsystem_t s; + const char *root_app, *app; char *argstr; int ret; @@ -855,6 +856,23 @@ int nvmf_add_ctrl(nvme_host_t h, nvme_ctrl_t c, } + root_app = nvme_root_get_application(h->r); + app = nvme_subsystem_get_application(s); + if (root_app) { + /* + * configuration is managed by an application, + * refuse to act on subsystems which either have + * no application set or which habe a different + * application string. + */ + if (!app || strcmp(app, root_app)) { + nvme_msg(h->r, LOG_INFO, "skip %s, not managed by %s\n", + nvme_subsystem_get_nqn(s), root_app); + errno = ENVME_CONNECT_INVAL; + return -1; + } + } + nvme_ctrl_set_discovered(c, true); if (traddr_is_hostname(h->r, c)) { char *traddr = c->traddr; diff --git a/src/nvme/tree.c b/src/nvme/tree.c index baa5fa65..52bc8b7d 100644 --- a/src/nvme/tree.c +++ b/src/nvme/tree.c @@ -466,6 +466,12 @@ struct nvme_subsystem *nvme_lookup_subsystem(struct nvme_host *h, if (name && s->name && strcmp(s->name, name)) continue; + if (h->r->application) { + if (!s->application) + continue; + if (strcmp(h->r->application, s->application)) + continue; + } return s; } return nvme_alloc_subsystem(h, name, subsysnqn); @@ -572,6 +578,8 @@ static int nvme_init_subsystem(nvme_subsystem_t s, const char *name) } s->name = strdup(name); s->sysfs_dir = (char *)path; + if (s->h->r->application) + s->application = strdup(s->h->r->application); return 0; }