2018-03-30 07:35:28 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# Test that btrfs-image can dump image correctly for a missing device (RAID1)
|
|
|
|
#
|
|
|
|
# At least for RAID1, btrfs-image should be able to handle one missing device
|
2023-08-08 06:08:42 +00:00
|
|
|
# without any problem. Only space cache v2 supported.
|
2018-03-30 07:35:28 +00:00
|
|
|
|
2023-04-19 15:08:41 +00:00
|
|
|
source "$TEST_TOP/common" || exit
|
2018-03-30 07:35:28 +00:00
|
|
|
|
|
|
|
check_prereq btrfs-image
|
|
|
|
check_prereq mkfs.btrfs
|
|
|
|
check_prereq btrfs
|
|
|
|
|
|
|
|
setup_root_helper
|
|
|
|
setup_loopdevs 2
|
|
|
|
prepare_loopdevs
|
|
|
|
dev1=${loopdevs[1]}
|
|
|
|
dev2=${loopdevs[2]}
|
|
|
|
|
|
|
|
# $1: device number to remove (either 1 or 2)
|
|
|
|
test_missing()
|
|
|
|
{
|
|
|
|
local bad_num
|
|
|
|
local bad_dev
|
|
|
|
local good_num
|
|
|
|
local good_dev
|
|
|
|
|
2024-06-12 23:39:06 +00:00
|
|
|
bad_num="$1"
|
2018-03-30 07:35:28 +00:00
|
|
|
bad_dev=${loopdevs[$bad_num]}
|
|
|
|
good_num=$((3 - $bad_num))
|
|
|
|
good_dev=${loopdevs[$good_num]}
|
|
|
|
|
|
|
|
run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -d raid1 -m raid1 "$dev1" "$dev2"
|
|
|
|
|
|
|
|
# fill the fs with some data, we could create space cache
|
2023-11-01 15:51:55 +00:00
|
|
|
cond_wait_for_loopdevs
|
2018-03-30 07:35:28 +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"
|
|
|
|
|
|
|
|
# now wipe the device
|
|
|
|
run_check wipefs -fa "$bad_dev"
|
|
|
|
|
|
|
|
# we don't care about the image but btrfs-image must not fail
|
|
|
|
run_check "$TOP/btrfs-image" "$good_dev" /dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
# Test with either device missing, so we're ensured to hit missing device
|
|
|
|
test_missing 1
|
|
|
|
test_missing 2
|
|
|
|
cleanup_loopdevs
|