From 4693e8226140289dcf8f0932af05895a38152817 Mon Sep 17 00:00:00 2001 From: Sidong Yang Date: Tue, 8 Jun 2021 15:35:20 +0000 Subject: [PATCH] btrfs-progs: device usage: print number of stripes in relevant profiles Print number of stripes for striped profiles in device usage commands. It helps to see profiles easily. The output is like below. /dev/vdc, ID: 1 Device size: 1.00GiB Device slack: 0.00B Data,RAID0/2: 912.62MiB Data,RAID0/3: 912.62MiB Metadata,RAID1: 102.38MiB System,RAID1: 8.00MiB Unallocated: 1.00MiB Multiple lines can appear in case a balance conversion process was interrupted or if there's been a new device added and new data written to the full stripe. Issue: #372 Signed-off-by: Sidong Yang Signed-off-by: David Sterba --- cmds/filesystem-usage.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/cmds/filesystem-usage.c b/cmds/filesystem-usage.c index 107453d4..7934a548 100644 --- a/cmds/filesystem-usage.c +++ b/cmds/filesystem-usage.c @@ -1192,20 +1192,41 @@ void print_device_chunks(struct device_info *devinfo, const char *r_mode; u64 flags; u64 size; + u64 num_stripes; + u64 profile; if (chunks_info_ptr[i].devid != devinfo->devid) continue; flags = chunks_info_ptr[i].type; + profile = (flags & BTRFS_BLOCK_GROUP_PROFILE_MASK); description = btrfs_group_type_str(flags); r_mode = btrfs_group_profile_str(flags); size = calc_chunk_size(chunks_info_ptr+i); - printf(" %s,%s:%*s%10s\n", - description, - r_mode, - (int)(20 - strlen(description) - strlen(r_mode)), "", - pretty_size_mode(size, unit_mode)); + num_stripes = chunks_info_ptr[i].num_stripes; + + switch (profile) { + case BTRFS_BLOCK_GROUP_RAID0: + case BTRFS_BLOCK_GROUP_RAID5: + case BTRFS_BLOCK_GROUP_RAID6: + case BTRFS_BLOCK_GROUP_RAID10: + printf(" %s,%s/%llu:%*s%10s\n", + description, + r_mode, + num_stripes, + (int)(20 - strlen(description) - strlen(r_mode) + - count_digits(num_stripes) - 1), "", + pretty_size_mode(size, unit_mode)); + break; + default: + printf(" %s,%s:%*s%10s\n", + description, + r_mode, + (int)(20 - strlen(description) - strlen(r_mode)), "", + pretty_size_mode(size, unit_mode)); + break; + } allocated += size;