[PATCH nvme-cli] huawei: filter out the partition disks

chengjike chengjike.cheng at huawei.com
Thu Oct 14 02:11:30 PDT 2021


When using "nvme huawei list" command, if the current disk has partitions,
disk partitions will be displayed. This is not expected!
So filter out the disk partitions through disk name.

Signed-off-by: chengjike <chengjike.cheng at huawei.com>
---
 plugins/huawei/huawei-nvme.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/plugins/huawei/huawei-nvme.c b/plugins/huawei/huawei-nvme.c
index 679578f..96de335 100644
--- a/plugins/huawei/huawei-nvme.c
+++ b/plugins/huawei/huawei-nvme.c
@@ -296,6 +296,8 @@ static int huawei_list(int argc, char **argv, struct command *command,
 	unsigned int i, n, fd, ret;
 	unsigned int huawei_num = 0;
 	int fmt;
+	int ctrl, ns, part;
+
 	const char *desc = "Retrieve basic information for the given huawei device";
 	struct config {
 		char *output_format;
@@ -326,6 +328,8 @@ static int huawei_list(int argc, char **argv, struct command *command,
 	}
 
 	for (i = 0; i < n; i++) {
+		if (sscanf(devices[i]->d_name, "nvme%dn%dp%d", &ctrl, &ns, &part) == 3) 
+			continue;
 		snprintf(path, sizeof(path), "/dev/%s", devices[i]->d_name);
 		fd = open(path, O_RDONLY);
 		ret = huawei_get_nvme_info(fd, &list_items[huawei_num], path);
-- 
2.21.0.windows.1




More information about the Linux-nvme mailing list