From: Hannes Reinecke Date: Tue, 22 Jun 2021 11:48:36 +0000 (+0200) Subject: nvme-topology: scan all controllers in scan_subsystem() X-Git-Tag: v1.15~37 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=ce9d818f420af6be0801004a77e91915587fc02f;p=users%2Fsagi%2Fnvme-cli.git nvme-topology: scan all controllers in scan_subsystem() 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 --- diff --git a/nvme-topology.c b/nvme-topology.c index 47121e44..6d2edaae 100644 --- a/nvme-topology.c +++ b/nvme-topology.c @@ -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;