Linux RAID subsystem development
 help / color / mirror / Atom feed
From: Miroslav Cimerman <mc@raidlab.org>
To: Song Liu <song@kernel.org>, Yu Kuai <yukuai@fygo.io>
Cc: Li Nan <magiclinan@didiglobal.com>, Xiao Ni <xiao@kernel.org>,
	NeilBrown <neil@brown.name>,
	Mariusz Tkaczyk <mtkaczyk@kernel.org>, Kenta Akagi <k@mgml.me>,
	linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 3/8] md/raid1,raid10: fail writes that waited while the array failed
Date: Fri, 27 Nov 2026 00:32:26 +0000	[thread overview]
Message-ID: <20261127003231.1180197-4-mc@raidlab.org> (raw)
In-Reply-To: <20261127003231.1180197-1-mc@raidlab.org>

md_submit_bio() fails new writes once MD_BROKEN is set. A write that
arrives while a failed device is being recorded passes that check and
waits for the superblock update. If the update fails on the last
working device, MD_BROKEN is set during the wait. The write then
continues, reaches only the remaining device and completes with
success. After a restart, both devices assemble as in sync, and reads
can return the old data.

Check MD_BROKEN again after the wait, and fail the write. dm-raid does
not go through md_submit_bio(), so leave it unchanged. Large raid10
discards go through raid10_handle_discard() and are left as they are.

Fixes: 9631abdbf406 ("md: Set MD_BROKEN for RAID1 and RAID10")
Cc: stable@vger.kernel.org
Signed-off-by: Miroslav Cimerman <mc@raidlab.org>
---
 drivers/md/raid1.c  | 12 ++++++++++++
 drivers/md/raid10.c | 11 +++++++++++
 2 files changed, 23 insertions(+)

diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 37d120a63778..88bbe81c7798 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -1489,6 +1489,18 @@ static bool raid1_write_request(struct mddev *mddev, struct bio *bio,
 
 	wait_blocked_rdev(mddev, bio);
 
+	/*
+	 * If the array failed while this write waited, the failed device
+	 * might not be recorded. Fail the write, as md_submit_bio() does,
+	 * except for dm-raid.
+	 */
+	if (unlikely(!mddev_is_dm(mddev) &&
+		     test_bit(MD_BROKEN, &mddev->flags))) {
+		bio_io_error(bio);
+		allow_barrier(conf, sector);
+		return false;
+	}
+
 	r1_bio = alloc_r1bio(mddev, bio);
 	r1_bio->sectors = max_sectors;
 
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index a97831823c68..a38b95585e35 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -1378,6 +1378,17 @@ static bool raid10_write_request(struct mddev *mddev, struct bio *bio,
 
 	wait_blocked_dev(mddev, r10_bio);
 
+	/*
+	 * If the array failed while this write waited, the failed device
+	 * might not be recorded. Fail the write, as md_submit_bio() does,
+	 * except for dm-raid.
+	 */
+	if (unlikely(!mddev_is_dm(mddev) &&
+		     test_bit(MD_BROKEN, &mddev->flags))) {
+		raid_end_bio_io(r10_bio);
+		return false;
+	}
+
 	max_sectors = r10_bio->sectors;
 
 	for (i = 0;  i < conf->copies; i++) {
-- 
2.53.0


  parent reply	other threads:[~2026-11-27  0:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27  0:32 [PATCH 0/8] md/raid1,raid10: fix writes acknowledged before a failure is recorded Miroslav Cimerman
2026-11-27  0:32 ` [PATCH 1/8] md/raid1,raid10: fail held writes when the array fails Miroslav Cimerman
2026-11-27  0:32 ` [PATCH 2/8] md/raid10: wait for the devices of the write in wait_blocked_dev() Miroslav Cimerman
2026-11-27  0:32 ` Miroslav Cimerman [this message]
2026-11-27  0:32 ` [PATCH 4/8] md/raid1,raid10: fail held writes that no working device has Miroslav Cimerman
2026-11-27  0:32 ` [PATCH 5/8] md/raid1,raid10: hold writes that fail on a faulty device Miroslav Cimerman
2026-11-27  0:57   ` sashiko-bot
2026-11-27  0:32 ` [PATCH 6/8] md/raid1: set MD_SB_CHANGE_PENDING under device_lock in raid1_error() Miroslav Cimerman
2026-11-27  0:32 ` [PATCH 7/8] md/raid1,raid10: hold writes that skip a newly failed device Miroslav Cimerman
2026-11-27  1:01   ` sashiko-bot
2026-11-27  0:32 ` [PATCH 8/8] md/raid1: hold write-behind writes that failed on a device Miroslav Cimerman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261127003231.1180197-4-mc@raidlab.org \
    --to=mc@raidlab.org \
    --cc=k@mgml.me \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=magiclinan@didiglobal.com \
    --cc=mtkaczyk@kernel.org \
    --cc=neil@brown.name \
    --cc=song@kernel.org \
    --cc=xiao@kernel.org \
    --cc=yukuai@fygo.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox