btrfs: use btrfs_raid_array to calculate number of parity stripes
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>
This commit is contained in:
parent
6dead96c1a
commit
0b30f71945
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue