Skip to content

Commit 0943fc4

Browse files
martin-gpyigaw
authored andcommitted
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 <[email protected]> Tested-by: Clayton Skaggs <[email protected]>
1 parent cd69ccb commit 0943fc4

File tree

1 file changed

+108
-15
lines changed

1 file changed

+108
-15
lines changed

plugins/netapp/netapp-nvme.c

Lines changed: 108 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,11 @@ static void netapp_get_ontap_labels(char *vsname, char *nspath,
250250

251251
static void netapp_smdevice_json(struct json_object *devices, char *devname,
252252
char *arrayname, char *volname, int nsid, char *nguid,
253-
char *ctrl, char *astate, char *size, long long lba,
254-
long long nsze)
253+
char *ctrl, char *astate, char *version, unsigned long long lba,
254+
unsigned long long nsze, unsigned long long nuse)
255255
{
256256
struct json_object *device_attrs;
257+
unsigned long long ns_size = nsze * lba;
257258

258259
device_attrs = json_create_object();
259260
json_object_add_value_string(device_attrs, "Device", devname);
@@ -263,9 +264,9 @@ static void netapp_smdevice_json(struct json_object *devices, char *devname,
263264
json_object_add_value_string(device_attrs, "Volume_ID", nguid);
264265
json_object_add_value_string(device_attrs, "Controller", ctrl);
265266
json_object_add_value_string(device_attrs, "Access_State", astate);
266-
json_object_add_value_string(device_attrs, "Size", size);
267-
json_object_add_value_int(device_attrs, "LBA_Data_Size", lba);
268-
json_object_add_value_int(device_attrs, "Namespace_Size", nsze);
267+
json_object_add_value_uint64(device_attrs, "LBA_Size", lba);
268+
json_object_add_value_uint64(device_attrs, "Namespace_Size", ns_size);
269+
json_object_add_value_string(device_attrs, "Version", version);
269270

270271
json_array_add_value_object(devices, device_attrs);
271272
}
@@ -293,6 +294,84 @@ static void netapp_ontapdevice_json(struct json_object *devices, char *devname,
293294
json_array_add_value_object(devices, device_attrs);
294295
}
295296

297+
static void netapp_smdevices_print_verbose(struct smdevice_info *devices,
298+
int count, int format, const char *devname)
299+
{
300+
int i, slta;
301+
char array_label[ARRAY_LABEL_LEN / 2 + 1];
302+
char volume_label[VOLUME_LABEL_LEN / 2 + 1];
303+
char nguid_str[33];
304+
unsigned long long lba;
305+
char size[128], used[128];
306+
char blk_size[128], version[9];
307+
308+
char *formatstr = NULL;
309+
char basestr[] =
310+
"%s, Array %s, Vol %s, NSID %d, ID %s, Ctrl %c, %s, %s, %s, %s\n";
311+
char columnstr[] =
312+
"%-16s %-30s %-30s %4d %32s %c %-12s %-9s %-9s %-9s\n";
313+
314+
if (format == NNORMAL)
315+
formatstr = basestr;
316+
else if (format == NCOLUMN) {
317+
/* print column headers and change the output string */
318+
printf("%-16s %-30s %-30s %-4s %-32s %-4s %-12s %-9s %-9s %-9s\n",
319+
"Device", "Array Name", "Volume Name", "NSID",
320+
"Volume ID", "Ctrl", "Access State", " Size",
321+
"Format", "Version");
322+
printf("%-16s %-30s %-30s %-4s %-32s %-4s %-12s %-9s %-9s %-9s\n",
323+
"----------------", "------------------------------",
324+
"------------------------------", "----",
325+
"--------------------------------", "----",
326+
"------------", "---------",
327+
"---------", "---------");
328+
formatstr = columnstr;
329+
}
330+
331+
for (i = 0; i < count; i++) {
332+
if (devname && !strcmp(devname, basename(devices[i].dev))) {
333+
/* found the device, fetch info for that alone */
334+
netapp_get_ns_attrs(size, used, blk_size, version,
335+
&lba, &devices[i].ctrl, &devices[i].ns);
336+
netapp_convert_string(array_label,
337+
(char *)&devices[i].ctrl.vs[20],
338+
ARRAY_LABEL_LEN / 2);
339+
slta = devices[i].ctrl.vs[0] & 0x1;
340+
netapp_convert_string(volume_label,
341+
(char *)devices[i].ns.vs,
342+
VOLUME_LABEL_LEN / 2);
343+
netapp_nguid_to_str(nguid_str, devices[i].ns.nguid);
344+
345+
printf(formatstr, devices[i].dev, array_label,
346+
volume_label, devices[i].nsid,
347+
nguid_str,
348+
slta ? 'A' : 'B', "unknown", size,
349+
blk_size, version);
350+
return;
351+
}
352+
}
353+
354+
for (i = 0; i < count; i++) {
355+
/* fetch info and print for all devices */
356+
netapp_get_ns_attrs(size, used, blk_size, version,
357+
&lba, &devices[i].ctrl, &devices[i].ns);
358+
netapp_convert_string(array_label,
359+
(char *)&devices[i].ctrl.vs[20],
360+
ARRAY_LABEL_LEN / 2);
361+
slta = devices[i].ctrl.vs[0] & 0x1;
362+
netapp_convert_string(volume_label,
363+
(char *)devices[i].ns.vs,
364+
VOLUME_LABEL_LEN / 2);
365+
netapp_nguid_to_str(nguid_str, devices[i].ns.nguid);
366+
367+
printf(formatstr, devices[i].dev, array_label,
368+
volume_label, devices[i].nsid,
369+
nguid_str,
370+
slta ? 'A' : 'B', "unknown", size,
371+
blk_size, version);
372+
}
373+
}
374+
296375
static void netapp_smdevices_print_regular(struct smdevice_info *devices,
297376
int count, int format, const char *devname)
298377
{
@@ -311,7 +390,7 @@ static void netapp_smdevices_print_regular(struct smdevice_info *devices,
311390
if (format == NNORMAL)
312391
formatstr = basestr;
313392
else if (format == NCOLUMN) {
314-
/* change output string and print column headers */
393+
/* print column headers and change the output string */
315394
printf("%-16s %-30s %-30s %-4s %-32s %-4s %-12s %-9s\n",
316395
"Device", "Array Name", "Volume Name", "NSID",
317396
"Volume ID", "Ctrl", "Access State", " Size");
@@ -371,7 +450,8 @@ static void netapp_smdevices_print_json(struct smdevice_info *devices,
371450
char volume_label[VOLUME_LABEL_LEN / 2 + 1];
372451
char nguid_str[33];
373452
unsigned long long lba;
374-
char size[128];
453+
char size[128], used[128];
454+
char blk_size[128], version[9];
375455

376456
/* prepare for the json output */
377457
root = json_create_object();
@@ -380,7 +460,8 @@ static void netapp_smdevices_print_json(struct smdevice_info *devices,
380460
for (i = 0; i < count; i++) {
381461
if (devname && !strcmp(devname, basename(devices[i].dev))) {
382462
/* found the device, fetch info for that alone */
383-
netapp_get_ns_size(size, &lba, &devices[i].ns);
463+
netapp_get_ns_attrs(size, used, blk_size, version,
464+
&lba, &devices[i].ctrl, &devices[i].ns);
384465
netapp_convert_string(array_label,
385466
(char *)&devices[i].ctrl.vs[20],
386467
ARRAY_LABEL_LEN / 2);
@@ -392,15 +473,18 @@ static void netapp_smdevices_print_json(struct smdevice_info *devices,
392473
netapp_smdevice_json(json_devices, devices[i].dev,
393474
array_label, volume_label,
394475
devices[i].nsid, nguid_str,
395-
slta ? "A" : "B", "unknown", size, lba,
396-
le64_to_cpu(devices[i].ns.nsze));
476+
slta ? "A" : "B", "unknown",
477+
version, lba,
478+
le64_to_cpu(devices[i].ns.nsze),
479+
le64_to_cpu(devices[i].ns.nuse));
397480
goto out;
398481
}
399482
}
400483

401484
for (i = 0; i < count; i++) {
402485
/* fetch info for all devices */
403-
netapp_get_ns_size(size, &lba, &devices[i].ns);
486+
netapp_get_ns_attrs(size, used, blk_size, version,
487+
&lba, &devices[i].ctrl, &devices[i].ns);
404488
netapp_convert_string(array_label,
405489
(char *)&devices[i].ctrl.vs[20],
406490
ARRAY_LABEL_LEN / 2);
@@ -412,7 +496,9 @@ static void netapp_smdevices_print_json(struct smdevice_info *devices,
412496
netapp_smdevice_json(json_devices, devices[i].dev,
413497
array_label, volume_label, devices[i].nsid,
414498
nguid_str, slta ? "A" : "B", "unknown",
415-
size, lba, le64_to_cpu(devices[i].ns.nsze));
499+
version, lba,
500+
le64_to_cpu(devices[i].ns.nsze),
501+
le64_to_cpu(devices[i].ns.nuse));
416502
}
417503

418504
out:
@@ -764,6 +850,7 @@ static int netapp_smdevices(int argc, char **argv, struct command *command,
764850
int num_smdevices = 0;
765851

766852
struct config {
853+
bool verbose;
767854
char *output_format;
768855
};
769856

@@ -772,6 +859,7 @@ static int netapp_smdevices(int argc, char **argv, struct command *command,
772859
};
773860

774861
OPT_ARGS(opts) = {
862+
OPT_FLAG("verbose", 'v', &cfg.verbose, "Increase output verbosity"),
775863
OPT_FMT("output-format", 'o', &cfg.output_format, "Output Format: normal|json|column"),
776864
OPT_END()
777865
};
@@ -826,9 +914,14 @@ static int netapp_smdevices(int argc, char **argv, struct command *command,
826914
}
827915

828916
if (num_smdevices) {
829-
if (fmt == NNORMAL || fmt == NCOLUMN)
830-
netapp_smdevices_print_regular(smdevices,
831-
num_smdevices, fmt, devname);
917+
if (fmt == NNORMAL || fmt == NCOLUMN) {
918+
if (argconfig_parse_seen(opts, "verbose"))
919+
netapp_smdevices_print_verbose(smdevices,
920+
num_smdevices, fmt, devname);
921+
else
922+
netapp_smdevices_print_regular(smdevices,
923+
num_smdevices, fmt, devname);
924+
}
832925
else if (fmt == NJSON)
833926
netapp_smdevices_print_json(smdevices,
834927
num_smdevices, devname);

0 commit comments

Comments
 (0)