Skip to content

Commit 5e36aba

Browse files
morbidrsakdave
authored andcommitted
btrfs: factor out RAID1 block mapping
Now that we have a container for the I/O geometry that has all the needed information for the block mappings of RAID1, 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 30e8534 commit 5e36aba

1 file changed

Lines changed: 21 additions & 10 deletions

File tree

fs/btrfs/volumes.c

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6371,6 +6371,26 @@ static void map_blocks_raid0(const struct btrfs_chunk_map *map,
63716371
io_geom->mirror_num = 1;
63726372
}
63736373

6374+
static void map_blocks_raid1(struct btrfs_fs_info *fs_info,
6375+
struct btrfs_chunk_map *map,
6376+
struct btrfs_io_geometry *io_geom,
6377+
bool dev_replace_is_ongoing)
6378+
{
6379+
if (io_geom->op != BTRFS_MAP_READ) {
6380+
io_geom->num_stripes = map->num_stripes;
6381+
return;
6382+
}
6383+
6384+
if (io_geom->mirror_num) {
6385+
io_geom->stripe_index = io_geom->mirror_num - 1;
6386+
return;
6387+
}
6388+
6389+
io_geom->stripe_index = find_live_mirror(fs_info, map, 0,
6390+
dev_replace_is_ongoing);
6391+
io_geom->mirror_num = io_geom->stripe_index + 1;
6392+
}
6393+
63746394
/*
63756395
* Map one logical range to one or more physical ranges.
63766396
*
@@ -6460,16 +6480,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
64606480
if (map->type & BTRFS_BLOCK_GROUP_RAID0) {
64616481
map_blocks_raid0(map, &io_geom);
64626482
} else if (map->type & BTRFS_BLOCK_GROUP_RAID1_MASK) {
6463-
if (op != BTRFS_MAP_READ) {
6464-
io_geom.num_stripes = map->num_stripes;
6465-
} else if (io_geom.mirror_num) {
6466-
io_geom.stripe_index = io_geom.mirror_num - 1;
6467-
} else {
6468-
io_geom.stripe_index = find_live_mirror(fs_info, map, 0,
6469-
dev_replace_is_ongoing);
6470-
io_geom.mirror_num = io_geom.stripe_index + 1;
6471-
}
6472-
6483+
map_blocks_raid1(fs_info, map, &io_geom, dev_replace_is_ongoing);
64736484
} else if (map->type & BTRFS_BLOCK_GROUP_DUP) {
64746485
if (op != BTRFS_MAP_READ) {
64756486
io_geom.num_stripes = map->num_stripes;

0 commit comments

Comments
 (0)