[PATCH 1/8] md/raid1,raid10: fail held writes when the array fails
From: Miroslav Cimerman
Date: Thu Nov 26 2026 - 19:32:56 EST
raid1 and raid10 hold a write that failed on one device until the
superblock records that device as faulty.
If the superblock write then fails on the last working device, the
error handler sets MD_BROKEN, keeps that device In_sync and requests no
new superblock update. md_update_sb() clears MD_SB_CHANGE_PENDING, and
the held write completes with success. No superblock records the failed
device. After a restart, both devices assemble as in sync, and reads
can return the old data of the failed one.
Fail the held writes when MD_BROKEN is set. dm-raid does not reject
writes when MD_BROKEN is set, so leave it unchanged.
Found with FuzzyRAID, a fault injection fuzzer for RAID
implementations.
Fixes: 55ce74d4bfe1 ("md/raid1: ensure device failure recorded before write request returns.")
Fixes: 95af587e95aa ("md/raid10: ensure device failure recorded before write request returns.")
Cc: stable@xxxxxxxxxxxxxxx # v5.19+
Signed-off-by: Miroslav Cimerman <mc@xxxxxxxxxxx>
---
drivers/md/raid1.c | 8 ++++++++
drivers/md/raid10.c | 8 ++++++++
2 files changed, 16 insertions(+)
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 25b80ad52f00..37d120a63778 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -2629,6 +2629,14 @@ static void raid1d(struct md_thread *thread)
list_del(&r1_bio->retry_list);
idx = sector_to_idx(r1_bio->sector);
atomic_dec(&conf->nr_queued[idx]);
+ /*
+ * If the array failed while this write was held, the
+ * failed copy might not be recorded. Fail the write,
+ * except for dm-raid.
+ */
+ if (!mddev_is_dm(mddev) &&
+ test_bit(MD_BROKEN, &mddev->flags))
+ clear_bit(R1BIO_Uptodate, &r1_bio->state);
if (test_bit(R1BIO_WriteError, &r1_bio->state))
close_write(r1_bio);
raid_end_bio_io(r1_bio);
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 68f42cad32a5..a65bd65ae7bd 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -2942,6 +2942,14 @@ static void raid10d(struct md_thread *thread)
retry_list);
list_del(&r10_bio->retry_list);
+ /*
+ * If the array failed while this write was held, the
+ * failed copy might not be recorded. Fail the write,
+ * except for dm-raid.
+ */
+ if (!mddev_is_dm(mddev) &&
+ test_bit(MD_BROKEN, &mddev->flags))
+ clear_bit(R10BIO_Uptodate, &r10_bio->state);
if (test_bit(R10BIO_WriteError,
&r10_bio->state))
close_write(r10_bio);
--
2.53.0