diff mbox series

[03/13] btrfs: factor out block-mapping for RAID0

Message ID 20231212-btrfs_map_block-cleanup-v1-3-b2d954d9a55b@wdc.com (mailing list archive)
State New, archived
Headers show
Series btrfs: clean up RAID I/O geometry calculation | expand

Commit Message

Johannes Thumshirn Dec. 12, 2023, 12:38 p.m. UTC
Now that we have a container for the I/O geometry that has all the needed
information for the block mappings of RAID0, factor out a helper calculating
this information.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 fs/btrfs/volumes.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

Comments

Christoph Hellwig Dec. 13, 2023, 8:50 a.m. UTC | #1
> +static void map_blocks_for_raid0(struct btrfs_chunk_map *map,

I'd skip the _for here as it is a bit redundant.

> +				 enum btrfs_map_op op,

Looking at all the patches: shouldn't the op also go into the
btrfs_io_geometry structure?
Johannes Thumshirn Dec. 13, 2023, 9:02 a.m. UTC | #2
On 13.12.23 09:51, Christoph Hellwig wrote:
>> +static void map_blocks_for_raid0(struct btrfs_chunk_map *map,
> 
> I'd skip the _for here as it is a bit redundant.

OK.

>> +				 enum btrfs_map_op op,
> 
> Looking at all the patches: shouldn't the op also go into the
> btrfs_io_geometry structure?

Would make sense yes.
diff mbox series

Patch

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index d0e529b3fd39..a5d85a77da25 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -6362,6 +6362,16 @@  static bool is_single_device_io(struct btrfs_fs_info *fs_info,
 	return true;
 }
 
+static void map_blocks_for_raid0(struct btrfs_chunk_map *map,
+				 enum btrfs_map_op op,
+				 struct btrfs_io_geometry *io_geom)
+{
+	io_geom->stripe_index = io_geom->stripe_nr % map->num_stripes;
+	io_geom->stripe_nr /= map->num_stripes;
+	if (op == BTRFS_MAP_READ)
+		io_geom->mirror_num = 1;
+}
+
 /*
  * Map one logical range to one or more physical ranges.
  *
@@ -6447,10 +6457,7 @@  int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
 	io_geom.stripe_index = 0;
 	io_geom.mirror_num = (mirror_num_ret ? *mirror_num_ret : 0);
 	if (map->type & BTRFS_BLOCK_GROUP_RAID0) {
-		io_geom.stripe_index = io_geom.stripe_nr % map->num_stripes;
-		io_geom.stripe_nr /= map->num_stripes;
-		if (op == BTRFS_MAP_READ)
-			io_geom.mirror_num = 1;
+		map_blocks_for_raid0(map, op, &io_geom);
 	} else if (map->type & BTRFS_BLOCK_GROUP_RAID1_MASK) {
 		if (op != BTRFS_MAP_READ) {
 			io_geom.num_stripes = map->num_stripes;