common/inject: refactor helpers to use new errortag interface
[xfstests-dev.git] / tests / xfs / 141
1 #! /bin/bash
2 # FS QA Test No. 141
3 #
4 # Use the XFS log record CRC error injection mechanism to test torn writes to
5 # the log. The error injection mechanism writes an invalid CRC and shuts down
6 # the filesystem. The test verifies that a subsequent remount recovers the log
7 # and that the filesystem is consistent.
8 #
9 # Note that this test requires a DEBUG mode kernel.
10 #
11 #-----------------------------------------------------------------------
12 # Copyright (c) 2015 Red Hat, Inc. All Rights Reserved.
13 #
14 # This program is free software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License as
16 # published by the Free Software Foundation.
17 #
18 # This program is distributed in the hope that it would be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 # GNU General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write the Free Software Foundation,
25 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
26 #-----------------------------------------------------------------------
27 #
28
29 seq=`basename $0`
30 seqres=$RESULT_DIR/$seq
31 echo "QA output created by $seq"
32
33 here=`pwd`
34 tmp=/tmp/$$
35 status=1        # failure is the default!
36 trap "_cleanup; exit \$status" 0 1 2 3 15
37
38 _cleanup()
39 {
40         cd /
41         rm -f $tmp.*
42         $KILLALL_PROG -9 fsstress > /dev/null 2>&1
43         wait > /dev/null 2>&1
44 }
45
46 rm -f $seqres.full
47
48 # get standard environment, filters and checks
49 . ./common/rc
50 . ./common/inject
51
52 # real QA test starts here
53
54 # Modify as appropriate.
55 _supported_fs xfs
56 _supported_os Linux
57 _require_xfs_io_error_injection "log_bad_crc"
58 _require_scratch
59 _require_command "$KILLALL_PROG" killall
60
61 echo "Silence is golden."
62
63 _scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
64 _scratch_mount
65
66 sdev=$(_short_dev $SCRATCH_DEV)
67
68 for i in $(seq 1 5); do
69         # Enable error injection. Use a random bad crc factor up to 100
70         # (increase this value to run fsstress longer).
71         factor=$((RANDOM % 100 + 1))
72         echo iteration $i log_badcrc_factor: $factor >> $seqres.full 2>&1
73         _scratch_inject_error "log_bad_crc" "$factor"
74
75         # Run fsstress until the filesystem shuts down. It will shut down
76         # automatically when error injection triggers.
77         $FSSTRESS_PROG -d $SCRATCH_MNT -p 4 -n 999999 >> $seqres.full 2>&1
78
79         # Verify that we can remount the fs. Log recovery should handle the torn
80         # write.
81         _scratch_unmount
82         _scratch_mount || _fail "failed to mount"
83 done
84
85 # success, all done
86 status=0
87 exit