File 0016-nvme-topology-scan-all-controllers-in-scan_subsystem.patch of Package nvme-cli.22025

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 |   22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

--- a/nvme-topology.c
+++ b/nvme-topology.c
@@ -102,21 +102,22 @@ static int scan_namespace(struct nvme_na
 		return ret;
 
 	fd = open(path, O_RDONLY);
-	if (fd < 0)
+	if (fd < 0) {
+		ret = fd;
 		goto free;
+	}
 
-	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)
@@ -242,7 +243,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);
@@ -279,8 +280,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;
+		}
 	}
 
 	while (i--)
openSUSE Build Service is sponsored by