From: Hannes Reinecke Date: Fri, 21 Jan 2022 11:53:51 +0000 (+0100) Subject: tree: only open controller device node if required X-Git-Tag: v1.0-rc1~1^2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=3c9fa45f3d7838fcbe5db8f8847995ac6fa7613f;p=users%2Fsagi%2Flibnvme.git tree: only open controller device node if required Opening the controller device will fail if the controller is resetting, so trying to open it during controller initialisation will fail, and the controller will not displayed correctly. So only try to open the controller device if required, allowing the initialisation to continue. Signed-off-by: Hannes Reinecke --- diff --git a/src/nvme/tree.c b/src/nvme/tree.c index 15520f05..c22d99e6 100644 --- a/src/nvme/tree.c +++ b/src/nvme/tree.c @@ -630,6 +630,12 @@ free_path: int nvme_ctrl_get_fd(nvme_ctrl_t c) { + if (c->fd < 0) { + c->fd = nvme_open(c->name); + if (c->fd < 0) + nvme_msg(LOG_ERR, "Failed to open ctrl %s, errno %d\n", + c->name, errno); + } return c->fd; } @@ -1106,15 +1112,14 @@ static int nvme_configure_ctrl(nvme_ctrl_t c, const char *path, d = opendir(path); if (!d) { + nvme_msg(LOG_ERR, "Failed to open ctrl dir %s, error %d\n", + path, errno); errno = ENODEV; return -1; } closedir(d); - c->fd = nvme_open(name); - if (c->fd < 0) - return c->fd; - + c->fd = -1; c->name = strdup(name); c->sysfs_dir = (char *)path; c->firmware = nvme_get_ctrl_attr(c, "firmware_rev");