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 <dsterba@suse.com>
This commit is contained in:
David Sterba 2021-10-06 23:22:31 +02:00
parent b29f1603b0
commit 80714610f3
3 changed files with 12 additions and 15 deletions

View File

@ -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;

View File

@ -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)

View File

@ -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