a84746b0492ce3b6c9a6fdcf1f9639b453e81419
[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 -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_flakey
53 _require_xfs_sysfs debug/log_recovery_delay
54
55 echo "Silence is golden."
56
57 _scratch_mkfs_xfs >/dev/null 2>&1
58 _scratch_mount
59
60 # Start a workload and shutdown the fs. The subsequent mount will require log
61 # recovery.
62 $FSSTRESS_PROG -n 9999 -p 2 -w -d $SCRATCH_MNT > /dev/null 2>&1 &
63 sleep 5
64 src/godown -f $SCRATCH_MNT
65 killall -q $FSSTRESS_PROG
66 wait
67 _scratch_unmount
68
69 # Initialize a dm-flakey device that will pass I/Os for 5s and fail thereafter.
70 _init_flakey
71 BLK_DEV_SIZE=`blockdev --getsz $SCRATCH_DEV`
72 FLAKEY_TABLE="0 $BLK_DEV_SIZE flakey $SCRATCH_DEV 0 5 180"
73 _load_flakey_table $FLAKEY_ALLOW_WRITES
74
75 # Set a 10s log recovery delay and mount the flakey device. This should allow
76 # initial writes to proceed (e.g., stale log block reset) and then let the
77 # flakey uptime timer expire such that I/Os will fail by the time log recovery
78 # starts.
79 echo 10 > /sys/fs/xfs/debug/log_recovery_delay
80
81 # The mount should fail due to dm-flakey. Note that this is dangerous on kernels
82 # without the xfs_buf log recovery race fixes.
83 _mount_flakey > /dev/null 2>&1
84
85 echo 0 > /sys/fs/xfs/debug/log_recovery_delay
86
87 _cleanup_flakey
88
89 # replay the log
90 _scratch_mount
91 _scratch_unmount
92
93 # success, all done
94 status=0
95 exit