btrfs: factor out block mapping for DUP profiles
authorJohannes Thumshirn <johannes.thumshirn@wdc.com>
Wed, 13 Dec 2023 14:43:00 +0000 (06:43 -0800)
committerDavid Sterba <dsterba@suse.com>
Fri, 15 Dec 2023 22:03:58 +0000 (23:03 +0100)
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>
fs/btrfs/volumes.c

index 2d25e82f24a4158c843e39a710d572b0333b5560..921c64a7289a4fb709853c664e7cb43e97959afd 100644 (file)
@@ -6391,6 +6391,22 @@ static void map_blocks_raid1(struct btrfs_fs_info *fs_info,
        io_geom->mirror_num = io_geom->stripe_index + 1;
 }
 
+static void map_blocks_dup(const struct btrfs_chunk_map *map,
+                          struct btrfs_io_geometry *io_geom)
+{
+       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->mirror_num = 1;
+}
+
 /*
  * Map one logical range to one or more physical ranges.
  *
@@ -6482,14 +6498,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
        } else if (map->type & BTRFS_BLOCK_GROUP_RAID1_MASK) {
                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;
-               } else if (io_geom.mirror_num) {
-                       io_geom.stripe_index = io_geom.mirror_num - 1;
-               } else {
-                       io_geom.mirror_num = 1;
-               }
-
+               map_blocks_dup(map, &io_geom);
        } else if (map->type & BTRFS_BLOCK_GROUP_RAID10) {
                u32 factor = map->num_stripes / map->sub_stripes;