Skip to content

Commit 1faaa87

Browse files
committed
btrfs-progs: ci: wait for loop devices before mount
Since a few days the CI started to fail randomly when there were loop devices used in the tests. The mount fails because some device is reported to be missing: $ losetup --show --find /dev/loop3 ... $ mkfs ... ERROR: device scan failed on '/dev/loop3': No such file or directory ... $ mount mount: /home/runner/work/btrfs-progs/btrfs-progs/tests/mnt: wrong fs type, bad option, bad superblock on /dev/loop3, missing codepage or helper program, or other error. $ dmesg ... BTRFS error (device loop0): devid 3 uuid 11d9c345-9527-433e-a024-7102659fa0ee is missing BTRFS error (device loop0): failed to read the system array: -2 BTRFS error (device loop0): open_ctree failed This was reproducible in the "cli" tests, but also happened on a local machine. To fix that wait for all loop devices before mount, the command 'btrfs device ready' should block until that. The convenience helper does that, for any standalone 'mount' used with loop devices this must be done manually. Signed-off-by: David Sterba <dsterba@suse.com>
1 parent eed5428 commit 1faaa87

File tree

10 files changed

+32
-0
lines changed

10 files changed

+32
-0
lines changed

tests/cli-tests/017-fi-show-missing/test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -d raid1 "${loopdevs[@]}"
2020
# Move the device, changing its path, simulating the device being missing
2121
run_check $SUDO_HELPER mv "$dev2" /dev/loop-non-existent
2222

23+
cond_wait_for_loopdevs
2324
run_check $SUDO_HELPER mount -o degraded $dev1 $TEST_MNT
2425

2526
if ! run_check_stdout $SUDO_HELPER "$TOP/btrfs" filesystem show "$TEST_MNT" | \

tests/common

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,9 @@ run_check_mount_test_dev()
648648
_fail "Invalid \$TEST_MNT: $TEST_MNT"
649649
}
650650

651+
# Wait for loopdevs before mount as this could fail in the CI for some reason
652+
cond_wait_for_loopdevs
653+
651654
run_check $SUDO_HELPER mount -t btrfs $loop_opt "$@" "$TEST_DEV" "$TEST_MNT"
652655
}
653656

@@ -834,6 +837,7 @@ prepare_loopdevs()
834837
chmod a+rw "$loopdev_prefix$i"
835838
truncate -s0 "$loopdev_prefix$i"
836839
truncate -s2g "$loopdev_prefix$i"
840+
run_check sync "$loopdev_prefix$i"
837841
loopdevs[$i]=`run_check_stdout $SUDO_HELPER losetup --find --show "$loopdev_prefix$i"`
838842
done
839843
}
@@ -851,6 +855,22 @@ cleanup_loopdevs()
851855
run_check $SUDO_HELPER losetup --all
852856
}
853857

