@@ -252,7 +252,7 @@ static void netapp_ontapdevice_json(struct json_object *devices, char *devname,
252
252
}
253
253
254
254
static void netapp_smdevices_print_regular (struct smdevice_info * devices ,
255
- int count , int format )
255
+ int count , int format , const char * devname )
256
256
{
257
257
int i , slta ;
258
258
char array_label [ARRAY_LABEL_LEN / 2 + 1 ];
@@ -281,6 +281,36 @@ static void netapp_smdevices_print_regular(struct smdevice_info *devices,
281
281
}
282
282
283
283
for (i = 0 ; i < count ; i ++ ) {
284
+ if (devname && !strcmp (devname , basename (devices [i ].dev ))) {
285
+ /* found the device, fetch info for that alone */
286
+ nvme_id_ns_flbas_to_lbaf_inuse (devices [i ].ns .flbas ,
287
+ & lba_index );
288
+ unsigned long long lba = 1ULL <<
289
+ devices [i ].ns .lbaf [lba_index ].ds ;
290
+ double nsze = le64_to_cpu (devices [i ].ns .nsze ) * lba ;
291
+ const char * s_suffix = suffix_si_get (& nsze );
292
+ char size [128 ];
293
+
294
+ sprintf (size , "%.2f%sB" , nsze , s_suffix );
295
+ netapp_convert_string (array_label ,
296
+ (char * )& devices [i ].ctrl .vs [20 ],
297
+ ARRAY_LABEL_LEN / 2 );
298
+ slta = devices [i ].ctrl .vs [0 ] & 0x1 ;
299
+ netapp_convert_string (volume_label ,
300
+ (char * )devices [i ].ns .vs ,
301
+ VOLUME_LABEL_LEN / 2 );
302
+ netapp_nguid_to_str (nguid_str , devices [i ].ns .nguid );
303
+
304
+ printf (formatstr , devices [i ].dev , array_label ,
305
+ volume_label , devices [i ].nsid ,
306
+ nguid_str ,
307
+ slta ? 'A' : 'B' , "unknown" , size );
308
+ return ;
309
+ }
310
+ }
311
+
312
+ for (i = 0 ; i < count ; i ++ ) {
313
+ /* fetch info for all devices */
284
314
nvme_id_ns_flbas_to_lbaf_inuse (devices [i ].ns .flbas , & lba_index );
285
315
unsigned long long lba = 1ULL <<
286
316
devices [i ].ns .lbaf [lba_index ].ds ;
@@ -294,17 +324,17 @@ static void netapp_smdevices_print_regular(struct smdevice_info *devices,
294
324
ARRAY_LABEL_LEN / 2 );
295
325
slta = devices [i ].ctrl .vs [0 ] & 0x1 ;
296
326
netapp_convert_string (volume_label , (char * )devices [i ].ns .vs ,
297
- VOLUME_LABEL_LEN / 2 );
327
+ VOLUME_LABEL_LEN / 2 );
298
328
netapp_nguid_to_str (nguid_str , devices [i ].ns .nguid );
329
+
299
330
printf (formatstr , devices [i ].dev , array_label ,
300
331
volume_label , devices [i ].nsid , nguid_str ,
301
332
slta ? 'A' : 'B' , "unknown" , size );
302
- }
303
333
}
304
334
}
305
335
306
336
static void netapp_smdevices_print_json (struct smdevice_info * devices ,
307
- int count )
337
+ int count , const char * devname )
308
338
{
309
339
struct json_object * root = NULL ;
310
340
struct json_object * json_devices = NULL ;
@@ -319,6 +349,36 @@ static void netapp_smdevices_print_json(struct smdevice_info *devices,
319
349
json_devices = json_create_array ();
320
350
321
351
for (i = 0 ; i < count ; i ++ ) {
352
+ if (devname && !strcmp (devname , basename (devices [i ].dev ))) {
353
+ /* found the device, fetch info for that alone */
354
+ nvme_id_ns_flbas_to_lbaf_inuse (devices [i ].ns .flbas ,
355
+ & lba_index );
356
+ unsigned long long lba = 1ULL <<
357
+ devices [i ].ns .lbaf [lba_index ].ds ;
358
+ double nsze = le64_to_cpu (devices [i ].ns .nsze ) * lba ;
359
+ const char * s_suffix = suffix_si_get (& nsze );
360
+ char size [128 ];
361
+
362
+ sprintf (size , "%.2f%sB" , nsze , s_suffix );
363
+ netapp_convert_string (array_label ,
364
+ (char * )& devices [i ].ctrl .vs [20 ],
365
+ ARRAY_LABEL_LEN / 2 );
366
+ slta = devices [i ].ctrl .vs [0 ] & 0x1 ;
367
+ netapp_convert_string (volume_label ,
368
+ (char * )devices [i ].ns .vs ,
369
+ VOLUME_LABEL_LEN / 2 );
370
+ netapp_nguid_to_str (nguid_str , devices [i ].ns .nguid );
371
+ netapp_smdevice_json (json_devices , devices [i ].dev ,
372
+ array_label , volume_label ,
373
+ devices [i ].nsid , nguid_str ,
374
+ slta ? "A" : "B" , "unknown" , size , lba ,
375
+ le64_to_cpu (devices [i ].ns .nsze ));
376
+ goto out ;
377
+ }
378
+ }
379
+
380
+ for (i = 0 ; i < count ; i ++ ) {
381
+ /* fetch info for all devices */
322
382
nvme_id_ns_flbas_to_lbaf_inuse (devices [i ].ns .flbas , & lba_index );
323
383
unsigned long long lba = 1ULL <<
324
384
devices [i ].ns .lbaf [lba_index ].ds ;
@@ -331,15 +391,17 @@ static void netapp_smdevices_print_json(struct smdevice_info *devices,
331
391
(char * )& devices [i ].ctrl .vs [20 ],
332
392
ARRAY_LABEL_LEN / 2 );
333
393
slta = devices [i ].ctrl .vs [0 ] & 0x1 ;
334
- netapp_convert_string (volume_label , (char * )devices [i ].ns .vs ,
394
+ netapp_convert_string (volume_label ,
395
+ (char * )devices [i ].ns .vs ,
335
396
VOLUME_LABEL_LEN / 2 );
336
397
netapp_nguid_to_str (nguid_str , devices [i ].ns .nguid );
337
398
netapp_smdevice_json (json_devices , devices [i ].dev ,
338
399
array_label , volume_label , devices [i ].nsid ,
339
- nguid_str , slta ? "A" : "B" , "unknown" , size ,
340
- lba , le64_to_cpu (devices [i ].ns .nsze ));
400
+ nguid_str , slta ? "A" : "B" , "unknown" ,
401
+ size , lba , le64_to_cpu (devices [i ].ns .nsze ));
341
402
}
342
403
404
+ out :
343
405
/* complete the json output */
344
406
json_object_add_value_array (root , "SMdevices" , json_devices );
345
407
json_print_object (root , NULL );
@@ -618,6 +680,7 @@ static int netapp_smdevices(int argc, char **argv, struct command *command,
618
680
int num , i , fd , ret , fmt ;
619
681
struct smdevice_info * smdevices ;
620
682
char path [264 ];
683
+ char * devname = NULL ;
621
684
int num_smdevices = 0 ;
622
685
623
686
struct config {
@@ -649,6 +712,18 @@ static int netapp_smdevices(int argc, char **argv, struct command *command,
649
712
return num ;
650
713
}
651
714
715
+ if (optind < argc )
716
+ devname = basename (argv [optind ++ ]);
717
+
718
+ if (devname ) {
719
+ int subsys_num , nsid ;
720
+
721
+ if (sscanf (devname , "nvme%dn%d" , & subsys_num , & nsid ) != 2 ) {
722
+ fprintf (stderr , "Invalid device name %s\n" , devname );
723
+ return - EINVAL ;
724
+ }
725
+ }
726
+
652
727
smdevices = calloc (num , sizeof (* smdevices ));
653
728
if (!smdevices ) {
654
729
fprintf (stderr , "Unable to allocate memory for devices.\n" );
@@ -673,9 +748,10 @@ static int netapp_smdevices(int argc, char **argv, struct command *command,
673
748
if (num_smdevices ) {
674
749
if (fmt == NNORMAL || fmt == NCOLUMN )
675
750
netapp_smdevices_print_regular (smdevices ,
676
- num_smdevices , fmt );
751
+ num_smdevices , fmt , devname );
677
752
else if (fmt == NJSON )
678
- netapp_smdevices_print_json (smdevices , num_smdevices );
753
+ netapp_smdevices_print_json (smdevices ,
754
+ num_smdevices , devname );
679
755
}
680
756
681
757
for (i = 0 ; i < num ; i ++ )
0 commit comments