From: Hannes Reinecke Date: Tue, 11 May 2021 13:38:20 +0000 (+0200) Subject: tree: initialize subsystem in nvme_init_ctrl() X-Git-Tag: v1.0-rc0~124^2~14 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=6493b6a5be377bf45dce0969636f5dde21dca6b4;p=users%2Fsagi%2Flibnvme.git tree: initialize subsystem in nvme_init_ctrl() 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 --- diff --git a/src/nvme/tree.c b/src/nvme/tree.c index 653521da..99941bac 100644 --- a/src/nvme/tree.c +++ b/src/nvme/tree.c @@ -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; }