[PATCH V4 nvme-cli 1/3] display faulty disk in "nvme list" command

chengjike chengjike.cheng at huawei.com
Fri Oct 8 05:25:51 PDT 2021


When NVMe Subsystem is connected with one or more controllers via fabric, such as NVMe-oF over RDMA,
if the link is faulty, some nvme disks on the host are unavailable and they won't be deleted immediately.
These disk should be displayed for users. So value of nsid set to be -1, and all the size info is zero,
which indicates that the namespace is "faulty" when run "nvme list" command.

Signed-off-by: chengjike <chengjike.cheng at huawei.com>
---
 src/nvme/tree.c | 28 +++++++++++-----------------
 1 file changed, 11 insertions(+), 17 deletions(-)

diff --git a/src/nvme/tree.c b/src/nvme/tree.c
index 2c5837a..07a687a 100644
--- a/src/nvme/tree.c
+++ b/src/nvme/tree.c
@@ -237,7 +237,8 @@ nvme_ns_t nvme_subsystem_next_ns(nvme_subsystem_t s, nvme_ns_t n)
 static void __nvme_free_ns(struct nvme_ns *n)
 {
 	list_del_init(&n->entry);
-	close(n->fd);
+	if (n->fd > 0)
+		close(n->fd);
 	free(n->name);
 	free(n->sysfs_dir);
 	free(n);
@@ -1053,9 +1054,6 @@ static int nvme_configure_ctrl(nvme_ctrl_t c, const char *path,
 	closedir(d);
 
 	c->fd = nvme_open(name);
-	if (c->fd < 0)
-		return c->fd;
-
 	c->name = strdup(name);
 	c->sysfs_dir = (char *)path;
 	c->firmware = nvme_get_ctrl_attr(c, "firmware_rev");
@@ -1552,27 +1550,23 @@ static nvme_ns_t nvme_ns_open(const char *name)
 	}
 
 	n->name = strdup(name);
+	n->nsid = -1;
 	n->fd = nvme_open(n->name);
+
 	if (n->fd < 0)
-		goto free_ns;
+		goto out;
 
-	if (nvme_get_nsid(n->fd, &n->nsid) < 0)
-		goto close_fd;
+	if (nvme_get_nsid(n->fd, &n->nsid) < 0) {
+		n->nsid = -1;
+		goto out;
+	}
 
 	if (nvme_ns_init(n) != 0)
-		goto close_fd;
-
+		n->nsid = -1;
+out:
 	list_head_init(&n->paths);
 	list_node_init(&n->entry);
-
 	return n;
-
-close_fd:
-	close(n->fd);
-free_ns:
-	free(n->name);
-	free(n);
-	return NULL;
 }
 
 static struct nvme_ns *__nvme_scan_namespace(const char *sysfs_dir, const char *name)
-- 
2.21.0.windows.1




More information about the Linux-nvme mailing list