* Re: [REGRESSION] md/raid10: far-layout member left with stale data after bitmap re-add (6.11+, 6.12.y, 6.18.y)
2026-11-30 19:31 [REGRESSION] md/raid10: far-layout member left with stale data after bitmap re-add (6.11+, 6.12.y, 6.18.y) Eric Hagberg
@ 2026-11-30 19:48 ` sashiko-bot
2026-12-04 17:46 ` [PATCH RESEND 0/3] md/raid10: fix old data left by skipped and interrupted sync Eric Hagberg
1 sibling, 0 replies; 10+ messages in thread
From: sashiko-bot @ 2026-11-30 19:48 UTC (permalink / raw)
To: Eric Hagberg, linux-raid; +Cc: yukuai
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] md/raid10: missing Signed-off-by trailer and informal inquiry
commit message
- [High] md/raid10: premature end-of-sync teardown and false abort in
raid10_sync_request()
- [High] md/raid10: infinite loop or 0-length bio in
raid10_sync_request() at resync_max
- [Medium] md/raid10: broken sectors_skipped accounting and tight skip
loop in raid10_sync_request()
- [Low] md/raid10: missing Fixes trailer for commit bc49694a9e8f in
commit message
--
commit d99e7ee24942d79bda6cdab910442b35145994a1
Author: Eric Hagberg <ehagberg@janestreet.com>
> md/raid10: far-layout member left with stale data after bitmap re-add (6.11+, 6.12.y, 6.18.y)
>
> Hi,
>
> On 6.12.y and 6.18.y, re-adding a member to a RAID10 array with the far
> layout and an internal bitmap can complete "successfully" ([UU]) while
> the re-added member still holds stale data for regions written while it
> was absent. 6.1.y is not affected. This was seen on 2-disk
> far=2 arrays (NVMe, internal bitmap, 64 MiB bitmap chunk) after a member
> dropped out and came back; filesystems on the arrays were corrupted and
> "check" reported non-zero mismatch_cnt.
>
> #regzbot introduced: bc49694a9e8f
>
> Reproducer (loop devices, 2 x 16 GiB zero-filled sparse files):
>
> mdadm --create /dev/md/r10 --run --assume-clean --metadata=1.2 \
> --level=10 --raid-devices=2 --layout=f2 --chunk=512 \
> --bitmap=internal --bitmap-chunk=65536 /dev/loopA /dev/loopB
> mdadm /dev/md/r10 --fail /dev/loopB --remove /dev/loopB
> # write a 64 MiB random payload with O_DIRECT to every third
> # 64 MiB bitmap chunk (85 regions)
> mdadm /dev/md/r10 --re-add /dev/loopB # bitmap-based recovery
> mdadm --wait /dev/md/r10 # until [UU]
> echo check > /sys/block/mdX/md/sync_action; mdadm --wait /dev/md/r10
> cat /sys/block/mdX/md/mismatch_cnt
> mdadm /dev/md/r10 --fail /dev/loopA --remove /dev/loopA
> # read the 85 regions back (now served only by loopB) and compare
>
> Results ("OK" = mismatch_cnt 0 and every region read back correctly from
> the re-added member):
>
> kernel far=2 near=2
> 6.1 OK OK
> 6.12 CORRUPTION OK
> 6.18 CORRUPTION OK
>
> We have not yet tested 7.x. A full script is available on request.
>
> Our analysis, which we would appreciate having checked:
>
> Commit bc49694a9e8f ("md: pass in max_sectors for pers->sync_request()"),
> merged in v6.11, removed the recomputation of max_sector at the
> 'skipped:' label in raid10_sync_request(). The giveup path still shrinks
> max_sector to sector_nr + max_sync, advances sector_nr to it and jumps
> back to the label, where "sector_nr >= max_sector" is now true. The
> function then takes the end-of-sync branch and calls the bitmap's
> close_sync(), which clears RESYNC on every bitmap chunk whose sync has
> started, as if it had completed.
>
> During a bitmap-based recovery, every region that is clean in the bitmap
> takes the giveup path. With the far layout, the data covered by one
> bitmap chunk is split between the first and second halves of the
> recovering member. Once a clean region is skipped, chunks whose first
> half has been recovered are treated as done, their second half is
> skipped, and the member is marked In_sync with stale data. Near layouts
> recover each bitmap chunk contiguously, which matches what we see.
>
> In mainline, 7435b73f05fb ("md/raid10: cleanup skip handling in
> raid10_sync_request"), in v7.0, removed the skip loop and carries
> "Fixes: bc49694a9e8f", but has no Cc: stable and is not in 6.12.y or
> 6.18.y. It is patch 11 of a 12-patch series and appears to depend on
> earlier patches in it (it stops checking rdev_set_badblocks() return
> values, which relies on "md: mark rdev Faulty when badblocks setting
> fails").
>
> Questions:
>
> 1. Does this analysis look right to you?
> 2. What is the preferred fix for 6.12.y and 6.18.y: backporting
> 7435b73f05fb together with the patches it depends on, or a smaller
> targeted fix?
>
> As a starting point for discussion only (not a formal submission), the
> minimal change we tried restores the pre-6.11 recomputation by resetting
> max_sector to the caller's value at the label. With it, the reproducer
> passes for both layouts on 6.12 and 6.18. We have since had
> concerns raised about it internally and would value your view on
> whether it is safe:
[Severity: High]
This commit is missing a Signed-off-by: trailer and has an informal
mailing-list inquiry as its changelog rather than a commit description.
[Severity: Low]
For a formal submission fixing the regression, the commit message should
also carry:
Fixes: bc49694a9e8f ("md: pass in max_sectors for pers->sync_request()")
> diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
> index 2a9c4ee982e02..bddab5f9909e2 100644
> --- a/drivers/md/raid10.c
> +++ b/drivers/md/raid10.c
> @@ -3150,6 +3150,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
> sector_t chunk_mask = conf->geo.chunk_mask;
> int page_idx = 0;
> int error_disk = -1;
> + sector_t orig_max_sector = max_sector;
>
> /*
> * Allow skipping a full rebuild for incremental assembly
> @@ -3171,6 +3172,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
> return 0;
>
> skipped:
> + max_sector = orig_max_sector;
> if (sector_nr >= max_sector) {
> conf->cluster_sync_low = 0;
> conf->cluster_sync_high = 0;
[Severity: High]
Can resetting max_sector at skipped: trigger premature end-of-sync
teardown and a false abort when a skipped region reaches the end of the
array?
md_do_sync() only updates mddev->curr_resync after ->sync_request()
returns, and only calls ->sync_request(mddev, max_sectors, max_sectors,
&skipped) to run the sector_nr >= max_sector teardown block after waiting
for mddev->recovery_active to drain. When a mid-sync call skips clean
bitmap blocks up to orig_max_sector via giveup:, sector_nr reaches
max_sector inside the active iteration while mddev->curr_resync is still
the starting offset j (< max_sector):
drivers/md/raid10.c:raid10_sync_request() {
...
if (sector_nr >= max_sector) {
...
if (mddev->curr_resync < max_sector) { /* aborted */
if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery))
md_bitmap_end_sync(mddev->bitmap, mddev->curr_resync,
&sync_blocks, 1);
else for (i = 0; i < conf->geo.raid_disks; i++) {
sector_t sect =
raid10_find_virt(conf, mddev->curr_resync, i);
md_bitmap_end_sync(mddev->bitmap, sect,
&sync_blocks, 1);
}
} else {
...
}
md_bitmap_close_sync(mddev->bitmap);
close_sync(conf);
*skipped = 1;
return sectors_skipped;
}
}
Because mddev->curr_resync < max_sector is always true here, this takes
the aborted branch (calling md_bitmap_end_sync(..., 1), which can re-mark
already-synced bitmap chunks with NEEDED_MASK, and skipping replacement
recovery_offset = MaxSector and conf->fullsync = 0). It also runs
md_bitmap_close_sync() while earlier recovery I/Os are still in flight,
and destroys conf->r10buf_pool in close_sync(conf) before md_do_sync()
makes its final end-of-sync call (which then re-initializes and
re-destroys r10buf_pool).
[Severity: High]
What happens when mddev->resync_max is set below orig_max_sector (for
example via /sys/block/mdX/md/sync_max) and the giveup -> skipped loop
advances sector_nr up to mddev->resync_max?
At skipped:, resetting max_sector = orig_max_sector makes sector_nr >=
max_sector false because sector_nr == mddev->resync_max < orig_max_sector.
Later in raid10_sync_request(), max_sector is clamped back down to
mddev->resync_max:
drivers/md/raid10.c:raid10_sync_request() {
...
if (max_sector > mddev->resync_max)
max_sector = mddev->resync_max; /* Don't do IO beyond here */
...
}
Execution then continues with sector_nr == max_sector. If the block at
resync_max is clean in the bitmap, chunks_skipped is set to -1 and giveup:
adds 0 to sector_nr, increments chunks_skipped back to 0, and jumps to
skipped: in an unbreakable infinite loop. If the block at resync_max
needs syncing, the page-adding loop sees len == 0 on page_idx == 0 and
submits a 0-sector bio with no pages.
[Severity: Medium]
Does re-enabling the internal giveup -> skipped loop across clean bitmap
regions also break sectors_skipped accounting when a dirty chunk follows
a skipped clean region?
When raid10_sync_request() skips clean bitmap blocks and then submits I/O
for a dirty block in the same call, it finishes with:
drivers/md/raid10.c:raid10_sync_request() {
...
if (sectors_skipped)
/* pretend they weren't skipped, it makes
* no important difference in this case
*/
md_done_sync(mddev, sectors_skipped, 1);
return sectors_skipped + nr_sectors;
}
This has several bad interactions with md_do_sync():
1. md_done_sync() takes a signed int blocks argument (truncating 64-bit
sector_t sectors_skipped above 1 TiB) and subtracts it from
mddev->recovery_active before raid10_sync_request() returns and before
md_do_sync() adds the returned sectors to mddev->recovery_active,
transiently underflowing recovery_active.
2. Because *skipped is 0, md_do_sync() adds sectors_skipped + nr_sectors
to io_sectors, counting skipped clean bitmap space as completed disk
I/O and inflating currspeed above speed_max(mddev), which stalls
recovery in msleep(500) for up to 30 seconds.
3. Because clean bitmap blocks set chunks_skipped = -1 and cap max_sync at
128 KiB, the internal loop scans clean regions in 128 KiB steps without
cond_resched() or MD_RECOVERY_INTR checks when conf->nr_waiting == 0,
and sleeps 1 jiffy per 128 KiB in schedule_timeout_uninterruptible(1)
whenever conf->nr_waiting > 0.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130193139.1401044-1-ehagberg@janestreet.com?part=1
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH RESEND 0/3] md/raid10: fix old data left by skipped and interrupted sync
2026-11-30 19:31 [REGRESSION] md/raid10: far-layout member left with stale data after bitmap re-add (6.11+, 6.12.y, 6.18.y) Eric Hagberg
2026-11-30 19:48 ` sashiko-bot
@ 2026-12-04 17:46 ` Eric Hagberg
2026-12-04 17:46 ` [PATCH RESEND 1/3] md/raid10: do not skip past the range that sync_request examined Eric Hagberg
` (2 more replies)
1 sibling, 3 replies; 10+ messages in thread
From: Eric Hagberg @ 2026-12-04 17:46 UTC (permalink / raw)
To: Song Liu, Yu Kuai
Cc: Eric Hagberg, Li Nan, Xiao Ni, Jason Chu, linux-raid,
linux-kernel, regressions
Hi,
Resending: my first send of this series reached only Song and Yu, not
the lists and other people on Cc. Nothing else has changed.
This follows up my report earlier in this thread. The three patches are
by Jason Chu; I am sending them on his behalf.
They fix cases in which raid10 with the classic write-intent bitmap
finishes a recovery or a resync while one copy still holds old data. md
reports the array as healthy afterwards. Each case is reproduced on
v7.4-rc5 with the shell script at the end of this mail (mdadm, loop
devices and sysfs; one test also uses dm-linear).
Patch 1: a bitmap based recovery that is not interrupted leaves old data
on the re-added member when the chunk size is below 64KiB. This is a
regression from 7435b73f05fb ("md/raid10: cleanup skip handling in
raid10_sync_request"), which dropped the limit of a skip to the range
that was examined.
Patch 2: a bitmap based recovery that is interrupted ("frozen" written
to sync_action, or the array stopped and reassembled) and then resumed
leaves old data on the re-added member. Reproduced with the far layout
and one returning member, and with the offset layout and two returning
members.
Patch 3: a resync that is interrupted just after it passed a bad block
near the end of a bitmap chunk forgets that the next bitmap chunk is
dirty. The restarted resync does not make the copies in that chunk
equal.
Results:
x86-64 KVM guest with two CPUs, 4KiB pages, mdadm 4.2, loop devices on
tmpfs. Each column is v7.4-rc5 with the patches up to that one applied.
The raid10 module was built from the patched raid10.c; the rest of the
kernel is the same in all columns. A kernel built without CONFIG_SMP
gave the same table.
v7.4-rc5 +1 +1,2 +1,2,3
far-recovery PASS PASS PASS PASS
recovery-small-chunk FAIL PASS PASS PASS
recovery-abort-far FAIL FAIL PASS PASS
recovery-abort-offset FAIL FAIL PASS PASS
resync-abort FAIL FAIL FAIL PASS
FAIL means that md reported the array idle and not degraded, a "check"
then counted mismatches, and the copies read from the member devices
were not the data that was written. The script prints the details. For
the last three tests Jason also ran each test with virtio disks and read
the same sectors from the disk images on the host after the guest had
exited. The host agreed with the guest on every copy.
The same script on bare metal (x86-64, a distribution userspace with
udev, mdadm 4.2), on 7.3.7 without and with the series:
7.3.7 +1,2,3
far-recovery PASS PASS
recovery-small-chunk FAIL PASS
recovery-abort-far FAIL PASS
recovery-abort-offset FAIL PASS
resync-abort FAIL PASS
For the recovery tests the failure counts on 7.3.7 are the same as on
v7.4-rc5.
On bare metal, with a separate script that interrupts recovery either
with "frozen" or with mdadm --stop and reassembly, the abort case that
patch 2 fixes also shows on 7.3.0 and on 6.1.193: in each case a
continued recovery is clean, and an interrupted and resumed one leaves
old copies on the returning member. Stopping and reassembling gives the
same result as "frozen", so an orderly reboot during recovery is enough.
"far-recovery" is the case that 7435b73f05fb fixed. It passes on
v7.4-rc5 and is in the script because it fails on the stable kernels
that have bc49694a9e8f ("md: pass in max_sectors for
pers->sync_request()") but not 7435b73f05fb. We see it on 6.12.117 and
6.18.65.
How this was found:
We run 6.12.y. A far layout array there returned old data after a
member was re-added. That is the "far-recovery" case, which I reported
earlier in this thread. While Jason prepared a backport of 7435b73f05fb
he tested the skip and abort paths of raid10_sync_request() and found
the three cases above. A backport that contains 7435b73f05fb and these
three patches is in testing on 6.12.117 and 6.18.65; we will send it to
stable@ once these patches are in mainline.
What was tested, and what was not:
- Live, v7.4-rc5: the table above. Nothing else was run on mainline.
The test kernels are minimal builds without KASAN, KCSAN or lockdep.
- Live, 6.12.117 with the backport: the same script, and a larger set
of QEMU runs with fault injection, power loss and KASAN, KCSAN and
lockdep kernels.
- The mainline patches are not the same text as the 6.12.y code. They
test for the classic bitmap with mddev->bitmap_id, patch 1 adds the
limit where 6.12.y still had it, and the abort branch is laid out
differently.
- Built for i386 and arm64 (raid10 built in) on 7.3.7 with the series,
and on 6.18.65 with the 6.18.y backport; arm64 also on 6.12.117 with
the 6.12.y backport. vmlinux links and there are no new warnings.
- Not tested: llbitmap, clustered md, dm-raid, reshape, and 64KiB
pages on mainline.
Known limits:
- After an interrupted recovery, a bitmap chunk whose copies were all
finished stays dirty and is copied again. After an interrupted
resync the bitmap is walked twice.
- The clean-bitmap return in the resync path can still move the cursor
past sync_max. No I/O is done past sync_max. Not changed here.
- From reading the code, not reproduced on mainline:
md_bitmap_get_counter() reports the span of a whole counter page for
a hijacked page, although each of its two counters covers half. The
walk added in patch 2 allows for that. The skip decisions in
raid10_sync_request() do not. Not changed here.
- raid1 and raid5 end an aborted sync in the same way (end_sync at
curr_resync, then close_sync). We did not examine or test them.
Questions:
1. Would you prefer the abort handling in md-bitmap.c, for example a
close_sync that takes the abort position and re-arms the chunks
from there on, as llbitmap_end_sync() already does? That could
serve raid1 and raid5 too. The patches keep it in raid10.c because
that is what we have tested.
2. For 6.12.y and 6.18.y: 7435b73f05fb alone makes the two
recovery-abort tests fail there, although they pass on 6.12.117 and
6.18.65 today. From reading the code, the early completion code in
those kernels happens to end the affected bitmap chunk as aborted.
We therefore plan to send one squashed patch for each to stable@.
If you or the stable maintainers prefer one patch for each mainline
commit, we can send that instead.
The analysis, the patches, their changelogs and the test script were
developed with AI coding assistants, then reviewed by Jason and me. The
results above come from the test runs described, not from the tools'
reasoning.
The patches are against md-7.5 (c526b7cd32f7) in the md tree and also
apply to v7.4-rc5.
Thanks,
Eric
The reproducer:
Run as root: sh md-raid10-sync-abort-repro.sh [test...]
It prints one RESULT line for each test and exits 1 if any test failed.
==== 8< ==== md-raid10-sync-abort-repro.sh ==== 8< ====
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
#
# Reproducers for lost write-intent bitmap state in md/raid10.
#
# Run as root:
#
# sh md-raid10-sync-abort-repro.sh [TEST...]
#
# TEST is one or more of:
#
# far-recovery bitmap recovery, far layout
# recovery-small-chunk bitmap recovery, 4 KiB chunks
# recovery-abort-far interrupted bitmap recovery, far layout,
# one returning member
# recovery-abort-offset interrupted bitmap recovery, offset layout,
# two returning members
# resync-abort interrupted resync with one bad block
# (needs dmsetup and dm-linear)
#
# With no argument, all five run. Each test prints one line
#
# RESULT test=<name> kernel=<uname -r> verdict=PASS|FAIL ...
#
# and the script exits 1 if any test failed.
#
# PASS means that every checked copy is current after md reports the
# array as idle and not degraded. FAIL means that md reports a healthy
# array while a member holds old data (recovery tests), or while two
# copies still differ in a region that the bitmap had marked dirty
# (resync test).
#
# Requirements: a kernel with raid10 and loop support, mdadm, losetup,
# blockdev, dd, cmp, tr, head and sha256sum.
#
# The script uses md$MD_NUM (default 127), loop devices on files under
# $WORK (default: a new directory under /tmp), and device-mapper names
# r10repro-*. It removes them on exit. It needs about 150 MiB in $WORK.
#
# Optional: MEMBERS="/dev/x /dev/y /dev/z" uses these three block
# devices (each at least 64 MiB, contents destroyed) instead of loop
# devices.
set -eu
MD_NUM=${MD_NUM:-127}
MD=/dev/md$MD_NUM
md=/sys/block/md$MD_NUM/md
WORK=${WORK:-}
MEMBERS=${MEMBERS:-}
# As in mdadm's own test suite: do not wait for udev, do not start units.
export MDADM_NO_UDEV=${MDADM_NO_UDEV:-1}
export MDADM_NO_SYSTEMCTL=${MDADM_NO_SYSTEMCTL:-1}
own_work=0
made_node=0
loops=""
dms=""
failed=0
die() {
echo "ERROR: $*" >&2
exit 2
}
stop_array() {
if [ -e "$md" ]; then
mdadm --stop "$MD" >/dev/null 2>&1 || true
fi
}
release_members() {
stop_array
for d in $dms; do
dmsetup remove "$d" >/dev/null 2>&1 || true
done
dms=""
for l in $loops; do
losetup -d "$l" >/dev/null 2>&1 || true
done
loops=""
}
cleanup() {
release_members
if [ "$made_node" = 1 ]; then
rm -f "$MD"
fi
if [ "$own_work" = 1 ]; then
rm -rf "$WORK"
fi
}
trap cleanup EXIT
# make_members COUNT SIZE_MIB: set M0..M(COUNT-1) to zero-filled devices.
make_members() {
count=$1
size_mib=$2
i=0
if [ -n "$MEMBERS" ]; then
for dev in $MEMBERS; do
[ "$i" -lt "$count" ] || break
dd if=/dev/zero of="$dev" bs=1M count="$size_mib" \
conv=fsync 2>/dev/null
eval "M$i=$dev"
i=$((i + 1))
done
[ "$i" -eq "$count" ] || die "MEMBERS must name $count devices"
return
fi
while [ "$i" -lt "$count" ]; do
rm -f "$WORK/member$i"
dd if=/dev/zero of="$WORK/member$i" bs=1M count="$size_mib" \
2>/dev/null
l=$(losetup -f)
losetup "$l" "$WORK/member$i"
loops="$loops $l"
eval "M$i=$l"
i=$((i + 1))
done
}
# Put a dm-linear device on top of M$1, so that its I/O can be held with
# "dmsetup suspend".
wrap_dm() {
eval "under=\$M$1"
sectors=$(blockdev --getsz "$under")
name=r10repro-$1
echo "0 $sectors linear $under 0" | dmsetup create "$name"
dms="$dms $name"
eval "M$1=/dev/mapper/$name"
}
md_node() {
if [ -e "$md/array_state" ] &&
[ "$(cat "$md/array_state")" != clear ]; then
die "md$MD_NUM is in use; set MD_NUM"
fi
if [ ! -e "$MD" ]; then
mknod "$MD" b 9 "$MD_NUM"
made_node=1
fi
}
# Print the md sysfs directory of the member in slot $1.
slot_dir() {
for d in "$md"/dev-*; do
if [ "$(cat "$d/slot")" = "$1" ]; then
echo "$d"
return
fi
done
die "no member in slot $1"
}
# wait_for SECONDS COMMAND...: poll until COMMAND succeeds.
wait_for() {
limit=$(($1 * 5))
shift
n=0
until "$@"; do
n=$((n + 1))
if [ "$n" -ge "$limit" ]; then
cat /proc/mdstat >&2
die "timed out waiting for: $*"
fi
sleep 0.2
done
}
is_idle() {
[ "$(cat "$md/sync_action")" = idle ]
}
is_idle_and_complete() {
is_idle && [ "$(cat "$md/degraded")" = 0 ]
}
# paused_at ACTION SECTOR: the sync thread waits at sync_max.
paused_at() {
read -r completed _ < "$md/sync_completed" || return 1
[ "$completed" = "$2" ] && [ "$(cat "$md/sync_action")" = "$1" ]
}
# Run "check" and print the number of sectors md found different.
scrub() {
echo check > "$md/sync_action"
sleep 1
wait_for 300 is_idle
cat "$md/mismatch_cnt"
}
# Make later raw reads of member devices come from the devices, not from
# stale page cache.
drop_member_cache() {
sync
for dev in "$@"; do
blockdev --flushbufs "$dev" 2>/dev/null || true
done
echo 3 > /proc/sys/vm/drop_caches
}
# read_member DEV SECTOR COUNT FILE: 512-byte sectors, absolute on DEV.
read_member() {
dd if="$1" of="$4" bs=512 skip="$2" count="$3" 2>/dev/null
}
# check_copy TEST MEMBER_INDEX SECTOR COUNT WANT_FILE: read one copy from a
# member, print what was found, and succeed if it matches WANT_FILE.
check_copy() {
eval "dev=\$M$2"
read_member "$dev" "$3" "$4" "$WORK/got"
want=$(sha256sum < "$5" | cut -c1-16)
got=$(sha256sum < "$WORK/got" | cut -c1-16)
echo "COPY test=$1 member=$2 dev=$dev sector=$3 count=$4" \
"want=$want got=$got"
[ "$want" = "$got" ]
}
pattern() {
head -c "$2" /dev/zero | tr '\000' "$1"
}
report() {
name=$1
verdict=$2
shift 2
echo "RESULT test=$name kernel=$(uname -r) verdict=$verdict $*"
if [ "$verdict" != PASS ]; then
failed=$((failed + 1))
fi
}
# --------------------------------------------------------------------
# far-recovery
#
# A member leaves a two-member far-2 array, data is written, and the member
# is re-added. Recovery is not interrupted.
# --------------------------------------------------------------------
test_far_recovery() {
make_members 2 64
md_node
mdadm --create "$MD" --run --quiet --assume-clean --metadata=1.2 \
--level=10 --layout=f2 --raid-devices=2 --chunk=64 \
--bitmap=internal --bitmap-chunk=1M "$M0" "$M1"
wait_for 30 is_idle
mdadm "$MD" --quiet --fail "$M1"
wait_for 30 mdadm "$MD" --quiet --remove "$M1"
[ "$(cat "$md/degraded")" = 1 ] || die "array is not degraded"
# 1 MiB of 'N' at 5, 20, 35 and 50 MiB while member 1 is out.
pattern N 1048576 > "$WORK/new"
for mib in 5 20 35 50; do
dd if="$WORK/new" of="$MD" bs=1M seek="$mib" count=1 \
oflag=direct conv=notrunc 2>/dev/null
done
sync
mdadm "$MD" --quiet --re-add "$M1"
wait_for 120 is_idle_and_complete
mismatches=$(scrub)
# Read the array from member 1 alone.
mdadm --stop "$MD" >/dev/null 2>&1
drop_member_cache "$M0" "$M1"
mdadm --assemble --run --readonly --quiet "$MD" "$M1" 2>/dev/null
stale=0
for mib in 5 20 35 50; do
dd if="$MD" of="$WORK/got" bs=1M skip="$mib" count=1 \
2>/dev/null
cmp -s "$WORK/new" "$WORK/got" || stale=$((stale + 1))
done
if [ "$stale" = 0 ] && [ "$mismatches" = 0 ]; then
verdict=PASS
else
verdict=FAIL
fi
report far-recovery "$verdict" \
"stale_regions_on_readded_member=$stale/4" \
"mismatch_cnt=$mismatches"
}
# --------------------------------------------------------------------
# recovery-small-chunk
#
# Three-member near-2 array with 4 KiB chunks and 64 KiB bitmap chunks.
# Member 1 leaves, every second 64 KiB of the first 1 MiB is written, and
# member 1 is re-added. Recovery is not interrupted. A clean range that is
# skipped must not carry the cursor past chunks that were not examined.
# --------------------------------------------------------------------
test_recovery_small_chunk() {
make_members 3 40
md_node
mdadm --create "$MD" --run --quiet --assume-clean --metadata=1.2 \
--level=10 --layout=n2 --raid-devices=3 --chunk=4 \
--bitmap=internal --bitmap-chunk=64K --size=32768 \
"$M0" "$M1" "$M2"
wait_for 30 is_idle
mdadm "$MD" --quiet --fail "$M1"
wait_for 30 mdadm "$MD" --quiet --remove "$M1"
[ "$(cat "$md/degraded")" = 1 ] || die "array is not degraded"
pattern N 65536 > "$WORK/new"
for k in 1 3 5 7 9 11 13 15; do
dd if="$WORK/new" of="$MD" bs=65536 seek="$k" count=1 \
oflag=direct conv=notrunc 2>/dev/null
done
sync
mdadm "$MD" --quiet --re-add "$M1"
wait_for 120 is_idle_and_complete
mismatches=$(scrub)
# Fail member 0, so that every block that has a copy on member 1
# and member 0 is now read from member 1.
mdadm "$MD" --quiet --fail "$M0"
drop_member_cache "$MD"
stale=0
for k in 1 3 5 7 9 11 13 15; do
dd if="$MD" of="$WORK/got" bs=65536 skip="$k" count=1 \
iflag=direct 2>/dev/null
cmp -s "$WORK/new" "$WORK/got" || stale=$((stale + 1))
done
if [ "$stale" = 0 ] && [ "$mismatches" = 0 ]; then
verdict=PASS
else
verdict=FAIL
fi
report recovery-small-chunk "$verdict" \
"stale_regions_read_without_member0=$stale/8" \
"mismatch_cnt=$mismatches"
}
# --------------------------------------------------------------------
# recovery-abort-far
#
# Three-member far-2 array, 64 KiB chunks, 256 KiB bitmap chunks. Member 1
# leaves, two 64 KiB chunks are written, member 1 is re-added. Recovery
# pauses at sync_max = 256 sectors and is stopped there with "frozen", then
# resumed. The two far copies on member 1 are behind the checkpoint in
# bitmap terms but not yet copied.
# --------------------------------------------------------------------
test_recovery_abort_far() {
make_members 3 40
md_node
mdadm --create "$MD" --run --quiet --assume-clean --metadata=1.2 \
--level=10 --layout=f2 --raid-devices=3 --chunk=64 \
--bitmap=internal --bitmap-chunk=256K --size=32768 \
--data-offset=1M "$M0" "$M1" "$M2"
wait_for 30 is_idle
offset=$(cat "$(slot_dir 1)/offset")
# For far-2 the second copy starts this many sectors into each member.
stride=$(cat "$md/component_size")
mdadm "$MD" --quiet --fail "$M1"
wait_for 30 mdadm "$MD" --quiet --remove "$M1"
[ "$(cat "$md/degraded")" = 1 ] || die "array is not degraded"
pattern A 65536 > "$WORK/expect0"
pattern B 65536 > "$WORK/expect3"
dd if="$WORK/expect0" of="$MD" bs=65536 seek=0 count=1 \
oflag=direct conv=notrunc 2>/dev/null
dd if="$WORK/expect3" of="$MD" bs=65536 seek=3 count=1 \
oflag=direct conv=notrunc 2>/dev/null
sync
echo 256 > "$md/sync_max"
mdadm "$MD" --quiet --re-add "$M1"
wait_for 60 paused_at recover 256
echo frozen > "$md/sync_action"
echo max > "$md/sync_max"
echo recover > "$md/sync_action"
wait_for 120 is_idle_and_complete
mismatches=$(scrub)
mdadm --stop "$MD" >/dev/null 2>&1
drop_member_cache "$M0" "$M1" "$M2"
stale=0
for i in 0 3; do
sector=$((offset + stride + (i / 3) * 128))
check_copy recovery-abort-far 1 "$sector" 128 \
"$WORK/expect$i" || stale=$((stale + 1))
done
if [ "$stale" = 0 ] && [ "$mismatches" = 0 ]; then
verdict=PASS
else
verdict=FAIL
fi
report recovery-abort-far "$verdict" \
"stale_copies_on_readded_member=$stale/2" \
"mismatch_cnt=$mismatches"
}
# --------------------------------------------------------------------
# recovery-abort-offset
#
# Three-member offset-3 array, 64 KiB chunks, 32 KiB bitmap chunks. Members
# 0 and 1 leave, two 32 KiB blocks are written, both members are re-added.
# Recovery is stopped at sync_max = 256 sectors and resumed. A bitmap chunk
# started for one returning member still has a copy outstanding on the
# other.
# --------------------------------------------------------------------
test_recovery_abort_offset() {
make_members 3 40
md_node
mdadm --create "$MD" --run --quiet --assume-clean --metadata=1.2 \
--level=10 --layout=o3 --raid-devices=3 --chunk=64 \
--bitmap=internal --bitmap-chunk=32K --size=32768 \
--data-offset=1M "$M0" "$M1" "$M2"
wait_for 30 is_idle
offset=$(cat "$(slot_dir 1)/offset")
echo frozen > "$md/sync_action"
mdadm "$MD" --quiet --fail "$M0"
wait_for 30 mdadm "$MD" --quiet --remove "$M0"
mdadm "$MD" --quiet --fail "$M1"
wait_for 30 mdadm "$MD" --quiet --remove "$M1"
[ "$(cat "$md/degraded")" = 2 ] || die "array is not doubly degraded"
pattern A 32768 > "$WORK/expect0"
pattern B 32768 > "$WORK/expect3"
dd if="$WORK/expect0" of="$MD" bs=32768 seek=0 count=1 \
oflag=direct conv=notrunc 2>/dev/null
dd if="$WORK/expect3" of="$MD" bs=32768 seek=3 count=1 \
oflag=direct conv=notrunc 2>/dev/null
sync
echo 256 > "$md/sync_max"
mdadm "$MD" --quiet --re-add "$M0"
mdadm "$MD" --quiet --re-add "$M1"
echo recover > "$md/sync_action"
wait_for 60 paused_at recover 256
echo frozen > "$md/sync_action"
echo max > "$md/sync_max"
echo recover > "$md/sync_action"
wait_for 120 is_idle_and_complete
mismatches=$(scrub)
mdadm --stop "$MD" >/dev/null 2>&1
drop_member_cache "$M0" "$M1" "$M2"
stale=0
for v in 0 3; do
for i in 0 1 2; do
# Member sector of the copy of block $v on member $i.
if [ "$v" = 0 ]; then
p=$((128 * i))
else
p=$((64 + 128 * ((i + 2) % 3)))
fi
check_copy recovery-abort-offset "$i" $((offset + p)) \
64 "$WORK/expect$v" || stale=$((stale + 1))
done
done
if [ "$stale" = 0 ] && [ "$mismatches" = 0 ]; then
verdict=PASS
else
verdict=FAIL
fi
report recovery-abort-offset "$verdict" \
"stale_copies=$stale/6" "mismatch_cnt=$mismatches"
}
# --------------------------------------------------------------------
# resync-abort
#
# Two-member near-2 array, 4 KiB chunks, 1 MiB bitmap chunks (2048 sectors).
# Bitmap chunks 0 and 1 are dirty, as after an unclean shutdown. The two
# copies of sector 3048 (in bitmap chunk 1) differ. Member 0 has one bad
# block at sector 2043, five sectors before the end of bitmap chunk 0.
#
# The resync pauses at sync_max = 2040. It is then allowed to run to 2048
# while member 1 is suspended, so that it stops with its cursor at 2044:
#
# [2040, 2043) read submitted, held by the suspended member
# [2043, 2044) bad block on member 0, only one copy readable,
# skipped. This call asks the bitmap about the page
# that starts at 2043. The page crosses into bitmap
# chunk 1, which is marked in progress.
# 2044 md waits for the held read before it goes on
#
# "frozen" interrupts the resync there. The interrupted resync is then
# restarted and runs to the end.
# --------------------------------------------------------------------
test_resync_abort() {
command -v dmsetup >/dev/null 2>&1 || {
echo "SKIP test=resync-abort (no dmsetup)"
return
}
make_members 2 16
wrap_dm 0
wrap_dm 1
md_node
mdadm --create "$MD" --run --quiet --assume-clean --metadata=1.2 \
--level=10 --layout=n2 --raid-devices=2 --chunk=4 \
--bitmap=internal --bitmap-chunk=1M --size=4096 \
"$M0" "$M1"
wait_for 30 is_idle
offset=$(cat "$(slot_dir 0)/offset")
[ "$offset" = "$(cat "$(slot_dir 1)/offset")" ] ||
die "members have different data offsets"
[ "$(cat "$md/bitmap/chunksize")" = 1048576 ] ||
die "unexpected bitmap chunk size"
# Same data on both copies, then make sector 3048 differ on member 1,
# as a write interrupted by a crash would.
pattern A 4194304 > "$WORK/fill"
dd if="$WORK/fill" of="$MD" bs=1M count=4 oflag=direct 2>/dev/null
sync
mdadm --stop "$MD" >/dev/null 2>&1
pattern B 512 > "$WORK/torn"
dd if="$WORK/torn" of="$M1" bs=512 seek=$((offset + 3048)) count=1 \
conv=notrunc,fsync 2>/dev/null
drop_member_cache "$M0" "$M1"
# On a host with udev, the write above can make udev assemble the
# array again on its own. Wait for it and stop that array, so that
# the assembly below is the only one.
if command -v udevadm >/dev/null 2>&1; then
udevadm settle || true
fi
stop_array
mdadm --assemble --run --quiet "$MD" "$M0" "$M1"
wait_for 30 is_idle
echo frozen > "$md/sync_action"
echo "$((offset + 2043)) 1" > "$(slot_dir 0)/bad_blocks"
echo "0 1" > "$md/bitmap_set_bits"
echo 2040 > "$md/sync_max"
echo resync > "$md/sync_action"
wait_for 60 paused_at resync 2040
dmsetup suspend r10repro-1
echo 2048 > "$md/sync_max"
sleep 1
echo frozen > "$md/sync_action" &
sleep 1
dmsetup resume r10repro-1
wait
[ "$(cat "$md/sync_action")" = frozen ] || die "resync was not stopped"
# Where md recorded the interrupted resync as having got to.
stopped_at=$(cat "$md/resync_start")
echo max > "$md/sync_max"
echo resync > "$md/sync_action"
sleep 1
wait_for 120 is_idle
mismatches=$(scrub)
mdadm --stop "$MD" >/dev/null 2>&1
drop_member_cache "$M0" "$M1"
# The resync copies member 0 over member 1, so both must hold 'A'.
head -c 512 "$WORK/fill" > "$WORK/expect"
copies=equal
check_copy resync-abort 0 $((offset + 3048)) 1 "$WORK/expect" ||
copies=differ
check_copy resync-abort 1 $((offset + 3048)) 1 "$WORK/expect" ||
copies=differ
if [ "$copies" = equal ] && [ "$mismatches" = 0 ]; then
verdict=PASS
else
verdict=FAIL
fi
report resync-abort "$verdict" "stopped_at=$stopped_at" \
"copies_of_sector_3048=$copies" "mismatch_cnt=$mismatches"
}
run_test() {
case "$1" in
far-recovery) test_far_recovery ;;
recovery-small-chunk) test_recovery_small_chunk ;;
recovery-abort-far) test_recovery_abort_far ;;
recovery-abort-offset) test_recovery_abort_offset ;;
resync-abort) test_resync_abort ;;
*) die "unknown test $1" ;;
esac
release_members
}
[ "$(id -u)" = 0 ] || die "run as root"
if [ -z "$WORK" ]; then
WORK=$(mktemp -d /tmp/r10repro.XXXXXX)
own_work=1
fi
mkdir -p "$WORK"
echo "kernel: $(uname -r)"
echo "mdadm: $(mdadm --version 2>&1)"
[ $# -gt 0 ] ||
set -- far-recovery recovery-small-chunk recovery-abort-far \
recovery-abort-offset resync-abort
for t in "$@"; do
echo "--- $t"
run_test "$t"
done
if [ "$failed" = 0 ]; then
echo "All tests passed."
else
echo "$failed test(s) failed."
exit 1
fi
==== 8< ==== end of script ==== 8< ====
Jason Chu (3):
md/raid10: do not skip past the range that sync_request examined
md/raid10: re-arm in-progress bitmap chunks when recovery is
interrupted
md/raid10: keep look-ahead bitmap chunks when resync is interrupted
drivers/md/raid10.c | 89 +++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 85 insertions(+), 4 deletions(-)
--
2.43.7
^ permalink raw reply [flat|nested] 10+ messages in thread