Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

btrfs-progs: Add corrupted leaf repair testcase #3

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions tests/fsck-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,63 @@ run_check()
"$@" >> $RESULT 2>&1 || _fail "failed: $@"
}

# For complicated fsck repair case,
# where even repairing is OK, it may still report problem before or after
# reparing since the repair needs several loops to repair all the problems
# but report checks it before all repair loops done
run_check_no_fail()
{
echo "############### $@" >> $RESULT 2>&1
"$@" >> $RESULT 2>&1
}

rm -f $RESULT

# test rely on corrupting blocks tool
run_check make btrfs-corrupt-block

# Supported test image formats:
# 1) btrfs-image dump(.img files)
# Some broken filesystem images are kept as .img files, created by the tool
# btrfs-image, and others are kept as .tar.xz files that contain raw filesystem
# btrfs-image
#
# 2) binary image dump only(only test.img in .tar.xz)
# Some are kept as .tar.xz files that contain raw filesystem
# image (the backing file of a loop device, as a sparse file). The reason for
# keeping some as tarballs of raw images is that for these cases btrfs-image
# isn't able to preserve all the (bad) filesystem structure for some reason.
# This provides great flexibility at the cost of large file size.
#
# 3) script generated dump(generate_image.sh + needed things in .tar.gz)
# The image is generated by the generate_image.sh script alone the needed
# files in the tarball, normally a quite small btrfs-image dump.
# This one combines the advatange of relative small btrfs-image and the
# flexibility to support corrupted image.
for i in $(find $here/tests/fsck-tests -name '*.img' -o -name '*.tar.xz' | sort)
do
echo " [TEST] $(basename $i)"
echo "testing image $i" >> $RESULT

extension=${i#*.}

if [ -f generate_image.sh ]; then
rm generate_image.sh
fi

if [ $extension == "img" ]; then
run_check $here/btrfs-image -r $i test.img
else
run_check tar xJf $i
fi

if [ -x generate_image.sh ]; then
./generate_image.sh
fi

$here/btrfsck test.img >> $RESULT 2>&1
[ $? -eq 0 ] && _fail "btrfsck should have detected corruption"

run_check $here/btrfsck --repair test.img
run_check_no_fail $here/btrfsck --repair test.img
run_check $here/btrfsck test.img
done

Expand Down
Binary file not shown.