3 # loop through all of our bad images and make sure fsck repairs them properly
5 # It's GPL, same as everything else in this tree.
11 RESULT="fsck-tests-results.txt"
15 echo "$*" | tee -a $RESULT
21 echo "############### $@" >> $RESULT 2>&1
22 "$@" >> $RESULT 2>&1 || _fail "failed: $@"
27 if ! [ -f $here/$1 ]; then
28 _fail "Failed prerequisities: $1";
34 # test rely on corrupting blocks tool
35 check_prereq btrfs-corrupt-block
36 check_prereq btrfs-image
39 # Some broken filesystem images are kept as .img files, created by the tool
40 # btrfs-image, and others are kept as .tar.xz files that contain raw filesystem
41 # image (the backing file of a loop device, as a sparse file). The reason for
42 # keeping some as tarballs of raw images is that for these cases btrfs-image
43 # isn't able to preserve all the (bad) filesystem structure for some reason.
44 for i in $(find $here/tests/fsck-tests -name '*.img' -o -name '*.tar.xz' | sort)
46 echo " [TEST] $(basename $i)"
47 echo "testing image $i" >> $RESULT
51 if [ $extension == "img" ]; then
52 run_check $here/btrfs-image -r $i test.img
57 $here/btrfs check test.img >> $RESULT 2>&1
58 [ $? -eq 0 ] && _fail "btrfs check should have detected corruption"
60 run_check $here/btrfs check --repair test.img
61 run_check $here/btrfs check test.img
64 if [ -z $TEST_DEV ] || [ -z $TEST_MNT ];then
65 echo " [NOTRUN] extent tree rebuild"
69 # test whether fsck can rebuild a corrupted extent tree
70 test_extent_tree_rebuild()
72 echo " [TEST] extent tree rebuild"
73 $here/mkfs.btrfs -f $TEST_DEV >> /dev/null 2>&1 || _fail "fail to mkfs"
75 run_check mount $TEST_DEV $TEST_MNT
76 cp -aR /lib/modules/`uname -r`/ $TEST_MNT 2>&1
78 for i in `seq 1 100`;do
79 $here/btrfs sub snapshot $TEST_MNT \
80 $TEST_MNT/snapaaaaaaa_$i >& /dev/null
82 run_check umount $TEST_DEV
84 # get extent root bytenr
85 extent_root_bytenr=`$here/btrfs-debug-tree -r $TEST_DEV | grep extent | awk '{print $7}'`
86 if [ -z $extent_root_bytenr ];then
87 _fail "fail to get extent root bytenr"
90 # corrupt extent root node block
91 run_check $here/btrfs-corrupt-block -l $extent_root_bytenr \
94 $here/btrfs check $TEST_DEV >& /dev/null && \
95 _fail "btrfs check should detect failure"
96 run_check $here/btrfs check --init-extent-tree $TEST_DEV
97 run_check $here/btrfs check $TEST_DEV
100 test_extent_tree_rebuild