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 7/8] md/raid1,raid10: hold writes that skip a newly failed device
Date: Fri, 27 Nov 2026 00:32:30 +0000	[thread overview]
Message-ID: <20261127003231.1180197-8-mc@raidlab.org> (raw)
In-Reply-To: <20261127003231.1180197-1-mc@raidlab.org>

A device can fail between the wait for blocked devices and the device
selection of a write. The selection skips Faulty devices, so the write
completes before the superblock records the failure. Before the commits
below, the selection waited for a Blocked device.

Give the write to a Faulty device while its failure might not be
recorded: while it is Blocked, or after MD_BROKEN. raid1_submit_write()
fails the copy at once, and the write is held. Waiting for Blocked
again would miss MD_BROKEN: md_update_sb() clears Blocked even when the
superblock write failed.

This needs "md/raid1,raid10: hold writes that fail on a faulty device"
and "md/raid1,raid10: fail held writes when the array fails".

Fixes: 88ed59c4cc6c ("md/raid1: factor out helper to handle blocked rdev from raid1_write_request()")
Fixes: f2e7e269a752 ("md/raid10: pull the code that wait for blocked dev into one function")
Cc: stable@vger.kernel.org
Signed-off-by: Miroslav Cimerman <mc@raidlab.org>
---
 drivers/md/raid1-10.c | 12 ++++++++++++
 drivers/md/raid1.c    |  9 ++++++++-
 drivers/md/raid10.c   | 13 +++++++++----
 3 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/drivers/md/raid1-10.c b/drivers/md/raid1-10.c
index 341a9785e3f2..f8fa9cdc4080 100644
--- a/drivers/md/raid1-10.c
+++ b/drivers/md/raid1-10.c
@@ -125,6 +125,18 @@ static inline void raid1_submit_write(struct bio *bio)
 		submit_bio_noacct(bio);
 }
 
+/*
+ * Give a write to a Faulty device while its failure might not be recorded:
+ * Blocked is set until it is, and after MD_BROKEN it might never be.
+ * raid1_submit_write() fails the copy, and the write is held.
+ */
+static inline bool raid1_write_to_faulty(struct mddev *mddev,
+					 struct md_rdev *rdev)
+{
+	return test_bit(Blocked, &rdev->flags) ||
+	       (!mddev_is_dm(mddev) && test_bit(MD_BROKEN, &mddev->flags));
+}
+
 static inline bool raid1_add_bio_to_plug(struct mddev *mddev, struct bio *bio,
 				      blk_plug_cb_fn unplug, int copies)
 {
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index f596b36ec6e1..508673e8c02e 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -1524,8 +1524,15 @@ static bool raid1_write_request(struct mddev *mddev, struct bio *bio,
 			write_behind = false;
 
 		r1_bio->bios[i] = NULL;
-		if (!rdev || test_bit(Faulty, &rdev->flags))
+		if (!rdev)
+			continue;
+		if (test_bit(Faulty, &rdev->flags)) {
+			if (raid1_write_to_faulty(mddev, rdev)) {
+				atomic_inc(&rdev->nr_pending);
+				r1_bio->bios[i] = bio;
+			}
 			continue;
+		}
 
 		if (test_bit(WriteErrorSeen, &rdev->flags)) {
 			sector_t first_bad;
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 519b6ac0accd..6ea84eb8bf87 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -1387,14 +1387,19 @@ static bool raid10_write_request(struct mddev *mddev, struct bio *bio,
 
 		rdev = conf->mirrors[d].rdev;
 		rrdev = conf->mirrors[d].replacement;
-		if (rdev && (test_bit(Faulty, &rdev->flags)))
+		r10_bio->devs[i].bio = NULL;
+		r10_bio->devs[i].repl_bio = NULL;
+
+		if (rdev && test_bit(Faulty, &rdev->flags)) {
+			if (raid1_write_to_faulty(mddev, rdev)) {
+				r10_bio->devs[i].bio = bio;
+				atomic_inc(&rdev->nr_pending);
+			}
 			rdev = NULL;
+		}
 		if (rrdev && (test_bit(Faulty, &rrdev->flags)))
 			rrdev = NULL;
 
-		r10_bio->devs[i].bio = NULL;
-		r10_bio->devs[i].repl_bio = NULL;
-
 		if (!rdev && !rrdev)
 			continue;
 		if (rdev && test_bit(WriteErrorSeen, &rdev->flags)) {
-- 
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 ` [PATCH 3/8] md/raid1,raid10: fail writes that waited while the array failed Miroslav Cimerman
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 ` Miroslav Cimerman [this message]
2026-11-27  1:01   ` [PATCH 7/8] md/raid1,raid10: hold writes that skip a newly failed device 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-8-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