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.
  *
        } 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;