2015-08-25 16:38:36 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# test btrfs-image with a missing device (uses loop devices)
|
|
|
|
#
|
2018-11-26 16:53:43 +00:00
|
|
|
# - btrfs-image must not loop indefinitely
|
2015-08-25 16:38:36 +00:00
|
|
|
# - btrfs-image will expectedly fail to produce the dump
|
|
|
|
|
2023-04-19 15:08:41 +00:00
|
|
|
source "$TEST_TOP/common" || exit
|
2015-08-25 16:38:36 +00:00
|
|
|
|
|
|
|
check_prereq btrfs-image
|
|
|
|
check_prereq mkfs.btrfs
|
|
|
|
check_prereq btrfs
|
|
|
|
|
|
|
|
setup_root_helper
|
|
|
|
|
|
|
|
test_image_dump()
|
|
|
|
{
|
2018-03-23 15:34:30 +00:00
|
|
|
run_check $SUDO_HELPER "$TOP/btrfs" check "$dev1"
|
2015-08-25 16:38:36 +00:00
|
|
|
# the output file will be deleted
|
2018-03-23 15:34:30 +00:00
|
|
|
run_mayfail $SUDO_HELPER "$TOP/btrfs-image" "$dev1" /tmp/test-img.dump
|
2015-08-25 16:38:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test_run()
|
|
|
|
{
|
2018-03-23 15:34:30 +00:00
|
|
|
run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -d raid1 -m raid1 "$dev1" "$dev2"
|
2015-08-25 16:38:36 +00:00
|
|
|
|
|
|
|
# we need extents to trigger reading from all devices
|
2023-11-01 15:51:55 +00:00
|
|
|
cond_wait_for_loopdevs
|
2018-03-23 15:34:30 +00:00
|
|
|
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"
|
2015-08-25 16:38:36 +00:00
|
|
|
|
|
|
|
test_image_dump
|
2018-03-23 15:34:30 +00:00
|
|
|
run_check $SUDO_HELPER "$TOP/btrfs" filesystem show "$dev1"
|
2015-08-25 16:38:36 +00:00
|
|
|
# create a degraded raid1 filesystem, check must succeed
|
|
|
|
# btrfs-image must not loop
|
2018-03-23 15:34:30 +00:00
|
|
|
run_mayfail wipefs -a "$dev2"
|
|
|
|
run_check $SUDO_HELPER losetup -d "$dev2"
|
2017-09-01 18:14:55 +00:00
|
|
|
unset loopdevs[2]
|
2018-03-23 15:34:30 +00:00
|
|
|
run_check $SUDO_HELPER "$TOP/btrfs" filesystem show "$dev1"
|
2015-08-25 16:38:36 +00:00
|
|
|
|
|
|
|
test_image_dump
|
|
|
|
}
|
|
|
|
|
2017-09-01 18:14:55 +00:00
|
|
|
setup_loopdevs 2
|
|
|
|
prepare_loopdevs
|
|
|
|
dev1=${loopdevs[1]}
|
|
|
|
dev2=${loopdevs[2]}
|
2015-08-25 16:38:36 +00:00
|
|
|
test_run
|
2017-09-01 18:14:55 +00:00
|
|
|
cleanup_loopdevs
|