From b738de4446c192871b92c8a357689b0e29181855 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 7 Oct 2021 01:29:47 +0200 Subject: [PATCH] btrfs-progs: use btrfs_bg_type_is_stripey for enumerated lists The striped profiles covering arbitrary number of devices are often hardcoded so use the new helper btrfs_bg_type_is_stripey for that. Signed-off-by: David Sterba --- cmds/filesystem-usage.c | 10 ++-------- cmds/rescue-chunk-recover.c | 17 +++++------------ 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/cmds/filesystem-usage.c b/cmds/filesystem-usage.c index 39633e46..7f810cd0 100644 --- a/cmds/filesystem-usage.c +++ b/cmds/filesystem-usage.c @@ -1226,11 +1226,7 @@ void print_device_chunks(struct device_info *devinfo, size = calc_chunk_size(chunks_info_ptr+i); 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: + if (btrfs_bg_type_is_stripey(profile)) { printf(" %s,%s/%llu:%*s%10s\n", description, r_mode, @@ -1238,14 +1234,12 @@ void print_device_chunks(struct device_info *devinfo, (int)(20 - strlen(description) - strlen(r_mode) - count_digits(num_stripes) - 1), "", pretty_size_mode(size, unit_mode)); - break; - default: + } else { 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; diff --git a/cmds/rescue-chunk-recover.c b/cmds/rescue-chunk-recover.c index 18d2d6b5..cdf0fe18 100644 --- a/cmds/rescue-chunk-recover.c +++ b/cmds/rescue-chunk-recover.c @@ -1572,9 +1572,7 @@ static int btrfs_get_device_extents(u64 chunk_object, static int calc_num_stripes(u64 type) { - if (type & (BTRFS_BLOCK_GROUP_RAID0 | - BTRFS_BLOCK_GROUP_RAID10 | - BTRFS_BLOCK_GROUP_RAID56_MASK)) + if (btrfs_bg_type_is_stripey(type)) return 0; else if (type & (BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_DUP)) @@ -1789,11 +1787,6 @@ no_extent_record: return 0; } -#define BTRFS_ORDERED_RAID (BTRFS_BLOCK_GROUP_RAID0 | \ - BTRFS_BLOCK_GROUP_RAID10 | \ - BTRFS_BLOCK_GROUP_RAID5 | \ - BTRFS_BLOCK_GROUP_RAID6) - static int btrfs_rebuild_chunk_stripes(struct recover_control *rc, struct chunk_record *chunk) { @@ -1805,10 +1798,10 @@ static int btrfs_rebuild_chunk_stripes(struct recover_control *rc, * is we can reorder the stripes in the system metadata chunk. */ if ((chunk->type_flags & BTRFS_BLOCK_GROUP_METADATA) && - (chunk->type_flags & BTRFS_ORDERED_RAID)) + btrfs_bg_type_is_stripey(chunk->type_flags)) ret =btrfs_rebuild_ordered_meta_chunk_stripes(rc, chunk); else if ((chunk->type_flags & BTRFS_BLOCK_GROUP_DATA) && - (chunk->type_flags & BTRFS_ORDERED_RAID)) + btrfs_bg_type_is_stripey(chunk->type_flags)) ret = 1; /* Be handled after the fs is opened. */ else ret = btrfs_rebuild_unordered_chunk_stripes(rc, chunk); @@ -2183,8 +2176,8 @@ static int btrfs_rebuild_ordered_data_chunk_stripes(struct recover_control *rc, u8 flags; list_for_each_entry_safe(chunk, next, &rc->unrepaired_chunks, list) { - if ((chunk->type_flags & BTRFS_BLOCK_GROUP_DATA) - && (chunk->type_flags & BTRFS_ORDERED_RAID)) { + if ((chunk->type_flags & BTRFS_BLOCK_GROUP_DATA) && + btrfs_bg_type_is_stripey(chunk->type_flags)) { flags = 0; err = rebuild_raid_data_chunk_stripes(rc, root, chunk, &flags);