Linux RAID subsystem development
 help / color / mirror / Atom feed
* [PATCH] md/raid5: fix inverted condition in rdev_set_badblocks call
@ 2026-10-17  7:43 zhanghao
  2026-10-17  7:49 ` sashiko-bot
  2026-10-17  8:37 ` [PATCH v2] " zhanghao
  0 siblings, 2 replies; 3+ messages in thread
From: zhanghao @ 2026-10-17  7:43 UTC (permalink / raw)
  To: song, yukuai; +Cc: magiclinan, xiao, linux-raid, linux-kernel, stable, zhanghao

Commit fd4d44c14ff6 ("md: mark rdev Faulty when badblocks setting fails")
attempted to unify badblock handling but introduced a logic inversion in
raid5_end_read_request().

The original check was:

    if (!(set_bad && In_sync && rdev_set_badblocks(...)))
            md_error(...);

which records badblocks when `set_bad && In_sync`, and calls md_error()
either when recording fails or when the rdev is not In_sync. The new
condition `if (!(set_bad && In_sync))` skips rdev_set_badblocks() exactly
during recovery/reshape (In_sync is set), so failed badblock updates no
longer trigger md_error() and the rdev is not marked Faulty. This allows
reconstruction to continue on a disk with a saturated badblock table,
potentially propagating corrupted data to the replacement disk.

Fix the condition to match the intended behavior: call rdev_set_badblocks()
when `set_bad && In_sync`, and let the callee handle md_error() on failure.

Fixes: fd4d44c14ff6 ("md: mark rdev Faulty when badblocks setting fails")
Cc: stable@vger.kernel.org
Signed-off-by: zhanghao <zh_exit@163.com>
---
 drivers/md/raid5.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index d52adf81065a..dcfb1bfa9ebf 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -2866,7 +2866,7 @@ static void raid5_end_read_request(struct bio * bi)
 		else {
 			clear_bit(R5_ReadError, &sh->dev[i].flags);
 			clear_bit(R5_ReWrite, &sh->dev[i].flags);
-			if (!(set_bad && test_bit(In_sync, &rdev->flags)))
+			if (set_bad && test_bit(In_sync, &rdev->flags))
 				rdev_set_badblocks(rdev, sh->sector,
 						   RAID5_STRIPE_SECTORS(conf), 0);
 		}
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-10-17  8:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-17  7:43 [PATCH] md/raid5: fix inverted condition in rdev_set_badblocks call zhanghao
2026-10-17  7:49 ` sashiko-bot
2026-10-17  8:37 ` [PATCH v2] " zhanghao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox