From 3c9fa45f3d7838fcbe5db8f8847995ac6fa7613f Mon Sep 17 00:00:00 2001 From: Hannes Reinecke Date: Fri, 21 Jan 2022 12:53:51 +0100 Subject: [PATCH] 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 --- src/nvme/tree.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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"); -- 2.50.1