From 3de68a0e8704869e72910b1a06e2e71692015e7b Mon Sep 17 00:00:00 2001 From: Anand Jain Date: Wed, 4 Sep 2019 21:29:47 +0800 Subject: [PATCH] btrfs-progs: tests: fix misc/021 when restoring overlapping stale data As misc-tests/021 image dump is restored on the same original loop device, this overlaps with the stale data and makes the test pass falsely. Fix this by using a new device for restore. And also, the btrfs-image dump and restore doesn't restore the file data, so any read on the files should be avoided. So instead of file data use file stat data for the checksum. Reported-by: Johannes Thumshirn Reviewed-by: Johannes Thumshirn Reviewed-by: Nikolay Borisov Signed-off-by: Anand Jain Signed-off-by: David Sterba --- tests/misc-tests/021-image-multi-devices/test.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/misc-tests/021-image-multi-devices/test.sh b/tests/misc-tests/021-image-multi-devices/test.sh index b1013b5d..5ed8f4b0 100755 --- a/tests/misc-tests/021-image-multi-devices/test.sh +++ b/tests/misc-tests/021-image-multi-devices/test.sh @@ -10,17 +10,18 @@ check_prereq btrfs setup_root_helper -setup_loopdevs 2 +setup_loopdevs 3 prepare_loopdevs loop1=${loopdevs[1]} loop2=${loopdevs[2]} +loop3=${loopdevs[3]} # 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) +orig_md5=$(run_check_stdout stat "$TEST_MNT/foobar" | md5sum | cut -d ' ' -f 1) run_check $SUDO_HELPER umount "$TEST_MNT" # Create the image to restore later. @@ -32,13 +33,13 @@ run_check $SUDO_HELPER "$TOP/btrfs-image" "$loop1" "$IMAGE" 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 "$TOP/btrfs-image" -r "$IMAGE" "$loop3" # Run check to make sure there is nothing wrong for the recovered image -run_check $SUDO_HELPER "$TOP/btrfs" check "$loop1" +run_check $SUDO_HELPER "$TOP/btrfs" check "$loop3" -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 mount "$loop3" "$TEST_MNT" +new_md5=$(run_check_stdout stat "$TEST_MNT/foobar" | md5sum | cut -d ' ' -f 1) run_check $SUDO_HELPER umount "$TEST_MNT" cleanup_loopdevs