@@ -317,7 +317,7 @@ static void netapp_smdevices_print(struct smdevice_info *devices, int count, int
317
317
}
318
318
319
319
static void netapp_ontapdevices_print_regular (struct ontapdevice_info * devices ,
320
- int count , int format )
320
+ int count , int format , const char * devname )
321
321
{
322
322
char vsname [ONTAP_LABEL_LEN ] = " " ;
323
323
char nspath [ONTAP_NS_PATHLEN ] = " " ;
@@ -346,6 +346,21 @@ static void netapp_ontapdevices_print_regular(struct ontapdevice_info *devices,
346
346
}
347
347
348
348
for (i = 0 ; i < count ; i ++ ) {
349
+ if (devname && !strcmp (devname , basename (devices [i ].dev ))) {
350
+ /* found the device, fetch and print for that alone */
351
+ netapp_get_ns_size (size , & lba , & devices [i ].ns );
352
+ nvme_uuid_to_string (devices [i ].uuid , uuid_str );
353
+ netapp_get_ontap_labels (vsname , nspath ,
354
+ devices [i ].log_data );
355
+
356
+ printf (formatstr , devices [i ].dev , vsname , nspath ,
357
+ devices [i ].nsid , uuid_str , size );
358
+ return ;
359
+ }
360
+ }
361
+
362
+ for (i = 0 ; i < count ; i ++ ) {
363
+ /* fetch info and print for all devices */
349
364
netapp_get_ns_size (size , & lba , & devices [i ].ns );
350
365
nvme_uuid_to_string (devices [i ].uuid , uuid_str );
351
366
netapp_get_ontap_labels (vsname , nspath , devices [i ].log_data );
@@ -356,7 +371,7 @@ static void netapp_ontapdevices_print_regular(struct ontapdevice_info *devices,
356
371
}
357
372
358
373
static void netapp_ontapdevices_print_json (struct ontapdevice_info * devices ,
359
- int count )
374
+ int count , const char * devname )
360
375
{
361
376
struct json_object * root = NULL ;
362
377
struct json_object * json_devices = NULL ;
@@ -372,6 +387,22 @@ static void netapp_ontapdevices_print_json(struct ontapdevice_info *devices,
372
387
json_devices = json_create_array ();
373
388
374
389
for (i = 0 ; i < count ; i ++ ) {
390
+ if (devname && !strcmp (devname , basename (devices [i ].dev ))) {
391
+ /* found the device, fetch info for that alone */
392
+ netapp_get_ns_size (size , & lba , & devices [i ].ns );
393
+ nvme_uuid_to_string (devices [i ].uuid , uuid_str );
394
+ netapp_get_ontap_labels (vsname , nspath , devices [i ].log_data );
395
+
396
+ netapp_ontapdevice_json (json_devices , devices [i ].dev ,
397
+ vsname , nspath , devices [i ].nsid ,
398
+ uuid_str , size , lba ,
399
+ le64_to_cpu (devices [i ].ns .nsze ));
400
+ goto out ;
401
+ }
402
+ }
403
+
404
+ for (i = 0 ; i < count ; i ++ ) {
405
+ /* fetch info for all devices */
375
406
netapp_get_ns_size (size , & lba , & devices [i ].ns );
376
407
nvme_uuid_to_string (devices [i ].uuid , uuid_str );
377
408
netapp_get_ontap_labels (vsname , nspath , devices [i ].log_data );
@@ -382,6 +413,7 @@ static void netapp_ontapdevices_print_json(struct ontapdevice_info *devices,
382
413
le64_to_cpu (devices [i ].ns .nsze ));
383
414
}
384
415
416
+ out :
385
417
/* complete the json output */
386
418
json_object_add_value_array (root , "ONTAPdevices" , json_devices );
387
419
json_print_object (root , NULL );
@@ -626,6 +658,7 @@ static int netapp_ontapdevices(int argc, char **argv, struct command *command,
626
658
int num , i , fd , ret , fmt ;
627
659
struct ontapdevice_info * ontapdevices ;
628
660
char path [264 ];
661
+ char * devname = NULL ;
629
662
int num_ontapdevices = 0 ;
630
663
631
664
struct config {
@@ -651,6 +684,18 @@ static int netapp_ontapdevices(int argc, char **argv, struct command *command,
651
684
return - EINVAL ;
652
685
}
653
686
687
+ if (optind < argc )
688
+ devname = basename (argv [optind ++ ]);
689
+
690
+ if (devname ) {
691
+ int subsys_num , nsid ;
692
+
693
+ if (sscanf (devname , "nvme%dn%d" , & subsys_num , & nsid ) != 2 ) {
694
+ fprintf (stderr , "Invalid device name %s\n" , devname );
695
+ return - EINVAL ;
696
+ }
697
+ }
698
+
654
699
num = scandir (dev_path , & devices , netapp_nvme_filter , alphasort );
655
700
if (num <= 0 ) {
656
701
fprintf (stderr , "No NVMe devices detected.\n" );
@@ -682,10 +727,10 @@ static int netapp_ontapdevices(int argc, char **argv, struct command *command,
682
727
if (num_ontapdevices ) {
683
728
if (fmt == NNORMAL || fmt == NCOLUMN )
684
729
netapp_ontapdevices_print_regular (ontapdevices ,
685
- num_ontapdevices , fmt );
730
+ num_ontapdevices , fmt , devname );
686
731
else if (fmt == NJSON )
687
732
netapp_ontapdevices_print_json (ontapdevices ,
688
- num_ontapdevices );
733
+ num_ontapdevices , devname );
689
734
}
690
735
691
736
for (i = 0 ; i < num ; i ++ )
0 commit comments