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

Chengjike (ISSP) chengjike.cheng at huawei.com
Sun Oct 17 20:49:26 PDT 2021


ping


在 2021/10/14 17:11, chengjike 写道:
> 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);



More information about the Linux-nvme mailing list