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>,
linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2] md/raid10: wait for the devices of the write in wait_blocked_dev()
Date: Fri, 4 Dec 2026 00:33:48 +0000 [thread overview]
Message-ID: <20261204003348.1219170-1-mc@raidlab.org> (raw)
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@vger.kernel.org
Signed-off-by: Miroslav Cimerman <mc@raidlab.org>
---
v2: sent on its own, v1 was 2/8 of
https://lore.kernel.org/linux-raid/20261127003231.1180197-1-mc@raidlab.org/
Found by code reading, not reproduced.
Prepared with help from an LLM.
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 68f42cad32a5..c4f44b14fe10 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;
base-commit: c526b7cd32f75fea6021ffdab287b81cf38ddeb7
--
2.53.0
reply other threads:[~2026-12-04 0:33 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261204003348.1219170-1-mc@raidlab.org \
--to=mc@raidlab.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=magiclinan@didiglobal.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.