2013-09-09 20:41:58 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# loop through all of our bad images and make sure fsck repairs them properly
|
|
|
|
#
|
|
|
|
# It's GPL, same as everything else in this tree.
|
|
|
|
#
|
|
|
|
|
|
|
|
here=`pwd`
|
2014-05-29 10:01:44 +00:00
|
|
|
TEST_DEV=
|
|
|
|
TEST_MNT=
|
|
|
|
RESULT="fsck-tests-results.txt"
|
2013-09-09 20:41:58 +00:00
|
|
|
|
|
|
|
_fail()
|
|
|
|
{
|
2014-05-29 10:01:44 +00:00
|
|
|
echo "$*" | tee -a $RESULT
|
2013-09-09 20:41:58 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2014-05-29 10:01:44 +00:00
|
|
|
run_check()
|
|
|
|
{
|
|
|
|
echo "############### $@" >> $RESULT 2>&1
|
|
|
|
"$@" >> $RESULT 2>&1 || _fail "failed: $@"
|
|
|
|
}
|
|
|
|
|
|
|
|
rm -f $RESULT
|
|
|
|
|
|
|
|
if [ -z $TEST_DEV ] || [ -z $TEST_MNT ];then
|
|
|
|
_fail "please set TEST_DEV and TEST_MNT"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# test rely on corrupting blocks tool
|
|
|
|
run_check make btrfs-corrupt-block
|
2013-09-09 20:41:58 +00:00
|
|
|
|
|
|
|
for i in $(find $here/tests/fsck-tests -name '*.img')
|
|
|
|
do
|
2013-10-01 12:58:33 +00:00
|
|
|
echo " [TEST] $(basename $i)"
|
2014-05-29 10:01:44 +00:00
|
|
|
echo "testing image $i" >> $RESULT
|
|
|
|
|
|
|
|
run_check $here/btrfs-image -r $i test.img
|
2013-09-09 20:41:58 +00:00
|
|
|
|
2014-05-29 10:01:44 +00:00
|
|
|
$here/btrfsck test.img >> $RESULT 2>&1
|
|
|
|
[ $? -eq 0 ] && _fail "btrfsck should have detected corruption"
|
2013-09-09 20:41:58 +00:00
|
|
|
|
2014-05-29 10:01:44 +00:00
|
|
|
run_check $here/btrfsck --repair test.img
|
|
|
|
run_check $here/btrfsck test.img
|
2013-09-09 20:41:58 +00:00
|
|
|
done
|
2014-05-29 10:01:44 +00:00
|
|
|
|
|
|
|
# test whether fsck can rebuild a corrupted extent tree
|
|
|
|
test_extent_tree_rebuild()
|
|
|
|
{
|
|
|
|
echo " [TEST] extent tree rebuild"
|
|
|
|
$here/mkfs.btrfs -f $TEST_DEV >> /dev/null 2>&1 || _fail "fail to mkfs"
|
|
|
|
|
|
|
|
run_check mount $TEST_DEV $TEST_MNT
|
|
|
|
cp -aR /lib/modules/`uname -r`/ $TEST_MNT 2>&1
|
|
|
|
|
|
|
|
for i in `seq 1 100`;do
|
|
|
|
$here/btrfs sub snapshot $TEST_MNT \
|
|
|
|
$TEST_MNT/snapaaaaaaa_$i >& /dev/null
|
|
|
|
done
|
|
|
|
run_check umount $TEST_DEV
|
|
|
|
|
|
|
|
# get extent root bytenr
|
|
|
|
extent_root_bytenr=`$here/btrfs-debug-tree -r $TEST_DEV | grep extent | awk '{print $7}'`
|
|
|
|
if [ -z $extent_root_bytenr ];then
|
|
|
|
_fail "fail to get extent root bytenr"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# corrupt extent root node block
|
|
|
|
run_check $here/btrfs-corrupt-block -l $extent_root_bytenr \
|
|
|
|
-b 4096 $TEST_DEV
|
|
|
|
|
|
|
|
$here/btrfs check $TEST_DEV >& /dev/null && \
|
|
|
|
_fail "fsck should detect failure"
|
|
|
|
run_check $here/btrfs check --init-extent-tree $TEST_DEV
|
|
|
|
run_check $here/btrfs check $TEST_DEV
|
|
|
|
}
|
|
|
|
|
|
|
|
test_extent_tree_rebuild
|