]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
tree: initialize subsystem in nvme_init_ctrl()
authorHannes Reinecke <hare@suse.de>
Tue, 11 May 2021 13:38:20 +0000 (15:38 +0200)
committerHannes Reinecke <hare@suse.de>
Sat, 19 Jun 2021 11:16:52 +0000 (13:16 +0200)
nvme_init_ctrl() might be called from a nvme_ctrl with no
subsystem set (eg after a connect call). So ensure to
re-scan the subsystem to have it fully initialized.

Signed-off-by: Hannes Reinecke <hare@suse.de>
src/nvme/tree.c

index 653521dab37e62016f72d6e9c439428445798b8b..99941bac6863b2efc01ee5e9e1064d85b522b55a 100644 (file)
@@ -1096,7 +1096,7 @@ static int __nvme_ctrl_init(nvme_ctrl_t c, const char *path, const char *name)
 int nvme_init_ctrl(nvme_host_t h, nvme_ctrl_t c, int instance)
 {
        nvme_subsystem_t s;
-       const char *subsys_name;
+       char *subsys_name = NULL;
        char *path, *name;
        int ret;
 
@@ -1128,9 +1128,18 @@ int nvme_init_ctrl(nvme_host_t h, nvme_ctrl_t c, int instance)
        if (!s) {
                errno = ENXIO;
                ret = -1;
+       } else if (!s->name) {
+               ret = asprintf(&path, "%s/%s", nvme_subsys_sysfs_dir,
+                              subsys_name);
+               if (ret > 0) {
+                       ret = nvme_init_subsystem(s, subsys_name, path);
+                       if (ret < 0)
+                               free(path);
+               }
        }
        c->s = s;
        list_add(&s->ctrls, &c->entry);
+       free(subsys_name);
        free(name);
        return ret;
 }