diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-11-09 08:09:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-11-09 08:09:59 +0000 |
commit | 3a023e2f691f3679889da0d63f377704e395e58a (patch) | |
tree | 90bcede47e76472c15225259d858ceb7987c9ff1 /plugins/netapp | |
parent | Releasing debian version 2.10.2-1. (diff) | |
download | nvme-cli-3a023e2f691f3679889da0d63f377704e395e58a.tar.xz nvme-cli-3a023e2f691f3679889da0d63f377704e395e58a.zip |
Merging upstream version 2.11.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'plugins/netapp')
-rw-r--r-- | plugins/netapp/netapp-nvme.c | 308 |
1 files changed, 244 insertions, 64 deletions
diff --git a/plugins/netapp/netapp-nvme.c b/plugins/netapp/netapp-nvme.c index 99f0a20..5c2e3d4 100644 --- a/plugins/netapp/netapp-nvme.c +++ b/plugins/netapp/netapp-nvme.c @@ -251,23 +251,24 @@ static void netapp_ontapdevice_json(struct json_object *devices, char *devname, json_array_add_value_object(devices, device_attrs); } -static void netapp_smdevices_print(struct smdevice_info *devices, int count, int format) +static void netapp_smdevices_print_regular(struct smdevice_info *devices, + int count, int format, const char *devname) { - struct json_object *root = NULL; - struct json_object *json_devices = NULL; int i, slta; char array_label[ARRAY_LABEL_LEN / 2 + 1]; char volume_label[VOLUME_LABEL_LEN / 2 + 1]; char nguid_str[33]; + __u8 lba_index; + + char *formatstr = NULL; char basestr[] = "%s, Array Name %s, Volume Name %s, NSID %d, Volume ID %s, Controller %c, Access State %s, %s\n"; char columnstr[] = "%-16s %-30s %-30s %4d %32s %c %-12s %9s\n"; - char *formatstr = basestr; /* default to "normal" output format */ - __u8 lba_index; - if (format == NCOLUMN) { - /* for column output, change output string and print column headers */ - formatstr = columnstr; + if (format == NNORMAL) + formatstr = basestr; + else if (format == NCOLUMN) { + /* change output string and print column headers */ printf("%-16s %-30s %-30s %-4s %-32s %-4s %-12s %-9s\n", "Device", "Array Name", "Volume Name", "NSID", "Volume ID", "Ctrl", "Access State", " Size"); @@ -276,51 +277,141 @@ static void netapp_smdevices_print(struct smdevice_info *devices, int count, int "------------------------------", "----", "--------------------------------", "----", "------------", "---------"); - } else if (format == NJSON) { - /* prepare for json output */ - root = json_create_object(); - json_devices = json_create_array(); + formatstr = columnstr; + } + + 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_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); + return; + } } 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; + 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_convert_string(array_label, (char *)&devices[i].ctrl.vs[20], - ARRAY_LABEL_LEN / 2); + 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); + VOLUME_LABEL_LEN / 2); netapp_nguid_to_str(nguid_str, devices[i].ns.nguid); - if (format == NJSON) - 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)); - else - printf(formatstr, devices[i].dev, array_label, + + printf(formatstr, devices[i].dev, array_label, volume_label, devices[i].nsid, nguid_str, slta ? 'A' : 'B', "unknown", size); } - - if (format == NJSON) { - /* complete the json output */ - json_object_add_value_array(root, "SMdevices", json_devices); - json_print_object(root, NULL); - printf("\n"); - json_free_object(root); - } } -static void netapp_ontapdevices_print(struct ontapdevice_info *devices, - int count, int format) +static void netapp_smdevices_print_json(struct smdevice_info *devices, + int count, const char *devname) { struct json_object *root = NULL; struct json_object *json_devices = NULL; + int i, slta; + char array_label[ARRAY_LABEL_LEN / 2 + 1]; + char volume_label[VOLUME_LABEL_LEN / 2 + 1]; + char nguid_str[33]; + __u8 lba_index; + + /* prepare for the json output */ + root = json_create_object(); + json_devices = json_create_array(); + + 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_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); + 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)); + goto out; + } + } + + 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_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); + 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)); + } + +out: + /* complete the json output */ + json_object_add_value_array(root, "SMdevices", json_devices); + json_print_object(root, NULL); + printf("\n"); + json_free_object(root); +} + +static void netapp_ontapdevices_print_regular(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; @@ -328,52 +419,99 @@ static void netapp_ontapdevices_print(struct ontapdevice_info *devices, char uuid_str[37] = " "; int i; - char basestr[] = "%s, Vserver %s, Namespace Path %s, NSID %d, UUID %s, %s\n"; + char *formatstr = NULL; + char basestr[] = + "%s, Vserver %s, Namespace Path %s, NSID %d, UUID %s, %s\n"; char columnstr[] = "%-16s %-25s %-50s %-4d %-38s %-9s\n"; - /* default to 'normal' output format */ - char *formatstr = basestr; - - if (format == NCOLUMN) { - /* change output string and print column headers */ - formatstr = columnstr; + if (format == NNORMAL) + formatstr = basestr; + else if (format == NCOLUMN) { printf("%-16s %-25s %-50s %-4s %-38s %-9s\n", - "Device", "Vserver", "Namespace Path", - "NSID", "UUID", "Size"); + "Device", "Vserver", "Namespace Path", + "NSID", "UUID", "Size"); printf("%-16s %-25s %-50s %-4s %-38s %-9s\n", - "----------------", "-------------------------", - "--------------------------------------------------", - "----", "--------------------------------------", - "---------"); - } else if (format == NJSON) { - /* prepare for json output */ - root = json_create_object(); - json_devices = json_create_array(); + "----------------", "-------------------------", + "--------------------------------------------------", + "----", "--------------------------------------", + "---------"); + 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_size(size, &lba, &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); + return; + } + } + for (i = 0; i < count; i++) { + /* fetch info and print for all devices */ netapp_get_ns_size(size, &lba, &devices[i].ns); nvme_uuid_to_string(devices[i].uuid, uuid_str); netapp_get_ontap_labels(vsname, nspath, devices[i].log_data); - if (format == NJSON) { + printf(formatstr, devices[i].dev, vsname, nspath, + devices[i].nsid, uuid_str, size); + } +} + +static void netapp_ontapdevices_print_json(struct ontapdevice_info *devices, + int count, const char *devname) +{ + struct json_object *root = NULL; + struct json_object *json_devices = NULL; + char vsname[ONTAP_LABEL_LEN] = " "; + char nspath[ONTAP_NS_PATHLEN] = " "; + unsigned long long lba; + char size[128]; + char uuid_str[37] = " "; + int i; + + /* prepare for the json output */ + root = json_create_object(); + json_devices = json_create_array(); + + 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); + 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)); - } else - printf(formatstr, devices[i].dev, vsname, nspath, - devices[i].nsid, uuid_str, size); + goto out; + } } - if (format == NJSON) { - /* complete the json output */ - json_object_add_value_array(root, "ONTAPdevices", json_devices); - json_print_object(root, NULL); - printf("\n"); - json_free_object(root); + for (i = 0; i < count; i++) { + /* fetch info for all devices */ + netapp_get_ns_size(size, &lba, &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)); } + +out: + /* complete the json output */ + json_object_add_value_array(root, "ONTAPdevices", json_devices); + json_print_object(root, NULL); + printf("\n"); + json_free_object(root); } static int nvme_get_ontap_c2_log(int fd, __u32 nsid, void *buf, __u32 buflen) @@ -470,6 +608,8 @@ static int netapp_ontapdevices_get_info(int fd, struct ontapdevice_info *item, return 0; } + memset(nsdescs, 0, 0x1000); + err = nvme_identify_ns_descs(fd, item->nsid, nsdescs); if (err) { fprintf(stderr, "Unable to identify namespace descriptor for %s (%s)\n", @@ -540,6 +680,7 @@ static int netapp_smdevices(int argc, char **argv, struct command *command, int num, i, fd, ret, fmt; struct smdevice_info *smdevices; char path[264]; + char *devname = NULL; int num_smdevices = 0; struct config { @@ -571,6 +712,18 @@ static int netapp_smdevices(int argc, char **argv, struct command *command, return num; } + if (optind < argc) + devname = basename(argv[optind++]); + + if (devname) { + int subsys_num, nsid; + + if (sscanf(devname, "nvme%dn%d", &subsys_num, &nsid) != 2) { + fprintf(stderr, "Invalid device name %s\n", devname); + return -EINVAL; + } + } + smdevices = calloc(num, sizeof(*smdevices)); if (!smdevices) { fprintf(stderr, "Unable to allocate memory for devices.\n"); @@ -592,8 +745,15 @@ static int netapp_smdevices(int argc, char **argv, struct command *command, close(fd); } - if (num_smdevices) - netapp_smdevices_print(smdevices, num_smdevices, fmt); + if (num_smdevices) { + if (fmt == NNORMAL || fmt == NCOLUMN) + netapp_smdevices_print_regular(smdevices, + num_smdevices, fmt, devname); + else if (fmt == NJSON) + netapp_smdevices_print_json(smdevices, + num_smdevices, devname); + } else + fprintf(stderr, "No smdevices detected\n"); for (i = 0; i < num; i++) free(devices[i]); @@ -611,6 +771,7 @@ static int netapp_ontapdevices(int argc, char **argv, struct command *command, int num, i, fd, ret, fmt; struct ontapdevice_info *ontapdevices; char path[264]; + char *devname = NULL; int num_ontapdevices = 0; struct config { @@ -636,6 +797,18 @@ static int netapp_ontapdevices(int argc, char **argv, struct command *command, return -EINVAL; } + if (optind < argc) + devname = basename(argv[optind++]); + + if (devname) { + int subsys_num, nsid; + + if (sscanf(devname, "nvme%dn%d", &subsys_num, &nsid) != 2) { + fprintf(stderr, "Invalid device name %s\n", devname); + return -EINVAL; + } + } + num = scandir(dev_path, &devices, netapp_nvme_filter, alphasort); if (num <= 0) { fprintf(stderr, "No NVMe devices detected.\n"); @@ -664,8 +837,15 @@ static int netapp_ontapdevices(int argc, char **argv, struct command *command, close(fd); } - if (num_ontapdevices) - netapp_ontapdevices_print(ontapdevices, num_ontapdevices, fmt); + if (num_ontapdevices) { + if (fmt == NNORMAL || fmt == NCOLUMN) + netapp_ontapdevices_print_regular(ontapdevices, + num_ontapdevices, fmt, devname); + else if (fmt == NJSON) + netapp_ontapdevices_print_json(ontapdevices, + num_ontapdevices, devname); + } else + fprintf(stderr, "No ontapdevices detected\n"); for (i = 0; i < num; i++) free(devices[i]); |