btrfs-progs/tests/misc-tests/006-image-on-missing-device/test.sh
David Sterba 1faaa874a1 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>
2023-11-03 18:04:37 +01:00

51 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
# test btrfs-image with a missing device (uses loop devices)
#
# - btrfs-image must not loop indefinitely
# - btrfs-image will expectedly fail to produce the dump
source "$TEST_TOP/common" || exit
check_prereq btrfs-image
check_prereq mkfs.btrfs
check_prereq btrfs
setup_root_helper
test_image_dump()
{
run_check $SUDO_HELPER "$TOP/btrfs" check "$dev1"
# the output file will be deleted
run_mayfail $SUDO_HELPER "$TOP/btrfs-image" "$dev1" /tmp/test-img.dump
}
test_run()
{
run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -d raid1 -m raid1 "$dev1" "$dev2"
# we need extents to trigger reading from all devices
cond_wait_for_loopdevs
run_check $SUDO_HELPER mount "$dev1" "$TEST_MNT"
run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/a" bs=1M count=10
run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/b" bs=4k count=1000 conv=sync
run_check $SUDO_HELPER umount "$TEST_MNT"
test_image_dump
run_check $SUDO_HELPER "$TOP/btrfs" filesystem show "$dev1"
# create a degraded raid1 filesystem, check must succeed
# btrfs-image must not loop
run_mayfail wipefs -a "$dev2"
run_check $SUDO_HELPER losetup -d "$dev2"
unset loopdevs[2]
run_check $SUDO_HELPER "$TOP/btrfs" filesystem show "$dev1"
test_image_dump
}
setup_loopdevs 2
prepare_loopdevs
dev1=${loopdevs[1]}
dev2=${loopdevs[2]}
test_run
cleanup_loopdevs