Skip to content

Commit 8938f11

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

1 file changed

Lines changed: 29 additions & 17 deletions

File tree

fs/btrfs/volumes.c

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6407,6 +6407,34 @@ static void map_blocks_dup(const struct btrfs_chunk_map *map,
64076407
io_geom->mirror_num = 1;
64086408
}
64096409

6410+
static void map_blocks_raid10(struct btrfs_fs_info *fs_info,
6411+
struct btrfs_chunk_map *map,
6412+
struct btrfs_io_geometry *io_geom,
6413+
bool dev_replace_is_ongoing)
6414+
{
6415+
u32 factor = map->num_stripes / map->sub_stripes;
6416+
int old_stripe_index;
6417+
6418+
io_geom->stripe_index = (io_geom->stripe_nr % factor) * map->sub_stripes;
6419+
io_geom->stripe_nr /= factor;
6420+
6421+
if (io_geom->op != BTRFS_MAP_READ) {
6422+
io_geom->num_stripes = map->sub_stripes;
6423+
return;
6424+
}
6425+
6426+
if (io_geom->mirror_num) {
6427+
io_geom->stripe_index += io_geom->mirror_num - 1;
6428+
return;
6429+
}
6430+
6431+
old_stripe_index = io_geom->stripe_index;
6432+
io_geom->stripe_index = find_live_mirror(fs_info, map,
6433+
io_geom->stripe_index,
6434+
dev_replace_is_ongoing);
6435+
io_geom->mirror_num = io_geom->stripe_index - old_stripe_index + 1;
6436+
}
6437+
64106438
/*
64116439
* Map one logical range to one or more physical ranges.
64126440
*
@@ -6500,23 +6528,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
65006528
} else if (map->type & BTRFS_BLOCK_GROUP_DUP) {
65016529
map_blocks_dup(map, &io_geom);
65026530
} else if (map->type & BTRFS_BLOCK_GROUP_RAID10) {
6503-
u32 factor = map->num_stripes / map->sub_stripes;
6504-
6505-
io_geom.stripe_index = (io_geom.stripe_nr % factor) * map->sub_stripes;
6506-
io_geom.stripe_nr /= factor;
6507-
6508-
if (op != BTRFS_MAP_READ)
6509-
io_geom.num_stripes = map->sub_stripes;
6510-
else if (io_geom.mirror_num)
6511-
io_geom.stripe_index += io_geom.mirror_num - 1;
6512-
else {
6513-
int old_stripe_index = io_geom.stripe_index;
6514-
io_geom.stripe_index = find_live_mirror(fs_info, map,
6515-
io_geom.stripe_index,
6516-
dev_replace_is_ongoing);
6517-
io_geom.mirror_num = io_geom.stripe_index - old_stripe_index + 1;
6518-
}
6519-
6531+
map_blocks_raid10(fs_info, map, &io_geom, dev_replace_is_ongoing);
65206532
} else if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) {
65216533
if (op != BTRFS_MAP_READ || io_geom.mirror_num > 1) {
65226534
/*

0 commit comments

Comments
 (0)