]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
fabrics: filter out subsystems with non-matching application string
authorHannes Reinecke <hare@suse.de>
Thu, 20 Apr 2023 10:38:10 +0000 (12:38 +0200)
committerDaniel Wagner <wagi@monom.org>
Mon, 12 Jun 2023 14:51:15 +0000 (16:51 +0200)
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 <hare@suse.de>
src/nvme/fabrics.c
src/nvme/tree.c

index eaee29bb6170cd7d9449b47fe712912b95c2eec6..bfc8cd3ca6983a8a2fdbd84ce17b067d4965a858 100644 (file)
@@ -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;
index baa5fa6566a59b3009f094ed66c102025046fb4a..52bc8b7d8c37556519a3da448c2abf6efc0c37bc 100644 (file)
@@ -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;
 }