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 # test rely on corrupting blocks tool
28 run_check make btrfs-corrupt-block
30 # Some broken filesystem images are kept as .img files, created by the tool
31 # btrfs-image, and others are kept as .tar.xz files that contain raw filesystem
32 # image (the backing file of a loop device, as a sparse file). The reason for
33 # keeping some as tarballs of raw images is that for these cases btrfs-image
34 # isn't able to preserve all the (bad) filesystem structure for some reason.
35 for i in $(find $here/tests/fsck-tests -name '*.img' -o -name '*.tar.xz' | sort)
37 echo " [TEST] $(basename $i)"
38 echo "testing image $i" >> $RESULT
42 if [ $extension == "img" ]; then
43 run_check $here/btrfs-image -r $i test.img
48 $here/btrfs check test.img >> $RESULT 2>&1
49 [ $? -eq 0 ] && _fail "btrfs check should have detected corruption"
51 run_check $here/btrfs check --repair test.img
52 run_check $here/btrfs check test.img
55 if [ -z $TEST_DEV ] || [ -z $TEST_MNT ];then
56 echo " [NOTRUN] extent tree rebuild"
60 # test whether fsck can rebuild a corrupted extent tree
61 test_extent_tree_rebuild()
63 echo " [TEST] extent tree rebuild"
64 $here/mkfs.btrfs -f $TEST_DEV >> /dev/null 2>&1 || _fail "fail to mkfs"
66 run_check mount $TEST_DEV $TEST_MNT
67 cp -aR /lib/modules/`uname -r`/ $TEST_MNT 2>&1
69 for i in `seq 1 100`;do
70 $here/btrfs sub snapshot $TEST_MNT \
71 $TEST_MNT/snapaaaaaaa_$i >& /dev/null
73 run_check umount $TEST_DEV
75 # get extent root bytenr
76 extent_root_bytenr=`$here/btrfs-debug-tree -r $TEST_DEV | grep extent | awk '{print $7}'`
77 if [ -z $extent_root_bytenr ];then
78 _fail "fail to get extent root bytenr"
81 # corrupt extent root node block
82 run_check $here/btrfs-corrupt-block -l $extent_root_bytenr \
85 $here/btrfs check $TEST_DEV >& /dev/null && \
86 _fail "btrfs check should detect failure"
87 run_check $here/btrfs check --init-extent-tree $TEST_DEV
88 run_check $here/btrfs check $TEST_DEV
91 test_extent_tree_rebuild