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.
|
|
|
|
#
|
|
|
|
|
2015-04-03 07:01:12 +00:00
|
|
|
unset TOP
|
2014-12-25 01:32:11 +00:00
|
|
|
unset LANG
|
|
|
|
LANG=C
|
2015-05-21 16:48:55 +00:00
|
|
|
SCRIPT_DIR=$(dirname $(readlink -f $0))
|
|
|
|
TOP=$(readlink -f $SCRIPT_DIR/../)
|
2014-12-25 01:32:11 +00:00
|
|
|
TEST_DEV=${TEST_DEV:-}
|
2015-04-03 07:01:12 +00:00
|
|
|
TEST_MNT=${TEST_MNT:-$TOP/tests/mnt}
|
|
|
|
RESULTS="$TOP/tests/fsck-tests-results.txt"
|
2014-12-25 01:32:11 +00:00
|
|
|
|
2015-04-03 07:01:12 +00:00
|
|
|
source $TOP/tests/common
|
2014-12-25 01:32:11 +00:00
|
|
|
|
2015-04-03 07:01:12 +00:00
|
|
|
# Allow child test to use $TOP and $RESULTS
|
|
|
|
export TOP
|
|
|
|
export RESULTS
|
2014-12-25 01:32:11 +00:00
|
|
|
# For custom script needs to verfiy recovery
|
|
|
|
export TEST_MNT
|
|
|
|
export LANG
|
2014-12-12 14:49:26 +00:00
|
|
|
|
2015-04-03 07:01:12 +00:00
|
|
|
rm -f $RESULTS
|
2014-12-25 01:32:11 +00:00
|
|
|
mkdir -p $TEST_MNT || _fail "unable to create mount point on $TEST_MNT"
|
2014-05-29 10:01:44 +00:00
|
|
|
|
|
|
|
# test rely on corrupting blocks tool
|
2014-12-12 14:49:26 +00:00
|
|
|
check_prereq btrfs-corrupt-block
|
|
|
|
check_prereq btrfs-image
|
|
|
|
check_prereq btrfs
|
2013-09-09 20:41:58 +00:00
|
|
|
|
2014-12-25 01:32:11 +00:00
|
|
|
# Each dir contains one type of error for btrfsck test.
|
|
|
|
# Each dir must be one of the following 2 types:
|
|
|
|
# 1) Only btrfs-image dump
|
|
|
|
# Only contains one or several btrfs-image dumps (.img)
|
|
|
|
# Each image will be tested by generic test routine
|
|
|
|
# (btrfsck --repair and btrfsck).
|
|
|
|
# This is for case that btree-healthy images.
|
|
|
|
# 2) Custom test script
|
|
|
|
# This dir contains test.sh which will do custom image
|
|
|
|
# generation/check/verification.
|
|
|
|
# This is for case btrfs-image can't dump or case needs extra
|
|
|
|
# check/verify
|
|
|
|
|
2015-04-03 07:01:12 +00:00
|
|
|
for i in $(find $TOP/tests/fsck-tests -maxdepth 1 -mindepth 1 -type d | sort)
|
2013-09-09 20:41:58 +00:00
|
|
|
do
|
2015-01-14 17:32:17 +00:00
|
|
|
echo " [TEST] $(basename $i)"
|
2014-12-25 01:32:11 +00:00
|
|
|
cd $i
|
2015-05-21 13:04:29 +00:00
|
|
|
echo "=== Entering $i" >> $RESULTS
|
2014-12-25 01:32:11 +00:00
|
|
|
if [ -x test.sh ]; then
|
|
|
|
# Type 2
|
|
|
|
./test.sh
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
_fail "test failed for case $(basename $i)"
|
|
|
|
fi
|
Btrfs-progs: check, ability to detect and fix outdated snapshot root items
This change adds code to detect and fix the issue introduced in the kernel
release 3.17, where creation of read-only snapshots lead to a corrupted
filesystem if they were created at a moment when the source subvolume/snapshot
had orphan items. The issue was that the on-disk root items became incorrect,
referring to the pre orphan cleanup root node instead of the post orphan
cleanup root node.
A test filesystem can be generated with the test case recently submitted for
xfstests/fstests, which is essencially the following (bash script):
workout()
{
ops=$1
procs=$2
num_snapshots=$3
_scratch_mkfs >> $seqres.full 2>&1
_scratch_mount
snapshot_cmd="$BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT"
snapshot_cmd="$snapshot_cmd $SCRATCH_MNT/snap_\`date +'%H_%M_%S_%N'\`"
run_check $FSSTRESS_PROG -p $procs \
-x "$snapshot_cmd" -X $num_snapshots -d $SCRATCH_MNT -n $ops
}
ops=10000
procs=4
snapshots=500
workout $ops $procs $snapshots
Example of btrfsck's (btrfs check) behaviour against such filesystem:
$ btrfsck /dev/loop0
root item for root 311, current bytenr 44630016, current gen 60, current level 1, new bytenr 44957696, new gen 61, new level 1
root item for root 1480, current bytenr 1003569152, current gen 1271, current level 1, new bytenr 1004175360, new gen 1272, new level 1
root item for root 1509, current bytenr 1037434880, current gen 1300, current level 1, new bytenr 1038467072, new gen 1301, new level 1
root item for root 1562, current bytenr 33636352, current gen 1354, current level 1, new bytenr 34455552, new gen 1355, new level 1
root item for root 3094, current bytenr 1011712000, current gen 2935, current level 1, new bytenr 1008484352, new gen 2936, new level 1
root item for root 3716, current bytenr 80805888, current gen 3578, current level 1, new bytenr 73515008, new gen 3579, new level 1
root item for root 4085, current bytenr 714031104, current gen 3958, current level 1, new bytenr 716816384, new gen 3959, new level 1
Found 7 roots with an outdated root item.
Please run a filesystem check with the option --repair to fix them.
$ echo $?
1
$ btrfsck --repair /dev/loop0
enabling repair mode
fixing root item for root 311, current bytenr 44630016, current gen 60, current level 1, new bytenr 44957696, new gen 61, new level 1
fixing root item for root 1480, current bytenr 1003569152, current gen 1271, current level 1, new bytenr 1004175360, new gen 1272, new level 1
fixing root item for root 1509, current bytenr 1037434880, current gen 1300, current level 1, new bytenr 1038467072, new gen 1301, new level 1
fixing root item for root 1562, current bytenr 33636352, current gen 1354, current level 1, new bytenr 34455552, new gen 1355, new level 1
fixing root item for root 3094, current bytenr 1011712000, current gen 2935, current level 1, new bytenr 1008484352, new gen 2936, new level 1
fixing root item for root 3716, current bytenr 80805888, current gen 3578, current level 1, new bytenr 73515008, new gen 3579, new level 1
fixing root item for root 4085, current bytenr 714031104, current gen 3958, current level 1, new bytenr 716816384, new gen 3959, new level 1
Fixed 7 roots.
Checking filesystem on /dev/loop0
UUID: 2186e9b9-c977-4a35-9c7b-69c6609d4620
checking extents
checking free space cache
cache and super generation don't match, space cache will be invalidated
checking fs roots
checking csums
checking root refs
found 618537000 bytes used err is 0
total csum bytes: 130824
total tree bytes: 601620480
total fs tree bytes: 580288512
total extent tree bytes: 18464768
btree space waste bytes: 136939144
file data blocks allocated: 34150318080
referenced 27815415808
Btrfs v3.17-rc3-2-gbbe1dd8
$ echo $?
0
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-10-17 17:20:08 +00:00
|
|
|
else
|
2014-12-25 01:32:11 +00:00
|
|
|
# Type 1
|
|
|
|
check_all_images `pwd`
|
Btrfs-progs: check, ability to detect and fix outdated snapshot root items
This change adds code to detect and fix the issue introduced in the kernel
release 3.17, where creation of read-only snapshots lead to a corrupted
filesystem if they were created at a moment when the source subvolume/snapshot
had orphan items. The issue was that the on-disk root items became incorrect,
referring to the pre orphan cleanup root node instead of the post orphan
cleanup root node.
A test filesystem can be generated with the test case recently submitted for
xfstests/fstests, which is essencially the following (bash script):
workout()
{
ops=$1
procs=$2
num_snapshots=$3
_scratch_mkfs >> $seqres.full 2>&1
_scratch_mount
snapshot_cmd="$BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT"
snapshot_cmd="$snapshot_cmd $SCRATCH_MNT/snap_\`date +'%H_%M_%S_%N'\`"
run_check $FSSTRESS_PROG -p $procs \
-x "$snapshot_cmd" -X $num_snapshots -d $SCRATCH_MNT -n $ops
}
ops=10000
procs=4
snapshots=500
workout $ops $procs $snapshots
Example of btrfsck's (btrfs check) behaviour against such filesystem:
$ btrfsck /dev/loop0
root item for root 311, current bytenr 44630016, current gen 60, current level 1, new bytenr 44957696, new gen 61, new level 1
root item for root 1480, current bytenr 1003569152, current gen 1271, current level 1, new bytenr 1004175360, new gen 1272, new level 1
root item for root 1509, current bytenr 1037434880, current gen 1300, current level 1, new bytenr 1038467072, new gen 1301, new level 1
root item for root 1562, current bytenr 33636352, current gen 1354, current level 1, new bytenr 34455552, new gen 1355, new level 1
root item for root 3094, current bytenr 1011712000, current gen 2935, current level 1, new bytenr 1008484352, new gen 2936, new level 1
root item for root 3716, current bytenr 80805888, current gen 3578, current level 1, new bytenr 73515008, new gen 3579, new level 1
root item for root 4085, current bytenr 714031104, current gen 3958, current level 1, new bytenr 716816384, new gen 3959, new level 1
Found 7 roots with an outdated root item.
Please run a filesystem check with the option --repair to fix them.
$ echo $?
1
$ btrfsck --repair /dev/loop0
enabling repair mode
fixing root item for root 311, current bytenr 44630016, current gen 60, current level 1, new bytenr 44957696, new gen 61, new level 1
fixing root item for root 1480, current bytenr 1003569152, current gen 1271, current level 1, new bytenr 1004175360, new gen 1272, new level 1
fixing root item for root 1509, current bytenr 1037434880, current gen 1300, current level 1, new bytenr 1038467072, new gen 1301, new level 1
fixing root item for root 1562, current bytenr 33636352, current gen 1354, current level 1, new bytenr 34455552, new gen 1355, new level 1
fixing root item for root 3094, current bytenr 1011712000, current gen 2935, current level 1, new bytenr 1008484352, new gen 2936, new level 1
fixing root item for root 3716, current bytenr 80805888, current gen 3578, current level 1, new bytenr 73515008, new gen 3579, new level 1
fixing root item for root 4085, current bytenr 714031104, current gen 3958, current level 1, new bytenr 716816384, new gen 3959, new level 1
Fixed 7 roots.
Checking filesystem on /dev/loop0
UUID: 2186e9b9-c977-4a35-9c7b-69c6609d4620
checking extents
checking free space cache
cache and super generation don't match, space cache will be invalidated
checking fs roots
checking csums
checking root refs
found 618537000 bytes used err is 0
total csum bytes: 130824
total tree bytes: 601620480
total fs tree bytes: 580288512
total extent tree bytes: 18464768
btree space waste bytes: 136939144
file data blocks allocated: 34150318080
referenced 27815415808
Btrfs v3.17-rc3-2-gbbe1dd8
$ echo $?
0
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-10-17 17:20:08 +00:00
|
|
|
fi
|
2015-04-03 07:01:12 +00:00
|
|
|
cd $TOP
|
2013-09-09 20:41:58 +00:00
|
|
|
done
|