}
}
-static void netapp_ontapdevices_print(struct ontapdevice_info *devices,
+static void netapp_ontapdevices_print_regular(struct ontapdevice_info *devices,
int count, int format)
{
- 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 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++) {
-
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) {
- 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);
+ printf(formatstr, devices[i].dev, vsname, nspath,
+ devices[i].nsid, uuid_str, size);
}
+}
- 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);
+static void netapp_ontapdevices_print_json(struct ontapdevice_info *devices,
+ int count)
+{
+ 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++) {
+ 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));
}
+
+ /* 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)
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);
+ else if (fmt == NJSON)
+ netapp_ontapdevices_print_json(ontapdevices,
+ num_ontapdevices);
+ }
for (i = 0; i < num; i++)
free(devices[i]);