@@ -2574,10 +2574,20 @@ void btrfs_mapping_tree_free(struct btrfs_mapping_tree *tree)
}
}
+int btrfs_map_num_copies(struct extent_map *em)
+{
+ struct map_lookup *map = (struct map_lookup *)em->bdev;
+
+ if (map->type & (BTRFS_BLOCK_GROUP_DUP | BTRFS_BLOCK_GROUP_RAID1))
+ return map->num_stripes;
+ if (map->type & BTRFS_BLOCK_GROUP_RAID10)
+ return map->sub_stripes;
+ return 1;
+}
+
int btrfs_num_copies(struct btrfs_mapping_tree *map_tree, u64 logical, u64 len)
{
struct extent_map *em;
- struct map_lookup *map;
struct extent_map_tree *em_tree = &map_tree->map_tree;
int ret;
@@ -2587,13 +2597,9 @@ int btrfs_num_copies(struct btrfs_mapping_tree *map_tree, u64 logical, u64 len)
BUG_ON(!em);
BUG_ON(em->start > logical || em->start + em->len < logical);
- map = (struct map_lookup *)em->bdev;
- if (map->type & (BTRFS_BLOCK_GROUP_DUP | BTRFS_BLOCK_GROUP_RAID1))
- ret = map->num_stripes;
- else if (map->type & BTRFS_BLOCK_GROUP_RAID10)
- ret = map->sub_stripes;
- else
- ret = 1;
+
+ ret = btrfs_map_num_copies(em);
+
free_extent_map(em);
return ret;
}
@@ -195,4 +195,5 @@ int find_free_dev_extent(struct btrfs_trans_handle *trans,
int btrfs_map_stripe_count(struct extent_map *em);
struct block_device *btrfs_map_stripe_bdev(struct extent_map *em, int stripe);
u64 btrfs_map_stripe_physical(struct extent_map *em, int stripe);
+int btrfs_map_num_copies(struct extent_map *em);
#endif