diff options
author | Johannes Thumshirn <johannes.thumshirn@wdc.com> | 2023-12-13 06:42:59 -0800 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2023-12-15 23:03:58 +0100 |
commit | 5e36aba8377b78b4ec8e15d29a1dee0d626d735d (patch) | |
tree | 499699d8aaf7496fda9e8cd00d0ccfbf9534e2de /fs/btrfs | |
parent | 30e8534b538e8e7372e49516a8cddacdfd80f863 (diff) |
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>
Diffstat (limited to 'fs/btrfs')
-rw-r--r-- | fs/btrfs/volumes.c | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 21a53acd52ac..2d25e82f24a4 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6371,6 +6371,26 @@ static void map_blocks_raid0(const struct btrfs_chunk_map *map, io_geom->mirror_num = 1; } +static void map_blocks_raid1(struct btrfs_fs_info *fs_info, + struct btrfs_chunk_map *map, + struct btrfs_io_geometry *io_geom, + bool dev_replace_is_ongoing) +{ + if (io_geom->op != BTRFS_MAP_READ) { + io_geom->num_stripes = map->num_stripes; + return; + } + + if (io_geom->mirror_num) { + io_geom->stripe_index = io_geom->mirror_num - 1; + return; + } + + io_geom->stripe_index = find_live_mirror(fs_info, map, 0, + dev_replace_is_ongoing); + io_geom->mirror_num = io_geom->stripe_index + 1; +} + /* * Map one logical range to one or more physical ranges. * @@ -6460,16 +6480,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, if (map->type & BTRFS_BLOCK_GROUP_RAID0) { map_blocks_raid0(map, &io_geom); } else if (map->type & BTRFS_BLOCK_GROUP_RAID1_MASK) { - if (op != BTRFS_MAP_READ) { - io_geom.num_stripes = map->num_stripes; - } else if (io_geom.mirror_num) { - io_geom.stripe_index = io_geom.mirror_num - 1; - } else { - io_geom.stripe_index = find_live_mirror(fs_info, map, 0, - dev_replace_is_ongoing); - io_geom.mirror_num = io_geom.stripe_index + 1; - } - + map_blocks_raid1(fs_info, map, &io_geom, dev_replace_is_ongoing); } else if (map->type & BTRFS_BLOCK_GROUP_DUP) { if (op != BTRFS_MAP_READ) { io_geom.num_stripes = map->num_stripes; |