@@ -251,23 +251,24 @@ static void netapp_ontapdevice_json(struct json_object *devices, char *devname,
251
251
json_array_add_value_object (devices , device_attrs );
252
252
}
253
253
254
- static void netapp_smdevices_print (struct smdevice_info * devices , int count , int format )
254
+ static void netapp_smdevices_print_regular (struct smdevice_info * devices ,
255
+ int count , int format )
255
256
{
256
- struct json_object * root = NULL ;
257
- struct json_object * json_devices = NULL ;
258
257
int i , slta ;
259
258
char array_label [ARRAY_LABEL_LEN / 2 + 1 ];
260
259
char volume_label [VOLUME_LABEL_LEN / 2 + 1 ];
261
260
char nguid_str [33 ];
261
+ __u8 lba_index ;
262
+
263
+ char * formatstr = NULL ;
262
264
char basestr [] =
263
265
"%s, Array Name %s, Volume Name %s, NSID %d, Volume ID %s, Controller %c, Access State %s, %s\n" ;
264
266
char columnstr [] = "%-16s %-30s %-30s %4d %32s %c %-12s %9s\n" ;
265
- char * formatstr = basestr ; /* default to "normal" output format */
266
- __u8 lba_index ;
267
267
268
- if (format == NCOLUMN ) {
269
- /* for column output, change output string and print column headers */
270
- formatstr = columnstr ;
268
+ if (format == NNORMAL )
269
+ formatstr = basestr ;
270
+ else if (format == NCOLUMN ) {
271
+ /* change output string and print column headers */
271
272
printf ("%-16s %-30s %-30s %-4s %-32s %-4s %-12s %-9s\n" ,
272
273
"Device" , "Array Name" , "Volume Name" , "NSID" ,
273
274
"Volume ID" , "Ctrl" , "Access State" , " Size" );
@@ -276,44 +277,74 @@ static void netapp_smdevices_print(struct smdevice_info *devices, int count, int
276
277
"------------------------------" , "----" ,
277
278
"--------------------------------" , "----" ,
278
279
"------------" , "---------" );
279
- } else if (format == NJSON ) {
280
- /* prepare for json output */
281
- root = json_create_object ();
282
- json_devices = json_create_array ();
280
+ formatstr = columnstr ;
283
281
}
284
282
285
283
for (i = 0 ; i < count ; i ++ ) {
286
284
nvme_id_ns_flbas_to_lbaf_inuse (devices [i ].ns .flbas , & lba_index );
287
- unsigned long long lba = 1ULL << devices [i ].ns .lbaf [lba_index ].ds ;
285
+ unsigned long long lba = 1ULL <<
286
+ devices [i ].ns .lbaf [lba_index ].ds ;
288
287
double nsze = le64_to_cpu (devices [i ].ns .nsze ) * lba ;
289
288
const char * s_suffix = suffix_si_get (& nsze );
290
289
char size [128 ];
291
290
292
291
sprintf (size , "%.2f%sB" , nsze , s_suffix );
293
- netapp_convert_string (array_label , (char * )& devices [i ].ctrl .vs [20 ],
294
- ARRAY_LABEL_LEN / 2 );
292
+ netapp_convert_string (array_label ,
293
+ (char * )& devices [i ].ctrl .vs [20 ],
294
+ ARRAY_LABEL_LEN / 2 );
295
295
slta = devices [i ].ctrl .vs [0 ] & 0x1 ;
296
296
netapp_convert_string (volume_label , (char * )devices [i ].ns .vs ,
297
297
VOLUME_LABEL_LEN / 2 );
298
298
netapp_nguid_to_str (nguid_str , devices [i ].ns .nguid );
299
- if (format == NJSON )
300
- netapp_smdevice_json (json_devices , devices [i ].dev ,
301
- array_label , volume_label , devices [i ].nsid ,
302
- nguid_str , slta ? "A" : "B" , "unknown" , size ,
303
- lba , le64_to_cpu (devices [i ].ns .nsze ));
304
- else
305
- printf (formatstr , devices [i ].dev , array_label ,
299
+ printf (formatstr , devices [i ].dev , array_label ,
306
300
volume_label , devices [i ].nsid , nguid_str ,
307
301
slta ? 'A' : 'B' , "unknown" , size );
302
+ }
308
303
}
304
+ }
305
+
306
+ static void netapp_smdevices_print_json (struct smdevice_info * devices ,
307
+ int count )
308
+ {
309
+ struct json_object * root = NULL ;
310
+ struct json_object * json_devices = NULL ;
311
+ int i , slta ;
312
+ char array_label [ARRAY_LABEL_LEN / 2 + 1 ];
313
+ char volume_label [VOLUME_LABEL_LEN / 2 + 1 ];
314
+ char nguid_str [33 ];
315
+ __u8 lba_index ;
309
316
310
- if (format == NJSON ) {
311
- /* complete the json output */
312
- json_object_add_value_array (root , "SMdevices" , json_devices );
313
- json_print_object (root , NULL );
314
- printf ("\n" );
315
- json_free_object (root );
317
+ /* prepare for the json output */
318
+ root = json_create_object ();
319
+ json_devices = json_create_array ();
320
+
321
+ for (i = 0 ; i < count ; i ++ ) {
322
+ nvme_id_ns_flbas_to_lbaf_inuse (devices [i ].ns .flbas , & lba_index );
323
+ unsigned long long lba = 1ULL <<
324
+ devices [i ].ns .lbaf [lba_index ].ds ;
325
+ double nsze = le64_to_cpu (devices [i ].ns .nsze ) * lba ;
326
+ const char * s_suffix = suffix_si_get (& nsze );
327
+ char size [128 ];
328
+
329
+ sprintf (size , "%.2f%sB" , nsze , s_suffix );
330
+ netapp_convert_string (array_label ,
331
+ (char * )& devices [i ].ctrl .vs [20 ],
332
+ ARRAY_LABEL_LEN / 2 );
333
+ slta = devices [i ].ctrl .vs [0 ] & 0x1 ;
334
+ netapp_convert_string (volume_label , (char * )devices [i ].ns .vs ,
335
+ VOLUME_LABEL_LEN / 2 );
336
+ netapp_nguid_to_str (nguid_str , devices [i ].ns .nguid );
337
+ netapp_smdevice_json (json_devices , devices [i ].dev ,
338
+ array_label , volume_label , devices [i ].nsid ,
339
+ nguid_str , slta ? "A" : "B" , "unknown" , size ,
340
+ lba , le64_to_cpu (devices [i ].ns .nsze ));
316
341
}
342
+
343
+ /* complete the json output */
344
+ json_object_add_value_array (root , "SMdevices" , json_devices );
345
+ json_print_object (root , NULL );
346
+ printf ("\n" );
347
+ json_free_object (root );
317
348
}
318
349
319
350
static void netapp_ontapdevices_print_regular (struct ontapdevice_info * devices ,
@@ -639,8 +670,13 @@ static int netapp_smdevices(int argc, char **argv, struct command *command,
639
670
close (fd );
640
671
}
641
672
642
- if (num_smdevices )
643
- netapp_smdevices_print (smdevices , num_smdevices , fmt );
673
+ if (num_smdevices ) {
674
+ if (fmt == NNORMAL || fmt == NCOLUMN )
675
+ netapp_smdevices_print_regular (smdevices ,
676
+ num_smdevices , fmt );
677
+ else if (fmt == NJSON )
678
+ netapp_smdevices_print_json (smdevices , num_smdevices );
679
+ }
644
680
645
681
for (i = 0 ; i < num ; i ++ )
646
682
free (devices [i ]);
0 commit comments