btrfs-progs/tests/misc-tests/035-receive-common-mount-point-prefix/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

53 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
# Test that receive determines the correct mount point path when there is
# another mount point that matches the destination's path as a prefix.
source "$TEST_TOP/common" || exit
# fix reverted in v4.20.2 due to reported breakage, the bug fixed by
# "Btrfs-progs: fix mount point detection due to partial prefix match" is still
# present
_not_run "fix not available"
check_prereq btrfs
check_prereq mkfs.btrfs
setup_root_helper
_mktemp_local dev1 1G
_mktemp_local dev2 1G
loop1=$(run_check_stdout $SUDO_HELPER losetup --find --show dev1)
loop2=$(run_check_stdout $SUDO_HELPER losetup --find --show dev2)
run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$loop1"
run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$loop2"
cond_wait_for_loopdevs
run_check $SUDO_HELPER mount "$loop1" "$TEST_MNT"
run_check $SUDO_HELPER mkdir "$TEST_MNT/ddis"
run_check $SUDO_HELPER mkdir "$TEST_MNT/ddis-not-a-mount"
cond_wait_for_loopdevs
run_check $SUDO_HELPER mount "$loop2" "$TEST_MNT/ddis"
echo "some data" | $SUDO_HELPER tee "$TEST_MNT/ddis/file" > /dev/null
run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r \
"$TEST_MNT/ddis" "$TEST_MNT/ddis/snap"
_mktemp_local send.data
run_check $SUDO_HELPER "$TOP/btrfs" send -f send.data "$TEST_MNT/ddis/snap"
# The following receive used to fail because it incorrectly determined the mount
# point of the destination path to be $TEST_MNT/ddis and not $TEST_MNT.
run_check $SUDO_HELPER "$TOP/btrfs" receive -f send.data \
"$TEST_MNT/ddis-not-a-mount"
run_check $SUDO_HELPER umount "$TEST_MNT/ddis"
run_check $SUDO_HELPER umount "$TEST_MNT"
# Cleanup loop devices and send data.
run_check $SUDO_HELPER losetup -d "$loop1"
run_check $SUDO_HELPER losetup -d "$loop2"
rm -f dev1 dev2 send.data