2014-12-25 01:32:15 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2015-04-03 07:01:12 +00:00
|
|
|
source $TOP/tests/common
|
2014-12-25 01:32:15 +00:00
|
|
|
|
2015-04-03 07:01:14 +00:00
|
|
|
check_prereq btrfs-debug-tree
|
2015-04-07 16:29:05 +00:00
|
|
|
check_prereq mkfs.btrfs
|
2015-04-03 07:01:14 +00:00
|
|
|
setup_root_helper
|
2015-07-27 12:24:31 +00:00
|
|
|
prepare_test_dev 1G
|
2014-12-25 01:32:15 +00:00
|
|
|
|
|
|
|
# test whether fsck can rebuild a corrupted extent tree
|
|
|
|
test_extent_tree_rebuild()
|
|
|
|
{
|
2015-04-03 07:01:14 +00:00
|
|
|
run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $TEST_DEV
|
2014-12-25 01:32:15 +00:00
|
|
|
|
2015-09-01 12:40:13 +00:00
|
|
|
run_check_mount_test_dev
|
2015-04-03 07:01:14 +00:00
|
|
|
run_check $SUDO_HELPER cp -aR /lib/modules/`uname -r`/ $TEST_MNT
|
2014-12-25 01:32:15 +00:00
|
|
|
|
|
|
|
for i in `seq 1 100`;do
|
2015-04-03 07:01:14 +00:00
|
|
|
run_check $SUDO_HELPER $TOP/btrfs sub snapshot $TEST_MNT \
|
|
|
|
$TEST_MNT/snapaaaaaaa_$i
|
2014-12-25 01:32:15 +00:00
|
|
|
done
|
2015-09-01 12:40:13 +00:00
|
|
|
run_check_umount_test_dev
|
2014-12-25 01:32:15 +00:00
|
|
|
|
|
|
|
# get extent root bytenr
|
2015-04-03 07:01:14 +00:00
|
|
|
extent_root_bytenr=`$SUDO_HELPER $TOP/btrfs-debug-tree -r $TEST_DEV | \
|
2014-12-25 01:32:15 +00:00
|
|
|
grep extent | awk '{print $7}'`
|
|
|
|
if [ -z $extent_root_bytenr ];then
|
|
|
|
_fail "fail to get extent root bytenr"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# corrupt extent root node block
|
2015-04-03 07:01:14 +00:00
|
|
|
run_check $SUDO_HELPER $TOP/btrfs-corrupt-block -l $extent_root_bytenr \
|
2014-12-25 01:32:15 +00:00
|
|
|
-b 4096 $TEST_DEV
|
|
|
|
|
2015-04-03 07:01:14 +00:00
|
|
|
$SUDO_HELPER $TOP/btrfs check $TEST_DEV >& /dev/null && \
|
2014-12-25 01:32:15 +00:00
|
|
|
_fail "btrfs check should detect failure"
|
2015-04-03 07:01:14 +00:00
|
|
|
run_check $SUDO_HELPER $TOP/btrfs check --init-extent-tree $TEST_DEV
|
|
|
|
run_check $SUDO_HELPER $TOP/btrfs check $TEST_DEV
|
2014-12-25 01:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test_extent_tree_rebuild
|