Skip to content

Commit

Permalink
btrfs: use ncopies from btrfs_raid_array in btrfs_num_copies()
Browse files Browse the repository at this point in the history
For all non-RAID56 profiles, we can use btrfs_raid_array[].ncopies
directly, only for RAID5 and RAID6 we need some extra handling as
there's no table value for that.

For RAID10 there's a change from sub_stripes to ncopies. The values are
the same but semantically we want to use number of copies, as this is
what btrfs_num_copies does.

Reviewed-by: Johannes Thumshirn <[email protected]>
Signed-off-by: Qu Wenruo <[email protected]>
Reviewed-by: David Sterba <[email protected]>
Signed-off-by: David Sterba <[email protected]>
  • Loading branch information
adam900710 authored and kdave committed Jul 25, 2022
1 parent 0b30f71 commit 6d322b4
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions fs/btrfs/volumes.c
Original file line number Diff line number Diff line change
Expand Up @@ -5717,7 +5717,8 @@ int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len)
{
struct extent_map *em;
struct map_lookup *map;
int ret;
enum btrfs_raid_types index;
int ret = 1;

em = btrfs_get_chunk_map(fs_info, logical, len);
if (IS_ERR(em))
Expand All @@ -5730,10 +5731,11 @@ int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len)
return 1;

map = em->map_lookup;
if (map->type & (BTRFS_BLOCK_GROUP_DUP | BTRFS_BLOCK_GROUP_RAID1_MASK))
ret = map->num_stripes;
else if (map->type & BTRFS_BLOCK_GROUP_RAID10)
ret = map->sub_stripes;
index = btrfs_bg_flags_to_raid_index(map->type);

/* Non-RAID56, use their ncopies from btrfs_raid_array. */
if (!(map->type & BTRFS_BLOCK_GROUP_RAID56_MASK))
ret = btrfs_raid_array[index].ncopies;
else if (map->type & BTRFS_BLOCK_GROUP_RAID5)
ret = 2;
else if (map->type & BTRFS_BLOCK_GROUP_RAID6)
Expand All @@ -5745,8 +5747,6 @@ int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len)
* stripe under reconstruction.
*/
ret = map->num_stripes;
else
ret = 1;
free_extent_map(em);

down_read(&fs_info->dev_replace.rwsem);
Expand Down

0 comments on commit 6d322b4

Please sign in to comment.