summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDimitri John Ledkov <xnox@ubuntu.com>2019-01-26 00:37:47 +0000
committerDimitri John Ledkov <xnox@ubuntu.com>2019-01-26 00:37:47 +0000
commit2fd02b1f5f50d499b8f19d0cc5e9bc9ed7e686cd (patch)
tree7557002a8de5892b17c04d1afcd8fdc99a0af4e7 /tests
parent03b9f8baf40383f4c2d709c656ca35bd75362dff (diff)
New upstream release
Diffstat (limited to 'tests')
-rwxr-xr-xtests/cli-tests/009-btrfstune/test.sh62
-rwxr-xr-xtests/fsck-tests/015-tree-reloc-tree/test.sh16
-rwxr-xr-xtests/fsck-tests/020-extent-ref-cases/test.sh5
-rw-r--r--tests/fsck-tests/020-extent-ref-cases/tree_reloc_for_data_reloc.img.xz (renamed from tests/fsck-tests/015-tree-reloc-tree/tree_reloc_for_data_reloc.img.xz)bin2112 -> 2112 bytes
-rw-r--r--tests/fsck-tests/020-extent-ref-cases/tree_reloc_for_fs_tree.img.xz (renamed from tests/fsck-tests/015-tree-reloc-tree/tree_reloc_for_fs_tree.img.xz)bin2424 -> 2424 bytes
-rw-r--r--tests/fsck-tests/026-bad-dir-item-name/description.txt41
-rwxr-xr-xtests/fsck-tests/026-bad-dir-item-name/test.sh13
-rw-r--r--tests/fsck-tests/036-bad-dev-extents/over_dev_boundary.img.xzbin0 -> 1640 bytes
-rwxr-xr-xtests/fsck-tests/036-bad-dev-extents/test.sh20
-rwxr-xr-xtests/fsck-tests/037-freespacetree-repair/test.sh7
-rwxr-xr-xtests/misc-tests/021-image-multi-devices/test.sh3
-rw-r--r--tests/misc-tests/034-metadata-uuid/disk1.raw.xzbin0 -> 78336 bytes
-rw-r--r--tests/misc-tests/034-metadata-uuid/disk2.raw.xzbin0 -> 77664 bytes
-rw-r--r--tests/misc-tests/034-metadata-uuid/disk3.raw.xzbin0 -> 78328 bytes
-rw-r--r--tests/misc-tests/034-metadata-uuid/disk4.raw.xzbin0 -> 77592 bytes
-rw-r--r--tests/misc-tests/034-metadata-uuid/disk5.raw.xzbin0 -> 78348 bytes
-rw-r--r--tests/misc-tests/034-metadata-uuid/disk6.raw.xzbin0 -> 77552 bytes
-rwxr-xr-xtests/misc-tests/034-metadata-uuid/test.sh225
-rwxr-xr-xtests/misc-tests/035-receive-common-mount-point-prefix/test.sh48
19 files changed, 409 insertions, 31 deletions
diff --git a/tests/cli-tests/009-btrfstune/test.sh b/tests/cli-tests/009-btrfstune/test.sh
new file mode 100755
index 0000000..c739946
--- /dev/null
+++ b/tests/cli-tests/009-btrfstune/test.sh
@@ -0,0 +1,62 @@
+#!/bin/bash
+# test all command line options of btrfstune
+
+source "$TEST_TOP/common"
+
+check_prereq btrfstune
+
+setup_root_helper
+prepare_test_dev
+
+test_do_mkfs() {
+ run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$@" "$TEST_DEV"
+}
+
+run_mayfail "$TOP/btrfstune" || true
+run_check "$TOP/btrfstune" --help
+
+run_mustfail "must not work on non-existent device" \
+ "$TOP/btrfstune" -r file-does-not-exist
+
+test_do_mkfs -O ^extref
+run_check "$TOP/btrfstune" -r "$TEST_DEV"
+
+test_do_mkfs -O ^skinny-metadata
+run_check "$TOP/btrfstune" -x "$TEST_DEV"
+
+test_do_mkfs -O ^no-holes
+run_check "$TOP/btrfstune" -n "$TEST_DEV"
+
+test_do_mkfs
+run_check "$TOP/btrfstune" -S 1 "$TEST_DEV"
+echo n | run_mayfail "$TOP/btrfstune" -S 0 "$TEST_DEV" || true
+run_check "$TOP/btrfstune" -f -S 0 "$TEST_DEV"
+
+run_mustfail "negative number for seeding status" \
+ "$TOP/btrfstune" -f -S -1 "$TEST_DEV"
+
+test_do_mkfs
+echo n | run_mayfail "$TOP/btrfstune" -u "$TEST_DEV" || true
+run_check "$TOP/btrfstune" -f -u "$TEST_DEV"
+
+uuid="e315420e-3a1f-4d81-849e-93b68b85b76f"
+baduuid="1-2-3-4-5"
+test_do_mkfs
+echo n | run_mayfail "$TOP/btrfstune" -U "$uuid" "$TEST_DEV" || true
+run_check "$TOP/btrfstune" -f -U "$uuid" "$TEST_DEV"
+
+run_mustfail "non-conforming uuid accepted" \
+ "$TOP/btrfstune" -U "$baduuid" "$TEST_DEV"
+
+test_do_mkfs
+echo n | run_mayfail "$TOP/btrfstune" -m "$TEST_DEV" || true
+run_check "$TOP/btrfstune" -f -m "$TEST_DEV"
+
+uuid="2a9716ee-2786-4baa-ab85-f82c50fa883c"
+test_do_mkfs
+run_mayfail "$TOP/btrfstune" -M "$uuid" "$TEST_DEV" || true
+test_do_mkfs
+run_check "$TOP/btrfstune" -f -M "$uuid" "$TEST_DEV"
+
+run_mustfail "non-conforming uuid accepted" \
+ "$TOP/btrfstune" -M "$baduuid" "$TEST_DEV"
diff --git a/tests/fsck-tests/015-tree-reloc-tree/test.sh b/tests/fsck-tests/015-tree-reloc-tree/test.sh
deleted file mode 100755
index 5d9d512..0000000
--- a/tests/fsck-tests/015-tree-reloc-tree/test.sh
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/bash
-# Make sure btrfs check won't report any false alerts for valid image with
-# reloc tree.
-#
-# Also due to the short life span of reloc tree, save the as dump example for
-# later usage.
-
-source "$TEST_TOP/common"
-
-check_prereq btrfs
-
-check_image() {
- run_check "$TOP/btrfs" check "$1"
-}
-
-check_all_images
diff --git a/tests/fsck-tests/020-extent-ref-cases/test.sh b/tests/fsck-tests/020-extent-ref-cases/test.sh
index a1bf75b..e7a5572 100755
--- a/tests/fsck-tests/020-extent-ref-cases/test.sh
+++ b/tests/fsck-tests/020-extent-ref-cases/test.sh
@@ -14,6 +14,11 @@
# Containing a block group and its first extent at
# the beginning of leaf.
# Which caused false alert for lowmem mode.
+#
+# Special cases with some rare backref types
+# * reloc tree
+# For both fs tree and data reloc tree.
+# Special for its backref pointing to itself and its short life span.
source "$TEST_TOP/common"
diff --git a/tests/fsck-tests/015-tree-reloc-tree/tree_reloc_for_data_reloc.img.xz b/tests/fsck-tests/020-extent-ref-cases/tree_reloc_for_data_reloc.img.xz
index 66d8bde..66d8bde 100644
--- a/tests/fsck-tests/015-tree-reloc-tree/tree_reloc_for_data_reloc.img.xz
+++ b/tests/fsck-tests/020-extent-ref-cases/tree_reloc_for_data_reloc.img.xz
Binary files differ
diff --git a/tests/fsck-tests/015-tree-reloc-tree/tree_reloc_for_fs_tree.img.xz b/tests/fsck-tests/020-extent-ref-cases/tree_reloc_for_fs_tree.img.xz
index 22af324..22af324 100644
--- a/tests/fsck-tests/015-tree-reloc-tree/tree_reloc_for_fs_tree.img.xz
+++ b/tests/fsck-tests/020-extent-ref-cases/tree_reloc_for_fs_tree.img.xz
Binary files differ
diff --git a/tests/fsck-tests/026-bad-dir-item-name/description.txt b/tests/fsck-tests/026-bad-dir-item-name/description.txt
new file mode 100644
index 0000000..2bdb0f8
--- /dev/null
+++ b/tests/fsck-tests/026-bad-dir-item-name/description.txt
@@ -0,0 +1,41 @@
+"default_case.img.xz" contains the fs with the following tree dump of fs tree:
+
+ [snip]
+ item 2 key (256 DIR_ITEM 751495445) itemoff 16019 itemsize 92
+ location key (259 INODE_ITEM 0) type FILE
+ transid 9 data_len 0 name_len 13
+ name: foor.WvG1c1Td
+ ^^^^^^^^^^^^^ Hash doesn't match with key
+ location key (260 INODE_ITEM 0) type FILE
+ transid 12 data_len 0 name_len 19
+ name: user.J3__T_Km3dVsW_
+ item 3 key (256 DIR_INDEX 4) itemoff 15976 itemsize 43
+ location key (259 INODE_ITEM 0) type FILE
+ transid 9 data_len 0 name_len 13
+ name: foor.WvG1c1Td
+ item 4 key (256 DIR_INDEX 5) itemoff 15927 itemsize 49
+ location key (260 INODE_ITEM 0) type FILE
+ transid 12 data_len 0 name_len 19
+ name: user.J3__T_Km3dVsW_
+ item 5 key (259 INODE_ITEM 0) itemoff 15767 itemsize 160
+ generation 9 transid 9 size 0 nbytes 0
+ block group 0 mode 100644 links 1 uid 0 gid 0 rdev 0
+ sequence 1 flags 0x0(none)
+ atime 1499844359.341125147 (2017-07-12 15:25:59)
+ ctime 1499844359.341125147 (2017-07-12 15:25:59)
+ mtime 1499844359.341125147 (2017-07-12 15:25:59)
+ otime 1499844359.341125147 (2017-07-12 15:25:59)
+ item 6 key (259 INODE_REF 256) itemoff 15744 itemsize 23
+ index 4 namelen 13 name: foor.WvG1c1Td
+ item 7 key (260 INODE_ITEM 0) itemoff 15584 itemsize 160
+ generation 12 transid 12 size 0 nbytes 0
+ block group 0 mode 100644 links 1 uid 0 gid 0 rdev 0
+ sequence 1 flags 0x0(none)
+ atime 1499844544.931130070 (2017-07-12 15:29:04)
+ ctime 1499844544.931130070 (2017-07-12 15:29:04)
+ mtime 1499844544.931130070 (2017-07-12 15:29:04)
+ otime 1499844544.931130070 (2017-07-12 15:29:04)
+ item 8 key (260 INODE_REF 256) itemoff 15555 itemsize 29
+ index 5 namelen 19 name: user.J3__T_Km3dVsW_
+
+Test case is going to check if btrfs check can detect and repair it.
diff --git a/tests/fsck-tests/026-bad-dir-item-name/test.sh b/tests/fsck-tests/026-bad-dir-item-name/test.sh
deleted file mode 100755
index a38bf04..0000000
--- a/tests/fsck-tests/026-bad-dir-item-name/test.sh
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/bin/bash
-#
-# confirm whether check detects name and hash mismatch in dir_item
-
-source "$TEST_TOP/common"
-
-check_prereq btrfs
-
-image=$(extract_image "./default_case.img.xz")
-
-run_mustfail "dir_item hash mismatch not found" "$TOP/btrfs" check "$image"
-
-rm -f "$image"
diff --git a/tests/fsck-tests/036-bad-dev-extents/over_dev_boundary.img.xz b/tests/fsck-tests/036-bad-dev-extents/over_dev_boundary.img.xz
new file mode 100644
index 0000000..47cb2a7
--- /dev/null
+++ b/tests/fsck-tests/036-bad-dev-extents/over_dev_boundary.img.xz
Binary files differ
diff --git a/tests/fsck-tests/036-bad-dev-extents/test.sh b/tests/fsck-tests/036-bad-dev-extents/test.sh
new file mode 100755
index 0000000..88ea0ae
--- /dev/null
+++ b/tests/fsck-tests/036-bad-dev-extents/test.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+#
+# Due to DUP chunk allocator bugs, we could allocate DUP chunks while its dev
+# extents could exist beyond device boundary.
+# And since all related items (block group, chunk, device used bytes) are all
+# valid, btrfs check won't report any error.
+#
+# This test case contains hand crafted minimal image, to test if btrfs check
+# can detect and report such error.
+
+source "$TEST_TOP/common"
+
+check_prereq btrfs
+
+check_image() {
+ run_mustfail "btrfs check failed to detect invalid dev extents" \
+ "$TOP/btrfs" check "$1"
+}
+
+check_all_images
diff --git a/tests/fsck-tests/037-freespacetree-repair/test.sh b/tests/fsck-tests/037-freespacetree-repair/test.sh
index 261d7cc..a0bdf9e 100755
--- a/tests/fsck-tests/037-freespacetree-repair/test.sh
+++ b/tests/fsck-tests/037-freespacetree-repair/test.sh
@@ -59,8 +59,11 @@ run_check "$TOP/mkfs.btrfs" -n 4k -f "$TEST_DEV"
run_check_mount_test_dev -oclear_cache,space_cache=v2
# create files which will populate the FST
-for i in {1..3000}; do
- run_check $SUDO_HELPER fallocate -l 4k "$TEST_MNT/file.$i"
+for i in {0..9}; do
+ for j in {1..300}; do
+ run_check $SUDO_HELPER fallocate -l 4k "$TEST_MNT/file.$j$i" &
+ done
+ wait
done
run_check_umount_test_dev
diff --git a/tests/misc-tests/021-image-multi-devices/test.sh b/tests/misc-tests/021-image-multi-devices/test.sh
index 5430847..26beae6 100755
--- a/tests/misc-tests/021-image-multi-devices/test.sh
+++ b/tests/misc-tests/021-image-multi-devices/test.sh
@@ -37,6 +37,9 @@ run_check $SUDO_HELPER wipefs -a "$loop2"
run_check $SUDO_HELPER "$TOP/btrfs-image" -r "$IMAGE" "$loop1"
+# Run check to make sure there is nothing wrong for the recovered image
+run_check "$TOP/btrfs" check "$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"
diff --git a/tests/misc-tests/034-metadata-uuid/disk1.raw.xz b/tests/misc-tests/034-metadata-uuid/disk1.raw.xz
new file mode 100644
index 0000000..24f47d2
--- /dev/null
+++ b/tests/misc-tests/034-metadata-uuid/disk1.raw.xz
Binary files differ
diff --git a/tests/misc-tests/034-metadata-uuid/disk2.raw.xz b/tests/misc-tests/034-metadata-uuid/disk2.raw.xz
new file mode 100644
index 0000000..a1c8037
--- /dev/null
+++ b/tests/misc-tests/034-metadata-uuid/disk2.raw.xz
Binary files differ
diff --git a/tests/misc-tests/034-metadata-uuid/disk3.raw.xz b/tests/misc-tests/034-metadata-uuid/disk3.raw.xz
new file mode 100644
index 0000000..25e9be6
--- /dev/null
+++ b/tests/misc-tests/034-metadata-uuid/disk3.raw.xz
Binary files differ
diff --git a/tests/misc-tests/034-metadata-uuid/disk4.raw.xz b/tests/misc-tests/034-metadata-uuid/disk4.raw.xz
new file mode 100644
index 0000000..f591cfe
--- /dev/null
+++ b/tests/misc-tests/034-metadata-uuid/disk4.raw.xz
Binary files differ
diff --git a/tests/misc-tests/034-metadata-uuid/disk5.raw.xz b/tests/misc-tests/034-metadata-uuid/disk5.raw.xz
new file mode 100644
index 0000000..e9095b7
--- /dev/null
+++ b/tests/misc-tests/034-metadata-uuid/disk5.raw.xz
Binary files differ
diff --git a/tests/misc-tests/034-metadata-uuid/disk6.raw.xz b/tests/misc-tests/034-metadata-uuid/disk6.raw.xz
new file mode 100644
index 0000000..9926ae4
--- /dev/null
+++ b/tests/misc-tests/034-metadata-uuid/disk6.raw.xz
Binary files differ
diff --git a/tests/misc-tests/034-metadata-uuid/test.sh b/tests/misc-tests/034-metadata-uuid/test.sh
new file mode 100755
index 0000000..72af047
--- /dev/null
+++ b/tests/misc-tests/034-metadata-uuid/test.sh
@@ -0,0 +1,225 @@
+#!/bin/bash
+
+source "$TEST_TOP/common"
+
+check_prereq mkfs.btrfs
+check_prereq btrfs
+check_prereq btrfstune
+check_prereq btrfs-image
+
+setup_root_helper
+prepare_test_dev
+
+function read_fsid {
+ local dev="$1"
+
+ echo $(run_check_stdout $SUDO_HELPER "$TOP/btrfs" inspect-internal \
+ dump-super "$dev" | awk '/fsid/ {print $2}' | head -n 1)
+}
+
+function read_metadata_uuid {
+ local dev="$1"
+
+ echo $(run_check_stdout $SUDO_HELPER "$TOP/btrfs" inspect-internal \
+ dump-super "$dev" | awk '/metadata_uuid/ {print $2}')
+}
+
+function check_btrfstune {
+ local fsid
+
+ echo "Checking btrfstune logic" >> "$RESULTS"
+ # test with random uuid
+ run_check $SUDO_HELPER "$TOP/btrfstune" -m "$TEST_DEV"
+
+ # check that specific uuid can set
+ run_check $SUDO_HELPER "$TOP/btrfstune" -M d88c8333-a652-4476-b225-2e9284eb59f1 "$TEST_DEV"
+
+ # test that having seed on already changed device doesn't work
+ run_mustfail "Managed to set seed on metadata uuid fs" \
+ $SUDO_HELPER "$TOP/btrfstune" -S 1 "$TEST_DEV"
+
+ # test that setting both seed and -m|M is forbidden
+ run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV"
+ run_mustfail "Succeeded setting seed and changing fs uuid" \
+ $SUDO_HELPER "$TOP/btrfstune" -S 1 -m "$TEST_DEV"
+
+ # test that having -m|-M on seed device is forbidden
+ run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV"
+ run_check $SUDO_HELPER "$TOP/btrfstune" -S 1 "$TEST_DEV"
+ run_mustfail "Succeded changing fsid on a seed device" $SUDO_HELPER "$TOP/btrfstune" -m "$TEST_DEV"
+
+ # test that using -U|-u on an fs with METADATA_UUID flag is forbidden
+ run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV"
+ run_check $SUDO_HELPER "$TOP/btrfstune" -m "$TEST_DEV"
+ run_mustfail "Succeeded triggering FSID rewrite while METADATA_UUID is active" \
+ $SUDO_HELPER "$TOP/btrfstune" -u "$TEST_DEV"
+
+}
+
+function check_dump_super_output {
+ local fsid
+ local metadata_uuid
+ local dev_item_match
+ local old_metadata_uuid
+
+ echo "Checking dump-super output" >> "$RESULTS"
+ # assert that metadata/fsid match on non-changed fs
+ fsid=$(read_fsid "$TEST_DEV")
+ metadata_uuid=$(read_metadata_uuid "$TEST_DEV")
+ [ "$fsid" = "$metadata_uuid" ] || _fail "fsid ("$fsid") doesn't match metadata_uuid ("$metadata_uuid")"
+
+ dev_item_match=$(run_check_stdout $SUDO_HELPER "$TOP/btrfs" inspect-internal dump-super \
+ "$TEST_DEV" | awk '/dev_item.fsid/ {print $3}')
+
+ [ $dev_item_match = "[match]" ] || _fail "dev_item.fsid doesn't match on non-metadata uuid fs"
+
+
+ echo "Checking output after fsid change" >> "$RESULTS"
+ # change metadatauuid and ensure everything in the output is still correct
+ old_metadata_uuid=$metadata_uuid
+ run_check $SUDO_HELPER "$TOP/btrfstune" -M d88c8333-a652-4476-b225-2e9284eb59f1 "$TEST_DEV"
+ fsid=$(read_fsid "$TEST_DEV")
+ metadata_uuid=$(read_metadata_uuid "$TEST_DEV")
+ dev_item_match=$(run_check_stdout $SUDO_HELPER "$TOP/btrfs" \
+ inspect-internal dump-super "$TEST_DEV" | awk '/dev_item.fsid/ {print $3}')
+
+ [ "$dev_item_match" = "[match]" ] || _fail "dev_item.fsid doesn't match on metadata uuid fs"
+ [ "$fsid" = "d88c8333-a652-4476-b225-2e9284eb59f1" ] || _fail "btrfstune metadata UUID change failed"
+ [ "$old_metadata_uuid" = "$metadata_uuid" ] || _fail "Metadata uuid change unexpectedly"
+
+ echo "Checking for incompat textual representation" >> "$RESULTS"
+ # check for textual output of the new incompat feature
+ run_check_stdout $SUDO_HELPER "$TOP/btrfs" inspect-internal dump-super \
+ "$TEST_DEV" | grep -q METADATA_UUID
+ [ $? -eq 0 ] || _fail "Didn't find textual representation of METADATA_UUID feature"
+
+ echo "Checking setting fsid back to original" >> "$RESULTS"
+ # ensure that setting the fsid back to the original works
+ run_check $SUDO_HELPER "$TOP/btrfstune" -M "$old_metadata_uuid" "$TEST_DEV"
+
+ fsid=$(read_fsid "$TEST_DEV")
+ metadata_uuid=$(read_metadata_uuid "$TEST_DEV")
+
+ [ "$fsid" = "$metadata_uuid" ] || _fail "FSID and METADATA_UUID don't match"
+ run_check_stdout $SUDO_HELPER "$TOP/btrfs" inspect-internal dump-super \
+ "$TEST_DEV" | grep -q METADATA_UUID
+ [ $? -eq 1 ] || _fail "METADATA_UUID feature still shown as enabled"
+}
+
+function check_image_restore {
+ local metadata_uuid
+ local fsid
+ local fsid_restored
+ local metadata_uuid_restored
+
+ echo "TESTING btrfs-image restore" >> "$RESULTS"
+ run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV"
+ run_check $SUDO_HELPER "$TOP/btrfstune" -m "$TEST_DEV"
+ fsid=$(read_fsid "$TEST_DEV")
+ metadata_uuid=$(read_metadata_uuid "$TEST_DEV")
+ run_mayfail $SUDO_HELPER "$TOP/btrfs-image" "$TEST_DEV" /tmp/test-img.dump
+ # erase the fs by creating a new one, wipefs is not sufficient as it just
+ # deletes the fs magic string
+ run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV"
+ run_check $SUDO_HELPER "$TOP/btrfs-image" -r /tmp/test-img.dump "$TEST_DEV"
+ fsid_restored=$(read_fsid "$TEST_DEV")
+ metadata_uuid_restored=$(read_metadata_uuid "$TEST_DEV")
+
+ [ "$fsid" = "$fsid_restored" ] || _fail "FSID don't match after restore"
+ [ "$metadata_uuid" = "$metadata_uuid_restored" ] || _fail "metadata uuids don't match after restore"
+}
+
+function check_inprogress_flag {
+ # check the flag is indeed cleared
+ run_check_stdout $SUDO_HELPER "$TOP/btrfs" inspect-internal dump-super \
+ $1 | grep -q 0x1000000001
+ [ $? -eq 1 ] || _fail "Found BTRFS_SUPER_FLAG_CHANGING_FSID_V2 set for $1"
+
+ run_check_stdout $SUDO_HELPER $TOP/btrfs inspect-internal dump-super \
+ $2 | grep -q 0x1000000001
+ [ $? -eq 1 ] || _fail "Found BTRFS_SUPER_FLAG_CHANGING_FSID_V2 set for $2"
+}
+
+function check_completed {
+ # check that metadata uuid is indeed completed
+ run_check_stdout $SUDO_HELPER "$TOP/btrfs" inspect-internal dump-super \
+ $1 | grep -q METADATA_UUID
+ [ $? -eq 0 ] || _fail "METADATA_UUID not set on $1"
+
+ run_check_stdout $SUDO_HELPER $TOP/btrfs inspect-internal dump-super \
+ $2 | grep -q METADATA_UUID
+ [ $? -eq 0 ] || _fail "METADATA_UUID not set on $2"
+}
+
+function check_multi_fsid_change {
+ check_inprogress_flag $1 $2
+ check_completed $1 $2
+}
+
+function failure_recovery {
+ local image1
+ local image2
+ local loop1
+ local loop2
+ local devcount
+
+ image1=$(extract_image "$1")
+ image2=$(extract_image "$2")
+ loop1=$(run_check_stdout $SUDO_HELPER losetup --find --show "$image1")
+ loop2=$(run_check_stdout $SUDO_HELPER losetup --find --show "$image2")
+
+ # Mount and unmount, on trans commit all disks should be consistent
+ run_check $SUDO_HELPER mount "$loop1" "$TEST_MNT"
+ run_check $SUDO_HELPER umount "$TEST_MNT"
+
+ # perform any specific check
+ $3 "$loop1" "$loop2"
+
+ # cleanup
+ run_check $SUDO_HELPER losetup -d "$loop1"
+ run_check $SUDO_HELPER losetup -d "$loop2"
+ rm -f "$image1" "$image2"
+}
+
+function reload_btrfs {
+ rmmod btrfs
+ modprobe btrfs
+}
+
+# for full coverage we need btrfs to actually be a module
+modinfo btrfs > /dev/null 2>&1 || _not_run "btrfs must be a module"
+modprobe -r btrfs || _not_run "btrfs must be unloadable"
+modprobe btrfs || _not_run "loading btrfs module failed"
+
+run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV"
+check_btrfstune
+
+run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV"
+check_dump_super_output
+
+run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV"
+check_image_restore
+
+# disk1 is an image which has no metadata uuid flags set and disk2 is part of
+# the same fs but has the in-progress flag set. Test that whicever is scanned
+# first will result in consistent filesystem.
+failure_recovery "./disk1.raw.xz" "./disk2.raw.xz" check_inprogress_flag
+reload_btrfs
+failure_recovery "./disk2.raw.xz" "./disk1.raw.xz" check_inprogress_flag
+
+reload_btrfs
+
+# disk4 contains an image in with the in-progress flag set and disk 3 is part
+# of the same filesystem but has both METADATA_UUID incompat and a new
+# metadata uuid set. So disk 3 must always take precedence
+failure_recovery "./disk3.raw.xz" "./disk4.raw.xz" check_completed
+reload_btrfs
+failure_recovery "./disk4.raw.xz" "./disk3.raw.xz" check_completed
+
+# disk5 contains an image which has undergone a successful fsid change more
+# than once, disk6 on the other hand is member of the same filesystem but
+# hasn't completed its last change. Thus it has both the FSID_CHANGING flag set
+# and METADATA_UUID flag set.
+failure_recovery "./disk5.raw.xz" "./disk6.raw.xz" check_multi_fsid_change
+reload_btrfs
+failure_recovery "./disk6.raw.xz" "./disk5.raw.xz" check_multi_fsid_change
diff --git a/tests/misc-tests/035-receive-common-mount-point-prefix/test.sh b/tests/misc-tests/035-receive-common-mount-point-prefix/test.sh
new file mode 100755
index 0000000..375ade2
--- /dev/null
+++ b/tests/misc-tests/035-receive-common-mount-point-prefix/test.sh
@@ -0,0 +1,48 @@
+#!/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"
+
+check_prereq btrfs
+check_prereq mkfs.btrfs
+
+setup_root_helper
+
+rm -f dev1 dev2
+run_check truncate -s 1G dev1
+run_check truncate -s 1G 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)
+
+run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$loop1"
+run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$loop2"
+
+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"
+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"
+
+run_check truncate -s 0 send.data
+chmod a+w 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