Skip to content

Commit 5aeb15c

Browse files
morbidrsakdave
authored andcommitted
btrfs: factor out block mapping for DUP profiles
Now that we have a container for the I/O geometry that has all the needed information for the block mappings of DUP, factor out a helper calculating this information. Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 5e36aba commit 5aeb15c

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

fs/btrfs/volumes.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6391,6 +6391,22 @@ static void map_blocks_raid1(struct btrfs_fs_info *fs_info,
63916391
io_geom->mirror_num = io_geom->stripe_index + 1;
63926392
}
63936393

6394+
static void map_blocks_dup(const struct btrfs_chunk_map *map,
6395+
struct btrfs_io_geometry *io_geom)
6396+
{
6397+
if (io_geom->op != BTRFS_MAP_READ) {
6398+
io_geom->num_stripes = map->num_stripes;
6399+
return;
6400+
}
6401+
6402+
if (io_geom->mirror_num) {
6403+
io_geom->stripe_index = io_geom->mirror_num - 1;
6404+
return;
6405+
}
6406+
6407+
io_geom->mirror_num = 1;
6408+
}
6409+
63946410
/*
63956411
* Map one logical range to one or more physical ranges.
63966412
*
@@ -6482,14 +6498,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
64826498
} else if (map->type & BTRFS_BLOCK_GROUP_RAID1_MASK) {
64836499
map_blocks_raid1(fs_info, map, &io_geom, dev_replace_is_ongoing);
64846500
} else if (map->type & BTRFS_BLOCK_GROUP_DUP) {
6485-
if (op != BTRFS_MAP_READ) {
6486-
io_geom.num_stripes = map->num_stripes;
6487-
} else if (io_geom.mirror_num) {
6488-
io_geom.stripe_index = io_geom.mirror_num - 1;
6489-
} else {
6490-
io_geom.mirror_num = 1;
6491-
}
6492-
6501+
map_blocks_dup(map, &io_geom);
64936502
} else if (map->type & BTRFS_BLOCK_GROUP_RAID10) {
64946503
u32 factor = map->num_stripes / map->sub_stripes;
64956504

0 commit comments

Comments
 (0)