From 63c8857b0e6a1128ea2add3b6defccc389446ef3 Mon Sep 17 00:00:00 2001 From: Maurizio Lombardi Date: Thu, 16 Jan 2025 11:09:24 +0100 Subject: [PATCH] Backport NetApp plugin fixes Resolves: RHEL-71521 Signed-off-by: Maurizio Lombardi --- 0001-netapp-ontapdev-add-verbose-output.patch | 239 ++++++++++++++++++ ...app-ontapdev-doc-add-verbose-details.patch | 39 +++ ...app-ontapdev-fix-fw-version-handling.patch | 52 ++++ ...tapdev-fix-JSON-output-for-nsze-nuse.patch | 42 +++ 0005-nvme-netapp-update-err-messages.patch | 53 ++++ 0006-netapp-smdev-remove-redundant-code.patch | 106 ++++++++ 0007-netapp-smdev-add-verbose-output.patch | 230 +++++++++++++++++ ...netapp-smdev-doc-add-verbose-details.patch | 40 +++ nvme-cli.spec | 13 +- 9 files changed, 813 insertions(+), 1 deletion(-) create mode 100644 0001-netapp-ontapdev-add-verbose-output.patch create mode 100644 0002-netapp-ontapdev-doc-add-verbose-details.patch create mode 100644 0003-netapp-ontapdev-fix-fw-version-handling.patch create mode 100644 0004-netapp-ontapdev-fix-JSON-output-for-nsze-nuse.patch create mode 100644 0005-nvme-netapp-update-err-messages.patch create mode 100644 0006-netapp-smdev-remove-redundant-code.patch create mode 100644 0007-netapp-smdev-add-verbose-output.patch create mode 100644 0008-netapp-smdev-doc-add-verbose-details.patch diff --git a/0001-netapp-ontapdev-add-verbose-output.patch b/0001-netapp-ontapdev-add-verbose-output.patch new file mode 100644 index 0000000..57236de --- /dev/null +++ b/0001-netapp-ontapdev-add-verbose-output.patch @@ -0,0 +1,239 @@ +From ab841e9a58688e64c5ce50e6159f34fc1a414c48 Mon Sep 17 00:00:00 2001 +From: Martin George +Date: Mon, 11 Nov 2024 22:08:39 +0530 +Subject: [PATCH] netapp-ontapdev: add verbose output + +Add a vebose output option to display additional information of +ONTAP devices on the host. + +Signed-off-by: Martin George +--- + plugins/netapp/netapp-nvme.c | 141 +++++++++++++++++++++++++++++++---- + 1 file changed, 126 insertions(+), 15 deletions(-) + +diff --git a/plugins/netapp/netapp-nvme.c b/plugins/netapp/netapp-nvme.c +index 9f05ffc5..cebd019e 100644 +--- a/plugins/netapp/netapp-nvme.c ++++ b/plugins/netapp/netapp-nvme.c +@@ -119,6 +119,42 @@ static void netapp_get_ns_size(char *size, unsigned long long *lba, + sprintf(size, "%.2f%sB", nsze, s_suffix); + } + ++static void netapp_get_ns_attrs(char *size, char *used, char *blk_size, ++ char *version, unsigned long long *lba, ++ struct nvme_id_ctrl *ctrl, struct nvme_id_ns *ns) ++{ ++ __u8 lba_index; ++ ++ nvme_id_ns_flbas_to_lbaf_inuse(ns->flbas, &lba_index); ++ *lba = 1ULL << ns->lbaf[lba_index].ds; ++ ++ /* get the namespace size */ ++ double nsze = le64_to_cpu(ns->nsze) * (*lba); ++ const char *s_suffix = suffix_si_get(&nsze); ++ ++ sprintf(size, "%.2f%sB", nsze, s_suffix); ++ ++ /* get the namespace utilization */ ++ double nuse = le64_to_cpu(ns->nuse) * (*lba); ++ const char *u_suffix = suffix_si_get(&nuse); ++ ++ sprintf(used, "%.2f%sB", nuse, u_suffix); ++ ++ /* get the namespace block size */ ++ long long addr = 1LL << ns->lbaf[lba_index].ds; ++ const char *l_suffix = suffix_binary_get(&addr); ++ ++ sprintf(blk_size, "%u%sB", (unsigned int)addr, l_suffix); ++ ++ /* get the ontap version */ ++ int i, max = sizeof(ctrl->fr); ++ ++ memcpy(version, ctrl->fr, sizeof(ctrl->fr)); ++ /* strip trailing whitespaces */ ++ for (i = max - 1; i >= 0 && version[i] == ' '; i--) ++ version[i] = '\0'; ++} ++ + static void ontap_labels_to_str(char *dst, char *src, int count) + { + int i; +@@ -235,7 +271,8 @@ static void netapp_smdevice_json(struct json_object *devices, char *devname, + + static void netapp_ontapdevice_json(struct json_object *devices, char *devname, + char *vsname, char *nspath, int nsid, char *uuid, +- char *size, long long lba, long long nsze) ++ unsigned long long lba, char *version, ++ unsigned long long nsze, unsigned long long nuse) + { + struct json_object *device_attrs; + +@@ -245,9 +282,10 @@ static void netapp_ontapdevice_json(struct json_object *devices, char *devname, + json_object_add_value_string(device_attrs, "Namespace_Path", nspath); + json_object_add_value_int(device_attrs, "NSID", nsid); + json_object_add_value_string(device_attrs, "UUID", uuid); +- json_object_add_value_string(device_attrs, "Size", size); +- json_object_add_value_int(device_attrs, "LBA_Data_Size", lba); +- json_object_add_value_int(device_attrs, "Namespace_Size", nsze); ++ json_object_add_value_uint64(device_attrs, "LBA_Data_Size", lba); ++ json_object_add_value_uint64(device_attrs, "Namespace_Size", nsze); ++ json_object_add_value_uint64(device_attrs, "UsedBytes", nuse); ++ json_object_add_value_string(device_attrs, "Version", version); + + json_array_add_value_object(devices, device_attrs); + } +@@ -410,6 +448,66 @@ out: + json_free_object(root); + } + ++static void netapp_ontapdevices_print_verbose(struct ontapdevice_info *devices, ++ int count, int format, const char *devname) ++{ ++ char vsname[ONTAP_LABEL_LEN] = " "; ++ char nspath[ONTAP_NS_PATHLEN] = " "; ++ unsigned long long lba; ++ char size[128], used[128]; ++ char blk_size[128], version[8]; ++ char uuid_str[37] = " "; ++ int i; ++ ++ char *formatstr = NULL; ++ char basestr[] = ++ "%s, Vserver %s, Path %s, NSID %d, UUID %s, %s, %s, %s, %s\n"; ++ char columnstr[] = "%-16s %-25s %-50s %-4d %-38s %-9s %-9s %-9s %-9s\n"; ++ ++ if (format == NNORMAL) ++ formatstr = basestr; ++ else if (format == NCOLUMN) { ++ printf("%-16s %-25s %-50s %-4s %-38s %-9s %-9s %-9s %-9s\n", ++ "Device", "Vserver", "Namespace Path", ++ "NSID", "UUID", "Size", "Used", ++ "Format", "Version"); ++ printf("%-16s %-25s %-50s %-4s %-38s %-9s %-9s %-9s %-9s\n", ++ "----------------", "-------------------------", ++ "--------------------------------------------------", ++ "----", "--------------------------------------", ++ "---------", "---------", "---------", "---------"); ++ formatstr = columnstr; ++ } ++ ++ for (i = 0; i < count; i++) { ++ if (devname && !strcmp(devname, basename(devices[i].dev))) { ++ /* found the device, fetch and print for that alone */ ++ netapp_get_ns_attrs(size, used, blk_size, version, ++ &lba, &devices[i].ctrl, &devices[i].ns); ++ nvme_uuid_to_string(devices[i].uuid, uuid_str); ++ netapp_get_ontap_labels(vsname, nspath, ++ devices[i].log_data); ++ ++ printf(formatstr, devices[i].dev, vsname, nspath, ++ devices[i].nsid, uuid_str, size, used, ++ blk_size, version); ++ return; ++ } ++ } ++ ++ for (i = 0; i < count; i++) { ++ /* fetch info and print for all devices */ ++ netapp_get_ns_attrs(size, used, blk_size, version, ++ &lba, &devices[i].ctrl, &devices[i].ns); ++ nvme_uuid_to_string(devices[i].uuid, uuid_str); ++ netapp_get_ontap_labels(vsname, nspath, devices[i].log_data); ++ ++ printf(formatstr, devices[i].dev, vsname, nspath, ++ devices[i].nsid, uuid_str, size, used, ++ blk_size, version); ++ } ++} ++ + static void netapp_ontapdevices_print_regular(struct ontapdevice_info *devices, + int count, int format, const char *devname) + { +@@ -472,7 +570,8 @@ static void netapp_ontapdevices_print_json(struct ontapdevice_info *devices, + char vsname[ONTAP_LABEL_LEN] = " "; + char nspath[ONTAP_NS_PATHLEN] = " "; + unsigned long long lba; +- char size[128]; ++ char size[128], used[128]; ++ char blk_size[128], version[8]; + char uuid_str[37] = " "; + int i; + +@@ -483,28 +582,33 @@ static void netapp_ontapdevices_print_json(struct ontapdevice_info *devices, + for (i = 0; i < count; i++) { + if (devname && !strcmp(devname, basename(devices[i].dev))) { + /* found the device, fetch info for that alone */ +- netapp_get_ns_size(size, &lba, &devices[i].ns); ++ netapp_get_ns_attrs(size, used, blk_size, version, ++ &lba, &devices[i].ctrl, &devices[i].ns); + nvme_uuid_to_string(devices[i].uuid, uuid_str); +- netapp_get_ontap_labels(vsname, nspath, devices[i].log_data); ++ netapp_get_ontap_labels(vsname, nspath, ++ devices[i].log_data); + + netapp_ontapdevice_json(json_devices, devices[i].dev, + vsname, nspath, devices[i].nsid, +- uuid_str, size, lba, +- le64_to_cpu(devices[i].ns.nsze)); ++ uuid_str, lba, version, ++ le64_to_cpu(devices[i].ns.nsze), ++ le64_to_cpu(devices[i].ns.nuse)); + goto out; + } + } + + for (i = 0; i < count; i++) { + /* fetch info for all devices */ +- netapp_get_ns_size(size, &lba, &devices[i].ns); ++ netapp_get_ns_attrs(size, used, blk_size, version, ++ &lba, &devices[i].ctrl, &devices[i].ns); + nvme_uuid_to_string(devices[i].uuid, uuid_str); + netapp_get_ontap_labels(vsname, nspath, devices[i].log_data); + + netapp_ontapdevice_json(json_devices, devices[i].dev, + vsname, nspath, devices[i].nsid, +- uuid_str, size, lba, +- le64_to_cpu(devices[i].ns.nsze)); ++ uuid_str, lba, version, ++ le64_to_cpu(devices[i].ns.nsze), ++ le64_to_cpu(devices[i].ns.nuse)); + } + + out: +@@ -776,6 +880,7 @@ static int netapp_ontapdevices(int argc, char **argv, struct command *command, + int num_ontapdevices = 0; + + struct config { ++ bool verbose; + char *output_format; + }; + +@@ -784,6 +889,7 @@ static int netapp_ontapdevices(int argc, char **argv, struct command *command, + }; + + OPT_ARGS(opts) = { ++ OPT_FLAG("verbose", 'v', &cfg.verbose, "Increase output verbosity"), + OPT_FMT("output-format", 'o', &cfg.output_format, "Output Format: normal|json|column"), + OPT_END() + }; +@@ -839,9 +945,14 @@ static int netapp_ontapdevices(int argc, char **argv, struct command *command, + } + + if (num_ontapdevices) { +- if (fmt == NNORMAL || fmt == NCOLUMN) +- netapp_ontapdevices_print_regular(ontapdevices, +- num_ontapdevices, fmt, devname); ++ if (fmt == NNORMAL || fmt == NCOLUMN) { ++ if (argconfig_parse_seen(opts, "verbose")) ++ netapp_ontapdevices_print_verbose(ontapdevices, ++ num_ontapdevices, fmt, devname); ++ else ++ netapp_ontapdevices_print_regular(ontapdevices, ++ num_ontapdevices, fmt, devname); ++ } + else if (fmt == NJSON) + netapp_ontapdevices_print_json(ontapdevices, + num_ontapdevices, devname); +-- +2.43.5 + diff --git a/0002-netapp-ontapdev-doc-add-verbose-details.patch b/0002-netapp-ontapdev-doc-add-verbose-details.patch new file mode 100644 index 0000000..ff243e0 --- /dev/null +++ b/0002-netapp-ontapdev-doc-add-verbose-details.patch @@ -0,0 +1,39 @@ +From a8d1efcaba26dd992d89da2e60999642d7ae8eca Mon Sep 17 00:00:00 2001 +From: Martin George +Date: Wed, 13 Nov 2024 00:14:07 +0530 +Subject: [PATCH] netapp-ontapdev-doc: add verbose details + +Add verbose option details to the ontapdevices documentation. + +Signed-off-by: Martin George +--- + Documentation/nvme-netapp-ontapdevices.txt | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +diff --git a/Documentation/nvme-netapp-ontapdevices.txt b/Documentation/nvme-netapp-ontapdevices.txt +index fc28947d..e56bae57 100644 +--- a/Documentation/nvme-netapp-ontapdevices.txt ++++ b/Documentation/nvme-netapp-ontapdevices.txt +@@ -8,7 +8,7 @@ nvme-netapp-ontapdevices - Display information about ONTAP devices + SYNOPSIS + -------- + [verse] +-'nvme netapp ontapdevices' [--output-format= | -o ] ++'nvme netapp ontapdevices' [--output-format= | -o ] [--verbose | -v] + + DESCRIPTION + ----------- +@@ -22,6 +22,10 @@ OPTIONS + Set the reporting format to 'normal' (default), 'column', or + 'json'. Only one output format can be used at a time. + ++-v:: ++--verbose:: ++ Display additional information of ONTAP devices on the host. ++ + EXAMPLES + -------- + * Display information, in a column-based format, for ONTAP devices. +-- +2.43.5 + diff --git a/0003-netapp-ontapdev-fix-fw-version-handling.patch b/0003-netapp-ontapdev-fix-fw-version-handling.patch new file mode 100644 index 0000000..0e9f3b5 --- /dev/null +++ b/0003-netapp-ontapdev-fix-fw-version-handling.patch @@ -0,0 +1,52 @@ +From 24961e9d228531f1cb60739239d7591aa70bdd53 Mon Sep 17 00:00:00 2001 +From: Martin George +Date: Fri, 29 Nov 2024 11:04:34 +0530 +Subject: [PATCH] netapp-ontapdev: fix fw version handling + +The string used to capture the fw version was not handled +properly. Fix the same. + +Signed-off-by: Martin George +--- + plugins/netapp/netapp-nvme.c | 9 +++++---- + 1 file changed, 5 insertions(+), 4 deletions(-) + +diff --git a/plugins/netapp/netapp-nvme.c b/plugins/netapp/netapp-nvme.c +index cebd019e..76e8ddf1 100644 +--- a/plugins/netapp/netapp-nvme.c ++++ b/plugins/netapp/netapp-nvme.c +@@ -146,10 +146,11 @@ static void netapp_get_ns_attrs(char *size, char *used, char *blk_size, + + sprintf(blk_size, "%u%sB", (unsigned int)addr, l_suffix); + +- /* get the ontap version */ ++ /* get the firmware version */ + int i, max = sizeof(ctrl->fr); + +- memcpy(version, ctrl->fr, sizeof(ctrl->fr)); ++ memcpy(version, ctrl->fr, max); ++ version[max] = '\0'; + /* strip trailing whitespaces */ + for (i = max - 1; i >= 0 && version[i] == ' '; i--) + version[i] = '\0'; +@@ -455,7 +456,7 @@ static void netapp_ontapdevices_print_verbose(struct ontapdevice_info *devices, + char nspath[ONTAP_NS_PATHLEN] = " "; + unsigned long long lba; + char size[128], used[128]; +- char blk_size[128], version[8]; ++ char blk_size[128], version[9]; + char uuid_str[37] = " "; + int i; + +@@ -571,7 +572,7 @@ static void netapp_ontapdevices_print_json(struct ontapdevice_info *devices, + char nspath[ONTAP_NS_PATHLEN] = " "; + unsigned long long lba; + char size[128], used[128]; +- char blk_size[128], version[8]; ++ char blk_size[128], version[9]; + char uuid_str[37] = " "; + int i; + +-- +2.43.5 + diff --git a/0004-netapp-ontapdev-fix-JSON-output-for-nsze-nuse.patch b/0004-netapp-ontapdev-fix-JSON-output-for-nsze-nuse.patch new file mode 100644 index 0000000..f120801 --- /dev/null +++ b/0004-netapp-ontapdev-fix-JSON-output-for-nsze-nuse.patch @@ -0,0 +1,42 @@ +From b5208a987bf85ae3f4e264e6df55a7fb9acd9907 Mon Sep 17 00:00:00 2001 +From: Martin George +Date: Fri, 29 Nov 2024 11:10:16 +0530 +Subject: [PATCH] netapp-ontapdev: fix JSON output for nsze & nuse + +The namespace size & utilization values printed in the JSON +output was incorrect. Fix the same. + +Signed-off-by: Martin George +--- + plugins/netapp/netapp-nvme.c | 8 +++++--- + 1 file changed, 5 insertions(+), 3 deletions(-) + +diff --git a/plugins/netapp/netapp-nvme.c b/plugins/netapp/netapp-nvme.c +index 76e8ddf1..6ff428d9 100644 +--- a/plugins/netapp/netapp-nvme.c ++++ b/plugins/netapp/netapp-nvme.c +@@ -276,6 +276,8 @@ static void netapp_ontapdevice_json(struct json_object *devices, char *devname, + unsigned long long nsze, unsigned long long nuse) + { + struct json_object *device_attrs; ++ unsigned long long ns_size = nsze * lba; ++ unsigned long long used_size = nuse * lba; + + device_attrs = json_create_object(); + json_object_add_value_string(device_attrs, "Device", devname); +@@ -283,9 +285,9 @@ static void netapp_ontapdevice_json(struct json_object *devices, char *devname, + json_object_add_value_string(device_attrs, "Namespace_Path", nspath); + json_object_add_value_int(device_attrs, "NSID", nsid); + json_object_add_value_string(device_attrs, "UUID", uuid); +- json_object_add_value_uint64(device_attrs, "LBA_Data_Size", lba); +- json_object_add_value_uint64(device_attrs, "Namespace_Size", nsze); +- json_object_add_value_uint64(device_attrs, "UsedBytes", nuse); ++ json_object_add_value_uint64(device_attrs, "LBA_Size", lba); ++ json_object_add_value_uint64(device_attrs, "Namespace_Size", ns_size); ++ json_object_add_value_uint64(device_attrs, "UsedBytes", used_size); + json_object_add_value_string(device_attrs, "Version", version); + + json_array_add_value_object(devices, device_attrs); +-- +2.43.5 + diff --git a/0005-nvme-netapp-update-err-messages.patch b/0005-nvme-netapp-update-err-messages.patch new file mode 100644 index 0000000..b227166 --- /dev/null +++ b/0005-nvme-netapp-update-err-messages.patch @@ -0,0 +1,53 @@ +From 6f1f902af071fc46b78485ce851ffaaeb444c25f Mon Sep 17 00:00:00 2001 +From: Martin George +Date: Fri, 29 Nov 2024 11:15:23 +0530 +Subject: [PATCH] nvme-netapp: update err messages + +Trivial fix to update a few error messages. + +Signed-off-by: Martin George +--- + plugins/netapp/netapp-nvme.c | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/plugins/netapp/netapp-nvme.c b/plugins/netapp/netapp-nvme.c +index 6ff428d9..aee65215 100644 +--- a/plugins/netapp/netapp-nvme.c ++++ b/plugins/netapp/netapp-nvme.c +@@ -816,7 +816,7 @@ static int netapp_smdevices(int argc, char **argv, struct command *command, + + num = scandir(dev_path, &devices, netapp_nvme_filter, alphasort); + if (num <= 0) { +- fprintf(stderr, "No NVMe devices detected.\n"); ++ fprintf(stderr, "No NVMe devices detected\n"); + return num; + } + +@@ -834,7 +834,7 @@ static int netapp_smdevices(int argc, char **argv, struct command *command, + + smdevices = calloc(num, sizeof(*smdevices)); + if (!smdevices) { +- fprintf(stderr, "Unable to allocate memory for devices.\n"); ++ fprintf(stderr, "Unable to allocate memory for devices\n"); + return -ENOMEM; + } + +@@ -921,13 +921,13 @@ static int netapp_ontapdevices(int argc, char **argv, struct command *command, + + num = scandir(dev_path, &devices, netapp_nvme_filter, alphasort); + if (num <= 0) { +- fprintf(stderr, "No NVMe devices detected.\n"); ++ fprintf(stderr, "No NVMe devices detected\n"); + return num; + } + + ontapdevices = calloc(num, sizeof(*ontapdevices)); + if (!ontapdevices) { +- fprintf(stderr, "Unable to allocate memory for devices.\n"); ++ fprintf(stderr, "Unable to allocate memory for devices\n"); + return -ENOMEM; + } + +-- +2.43.5 + diff --git a/0006-netapp-smdev-remove-redundant-code.patch b/0006-netapp-smdev-remove-redundant-code.patch new file mode 100644 index 0000000..d0643b7 --- /dev/null +++ b/0006-netapp-smdev-remove-redundant-code.patch @@ -0,0 +1,106 @@ +From b8c9a3c1ee55c2477ce1ce0348014aa891dee58d Mon Sep 17 00:00:00 2001 +From: Martin George +Date: Tue, 3 Dec 2024 13:16:17 +0530 +Subject: [PATCH] netapp-smdev: remove redundant code + +Remove redundant code in regular and JSON functions, which is +already invoked in a separate function. + +Signed-off-by: Martin George +--- + plugins/netapp/netapp-nvme.c | 44 +++++++----------------------------- + 1 file changed, 8 insertions(+), 36 deletions(-) + +diff --git a/plugins/netapp/netapp-nvme.c b/plugins/netapp/netapp-nvme.c +index aee65215..f839852d 100644 +--- a/plugins/netapp/netapp-nvme.c ++++ b/plugins/netapp/netapp-nvme.c +@@ -300,7 +300,8 @@ static void netapp_smdevices_print_regular(struct smdevice_info *devices, + char array_label[ARRAY_LABEL_LEN / 2 + 1]; + char volume_label[VOLUME_LABEL_LEN / 2 + 1]; + char nguid_str[33]; +- __u8 lba_index; ++ unsigned long long lba; ++ char size[128]; + + char *formatstr = NULL; + char basestr[] = +@@ -325,15 +326,7 @@ static void netapp_smdevices_print_regular(struct smdevice_info *devices, + for (i = 0; i < count; i++) { + if (devname && !strcmp(devname, basename(devices[i].dev))) { + /* found the device, fetch info for that alone */ +- nvme_id_ns_flbas_to_lbaf_inuse(devices[i].ns.flbas, +- &lba_index); +- unsigned long long lba = 1ULL << +- devices[i].ns.lbaf[lba_index].ds; +- double nsze = le64_to_cpu(devices[i].ns.nsze) * lba; +- const char *s_suffix = suffix_si_get(&nsze); +- char size[128]; +- +- sprintf(size, "%.2f%sB", nsze, s_suffix); ++ netapp_get_ns_size(size, &lba, &devices[i].ns); + netapp_convert_string(array_label, + (char *)&devices[i].ctrl.vs[20], + ARRAY_LABEL_LEN / 2); +@@ -353,14 +346,7 @@ static void netapp_smdevices_print_regular(struct smdevice_info *devices, + + for (i = 0; i < count; i++) { + /* fetch info for all devices */ +- nvme_id_ns_flbas_to_lbaf_inuse(devices[i].ns.flbas, &lba_index); +- unsigned long long lba = 1ULL << +- devices[i].ns.lbaf[lba_index].ds; +- double nsze = le64_to_cpu(devices[i].ns.nsze) * lba; +- const char *s_suffix = suffix_si_get(&nsze); +- char size[128]; +- +- sprintf(size, "%.2f%sB", nsze, s_suffix); ++ netapp_get_ns_size(size, &lba, &devices[i].ns); + netapp_convert_string(array_label, + (char *)&devices[i].ctrl.vs[20], + ARRAY_LABEL_LEN / 2); +@@ -384,7 +370,8 @@ static void netapp_smdevices_print_json(struct smdevice_info *devices, + char array_label[ARRAY_LABEL_LEN / 2 + 1]; + char volume_label[VOLUME_LABEL_LEN / 2 + 1]; + char nguid_str[33]; +- __u8 lba_index; ++ unsigned long long lba; ++ char size[128]; + + /* prepare for the json output */ + root = json_create_object(); +@@ -393,15 +380,7 @@ static void netapp_smdevices_print_json(struct smdevice_info *devices, + for (i = 0; i < count; i++) { + if (devname && !strcmp(devname, basename(devices[i].dev))) { + /* found the device, fetch info for that alone */ +- nvme_id_ns_flbas_to_lbaf_inuse(devices[i].ns.flbas, +- &lba_index); +- unsigned long long lba = 1ULL << +- devices[i].ns.lbaf[lba_index].ds; +- double nsze = le64_to_cpu(devices[i].ns.nsze) * lba; +- const char *s_suffix = suffix_si_get(&nsze); +- char size[128]; +- +- sprintf(size, "%.2f%sB", nsze, s_suffix); ++ netapp_get_ns_size(size, &lba, &devices[i].ns); + netapp_convert_string(array_label, + (char *)&devices[i].ctrl.vs[20], + ARRAY_LABEL_LEN / 2); +@@ -421,14 +400,7 @@ static void netapp_smdevices_print_json(struct smdevice_info *devices, + + for (i = 0; i < count; i++) { + /* fetch info for all devices */ +- nvme_id_ns_flbas_to_lbaf_inuse(devices[i].ns.flbas, &lba_index); +- unsigned long long lba = 1ULL << +- devices[i].ns.lbaf[lba_index].ds; +- double nsze = le64_to_cpu(devices[i].ns.nsze) * lba; +- const char *s_suffix = suffix_si_get(&nsze); +- char size[128]; +- +- sprintf(size, "%.2f%sB", nsze, s_suffix); ++ netapp_get_ns_size(size, &lba, &devices[i].ns); + netapp_convert_string(array_label, + (char *)&devices[i].ctrl.vs[20], + ARRAY_LABEL_LEN / 2); +-- +2.43.5 + diff --git a/0007-netapp-smdev-add-verbose-output.patch b/0007-netapp-smdev-add-verbose-output.patch new file mode 100644 index 0000000..5a7a5de --- /dev/null +++ b/0007-netapp-smdev-add-verbose-output.patch @@ -0,0 +1,230 @@ +From 0943fc446609996dc6acf2fae7f31a6c20c28e06 Mon Sep 17 00:00:00 2001 +From: Martin George +Date: Wed, 4 Dec 2024 00:24:48 +0530 +Subject: [PATCH] netapp-smdev: add verbose output + +Add a verbose option to display additional information of smdevices +on the host. And while at it, make a few corrections/modifications +to the JSON output as well. + +Signed-off-by: Martin George +Tested-by: Clayton Skaggs +--- + plugins/netapp/netapp-nvme.c | 123 ++++++++++++++++++++++++++++++----- + 1 file changed, 108 insertions(+), 15 deletions(-) + +diff --git a/plugins/netapp/netapp-nvme.c b/plugins/netapp/netapp-nvme.c +index f839852d..d86e93e1 100644 +--- a/plugins/netapp/netapp-nvme.c ++++ b/plugins/netapp/netapp-nvme.c +@@ -250,10 +250,11 @@ static void netapp_get_ontap_labels(char *vsname, char *nspath, + + static void netapp_smdevice_json(struct json_object *devices, char *devname, + char *arrayname, char *volname, int nsid, char *nguid, +- char *ctrl, char *astate, char *size, long long lba, +- long long nsze) ++ char *ctrl, char *astate, char *version, unsigned long long lba, ++ unsigned long long nsze, unsigned long long nuse) + { + struct json_object *device_attrs; ++ unsigned long long ns_size = nsze * lba; + + device_attrs = json_create_object(); + json_object_add_value_string(device_attrs, "Device", devname); +@@ -263,9 +264,9 @@ static void netapp_smdevice_json(struct json_object *devices, char *devname, + json_object_add_value_string(device_attrs, "Volume_ID", nguid); + json_object_add_value_string(device_attrs, "Controller", ctrl); + json_object_add_value_string(device_attrs, "Access_State", astate); +- json_object_add_value_string(device_attrs, "Size", size); +- json_object_add_value_int(device_attrs, "LBA_Data_Size", lba); +- json_object_add_value_int(device_attrs, "Namespace_Size", nsze); ++ json_object_add_value_uint64(device_attrs, "LBA_Size", lba); ++ json_object_add_value_uint64(device_attrs, "Namespace_Size", ns_size); ++ json_object_add_value_string(device_attrs, "Version", version); + + json_array_add_value_object(devices, device_attrs); + } +@@ -293,6 +294,84 @@ static void netapp_ontapdevice_json(struct json_object *devices, char *devname, + json_array_add_value_object(devices, device_attrs); + } + ++static void netapp_smdevices_print_verbose(struct smdevice_info *devices, ++ int count, int format, const char *devname) ++{ ++ int i, slta; ++ char array_label[ARRAY_LABEL_LEN / 2 + 1]; ++ char volume_label[VOLUME_LABEL_LEN / 2 + 1]; ++ char nguid_str[33]; ++ unsigned long long lba; ++ char size[128], used[128]; ++ char blk_size[128], version[9]; ++ ++ char *formatstr = NULL; ++ char basestr[] = ++ "%s, Array %s, Vol %s, NSID %d, ID %s, Ctrl %c, %s, %s, %s, %s\n"; ++ char columnstr[] = ++ "%-16s %-30s %-30s %4d %32s %c %-12s %-9s %-9s %-9s\n"; ++ ++ if (format == NNORMAL) ++ formatstr = basestr; ++ else if (format == NCOLUMN) { ++ /* print column headers and change the output string */ ++ printf("%-16s %-30s %-30s %-4s %-32s %-4s %-12s %-9s %-9s %-9s\n", ++ "Device", "Array Name", "Volume Name", "NSID", ++ "Volume ID", "Ctrl", "Access State", " Size", ++ "Format", "Version"); ++ printf("%-16s %-30s %-30s %-4s %-32s %-4s %-12s %-9s %-9s %-9s\n", ++ "----------------", "------------------------------", ++ "------------------------------", "----", ++ "--------------------------------", "----", ++ "------------", "---------", ++ "---------", "---------"); ++ formatstr = columnstr; ++ } ++ ++ for (i = 0; i < count; i++) { ++ if (devname && !strcmp(devname, basename(devices[i].dev))) { ++ /* found the device, fetch info for that alone */ ++ netapp_get_ns_attrs(size, used, blk_size, version, ++ &lba, &devices[i].ctrl, &devices[i].ns); ++ netapp_convert_string(array_label, ++ (char *)&devices[i].ctrl.vs[20], ++ ARRAY_LABEL_LEN / 2); ++ slta = devices[i].ctrl.vs[0] & 0x1; ++ netapp_convert_string(volume_label, ++ (char *)devices[i].ns.vs, ++ VOLUME_LABEL_LEN / 2); ++ netapp_nguid_to_str(nguid_str, devices[i].ns.nguid); ++ ++ printf(formatstr, devices[i].dev, array_label, ++ volume_label, devices[i].nsid, ++ nguid_str, ++ slta ? 'A' : 'B', "unknown", size, ++ blk_size, version); ++ return; ++ } ++ } ++ ++ for (i = 0; i < count; i++) { ++ /* fetch info and print for all devices */ ++ netapp_get_ns_attrs(size, used, blk_size, version, ++ &lba, &devices[i].ctrl, &devices[i].ns); ++ netapp_convert_string(array_label, ++ (char *)&devices[i].ctrl.vs[20], ++ ARRAY_LABEL_LEN / 2); ++ slta = devices[i].ctrl.vs[0] & 0x1; ++ netapp_convert_string(volume_label, ++ (char *)devices[i].ns.vs, ++ VOLUME_LABEL_LEN / 2); ++ netapp_nguid_to_str(nguid_str, devices[i].ns.nguid); ++ ++ printf(formatstr, devices[i].dev, array_label, ++ volume_label, devices[i].nsid, ++ nguid_str, ++ slta ? 'A' : 'B', "unknown", size, ++ blk_size, version); ++ } ++} ++ + static void netapp_smdevices_print_regular(struct smdevice_info *devices, + int count, int format, const char *devname) + { +@@ -311,7 +390,7 @@ static void netapp_smdevices_print_regular(struct smdevice_info *devices, + if (format == NNORMAL) + formatstr = basestr; + else if (format == NCOLUMN) { +- /* change output string and print column headers */ ++ /* print column headers and change the output string */ + printf("%-16s %-30s %-30s %-4s %-32s %-4s %-12s %-9s\n", + "Device", "Array Name", "Volume Name", "NSID", + "Volume ID", "Ctrl", "Access State", " Size"); +@@ -371,7 +450,8 @@ static void netapp_smdevices_print_json(struct smdevice_info *devices, + char volume_label[VOLUME_LABEL_LEN / 2 + 1]; + char nguid_str[33]; + unsigned long long lba; +- char size[128]; ++ char size[128], used[128]; ++ char blk_size[128], version[9]; + + /* prepare for the json output */ + root = json_create_object(); +@@ -380,7 +460,8 @@ static void netapp_smdevices_print_json(struct smdevice_info *devices, + for (i = 0; i < count; i++) { + if (devname && !strcmp(devname, basename(devices[i].dev))) { + /* found the device, fetch info for that alone */ +- netapp_get_ns_size(size, &lba, &devices[i].ns); ++ netapp_get_ns_attrs(size, used, blk_size, version, ++ &lba, &devices[i].ctrl, &devices[i].ns); + netapp_convert_string(array_label, + (char *)&devices[i].ctrl.vs[20], + ARRAY_LABEL_LEN / 2); +@@ -392,15 +473,18 @@ static void netapp_smdevices_print_json(struct smdevice_info *devices, + netapp_smdevice_json(json_devices, devices[i].dev, + array_label, volume_label, + devices[i].nsid, nguid_str, +- slta ? "A" : "B", "unknown", size, lba, +- le64_to_cpu(devices[i].ns.nsze)); ++ slta ? "A" : "B", "unknown", ++ version, lba, ++ le64_to_cpu(devices[i].ns.nsze), ++ le64_to_cpu(devices[i].ns.nuse)); + goto out; + } + } + + for (i = 0; i < count; i++) { + /* fetch info for all devices */ +- netapp_get_ns_size(size, &lba, &devices[i].ns); ++ netapp_get_ns_attrs(size, used, blk_size, version, ++ &lba, &devices[i].ctrl, &devices[i].ns); + netapp_convert_string(array_label, + (char *)&devices[i].ctrl.vs[20], + ARRAY_LABEL_LEN / 2); +@@ -412,7 +496,9 @@ static void netapp_smdevices_print_json(struct smdevice_info *devices, + netapp_smdevice_json(json_devices, devices[i].dev, + array_label, volume_label, devices[i].nsid, + nguid_str, slta ? "A" : "B", "unknown", +- size, lba, le64_to_cpu(devices[i].ns.nsze)); ++ version, lba, ++ le64_to_cpu(devices[i].ns.nsze), ++ le64_to_cpu(devices[i].ns.nuse)); + } + + out: +@@ -764,6 +850,7 @@ static int netapp_smdevices(int argc, char **argv, struct command *command, + int num_smdevices = 0; + + struct config { ++ bool verbose; + char *output_format; + }; + +@@ -772,6 +859,7 @@ static int netapp_smdevices(int argc, char **argv, struct command *command, + }; + + OPT_ARGS(opts) = { ++ OPT_FLAG("verbose", 'v', &cfg.verbose, "Increase output verbosity"), + OPT_FMT("output-format", 'o', &cfg.output_format, "Output Format: normal|json|column"), + OPT_END() + }; +@@ -826,9 +914,14 @@ static int netapp_smdevices(int argc, char **argv, struct command *command, + } + + if (num_smdevices) { +- if (fmt == NNORMAL || fmt == NCOLUMN) +- netapp_smdevices_print_regular(smdevices, +- num_smdevices, fmt, devname); ++ if (fmt == NNORMAL || fmt == NCOLUMN) { ++ if (argconfig_parse_seen(opts, "verbose")) ++ netapp_smdevices_print_verbose(smdevices, ++ num_smdevices, fmt, devname); ++ else ++ netapp_smdevices_print_regular(smdevices, ++ num_smdevices, fmt, devname); ++ } + else if (fmt == NJSON) + netapp_smdevices_print_json(smdevices, + num_smdevices, devname); +-- +2.43.5 + diff --git a/0008-netapp-smdev-doc-add-verbose-details.patch b/0008-netapp-smdev-doc-add-verbose-details.patch new file mode 100644 index 0000000..650ab42 --- /dev/null +++ b/0008-netapp-smdev-doc-add-verbose-details.patch @@ -0,0 +1,40 @@ +From cd69ccb4d51b4c0b1f772f9fef42fbf441e4a7f2 Mon Sep 17 00:00:00 2001 +From: Martin George +Date: Tue, 3 Dec 2024 13:26:56 +0530 +Subject: [PATCH] netapp-smdev-doc: add verbose details + +Add verbose option details to the smdevices documentation. + +Signed-off-by: Martin George +Tested-by: Clayton Skaggs +--- + Documentation/nvme-netapp-smdevices.txt | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +diff --git a/Documentation/nvme-netapp-smdevices.txt b/Documentation/nvme-netapp-smdevices.txt +index cb68acf7..c135ff0c 100644 +--- a/Documentation/nvme-netapp-smdevices.txt ++++ b/Documentation/nvme-netapp-smdevices.txt +@@ -8,7 +8,7 @@ nvme-netapp-smdevices - Display information for each NVMe path to an E-Series vo + SYNOPSIS + -------- + [verse] +-'nvme netapp smdevices' [--output-format= | -o ] ++'nvme netapp smdevices' [--output-format= | -o ] [--verbose | -v] + + DESCRIPTION + ----------- +@@ -23,6 +23,10 @@ OPTIONS + Set the reporting format to 'normal' (default), 'column', or + 'json'. Only one output format can be used at a time. + ++-v:: ++--verbose:: ++ Display additional information of E-Series devices on the host. ++ + EXAMPLES + -------- + * Display information, in a column-based format, for each path to an E-Series +-- +2.43.5 + diff --git a/nvme-cli.spec b/nvme-cli.spec index efe060f..af785ba 100644 --- a/nvme-cli.spec +++ b/nvme-cli.spec @@ -5,7 +5,7 @@ Name: nvme-cli Version: 2.11 -Release: 2%{?dist} +Release: 3%{?dist} Summary: NVMe management command line interface License: GPL-2.0-only @@ -13,6 +13,14 @@ URL: https://github.com/linux-nvme/nvme-cli Source0: %{url}/archive/v%{version}/%{name}-%{version}.tar.gz Source1: 99-nvme-nbft-connect.sh Source2: 99-nvme-nbft-no-ignore-carrier.conf +Patch0: 0001-netapp-ontapdev-add-verbose-output.patch +Patch1: 0002-netapp-ontapdev-doc-add-verbose-details.patch +Patch2: 0003-netapp-ontapdev-fix-fw-version-handling.patch +Patch3: 0004-netapp-ontapdev-fix-JSON-output-for-nsze-nuse.patch +Patch4: 0005-nvme-netapp-update-err-messages.patch +Patch5: 0006-netapp-smdev-remove-redundant-code.patch +Patch6: 0007-netapp-smdev-add-verbose-output.patch +Patch7: 0008-netapp-smdev-doc-add-verbose-details.patch BuildRequires: meson >= 0.50.0 BuildRequires: gcc gcc-c++ @@ -96,6 +104,9 @@ if [ $1 -eq 1 ] || [ $1 -eq 2 ]; then fi %changelog +* Thu Jan 16 2025 Maurizio Lombardi - 2.11-3 +- NetApp fixes for RHEL-71521 + * Fri Nov 15 2024 Maurizio Lombardi - 2.11-2 - Rebuild for RHEL-67144