summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2018-01-23 16:25:11 +0100
committerDavid Sterba <dsterba@suse.com>2018-01-31 15:14:02 +0100
commitde802a47e0d7474bd446c5eb6974a33dacca5100 (patch)
treebaeffe1e5ea46cd35ec42b470b7a0aff2bea3fe3
parente764625f90f947f927f78b4166a34d9d5755ef63 (diff)
btrfs-progs: tests: 029-super-recovery: cleanup the test
Transform the test to the common helpers and don't manage the loop devices here. The test category changes from check to misc. Signed-off-by: David Sterba <dsterba@suse.com>
-rwxr-xr-xtests/misc-tests/028-superblock-recover/test.sh (renamed from tests/fsck-tests/029-superblock-recovery/test.sh)43
1 files changed, 18 insertions, 25 deletions
diff --git a/tests/fsck-tests/029-superblock-recovery/test.sh b/tests/misc-tests/028-superblock-recover/test.sh
index c1dfe7f5..1175e480 100755
--- a/tests/fsck-tests/029-superblock-recovery/test.sh
+++ b/tests/misc-tests/028-superblock-recover/test.sh
@@ -1,6 +1,5 @@
#!/bin/bash
-# Test that any superblock is correctly detected
-# and fixed by btrfs rescue
+# Test that any superblock is correctly detected and fixed by btrfs rescue
source "$TOP/tests/common"
@@ -9,56 +8,50 @@ check_prereq mkfs.btrfs
check_prereq btrfs-select-super
setup_root_helper
-
-rm -f dev1
-run_check truncate -s 260G dev1
-loop=$(run_check_stdout $SUDO_HELPER losetup --find --show dev1)
+prepare_test_dev 260G
# Create the test file system.
-run_check $SUDO_HELPER "$TOP"/mkfs.btrfs -f "$loop"
+run_check $SUDO_HELPER "$TOP"/mkfs.btrfs -f "$TEST_DEV"
function check_corruption {
local sb_offset=$1
local source_sb=$2
-
# First we ensure we can mount it successfully
- run_check $SUDO_HELPER mount $loop "$TEST_MNT"
- run_check $SUDO_HELPER umount "$TEST_MNT"
+ run_check_mount_test_dev
+ run_check_umount_test_dev
# Now corrupt 1k of the superblock at sb_offset
- run_check $SUDO_HELPER dd bs=1K count=1 seek=$(($sb_offset + 1)) if=/dev/zero of="$loop"
+ run_check $SUDO_HELPER dd bs=1K count=1 seek=$(($sb_offset + 1)) if=/dev/zero of="$TEST_DEV" conv=notrunc
- #if corrupting one of the sb copies, copy it over the initial superblock
+ # if corrupting one of the sb copies, copy it over the initial superblock
if [ ! -z $source_sb ]; then
local shift_val=$((16 << $source_sb * 12 ))
- run_check $SUDO_HELPER dd bs=1K count=4 seek=64 skip=$shift_val if="$loop" of="$loop"
+ run_check $SUDO_HELPER dd bs=1K count=4 seek=64 skip=$shift_val if="$TEST_DEV" of="$TEST_DEV" conv=notrunc
fi
- run_mustfail "Mounted fs with corrupted superblock" \
- $SUDO_HELPER mount $loop "$TEST_MNT"
+ # we can't use our mount helper, the following works for file image and
+ # block device as TEST_DEV
+ run_mustfail "mounted fs with corrupted superblock" \
+ $SUDO_HELPER mount "$TEST_DEV" "$TEST_MNT"
# Now run btrfs rescue which should fix the superblock. It uses 2
# to signal success of recovery use mayfail to ignore that retval
# but still log the output of the command
- run_mayfail $SUDO_HELPER "$TOP"/btrfs rescue super-recover -yv "$loop"
+ run_mayfail $SUDO_HELPER "$TOP"/btrfs rescue super-recover -yv "$TEST_DEV"
if [ $? != 2 ]; then
_fail "couldn't rescue super"
fi
- run_check $SUDO_HELPER mount $loop "$TEST_MNT"
- run_check $SUDO_HELPER umount "$TEST_MNT"
+ run_check_mount_test_dev
+ run_check_umount_test_dev
}
-_log "Corrupting first superblock"
+# Corrupting first superblock
check_corruption 64
-_log "Corrupting second superblock"
+# Corrupting second superblock
check_corruption 65536 1
-_log "Corrupting third superblock"
+# Corrupting third superblock
check_corruption 268435456 2
-
-# Cleanup
-run_check $SUDO_HELPER losetup -d "$loop"
-rm -f dev1