]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme-topology: scan all controllers in scan_subsystem()
authorHannes Reinecke <hare@suse.de>
Tue, 22 Jun 2021 11:48:36 +0000 (13:48 +0200)
committerKeith Busch <kbusch@kernel.org>
Tue, 22 Jun 2021 17:10:54 +0000 (11:10 -0600)
When a controller is unavailable or resetting during scan_subsystem()
we should be checking all available controllers for this namespace
to avoid a spurious failure.

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

index 47121e44373018d84fd4a8de71f325c6d8e197b3..6d2edaaec8e653f16333e3c7efa8ae1ba7dacc92 100644 (file)
@@ -155,23 +155,23 @@ static int scan_namespace(struct nvme_namespace *n)
                return ret;
 
        fd = open(path, O_RDONLY);
-       if (fd < 0)
+       if (fd < 0) {
+               ret = fd;
                goto free;
-
+       }
        if (!n->nsid) {
-               n->nsid = nvme_get_nsid(fd);
-               if (n->nsid < 0)
+               ret = nvme_get_nsid(fd);
+               if (ret < 0)
                        goto close_fd;
+               n->nsid = ret;
        }
 
        ret = nvme_identify_ns(fd, n->nsid, 0, &n->ns);
-       if (ret < 0)
-               goto close_fd;
 close_fd:
        close(fd);
 free:
        free(path);
-       return 0;
+       return ret;
 }
 
 static char *get_nvme_ctrl_path_ana_state(char *path, int nsid)
@@ -382,8 +382,11 @@ static int scan_subsystem(struct nvme_subsystem *s, __u32 ns_instance, int nsid)
                for (i = 0; i < s->nr_namespaces; i++) {
                        n = &s->namespaces[i];
                        n->name = strdup(ns[i]->d_name);
-                       n->ctrl = &s->ctrls[0];
-                       scan_namespace(n);
+                       for (j = 0; j < s->nr_ctrls; j++) {
+                               n->ctrl = &s->ctrls[j];
+                               if (!scan_namespace(n))
+                                       break;
+                       }
                }
        } else {
                i = s->nr_namespaces;