[PATCH RESEND 2/3] md/raid10: re-arm in-progress bitmap chunks when recovery is interrupted
From: Eric Hagberg
Date: Fri Dec 04 2026 - 12:46:45 EST
From: Jason Chu <jaschu@xxxxxxxxxxxxxx>
Recovery walks member sectors, but the write-intent bitmap tracks array
sectors. When raid10_sync_request() finds work at a member sector it
calls md_bitmap_start_sync() for the array sector that maps to it. With
the classic bitmap this moves the bitmap chunk from NEEDED to RESYNC. The
same bitmap chunk can cover copies at member sectors that recovery has
not reached yet:
- With the far layout, a bitmap chunk larger than the raid chunk covers
array chunks whose copies on the recovering member are far apart: near
the start of the member for one array chunk, and in the far section
for the next.
- With two members recovering together, a bitmap chunk is started when
the cursor reaches the copy on one member. The copy of the same data
on the other member can be at a later member sector.
When recovery is interrupted, the final call to raid10_sync_request()
ends only the chunks that curr_resync maps to, one per slot.
bitmap_close_sync() then clears RESYNC on all other chunks without
setting NEEDED, as if their work was done. md saves curr_resync as the
recovery offset. When recovery resumes from there, start_sync() reports
those chunks as clean, the remaining copies are skipped, and the member
is marked In_sync while it holds old data.
No device error is needed. Writing "frozen" to sync_action during a
bitmap based recovery, and then letting recovery continue, is enough.
Reproduced on v7.4-rc5 in a KVM guest with the script in the cover
letter. Both tests stop recovery with "frozen" while it is paused at
sync_max, and then let it finish:
recovery-abort-far (3 members, far=2, one member re-added)
before: verdict=FAIL stale_copies_on_readded_member=2/2
mismatch_cnt=256
after: verdict=PASS stale_copies_on_readded_member=0/2
mismatch_cnt=0
recovery-abort-offset (3 members, offset=3, two members re-added)
before: verdict=FAIL stale_copies=1/6 mismatch_cnt=64
after: verdict=PASS stale_copies=0/6 mismatch_cnt=0
On an aborted recovery with the classic bitmap, do not call close_sync().
Walk the bitmap and end every chunk as aborted, which turns RESYNC back
into NEEDED. A chunk whose copies were all finished before the
interruption stays dirty and is copied again later. That is extra work,
but no copy is skipped.
The walk steps by the span that end_sync() reports. A counter page that
is missing or hijacked reports the span of a whole page, and a hijacked
page has one counter for each half, so the walk also visits the last
sector of such a span.
llbitmap is left alone: llbitmap_end_sync() already aborts every syncing
chunk from the given offset to the end of the bitmap. llbitmap was not
tested.
Fixes: 6cce3b23f6f8 ("[PATCH] md: write intent bitmap support for raid10")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Jason Chu <jaschu@xxxxxxxxxxxxxx>
Signed-off-by: Eric Hagberg <ehagberg@xxxxxxxxxxxxxx>
---
drivers/md/raid10.c | 59 +++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 57 insertions(+), 2 deletions(-)
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 3ef0143..e42abe7 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -3071,6 +3071,51 @@ static void raid10_set_cluster_sync_high(struct r10conf *conf)
conf->cluster_sync_high = conf->cluster_sync_low + window_size;
}
+/*
+ * llbitmap's end_sync already aborts every syncing chunk from the given
+ * offset to the end. The classic bitmap ends one chunk per call.
+ */
+static bool raid10_classic_bitmap(struct mddev *mddev)
+{
+ return mddev->bitmap_id == ID_BITMAP && md_bitmap_enabled(mddev, false);
+}
+
+/*
+ * Re-arm the classic bitmap's in-progress chunks from @start to the end of
+ * the array, so that they are synced again.
+ *
+ * Recovery walks member sectors, but the bitmap tracks array sectors. A
+ * chunk that was started for one copy can still cover copies that recovery
+ * has not reached: on another returning member, or further into the same
+ * member for the far layout. An aborted recovery therefore re-arms every
+ * in-progress chunk (@start == 0). A chunk whose copies are all done may
+ * stay dirty and be copied again, but an unfinished copy is not skipped.
+ */
+static void raid10_abort_sync_bitmap(struct mddev *mddev, sector_t start)
+{
+ /* The bitmap chunk size is a power of two. */
+ sector_t chunk_sectors = mddev->bitmap_info.chunksize >> SECTOR_SHIFT;
+ sector_t limit = mddev->resync_max_sectors;
+ sector_t sector = round_down(start, chunk_sectors);
+
+ while (sector < limit) {
+ sector_t blocks;
+
+ mddev->bitmap_ops->end_sync(mddev, sector, &blocks);
+ blocks = min(blocks, limit - sector);
+ sector += blocks;
+ /*
+ * Missing and hijacked counter pages report a whole page
+ * span. A hijacked page has two counters, one for each
+ * half. Visit the last sector of the span as well, in
+ * case it uses the other counter.
+ */
+ if (blocks > chunk_sectors)
+ mddev->bitmap_ops->end_sync(mddev, sector - 1, &blocks);
+ cond_resched();
+ }
+}
+
/*
* perform a "sync" on one "block"
*
@@ -3136,6 +3181,8 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
return 0;
if (sector_nr >= max_sector) {
+ bool aborted = mddev->curr_resync < max_sector;
+
conf->cluster_sync_low = 0;
conf->cluster_sync_high = 0;
@@ -3154,7 +3201,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
return 0;
}
- if (mddev->curr_resync < max_sector) { /* aborted */
+ if (aborted) {
if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery))
md_bitmap_end_sync(mddev, mddev->curr_resync,
&sync_blocks);
@@ -3182,8 +3229,16 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
}
conf->fullsync = 0;
}
- if (md_bitmap_enabled(mddev, false))
+ if (aborted && raid10_classic_bitmap(mddev) &&
+ !test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) {
+ /*
+ * close_sync would clear in-progress chunks that
+ * still have copies outstanding.
+ */
+ raid10_abort_sync_bitmap(mddev, 0);
+ } else if (md_bitmap_enabled(mddev, false)) {
mddev->bitmap_ops->close_sync(mddev);
+ }
close_sync(conf);
*skipped = 1;
return 0;
--
2.43.7