From 80714610f36edf3da476d0166a1bf37da1250c8a Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 6 Oct 2021 23:22:31 +0200 Subject: [PATCH] btrfs-progs: use raid table for ncopies There's opencoded value of raid table ncopies in print_filesystem_usage_overall, add a helper and use it. Signed-off-by: David Sterba --- cmds/filesystem-usage.c | 19 ++++--------------- kernel-shared/volumes.c | 7 +++++++ kernel-shared/volumes.h | 1 + 3 files changed, 12 insertions(+), 15 deletions(-) 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