path: root/tests/misc-tests
diff options
authorFilipe Manana <>2017-05-17 02:41:31 +0100
committerDavid Sterba <>2017-06-26 17:07:54 +0200
commitc1c987503412a8e98e40da2548c6b78888535641 (patch)
tree726c561890f450849ee162fc5dbb93bd8a2856db /tests/misc-tests
parent3a05074c167ceea8c49a902b383c307c0c61eec2 (diff)
btrfs-progs: test for restoring multiple devices fs into a single device
Test that we are able to create an image from a multiple devices fs, that we are able to restore that image into a single device and finally that we are able to mount it. Signed-off-by: Filipe Manana <> Reviewed-by: Liu Bo <> [ added shell quotation and chmod a+w so testsuite on NFS works ] Signed-off-by: David Sterba <>
Diffstat (limited to 'tests/misc-tests')
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/misc-tests/021-image-multi-devices/ b/tests/misc-tests/021-image-multi-devices/
new file mode 100755
index 00000000..abf67f90
--- /dev/null
+++ b/tests/misc-tests/021-image-multi-devices/
@@ -0,0 +1,50 @@
+# Test btrfs-image with multiple devices filesystem and verify that restoring
+# the created image works against a single device.
+source "$TOP/tests/common"
+check_prereq btrfs-image
+check_prereq mkfs.btrfs
+check_prereq btrfs
+rm -f dev1 dev2
+run_check truncate -s 2G dev1
+run_check truncate -s 2G dev2
+chmod a+w dev1 dev2
+loop1=$(run_check_stdout $SUDO_HELPER losetup --find --show dev1)
+loop2=$(run_check_stdout $SUDO_HELPER losetup --find --show dev2)
+# Create the test file system.
+run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f $loop1 $loop2
+run_check $SUDO_HELPER mount $loop1 "$TEST_MNT"
+run_check $SUDO_HELPER dd bs=1M count=1 if=/dev/zero "of=$TEST_MNT/foobar"
+orig_md5=$(run_check_stdout md5sum "$TEST_MNT/foobar" | cut -d ' ' -f 1)
+run_check $SUDO_HELPER umount "$TEST_MNT"
+# Create the image to restore later.
+run_check $SUDO_HELPER "$TOP/btrfs-image" $loop1 "$IMAGE"
+# Wipe out the filesystem from the devices, restore the image on a single
+# device, check everything works and file foobar is there and with 1Mb of
+# zeroes.
+run_check $SUDO_HELPER wipefs -a $loop1
+run_check $SUDO_HELPER wipefs -a $loop2
+run_check $SUDO_HELPER $TOP/btrfs-image -r "$IMAGE" $loop1
+run_check $SUDO_HELPER mount $loop1 "$TEST_MNT"
+new_md5=$(run_check_stdout md5sum "$TEST_MNT/foobar" | cut -d ' ' -f 1)
+run_check $SUDO_HELPER umount "$TEST_MNT"
+# Cleanup loop devices.
+run_check $SUDO_HELPER losetup -d $loop1
+run_check $SUDO_HELPER losetup -d $loop2
+rm -f dev1 dev2
+# Compare the file digests.
+[ $orig_md5 == $new_md5 ] || _fail "File digests do not match"