f38743c3098272f21321b2be618c9d9a1d972d54
[xfstests-dev.git] / tests / xfs / 051
1 #! /bin/bash
2 # FS QA Test No. 051
3 #
4 # Simulate a buffer use after free race in XFS log recovery. The race triggers
5 # on I/O failures during log recovery. Note that this test is dangerous as it
6 # causes BUG() errors or a panic.
7 #
8 #-----------------------------------------------------------------------
9 # Copyright (c) 2013 Oracle, Inc.  All Rights Reserved.
10 #
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License as
13 # published by the Free Software Foundation.
14 #
15 # This program is distributed in the hope that it would be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write the Free Software Foundation,
22 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23 #-----------------------------------------------------------------------
24 #
25
26 seq=`basename $0`
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=1        # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 _cleanup()
36 {
37         cd /
38         rm -f $tmp.*
39         $KILLALL_PROG -9 $FSSTRESS_PROG > /dev/null 2>&1
40         _scratch_unmount > /dev/null 2>&1
41 }
42
43 # get standard environment, filters and checks
44 . ./common/rc
45 . ./common/dmflakey
46
47 # Modify as appropriate.
48 _supported_fs xfs
49 _supported_os Linux
50
51 _require_scratch
52 _require_dm_target flakey
53 _require_xfs_sysfs debug/log_recovery_delay
54 _require_command "$KILLALL_PROG" killall
55
56 echo "Silence is golden."
57
58 _scratch_mkfs_xfs >/dev/null 2>&1
59 _scratch_mount
60
61 # Start a workload and shutdown the fs. The subsequent mount will require log
62 # recovery.
63 $FSSTRESS_PROG -n 9999 -p 2 -w -d $SCRATCH_MNT > /dev/null 2>&1 &
64 sleep 5
65 src/godown -f $SCRATCH_MNT
66 $KILLALL_PROG -q $FSSTRESS_PROG
67 wait
68 _scratch_unmount
69
70 # Initialize a dm-flakey device that will pass I/Os for 5s and fail thereafter.
71 _init_flakey
72 BLK_DEV_SIZE=`blockdev --getsz $SCRATCH_DEV`
73 FLAKEY_TABLE="0 $BLK_DEV_SIZE flakey $SCRATCH_DEV 0 5 180"
74 _load_flakey_table $FLAKEY_ALLOW_WRITES
75
76 # Set a 10s log recovery delay and mount the flakey device. This should allow
77 # initial writes to proceed (e.g., stale log block reset) and then let the
78 # flakey uptime timer expire such that I/Os will fail by the time log recovery
79 # starts.
80 echo 10 > /sys/fs/xfs/debug/log_recovery_delay
81
82 # The mount should fail due to dm-flakey. Note that this is dangerous on kernels
83 # without the xfs_buf log recovery race fixes.
84 _mount_flakey > /dev/null 2>&1
85
86 echo 0 > /sys/fs/xfs/debug/log_recovery_delay
87
88 _cleanup_flakey
89
90 # replay the log
91 _scratch_mount
92 _scratch_unmount
93
94 # success, all done
95 status=0
96 exit