[PATCH 23/26] btrfs: use xor_gen

Christoph Hellwig
2026-03-24T06:27:28Z

Use the new xor_gen helper instead of open coding the loop around
xor_blocks. This helper is very similar to the existing run_xor helper
in btrfs, except that the destination buffer is passed explicitly.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/raid56.c | 27 ++++-----------------------
1 file changed, 4 insertions(+), 23 deletions(-)

diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
index 02105d68accb..ad091c56ce77 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -617,26 +617,6 @@ static void cache_rbio(struct btrfs_raid_bio *rbio)
spin_unlock(&table->cache_lock);
}

-/*
- * helper function to run the xor_blocks api. It is only
- * able to do MAX_XOR_BLOCKS at a time, so we need to
- * loop through.
- */
-static void run_xor(void **pages, int src_cnt, ssize_t len)
-{
- int src_off = 0;
- int xor_src_cnt = 0;
- void *dest = pages[src_cnt];
-
- while(src_cnt > 0) {
- xor_src_cnt = min(src_cnt, MAX_XOR_BLOCKS);
- xor_blocks(xor_src_cnt, len, dest, pages + src_off);
-
- src_cnt -= xor_src_cnt;
- src_off += xor_src_cnt;
- }
-}
-
/*
* Returns true if the bio list inside this rbio covers an entire stripe (no
* rmw required).
@@ -1434,7 +1414,8 @@ static void generate_pq_vertical_step(struct btrfs_raid_bio *rbio, unsigned int
} else {
/* raid5 */
memcpy(pointers[rbio->nr_data], pointers[0], step);
- run_xor(pointers + 1, rbio->nr_data - 1, step);
+ xor_gen(pointers[rbio->nr_data], pointers + 1, rbio->nr_data - 1,
+ step);
}
for (stripe = stripe - 1; stripe >= 0; stripe--)
kunmap_local(pointers[stripe]);
@@ -2034,7 +2015,7 @@ static void recover_vertical_step(struct btrfs_raid_bio *rbio,
pointers[rbio->nr_data - 1] = p;

/* Xor in the rest */
- run_xor(pointers, rbio->nr_data - 1, step);
+ xor_gen(p, pointers, rbio->nr_data - 1, step);
}

cleanup:
@@ -2672,7 +2653,7 @@ static bool verify_one_parity_step(struct btrfs_raid_bio *rbio,
} else {
/* RAID5. */
memcpy(pointers[nr_data], pointers[0], step);
- run_xor(pointers + 1, nr_data - 1, step);
+ xor_gen(pointers[nr_data], pointers + 1, nr_data - 1, step);
}

/* Check scrubbing parity and repair it. */
--
2.47.3