[PATCH RFC 3/6] btrfs: Add stripe_physical function

From: Michal Rostecki
Date: Tue Feb 09 2021 - 18:54:31 EST


From: Michal Rostecki <mrostecki@xxxxxxxx>

Move the calculation of the physical address for a stripe to the new
function - stripe_physical(). It can be used by raid1 read policies to
calculate the offset and select mirrors based on I/O locality.

Signed-off-by: Michal Rostecki <mrostecki@xxxxxxxx>
---
fs/btrfs/volumes.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 292175206873..1ac364a2f105 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -5498,6 +5498,23 @@ int btrfs_is_parity_mirror(struct btrfs_fs_info *fs_info, u64 logical, u64 len)
return ret;
}

+/*
+ * Calculates the physical location for the given stripe and I/O geometry.
+ *
+ * @map: mapping containing the logical extent
+ * @stripe_index: index of the stripe to make a calculation for
+ * @stripe_offset: offset of the block in its stripe
+ * @stripe_nr: index of the stripe whete the block falls in
+ *
+ * Returns the physical location.
+ */
+static u64 stripe_physical(struct map_lookup *map, u32 stripe_index,
+ u64 stripe_offset, u64 stripe_nr)
+{
+ return map->stripes[stripe_index].physical + stripe_offset +
+ stripe_nr * map->stripe_len;
+}
+
static int find_live_mirror(struct btrfs_fs_info *fs_info,
struct map_lookup *map, int first,
int dev_replace_is_ongoing)
@@ -6216,8 +6233,9 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
}

for (i = 0; i < num_stripes; i++) {
- bbio->stripes[i].physical = map->stripes[stripe_index].physical +
- stripe_offset + stripe_nr * map->stripe_len;
+ bbio->stripes[i].physical = stripe_physical(map, stripe_index,
+ stripe_offset,
+ stripe_nr);
bbio->stripes[i].dev = map->stripes[stripe_index].dev;
stripe_index++;
}
--
2.30.0