summaryrefslogtreecommitdiff
path: root/tests/misc-tests
diff options
context:
space:
mode:
authorQu Wenruo <wqu@suse.com>2018-03-30 15:35:28 +0800
committerDavid Sterba <dsterba@suse.com>2018-03-30 22:15:55 +0200
commita4cd4ae0b38a79fdc61aebf81267d5e10bb39d8f (patch)
tree649064350c9ed35b59f41ba1b7bf9447b85e7e54 /tests/misc-tests
parent6af3cc08ddb5c0165d357ffa36422c2716ebd2a0 (diff)
btrfs-progs: tests: Test if btrfs-image can handle RAID1 missing device
Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'tests/misc-tests')
-rwxr-xr-xtests/misc-tests/030-missing-device-image/test.sh58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/misc-tests/030-missing-device-image/test.sh b/tests/misc-tests/030-missing-device-image/test.sh
new file mode 100755
index 00000000..a04efe8f
--- /dev/null
+++ b/tests/misc-tests/030-missing-device-image/test.sh
@@ -0,0 +1,58 @@
+#!/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
+# without any problem
+
+source "$TEST_TOP/common"
+
+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
+
+ bad_num=$1
+ 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
+ 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"
+
+ # make sure we have space cache
+ if ! run_check_stdout "$TOP/btrfs" inspect dump-tree -t root "$dev1" |
+ grep -q "EXTENT_DATA"; then
+ # Normally the above operation should create the space cache.
+ # If not, it may mean we have migrated to v2 cache by default
+ _not_run "unable to create v1 space cache"
+ fi
+
+ # 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