Skip to content

Commit ab841e9

Browse files
martin-gpyigaw
authored andcommitted
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 ac48189 commit ab841e9

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
@@ -119,6 +119,42 @@ static void netapp_get_ns_size(char *size, unsigned long long *lba,
119119
sprintf(size, "%.2f%sB", nsze, s_suffix);
120120
}
121121

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

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

@@ -245,9 +282,10 @@ static void netapp_ontapdevice_json(struct json_object *devices, char *devname,
245282
json_object_add_value_string(device_attrs, "Namespace_Path", nspath);
246283
json_object_add_value_int(device_attrs, "NSID", nsid);
247284
json_object_add_value_string(device_attrs, "UUID", uuid);
248-
json_object_add_value_string(device_attrs, "Size", size);
249-
json_object_add_value_int(device_attrs, "LBA_Data_Size", lba);
250-
json_object_add_value_int(device_attrs, "Namespace_Size", nsze);
285+
json_object_add_value_uint64(device_attrs, "LBA_Data_Size", lba);
286+
json_object_add_value_uint64(device_attrs, "Namespace_Size", nsze);
287+
json_object_add_value_uint64(device_attrs, "UsedBytes", nuse);
288+
json_object_add_value_string(device_attrs, "Version", version);
251289

252290
json_array_add_value_object(devices, device_attrs);
253291
}
@@ -410,6 +448,66 @@ static void netapp_smdevices_print_json(struct smdevice_info *devices,
410448
json_free_object(root);
411449
}
412450

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

@@ -483,28 +582,33 @@ static void netapp_ontapdevices_print_json(struct ontapdevice_info *devices,
483582
for (i = 0; i < count; i++) {
484583
if (devname && !strcmp(devname, basename(devices[i].dev))) {
485584
/* found the device, fetch info for that alone */
486-
netapp_get_ns_size(size, &lba, &devices[i].ns);
585+
netapp_get_ns_attrs(size, used, blk_size, version,
586+
&lba, &devices[i].ctrl, &devices[i].ns);
487587
nvme_uuid_to_string(devices[i].uuid, uuid_str);
488-
netapp_get_ontap_labels(vsname, nspath, devices[i].log_data);
588+
netapp_get_ontap_labels(vsname, nspath,
589+
devices[i].log_data);
489590

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

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

504607
netapp_ontapdevice_json(json_devices, devices[i].dev,
505608
vsname, nspath, devices[i].nsid,
506-
uuid_str, size, lba,
507-
le64_to_cpu(devices[i].ns.nsze));
609+
uuid_str, lba, version,
610+
le64_to_cpu(devices[i].ns.nsze),
611+
le64_to_cpu(devices[i].ns.nuse));
508612
}
509613

510614
out:
@@ -776,6 +880,7 @@ static int netapp_ontapdevices(int argc, char **argv, struct command *command,
776880
int num_ontapdevices = 0;
777881

778882
struct config {
883+
bool verbose;
779884
char *output_format;
780885
};
781886

@@ -784,6 +889,7 @@ static int netapp_ontapdevices(int argc, char **argv, struct command *command,
784889
};
785890

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

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

0 commit comments

Comments
 (0)