]> git.baikalelectronics.ru Git - kernel.git/commitdiff
btrfs: use btrfs_raid_array to calculate number of parity stripes
authorQu Wenruo <wqu@suse.com>
Fri, 13 May 2022 08:34:30 +0000 (16:34 +0800)
committerDavid Sterba <dsterba@suse.com>
Mon, 25 Jul 2022 15:45:36 +0000 (17:45 +0200)
Use the raid table instead of hard coded values and rename the helper as
it is exported.  This could make later extension on RAID56 based
profiles easier.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/raid56.c
fs/btrfs/raid56.h
fs/btrfs/volumes.c
fs/btrfs/volumes.h

index f002334d244a77b56739df1477894e3a0a8fbf2e..0f0368e63e5af14fbbdde3497f98801897a17368 100644 (file)
@@ -922,7 +922,6 @@ static struct btrfs_raid_bio *alloc_rbio(struct btrfs_fs_info *fs_info,
        const unsigned int stripe_nsectors = stripe_len >> fs_info->sectorsize_bits;
        const unsigned int num_sectors = stripe_nsectors * real_stripes;
        struct btrfs_raid_bio *rbio;
-       int nr_data = 0;
        void *p;
 
        ASSERT(IS_ALIGNED(stripe_len, PAGE_SIZE));
@@ -976,14 +975,9 @@ static struct btrfs_raid_bio *alloc_rbio(struct btrfs_fs_info *fs_info,
        CONSUME_ALLOC(rbio->finish_pointers, real_stripes);
 #undef  CONSUME_ALLOC
 
-       if (bioc->map_type & BTRFS_BLOCK_GROUP_RAID5)
-               nr_data = real_stripes - 1;
-       else if (bioc->map_type & BTRFS_BLOCK_GROUP_RAID6)
-               nr_data = real_stripes - 2;
-       else
-               BUG();
+       ASSERT(btrfs_nr_parity_stripes(bioc->map_type));
+       rbio->nr_data = real_stripes - btrfs_nr_parity_stripes(bioc->map_type);
 
-       rbio->nr_data = nr_data;
        return rbio;
 }
 
index 3b22657ca857e3b8f362cfd6970b281593226266..c73bceb2b461625b7529f7c445c61269e46feb60 100644 (file)
@@ -155,19 +155,9 @@ struct raid56_bio_trace_info {
        u8 stripe_nr;
 };
 
-static inline int nr_parity_stripes(const struct map_lookup *map)
-{
-       if (map->type & BTRFS_BLOCK_GROUP_RAID5)
-               return 1;
-       else if (map->type & BTRFS_BLOCK_GROUP_RAID6)
-               return 2;
-       else
-               return 0;
-}
-
 static inline int nr_data_stripes(const struct map_lookup *map)
 {
-       return map->num_stripes - nr_parity_stripes(map);
+       return map->num_stripes - btrfs_nr_parity_stripes(map->type);
 }
 
 #define RAID5_P_STRIPE ((u64)-2)
index 75a59423a1bfefcf4ddfaa05df5e41477e25cf32..e40c0d59c4a07ea1ab5945b2ac7e9c0d0741ff5a 100644 (file)
@@ -182,6 +182,13 @@ const char *btrfs_bg_type_to_raid_name(u64 flags)
        return btrfs_raid_array[index].raid_name;
 }
 
+int btrfs_nr_parity_stripes(u64 type)
+{
+       enum btrfs_raid_types index = btrfs_bg_flags_to_raid_index(type);
+
+       return btrfs_raid_array[index].nparity;
+}
+
 /*
  * Fill @buf with textual description of @bg_flags, no more than @size_buf
  * bytes including terminating null byte.
index f19916a69beafa236d063af2a0cea9dd769409b8..b61508723d5d2209ed708566da8479a487c6c149 100644 (file)
@@ -634,6 +634,7 @@ int btrfs_is_parity_mirror(struct btrfs_fs_info *fs_info,
 unsigned long btrfs_full_stripe_len(struct btrfs_fs_info *fs_info,
                                    u64 logical);
 u64 btrfs_calc_stripe_length(const struct extent_map *em);
+int btrfs_nr_parity_stripes(u64 type);
 int btrfs_chunk_alloc_add_chunk_item(struct btrfs_trans_handle *trans,
                                     struct btrfs_block_group *bg);
 int btrfs_remove_chunk(struct btrfs_trans_handle *trans, u64 chunk_offset);