[PATCH 2/8] md/raid10: wait for the devices of the write in wait_blocked_dev()
From: Miroslav Cimerman
Date: Thu Nov 26 2026 - 19:32:52 EST
wait_blocked_dev() checks conf->mirrors[i] for copy i of the write, but
copy i is on device r10_bio->devs[i].devnum. With more devices than
copies, a write to other devices does not wait for a blocked device or
for an unacknowledged bad block on them. With a far or offset layout,
the bad block check uses the address of a copy on another device. The
write can then complete before md records the failure or the bad block.
Check the device of each copy. raid10_handle_discard() does not set
devs[].devnum, so discards still check the first conf->copies devices,
as before.
Fixes: f2e7e269a752 ("md/raid10: pull the code that wait for blocked dev into one function")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Miroslav Cimerman <mc@xxxxxxxxxxx>
---
drivers/md/raid10.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index a65bd65ae7bd..a97831823c68 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -1273,9 +1273,11 @@ static void wait_blocked_dev(struct mddev *mddev, struct r10bio *r10_bio)
retry_wait:
blocked_rdev = NULL;
for (i = 0; i < conf->copies; i++) {
+ /* A discard (sectors == 0) does not use devs[].devnum. */
+ int d = r10_bio->sectors ? r10_bio->devs[i].devnum : i;
struct md_rdev *rdev, *rrdev;
- rdev = conf->mirrors[i].rdev;
+ rdev = conf->mirrors[d].rdev;
if (rdev) {
sector_t dev_sector = r10_bio->devs[i].addr;
@@ -1300,7 +1302,7 @@ static void wait_blocked_dev(struct mddev *mddev, struct r10bio *r10_bio)
}
}
- rrdev = conf->mirrors[i].replacement;
+ rrdev = conf->mirrors[d].replacement;
if (rrdev && rdev_blocked(rrdev)) {
atomic_inc(&rrdev->nr_pending);
blocked_rdev = rrdev;
--
2.53.0