File 0006-nvme-topology-scan-all-controllers-in-scan_subsystem.patch of Package nvme-cli.20721
From: Hannes Reinecke <hare@suse.de>
Date: Tue, 22 Jun 2021 13:48:36 +0200
Subject: nvme-topology: scan all controllers in scan_subsystem()
References: bsc#1186719
Git-commit: ce9d818f420af6be0801004a77e91915587fc02f
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 | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)
--- a/nvme-topology.c
+++ b/nvme-topology.c
@@ -149,23 +149,23 @@ static int scan_namespace(struct nvme_na
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)
@@ -318,7 +318,7 @@ static int scan_subsystem(struct nvme_su
struct dirent **ctrls, **ns;
struct nvme_namespace *n;
struct nvme_ctrl *c;
- int i, ret;
+ int i, j, ret;
char *path;
ret = asprintf(&path, "%s%s", subsys_dir, s->name);
@@ -356,8 +356,11 @@ static int scan_subsystem(struct nvme_su
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;