@@ -273,6 +273,34 @@ static void splice_device_list(struct list_head *seed_devices,
273
273
list_splice (seed_devices , all_devices );
274
274
}
275
275
276
+ static void print_filesystem_info (char * label , char uuidbuf [BTRFS_UUID_UNPARSED_SIZE ],
277
+ u64 bytes_used , u64 num_devices ,
278
+ unsigned unit_mode )
279
+ {
280
+ if (label )
281
+ pr_verbose (LOG_DEFAULT , "Label: '%s' " , label );
282
+ else
283
+ pr_verbose (LOG_DEFAULT , "Label: none " );
284
+
285
+ pr_verbose (LOG_DEFAULT , " uuid: %s\n\tTotal devices %llu FS bytes used %s\n" , uuidbuf ,
286
+ num_devices ,
287
+ pretty_size_mode (bytes_used ,
288
+ unit_mode ));
289
+ }
290
+
291
+ static void print_filesystem_device (u64 devid , u64 total_bytes , u64 bytes_used ,
292
+ char * path ,
293
+ bool missing ,
294
+ unsigned unit_mode )
295
+ {
296
+ pr_verbose (LOG_DEFAULT , "\tdevid %4llu size %s used %s path %s%s\n" ,
297
+ devid ,
298
+ pretty_size_mode (total_bytes , unit_mode ),
299
+ pretty_size_mode (bytes_used , unit_mode ),
300
+ path ,
301
+ missing ? " MISSING" : "" );
302
+ }
303
+
276
304
static void print_devices (struct btrfs_fs_devices * fs_devices ,
277
305
u64 * devs_found , unsigned unit_mode )
278
306
{
@@ -290,12 +318,11 @@ static void print_devices(struct btrfs_fs_devices *fs_devices,
290
318
291
319
list_sort (NULL , all_devices , cmp_device_id );
292
320
list_for_each_entry (device , all_devices , dev_list ) {
293
- pr_verbose (LOG_DEFAULT , "\tdevid %4llu size %s used %s path %s\n" ,
294
- device -> devid ,
295
- pretty_size_mode (device -> total_bytes , unit_mode ),
296
- pretty_size_mode (device -> bytes_used , unit_mode ),
297
- device -> name );
298
-
321
+ print_filesystem_device (device -> devid ,
322
+ device -> total_bytes , device -> bytes_used ,
323
+ device -> name ,
324
+ false,
325
+ unit_mode );
299
326
(* devs_found )++ ;
300
327
}
301
328
}
@@ -314,14 +341,11 @@ static void print_one_uuid(struct btrfs_fs_devices *fs_devices,
314
341
uuid_unparse (fs_devices -> fsid , uuidbuf );
315
342
device = list_entry (fs_devices -> devices .next , struct btrfs_device ,
316
343
dev_list );
317
- if (device -> label && device -> label [0 ])
318
- pr_verbose (LOG_DEFAULT , "Label: '%s' " , device -> label );
319
- else
320
- pr_verbose (LOG_DEFAULT , "Label: none " );
321
-
322
344
total = device -> total_devs ;
323
- pr_verbose (LOG_DEFAULT , " uuid: %s\n\tTotal devices %llu FS bytes used %s\n" , uuidbuf ,
324
- total , pretty_size_mode (device -> super_bytes_used , unit_mode ));
345
+
346
+ print_filesystem_info (device -> label && device -> label [0 ] ? device -> label : NULL , uuidbuf ,
347
+ device -> super_bytes_used , total ,
348
+ unit_mode );
325
349
326
350
print_devices (fs_devices , & devs_found , unit_mode );
327
351
@@ -360,15 +384,9 @@ static int print_one_fs(struct btrfs_ioctl_fs_info_args *fs_info,
360
384
return ret ;
361
385
362
386
uuid_unparse (fs_info -> fsid , uuidbuf );
363
- if (label && * label )
364
- pr_verbose (LOG_DEFAULT , "Label: '%s' " , label );
365
- else
366
- pr_verbose (LOG_DEFAULT , "Label: none " );
367
-
368
- pr_verbose (LOG_DEFAULT , " uuid: %s\n\tTotal devices %llu FS bytes used %s\n" , uuidbuf ,
369
- fs_info -> num_devices ,
370
- pretty_size_mode (calc_used_bytes (space_info ),
371
- unit_mode ));
387
+ print_filesystem_info (label && * label ? label : NULL , uuidbuf ,
388
+ calc_used_bytes (space_info ), fs_info -> num_devices ,
389
+ unit_mode );
372
390
373
391
for (i = 0 ; i < fs_info -> num_devices ; i ++ ) {
374
392
char * canonical_path ;
@@ -378,18 +396,20 @@ static int print_one_fs(struct btrfs_ioctl_fs_info_args *fs_info,
378
396
/* Add check for missing devices even mounted */
379
397
fd = open ((char * )tmp_dev_info -> path , O_RDONLY );
380
398
if (fd < 0 ) {
381
- pr_verbose (LOG_DEFAULT , "\tdevid %4llu size 0 used 0 path %s MISSING\n" ,
382
- tmp_dev_info -> devid , tmp_dev_info -> path );
399
+ print_filesystem_device (tmp_dev_info -> devid ,
400
+ 0 , 0 ,
401
+ (char * )tmp_dev_info -> path ,
402
+ true,
403
+ unit_mode );
383
404
continue ;
384
-
385
405
}
386
406
close (fd );
387
407
canonical_path = path_canonicalize ((char * )tmp_dev_info -> path );
388
- pr_verbose ( LOG_DEFAULT , "\tdevid %4llu size %s used %s path %s\n" ,
389
- tmp_dev_info -> devid ,
390
- pretty_size_mode ( tmp_dev_info -> total_bytes , unit_mode ) ,
391
- pretty_size_mode ( tmp_dev_info -> bytes_used , unit_mode ) ,
392
- canonical_path );
408
+ print_filesystem_device ( tmp_dev_info -> devid ,
409
+ tmp_dev_info -> total_bytes , tmp_dev_info -> bytes_used ,
410
+ canonical_path ,
411
+ false ,
412
+ unit_mode );
393
413
394
414
free (canonical_path );
395
415
}
0 commit comments