diff --git a/cmds/filesystem-usage.c b/cmds/filesystem-usage.c index 6c0f9aa9..b5d0696f 100644 --- a/cmds/filesystem-usage.c +++ b/cmds/filesystem-usage.c @@ -33,6 +33,7 @@ #include "cmds/filesystem-usage.h" #include "cmds/commands.h" #include "kernel-shared/disk-io.h" +#include "kernel-shared/volumes.h" #include "common/open-utils.h" #include "common/units.h" #include "version.h" @@ -499,27 +500,15 @@ static int print_filesystem_usage_overall(int fd, struct chunk_info *chunkinfo, int ratio; u64 flags = sargs->spaces[i].flags; + ratio = btrfs_bg_type_to_ncopies(flags); + /* * The RAID5/6 ratio depends on the number of stripes and is * computed separately. Setting ratio to 0 will not account * the chunks in this loop. */ - if (flags & BTRFS_BLOCK_GROUP_RAID0) - ratio = 1; - else if (flags & BTRFS_BLOCK_GROUP_RAID1) - ratio = 2; - else if (flags & BTRFS_BLOCK_GROUP_RAID1C3) - ratio = 3; - else if (flags & BTRFS_BLOCK_GROUP_RAID1C4) - ratio = 4; - else if (flags & BTRFS_BLOCK_GROUP_RAID5) + if (flags & BTRFS_BLOCK_GROUP_RAID56_MASK) ratio = 0; - else if (flags & BTRFS_BLOCK_GROUP_RAID6) - ratio = 0; - else if (flags & BTRFS_BLOCK_GROUP_DUP) - ratio = 2; - else if (flags & BTRFS_BLOCK_GROUP_RAID10) - ratio = 2; else ratio = 1; diff --git a/kernel-shared/volumes.c b/kernel-shared/volumes.c index 28f66397..043c55c8 100644 --- a/kernel-shared/volumes.c +++ b/kernel-shared/volumes.c @@ -224,6 +224,13 @@ int btrfs_bg_type_to_devs_min(u64 flags) return btrfs_raid_array[index].devs_min; } +int btrfs_bg_type_to_ncopies(u64 flags) +{ + const int index = btrfs_bg_flags_to_raid_index(flags); + + return btrfs_raid_array[index].ncopies; +} + static inline int nr_parity_stripes(struct map_lookup *map) { if (map->type & BTRFS_BLOCK_GROUP_RAID5) diff --git a/kernel-shared/volumes.h b/kernel-shared/volumes.h index 96061dac..058c5317 100644 --- a/kernel-shared/volumes.h +++ b/kernel-shared/volumes.h @@ -311,5 +311,6 @@ int btrfs_bg_type_to_factor(u64 flags); const char *btrfs_bg_type_to_raid_name(u64 flags); int btrfs_bg_type_to_tolerated_failures(u64 flags); int btrfs_bg_type_to_devs_min(u64 flags); +int btrfs_bg_type_to_ncopies(u64 flags); #endif