@@ -310,6 +310,34 @@ static void splice_device_list(struct list_head *seed_devices,
310310 list_splice (seed_devices , all_devices );
311311}
312312
313+ static void print_filesystem_info (char * label , char uuidbuf [BTRFS_UUID_UNPARSED_SIZE ],
314+ u64 bytes_used , u64 num_devices ,
315+ unsigned unit_mode )
316+ {
317+ if (label )
318+ pr_verbose (LOG_DEFAULT , "Label: '%s' " , label );
319+ else
320+ pr_verbose (LOG_DEFAULT , "Label: none " );
321+
322+ pr_verbose (LOG_DEFAULT , " uuid: %s\n\tTotal devices %llu FS bytes used %s\n" , uuidbuf ,
323+ num_devices ,
324+ pretty_size_mode (bytes_used ,
325+ unit_mode ));
326+ }
327+
328+ static void print_filesystem_device (u64 devid , u64 total_bytes , u64 bytes_used ,
329+ char * path ,
330+ bool missing ,
331+ unsigned unit_mode )
332+ {
333+ pr_verbose (LOG_DEFAULT , "\tdevid %4llu size %s used %s path %s%s\n" ,
334+ devid ,
335+ pretty_size_mode (total_bytes , unit_mode ),
336+ pretty_size_mode (bytes_used , unit_mode ),
337+ path ,
338+ missing ? " MISSING" : "" );
339+ }
340+
313341static void print_devices (struct btrfs_fs_devices * fs_devices ,
314342 u64 * devs_found , unsigned unit_mode )
315343{
@@ -327,12 +355,11 @@ static void print_devices(struct btrfs_fs_devices *fs_devices,
327355
328356 list_sort (NULL , all_devices , cmp_device_id );
329357 list_for_each_entry (device , all_devices , dev_list ) {
330- pr_verbose (LOG_DEFAULT , "\tdevid %4llu size %s used %s path %s\n" ,
331- device -> devid ,
332- pretty_size_mode (device -> total_bytes , unit_mode ),
333- pretty_size_mode (device -> bytes_used , unit_mode ),
334- device -> name );
335-
358+ print_filesystem_device (device -> devid ,
359+ device -> total_bytes , device -> bytes_used ,
360+ device -> name ,
361+ false,
362+ unit_mode );
336363 (* devs_found )++ ;
337364 }
338365}
@@ -351,14 +378,11 @@ static void print_one_uuid(struct btrfs_fs_devices *fs_devices,
351378 uuid_unparse (fs_devices -> fsid , uuidbuf );
352379 device = list_entry (fs_devices -> devices .next , struct btrfs_device ,
353380 dev_list );
354- if (device -> label && device -> label [0 ])
355- pr_verbose (LOG_DEFAULT , "Label: '%s' " , device -> label );
356- else
357- pr_verbose (LOG_DEFAULT , "Label: none " );
358-
359381 total = device -> total_devs ;
360- pr_verbose (LOG_DEFAULT , " uuid: %s\n\tTotal devices %llu FS bytes used %s\n" , uuidbuf ,
361- total , pretty_size_mode (device -> super_bytes_used , unit_mode ));
382+
383+ print_filesystem_info (device -> label && device -> label [0 ] ? device -> label : NULL , uuidbuf ,
384+ device -> super_bytes_used , total ,
385+ unit_mode );
362386
363387 print_devices (fs_devices , & devs_found , unit_mode );
364388
@@ -396,15 +420,9 @@ static int print_one_fs(struct btrfs_ioctl_fs_info_args *fs_info,
396420 return ret ;
397421
398422 uuid_unparse (fs_info -> fsid , uuidbuf );
399- if (label && * label )
400- pr_verbose (LOG_DEFAULT , "Label: '%s' " , label );
401- else
402- pr_verbose (LOG_DEFAULT , "Label: none " );
403-
404- pr_verbose (LOG_DEFAULT , " uuid: %s\n\tTotal devices %llu FS bytes used %s\n" , uuidbuf ,
405- fs_info -> num_devices ,
406- pretty_size_mode (calc_used_bytes (space_info ),
407- unit_mode ));
423+ print_filesystem_info (label && * label ? label : NULL , uuidbuf ,
424+ calc_used_bytes (space_info ), fs_info -> num_devices ,
425+ unit_mode );
408426
409427 for (i = 0 ; i < fs_info -> num_devices ; i ++ ) {
410428 char * canonical_path ;
@@ -414,18 +432,20 @@ static int print_one_fs(struct btrfs_ioctl_fs_info_args *fs_info,
414432 /* Add check for missing devices even mounted */
415433 fd = open ((char * )tmp_dev_info -> path , O_RDONLY );
416434 if (fd < 0 ) {
417- pr_verbose (LOG_DEFAULT , "\tdevid %4llu size 0 used 0 path %s MISSING\n" ,
418- tmp_dev_info -> devid , tmp_dev_info -> path );
435+ print_filesystem_device (tmp_dev_info -> devid ,
436+ 0 , 0 ,
437+ (char * )tmp_dev_info -> path ,
438+ true,
439+ unit_mode );
419440 continue ;
420-
421441 }
422442 close (fd );
423443 canonical_path = path_canonicalize ((char * )tmp_dev_info -> path );
424- pr_verbose ( LOG_DEFAULT , "\tdevid %4llu size %s used %s path %s\n" ,
425- tmp_dev_info -> devid ,
426- pretty_size_mode ( tmp_dev_info -> total_bytes , unit_mode ) ,
427- pretty_size_mode ( tmp_dev_info -> bytes_used , unit_mode ) ,
428- canonical_path );
444+ print_filesystem_device ( tmp_dev_info -> devid ,
445+ tmp_dev_info -> total_bytes , tmp_dev_info -> bytes_used ,
446+ canonical_path ,
447+ false ,
448+ unit_mode );
429449
430450 free (canonical_path );
431451 }
0 commit comments