[PATCH nvme-cli 1/3] filter disk partitions in command "nvme huawei list"

chengjike chengjike.cheng at huawei.com
Tue Aug 17 08:07:13 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.

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

diff --git a/plugins/huawei/huawei-nvme.c b/plugins/huawei/huawei-nvme.c
index b39d861..f36c7a5 100644
--- a/plugins/huawei/huawei-nvme.c
+++ b/plugins/huawei/huawei-nvme.c
@@ -301,6 +301,7 @@ 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;
@@ -331,6 +332,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.24.0.windows.2




More information about the Linux-nvme mailing list