Skip to content

Commit b1e2de4

Browse files
committed
btrfs-progs: mkfs: print zone count for each device
In zoned mode print zone count for each device, the zone size must be the same so it's sufficient to print it in the summary. $ mkfs.btrfs -O zoned /dev/nullb[0-3] ... Zoned device: yes Zone size: 16.00MiB ... Devices: ID SIZE ZONES PATH 1 512.00MiB 32 /dev/nullb0 2 256.00MiB 16 /dev/nullb1 3 1.00GiB 64 /dev/nullb2 4 2.00GiB 128 /dev/nullb3 Issue: #693 Signed-off-by: David Sterba <dsterba@suse.com>
1 parent f240c61 commit b1e2de4

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

mkfs/main.c

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include "common/box.h"
5858
#include "common/units.h"
5959
#include "common/string-utils.h"
60+
#include "common/string-table.h"
6061
#include "cmds/commands.h"
6162
#include "check/qgroup-verify.h"
6263
#include "mkfs/common.h"
@@ -486,11 +487,13 @@ static int _cmp_device_by_id(void *priv, struct list_head *a,
486487
list_entry(b, struct btrfs_device, dev_list)->devid;
487488
}
488489

489-
static void list_all_devices(struct btrfs_root *root)
490+
static void list_all_devices(struct btrfs_root *root, bool is_zoned)
490491
{
491492
struct btrfs_fs_devices *fs_devices;
492493
struct btrfs_device *device;
493494
int number_of_devices = 0;
495+
struct string_table *tab;
496+
int row, col;
494497

495498
fs_devices = root->fs_info->fs_devices;
496499

@@ -501,15 +504,31 @@ static void list_all_devices(struct btrfs_root *root)
501504

502505
printf("Number of devices: %d\n", number_of_devices);
503506
printf("Devices:\n");
504-
printf(" ID SIZE PATH\n");
507+
if (is_zoned)
508+
tab = table_create(4, number_of_devices + 1);
509+
else
510+
tab = table_create(3, number_of_devices + 1);
511+
tab->spacing = STRING_TABLE_SPACING_2;
512+
col = 0;
513+
table_printf(tab, col++, 0, "> ID");
514+
table_printf(tab, col++, 0, "> SIZE");
515+
if (is_zoned)
516+
table_printf(tab, col++, 0, ">ZONES");
517+
table_printf(tab, col++, 0, "<PATH");
518+
519+
row = 1;
505520
list_for_each_entry(device, &fs_devices->devices, dev_list) {
506-
printf(" %3llu %10s %s\n",
507-
device->devid,
508-
pretty_size(device->total_bytes),
509-
device->name);
510-
}
511-
521+
col = 0;
522+
table_printf(tab, col++, row, ">%llu", device->devid);
523+
table_printf(tab, col++, row, ">%s", pretty_size(device->total_bytes));
524+
if (is_zoned)
525+
table_printf(tab, col++, row, ">%u", device->zone_info->nr_zones);
526+
table_printf(tab, col++, row, "<%s", device->name);
527+
row++;
528+
}
529+
table_dump(tab);
512530
printf("\n");
531+
table_free(tab);
513532
}
514533

515534
static bool is_temp_block_group(struct extent_buffer *node,
@@ -2016,7 +2035,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
20162035
printf("Checksum: %s\n",
20172036
btrfs_super_csum_name(mkfs_cfg.csum_type));
20182037

2019-
list_all_devices(root);
2038+
list_all_devices(root, opt_zoned);
20202039

20212040
if (mkfs_cfg.csum_type == BTRFS_CSUM_TYPE_SHA256) {
20222041
printf(

0 commit comments

Comments
 (0)