From: "Li Youhong" <dayou5941@163.com>
To: song@kernel.org, yukuai@fygo.io
Cc: magiclinan@didiglobal.com, xiao@kernel.org,
linux-raid@vger.kernel.org, Li Youhong <liyouhong@kylinos.cn>
Subject: [PATCH 1/3] md: add rdev_record_write_error() helper
Date: Thu, 27 Aug 2026 15:56:18 +0800 [thread overview]
Message-ID: <20260827075620.3599227-2-dayou5941@163.com> (raw)
In-Reply-To: <20260827075620.3599227-1-dayou5941@163.com>
From: Li Youhong <liyouhong@kylinos.cn>
The WriteErrorSeen + WantReplacement + MD_RECOVERY_NEEDED sequence is
duplicated across raid1, raid10 and raid5. Factor it into a small
inline helper for readability. No functional change.
Signed-off-by: Li Youhong <liyouhong@kylinos.cn>
---
drivers/md/md.h | 7 +++++++
drivers/md/raid1.c | 16 +++-------------
drivers/md/raid10.c | 21 ++++-----------------
drivers/md/raid5.c | 5 +----
4 files changed, 15 insertions(+), 34 deletions(-)
diff --git a/drivers/md/md.h b/drivers/md/md.h
index b6d2e8929a0f..6440da292105 100644
--- a/drivers/md/md.h
+++ b/drivers/md/md.h
@@ -989,6 +989,13 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
}
}
+static inline void rdev_record_write_error(struct md_rdev *rdev)
+{
+ set_bit(WriteErrorSeen, &rdev->flags);
+ if (!test_and_set_bit(WantReplacement, &rdev->flags))
+ set_bit(MD_RECOVERY_NEEDED, &rdev->mddev->recovery);
+}
+
static inline int mddev_is_clustered(struct mddev *mddev)
{
return mddev->cluster_info && mddev->bitmap_info.nodes > 1;
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index f0646fb24371..9d8441348f14 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -483,10 +483,7 @@ static void raid1_end_write_request(struct bio *bio)
* 'one mirror IO has finished' event handler:
*/
if (bio->bi_status && !ignore_error) {
- set_bit(WriteErrorSeen, &rdev->flags);
- if (!test_and_set_bit(WantReplacement, &rdev->flags))
- set_bit(MD_RECOVERY_NEEDED, &
- conf->mddev->recovery);
+ rdev_record_write_error(rdev);
if (test_bit(FailFast, &rdev->flags) &&
(bio->bi_opf & MD_FAILFAST) &&
@@ -2067,10 +2064,7 @@ static void end_sync_write(struct bio *bio)
if (bio->bi_status) {
abort_sync_write(mddev, r1_bio);
- set_bit(WriteErrorSeen, &rdev->flags);
- if (!test_and_set_bit(WantReplacement, &rdev->flags))
- set_bit(MD_RECOVERY_NEEDED, &
- mddev->recovery);
+ rdev_record_write_error(rdev);
set_bit(R1BIO_WriteError, &r1_bio->state);
} else if (rdev_has_badblock(rdev, r1_bio->sector, r1_bio->sectors) &&
!rdev_has_badblock(conf->mirrors[r1_bio->read_disk].rdev,
@@ -2088,11 +2082,7 @@ static int r1_sync_page_io(struct md_rdev *rdev, sector_t sector,
/* success */
return 1;
if (rw == REQ_OP_WRITE) {
- set_bit(WriteErrorSeen, &rdev->flags);
- if (!test_and_set_bit(WantReplacement,
- &rdev->flags))
- set_bit(MD_RECOVERY_NEEDED, &
- rdev->mddev->recovery);
+ rdev_record_write_error(rdev);
}
/* need to record an error - either for the block or the device */
rdev_set_badblocks(rdev, sector, sectors, 0);
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 1093c798d9dd..c4218d6483ed 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -496,10 +496,7 @@ static void raid10_end_write_request(struct bio *bio)
*/
md_error(rdev->mddev, rdev);
else {
- set_bit(WriteErrorSeen, &rdev->flags);
- if (!test_and_set_bit(WantReplacement, &rdev->flags))
- set_bit(MD_RECOVERY_NEEDED,
- &rdev->mddev->recovery);
+ rdev_record_write_error(rdev);
dec_rdev = 0;
if (test_bit(FailFast, &rdev->flags) &&
@@ -2299,10 +2296,7 @@ static void end_sync_write(struct bio *bio)
if (repl)
md_error(mddev, rdev);
else {
- set_bit(WriteErrorSeen, &rdev->flags);
- if (!test_and_set_bit(WantReplacement, &rdev->flags))
- set_bit(MD_RECOVERY_NEEDED,
- &rdev->mddev->recovery);
+ rdev_record_write_error(rdev);
set_bit(R10BIO_WriteError, &r10_bio->state);
}
} else if (rdev_has_badblock(rdev, r10_bio->devs[slot].addr,
@@ -2500,11 +2494,7 @@ static void fix_recovery_read_error(struct r10bio *r10_bio)
pages[idx],
REQ_OP_WRITE, false);
if (!ok) {
- set_bit(WriteErrorSeen, &rdev->flags);
- if (!test_and_set_bit(WantReplacement,
- &rdev->flags))
- set_bit(MD_RECOVERY_NEEDED,
- &rdev->mddev->recovery);
+ rdev_record_write_error(rdev);
}
}
if (!ok) {
@@ -2585,10 +2575,7 @@ static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
/* success */
return 1;
if (op == REQ_OP_WRITE) {
- set_bit(WriteErrorSeen, &rdev->flags);
- if (!test_and_set_bit(WantReplacement, &rdev->flags))
- set_bit(MD_RECOVERY_NEEDED,
- &rdev->mddev->recovery);
+ rdev_record_write_error(rdev);
}
/* need to record an error - either for the block or the device */
rdev_set_badblocks(rdev, sector, sectors, 0);
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index b91545ce090d..caacc06c52c5 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -2888,11 +2888,8 @@ static void raid5_end_write_request(struct bio *bi)
set_bit(R5_MadeGoodRepl, &sh->dev[i].flags);
} else {
if (bi->bi_status) {
- set_bit(WriteErrorSeen, &rdev->flags);
+ rdev_record_write_error(rdev);
set_bit(R5_WriteError, &sh->dev[i].flags);
- if (!test_and_set_bit(WantReplacement, &rdev->flags))
- set_bit(MD_RECOVERY_NEEDED,
- &rdev->mddev->recovery);
} else if (rdev_has_badblock(rdev, sh->sector,
RAID5_STRIPE_SECTORS(conf))) {
set_bit(R5_MadeGood, &sh->dev[i].flags);
--
2.25.1
next prev parent reply other threads:[~2026-08-27 7:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-27 7:56 [PATCH 0/3] md: raid helper cleanups Li Youhong
2026-08-27 7:56 ` Li Youhong [this message]
2026-08-27 7:56 ` [PATCH 2/3] md/raid1-10: add rdev_bb_block_sectors() helper Li Youhong
2026-08-27 8:15 ` sashiko-bot
2026-08-27 7:56 ` [PATCH 3/3] md/raid1-10: share flush_bio_list between raid1 and raid10 Li Youhong
2026-09-05 2:43 ` [PATCH 0/3] md: raid helper cleanups yu kuai
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=20260827075620.3599227-2-dayou5941@163.com \
--to=dayou5941@163.com \
--cc=linux-raid@vger.kernel.org \
--cc=liyouhong@kylinos.cn \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox