Skip to content

Commit f708c3e

Browse files
committed
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 <[email protected]>
1 parent b96cd2d commit f708c3e

File tree

1 file changed

+126
-15
lines changed

1 file changed

+126
-15
lines changed

plugins/netapp/netapp-nvme.c

Lines changed: 126 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,42 @@ static void netapp_get_ns_size(char *size, unsigned long long *lba,
118118
sprintf(size, "%.2f%sB", nsze, s_suffix);
119119
}
120120

121+
static void netapp_get_ns_attrs(char *size, char *used, char *blk_size,
122+
char *version, unsigned long long *lba,
123+
struct nvme_id_ctrl *ctrl, struct nvme_id_ns *ns)
124+
{
125+
__u8 lba_index;
126+
127+
nvme_id_ns_flbas_to_lbaf_inuse(ns->flbas, &lba_index);
128+
*lba = 1ULL << ns->lbaf[lba_index].ds;
129+
130+
/* get the namespace size */
131+
double nsze = le64_to_cpu(ns->nsze) * (*lba);
132+
const char *s_suffix = suffix_si_get(&nsze);
133+
134+
sprintf(size, "%.2f%sB", nsze, s_suffix);
135+
136+
/* get the namespace utilization */
137+
double nuse = le64_to_cpu(ns->nuse) * (*lba);
138+
const char *u_suffix = suffix_si_get(&nuse);
139+
140+
sprintf(used, "%.2f%sB", nuse, u_suffix);
141+
142+
/* get the namespace block size */
143+
long long addr = 1LL << ns->lbaf[lba_index].ds;
144+
const char *l_suffix = suffix_binary_get(&addr);
145+
146+
sprintf(blk_size, "%u%sB", (unsigned int)addr, l_suffix);
147+
148+
/* get the ontap version */
149+
int i, max = sizeof(ctrl->fr);
150+
151+
memcpy(version, ctrl->fr, sizeof(ctrl->fr));
152+
/* strip trailing whitespaces */
153+
for (i = max - 1; i >= 0 && version[i] == ' '; i--)
154+
version[i] = '\0';
155+
}
156+
121157
static void ontap_labels_to_str(char *dst, char *src, int count)
122158
{
123159
int i;
@@ -234,7 +270,8 @@ static void netapp_smdevice_json(struct json_object *devices, char *devname,
234270

235271
static void netapp_ontapdevice_json(struct json_object *devices, char *devname,
236272
char *vsname, char *nspath, int nsid, char *uuid,
237-
char *size, long long lba, long long nsze)
273+
unsigned long long lba, char *version,
274+
unsigned long long nsze, unsigned long long nuse)
238275
{
239276
struct json_object *device_attrs;
240277

@@ -244,9 +281,10 @@ static void netapp_ontapdevice_json(struct json_object *devices, char *devname,
244281
json_object_add_value_string(device_attrs, "Namespace_Path", nspath);
245282
json_object_add_value_int(device_attrs, "NSID", nsid);
246283
json_object_add_value_string(device_attrs, "UUID", uuid);
247-
json_object_add_value_string(device_attrs, "Size", size);
248-
json_object_add_value_int(device_attrs, "LBA_Data_Size", lba);
249-
json_object_add_value_int(device_attrs, "Namespace_Size", nsze);
284+
json_object_add_value_uint64(device_attrs, "LBA_Data_Size", lba);
285+
json_object_add_value_uint64(device_attrs, "Namespace_Size", nsze);
286+
json_object_add_value_uint64(device_attrs, "UsedBytes", nuse);
287+
json_object_add_value_string(device_attrs, "Version", version);
250288

251289
json_array_add_value_object(devices, device_attrs);
252290
}
@@ -409,6 +447,66 @@ static void netapp_smdevices_print_json(struct smdevice_info *devices,
409447
json_free_object(root);
410448
}
411449

450+
static void netapp_ontapdevices_print_verbose(struct ontapdevice_info *devices,
451+
int count, int format, const char *devname)
452+
{
453+
char vsname[ONTAP_LABEL_LEN] = " ";
454+
char nspath[ONTAP_NS_PATHLEN] = " ";
455+
unsigned long long lba;
456+
char size[128], used[128];
457+
char blk_size[128], version[8];
458+
char uuid_str[37] = " ";
459+
int i;
460+
461+
char *formatstr = NULL;
462+
char basestr[] =
463+
"%s, Vserver %s, Path %s, NSID %d, UUID %s, %s, %s, %s, %s\n";
464+
char columnstr[] = "%-16s %-25s %-50s %-4d %-38s %-9s %-9s %-9s %-9s\n";
465+
466+
if (format == NNORMAL)
467+
formatstr = basestr;
468+
else if (format == NCOLUMN) {
469+
printf("%-16s %-25s %-50s %-4s %-38s %-9s %-9s %-9s %-9s\n",
470+
"Device", "Vserver", "Namespace Path",
471+
"NSID", "UUID", "Size", "Used",
472+
"Format", "Version");
473+
printf("%-16s %-25s %-50s %-4s %-38s %-9s %-9s %-9s %-9s\n",
474+
"----------------", "-------------------------",
475+
"--------------------------------------------------",
476+
"----", "--------------------------------------",
477+
"---------", "---------", "---------", "---------");
478+
formatstr = columnstr;
479+
}
480+
481+
for (i = 0; i < count; i++) {
482+
if (devname && !strcmp(devname, basename(devices[i].dev))) {
483+
/* found the device, fetch and print for that alone */
484+
netapp_get_ns_attrs(size, used, blk_size, version,
485+
&lba, &devices[i].ctrl, &devices[i].ns);
486+
nvme_uuid_to_string(devices[i].uuid, uuid_str);
487+
netapp_get_ontap_labels(vsname, nspath,
488+
devices[i].log_data);
489+
490+
printf(formatstr, devices[i].dev, vsname, nspath,
491+
devices[i].nsid, uuid_str, size, used,
492+
blk_size, version);
493+
return;
494+
}
495+
}
496+
497+
for (i = 0; i < count; i++) {
498+
/* fetch info and print for all devices */
499+
netapp_get_ns_attrs(size, used, blk_size, version,
500+
&lba, &devices[i].ctrl, &devices[i].ns);
501+
nvme_uuid_to_string(devices[i].uuid, uuid_str);
502+
netapp_get_ontap_labels(vsname, nspath, devices[i].log_data);
503+
504+
printf(formatstr, devices[i].dev, vsname, nspath,
505+
devices[i].nsid, uuid_str, size, used,
506+
blk_size, version);
507+
}
508+
}
509+
412510
static void netapp_ontapdevices_print_regular(struct ontapdevice_info *devices,
413511
int count, int format, const char *devname)
414512
{
@@ -471,7 +569,8 @@ static void netapp_ontapdevices_print_json(struct ontapdevice_info *devices,
471569
char vsname[ONTAP_LABEL_LEN] = " ";
472570
char nspath[ONTAP_NS_PATHLEN] = " ";
473571
unsigned long long lba;
474-
char size[128];
572+
char size[128], used[128];
573+
char blk_size[128], version[8];
475574
char uuid_str[37] = " ";
476575
int i;
477576

@@ -482,28 +581,33 @@ static void netapp_ontapdevices_print_json(struct ontapdevice_info *devices,
482581
for (i = 0; i < count; i++) {
483582
if (devname && !strcmp(devname, basename(devices[i].dev))) {
484583
/* found the device, fetch info for that alone */
485-
netapp_get_ns_size(size, &lba, &devices[i].ns);
584+
netapp_get_ns_attrs(size, used, blk_size, version,
585+
&lba, &devices[i].ctrl, &devices[i].ns);
486586
nvme_uuid_to_string(devices[i].uuid, uuid_str);
487-
netapp_get_ontap_labels(vsname, nspath, devices[i].log_data);
587+
netapp_get_ontap_labels(vsname, nspath,
588+
devices[i].log_data);
488589

489590
netapp_ontapdevice_json(json_devices, devices[i].dev,
490591
vsname, nspath, devices[i].nsid,
491-
uuid_str, size, lba,
492-
le64_to_cpu(devices[i].ns.nsze));
592+
uuid_str, lba, version,
593+
le64_to_cpu(devices[i].ns.nsze),
594+
le64_to_cpu(devices[i].ns.nuse));
493595
goto out;
494596
}
495597
}
496598

497599
for (i = 0; i < count; i++) {
498600
/* fetch info for all devices */
499-
netapp_get_ns_size(size, &lba, &devices[i].ns);
601+
netapp_get_ns_attrs(size, used, blk_size, version,
602+
&lba, &devices[i].ctrl, &devices[i].ns);
500603
nvme_uuid_to_string(devices[i].uuid, uuid_str);
501604
netapp_get_ontap_labels(vsname, nspath, devices[i].log_data);
502605

503606
netapp_ontapdevice_json(json_devices, devices[i].dev,
504607
vsname, nspath, devices[i].nsid,
505-
uuid_str, size, lba,
506-
le64_to_cpu(devices[i].ns.nsze));
608+
uuid_str, lba, version,
609+
le64_to_cpu(devices[i].ns.nsze),
610+
le64_to_cpu(devices[i].ns.nuse));
507611
}
508612

509613
out:
@@ -775,6 +879,7 @@ static int netapp_ontapdevices(int argc, char **argv, struct command *command,
775879
int num_ontapdevices = 0;
776880

777881
struct config {
882+
bool verbose;
778883
char *output_format;
779884
};
780885

@@ -783,6 +888,7 @@ static int netapp_ontapdevices(int argc, char **argv, struct command *command,
783888
};
784889

785890
OPT_ARGS(opts) = {
891+
OPT_FLAG("verbose", 'v', &cfg.verbose, "Increase output verbosity"),
786892
OPT_FMT("output-format", 'o', &cfg.output_format, "Output Format: normal|json|column"),
787893
OPT_END()
788894
};
@@ -838,9 +944,14 @@ static int netapp_ontapdevices(int argc, char **argv, struct command *command,
838944
}
839945

840946
if (num_ontapdevices) {
841-
if (fmt == NNORMAL || fmt == NCOLUMN)
842-
netapp_ontapdevices_print_regular(ontapdevices,
843-
num_ontapdevices, fmt, devname);
947+
if (fmt == NNORMAL || fmt == NCOLUMN) {
948+
if (argconfig_parse_seen(opts, "verbose"))
949+
netapp_ontapdevices_print_verbose(ontapdevices,
950+
num_ontapdevices, fmt, devname);
951+
else
952+
netapp_ontapdevices_print_regular(ontapdevices,
953+
num_ontapdevices, fmt, devname);
954+
}
844955
else if (fmt == NJSON)
845956
netapp_ontapdevices_print_json(ontapdevices,
846957
num_ontapdevices, devname);

0 commit comments

Comments
 (0)