858+
# Loop devices may not be ready for mount after mkfs (observed in the CI), wait
859+
# for them explicitly. Errors are reported but tolerated, the mount could succeed
860+
# eventually or the whole test will fail anyway.
861+
wait_for_loopdevs()
862+
{
863+
for dev in ${loopdevs[@]}; do
864+
run_mayfail $SUDO_HELPER "$TOP/btrfs" device ready "$dev"
865+
done
866+
}
867+
868+
cond_wait_for_loopdevs() {
869+
if [ -n "${loopdevs[1]}" ]; then
870+
wait_for_loopdevs
871+
fi
872+
}
873+
854874
init_env()
855875
{
856876
TEST_MNT="${TEST_MNT:-$TEST_TOP/mnt}"

tests/fsck-tests/052-init-csum-tree/test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ run_check $SUDO_HELPER dd if=/dev/urandom of="$TEST_MNT/nodatasum_file" \
2121
bs=16k count=1 status=noxfer > /dev/null 2>&1
2222

2323
# Revert to default datasum
24+
cond_wait_for_loopdevs
2425
run_check $SUDO_HELPER mount -o remount,datasum "$TEST_MNT"
2526

2627
# Then create an inode with datasum, but all preallocated extents

tests/misc-tests/006-image-on-missing-device/test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ test_run()
2424
run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -d raid1 -m raid1 "$dev1" "$dev2"
2525

2626
# we need extents to trigger reading from all devices
27+
cond_wait_for_loopdevs
2728
run_check $SUDO_HELPER mount "$dev1" "$TEST_MNT"
2829
run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/a" bs=1M count=10
2930
run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/b" bs=4k count=1000 conv=sync

tests/misc-tests/021-image-multi-devices/test.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ loop3=${loopdevs[3]}
1919
# Create the test file system.
2020

2121
run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$loop1" "$loop2"
22+
cond_wait_for_loopdevs
2223
run_check $SUDO_HELPER mount "$loop1" "$TEST_MNT"
2324
run_check $SUDO_HELPER dd bs=1M count=1 if=/dev/zero of="$TEST_MNT/foobar"
2425
orig_md5=$(run_check_stdout stat "$TEST_MNT/foobar" | md5sum | cut -d ' ' -f 1)
@@ -38,6 +39,7 @@ run_check $SUDO_HELPER "$TOP/btrfs-image" -r "$IMAGE" "$loop3"
3839
# Run check to make sure there is nothing wrong for the recovered image
3940
run_check $SUDO_HELPER "$TOP/btrfs" check "$loop3"
4041

42+
cond_wait_for_loopdevs
4143
run_check $SUDO_HELPER mount "$loop3" "$TEST_MNT"
4244
new_md5=$(run_check_stdout stat "$TEST_MNT/foobar" | md5sum | cut -d ' ' -f 1)
4345
run_check $SUDO_HELPER umount "$TEST_MNT"

tests/misc-tests/030-missing-device-image/test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ test_missing()
3232
run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -d raid1 -m raid1 "$dev1" "$dev2"
3333

3434
# fill the fs with some data, we could create space cache
35+
cond_wait_for_loopdevs
3536
run_check $SUDO_HELPER mount "$dev1" "$TEST_MNT"
3637
run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/a" bs=1M count=10
3738
run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/b" bs=4k count=1000 conv=sync

tests/misc-tests/035-receive-common-mount-point-prefix/test.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ loop2=$(run_check_stdout $SUDO_HELPER losetup --find --show dev2)
2323
run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$loop1"
2424
run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$loop2"
2525

26+
cond_wait_for_loopdevs
2627
run_check $SUDO_HELPER mount "$loop1" "$TEST_MNT"
2728
run_check $SUDO_HELPER mkdir "$TEST_MNT/ddis"
2829
run_check $SUDO_HELPER mkdir "$TEST_MNT/ddis-not-a-mount"
30+
cond_wait_for_loopdevs
2931
run_check $SUDO_HELPER mount "$loop2" "$TEST_MNT/ddis"
3032

3133
echo "some data" | $SUDO_HELPER tee "$TEST_MNT/ddis/file" > /dev/null

tests/misc-tests/046-seed-multi-mount/test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ nextdevice() {
4747
run_check $SUDO_HELPER "$TOP/btrfs" device add ${loopdevs[$nextdev]} "$TEST_MNT"
4848
# Although seed sprout would make the fs RW, explicitly remount it RW
4949
# just in case of future behavior change.
50+
cond_wait_for_loopdevs
5051
run_check $SUDO_HELPER mount -o remount,rw "$TEST_MNT"
5152
# Rewrite the file
5253
md5sum=$(run_check_stdout md5sum "$TEST_MNT/file$nextdev" | awk '{print $1}')

tests/mkfs-tests/001-basic-profiles/test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ test_get_info()
2424
# device RAID0 as the same.
2525
# Thus kernel may create new SINGLE chunks, causing extra warning
2626
# when testing single device RAID0.
27+
cond_wait_for_loopdevs
2728
run_check $SUDO_HELPER mount -o ro "$dev1" "$TEST_MNT"
2829
run_check_stdout "$TOP/btrfs" filesystem df "$TEST_MNT" > "$tmp_out"
2930
if grep -q "Multiple block group profiles detected" "$tmp_out"; then

tests/mkfs-tests/027-rootdir-inode/test.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ check_global_prereq getfattr
2525
# doesn't support xattr.
2626
# Instead we go $TEST_TOP/btrfs-progs-mkfs-tests-027.XXXXXX/ instead.
2727
run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$tmp_dev"
28+
cond_wait_for_loopdevs
2829
run_check $SUDO_HELPER mount -t btrfs "$tmp_dev" "$TEST_MNT"
2930

3031
run_check $SUDO_HELPER mkdir "$TEST_MNT/source_dir/"
@@ -39,6 +40,7 @@ run_check $SUDO_HELPER setfattr -n user.foobar "$TEST_MNT/source_dir/foobar"
3940
run_check $SUDO_HELPER "$TOP/mkfs.btrfs" --rootdir "$TEST_MNT/source_dir" -f "$real_dev"
4041
run_check $SUDO_HELPER umount "$TEST_MNT"
4142

43+
cond_wait_for_loopdevs
4244
run_check $SUDO_HELPER mount -t btrfs "$real_dev" "$TEST_MNT"
4345

4446
new_mode=$(run_check_stdout $SUDO_HELPER stat "$TEST_MNT/" | grep "Uid:")

0 commit comments

Comments
 (0)