From 76743171391ee1784db01749e9957d47932f076c Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 12 Oct 2021 17:29:06 +0200 Subject: [PATCH] btrfs-progs: fi usage: use one formula for chunk size calculation The profile descriptions allow us to use a single formula to calculate chunk size. Right now there are no profiles with parity (raid5-like) and sub_stripes (raid10-like), which makes it easier. - parity stripes are subtracted from the total count - then divided by number of sub stripes Practically speaking, 1:1 copy profiles do not have any adjustments. Signed-off-by: David Sterba --- cmds/filesystem-usage.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/cmds/filesystem-usage.c b/cmds/filesystem-usage.c index 7f810cd0..92c87ef8 100644 --- a/cmds/filesystem-usage.c +++ b/cmds/filesystem-usage.c @@ -810,17 +810,13 @@ int load_chunk_and_device_info(int fd, struct chunk_info **chunkinfo, */ static u64 calc_chunk_size(struct chunk_info *ci) { - if (ci->type & BTRFS_BLOCK_GROUP_RAID0) - return ci->size / ci->num_stripes; - else if (ci->type & BTRFS_BLOCK_GROUP_RAID1_MASK) - return ci->size ; - else if (ci->type & BTRFS_BLOCK_GROUP_DUP) - return ci->size ; - else if (ci->type & BTRFS_BLOCK_GROUP_RAID56_MASK) - return ci->size / (ci->num_stripes - btrfs_bg_type_to_nparity(ci->type)); - else if (ci->type & BTRFS_BLOCK_GROUP_RAID10) - return ci->size / (ci->num_stripes / btrfs_bg_type_to_sub_stripes(ci->type)); - return ci->size; + u32 div; + + /* No parity + sub_stripes, so order of "-" and "/" does not matter */ + div = (ci->num_stripes - btrfs_bg_type_to_nparity(ci->type)) / + btrfs_bg_type_to_sub_stripes(ci->type); + + return ci->size / div; } /*