Skip to content

Commit

Permalink
btrfs-progs: device usage: print number of stripes in relevant profiles
Browse files Browse the repository at this point in the history
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 <realwakka@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
  • Loading branch information
realwakka authored and kdave committed Jun 23, 2021
1 parent c3acaee commit 4693e82
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions cmds/filesystem-usage.c
Expand Up @@ -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;

Expand Down

0 comments on commit 4693e82

Please sign in to comment.