]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
tree: only open controller device node if required
authorHannes Reinecke <hare@suse.de>
Fri, 21 Jan 2022 11:53:51 +0000 (12:53 +0100)
committerHannes Reinecke <hare@suse.de>
Fri, 21 Jan 2022 11:53:51 +0000 (12:53 +0100)
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 <hare@suse.de>
src/nvme/tree.c

index 15520f05c5cbe36c07793234ec94c3c2c02c2888..c22d99e689d5960039e880d1d37289679fdf5eff 100644 (file)
@@ -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");