xfs: Check for extent overflow when trivally adding a new extent
[xfstests-dev.git] / tests / xfs / 051
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2013 Oracle, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 051
6 #
7 # Simulate a buffer use after free race in XFS log recovery. The race triggers
8 # on I/O failures during log recovery. Note that this test is dangerous as it
9 # causes BUG() errors or a panic.
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
15 here=`pwd`
16 tmp=/tmp/$$
17 status=1        # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
19
20 _cleanup()
21 {
22         cd /
23         rm -f $tmp.*
24         $KILLALL_PROG -9 $FSSTRESS_PROG > /dev/null 2>&1
25         _scratch_unmount > /dev/null 2>&1
26 }
27
28 # get standard environment, filters and checks
29 . ./common/rc
30 . ./common/dmflakey
31
32 # Modify as appropriate.
33 _supported_fs xfs
34
35 _require_scratch
36 _require_dm_target flakey
37 _require_xfs_sysfs debug/log_recovery_delay
38 _require_command "$KILLALL_PROG" killall
39
40 echo "Silence is golden."
41
42 _scratch_mkfs_xfs >/dev/null 2>&1
43 _scratch_mount
44
45 # Start a workload and shutdown the fs. The subsequent mount will require log
46 # recovery.
47 $FSSTRESS_PROG -n 9999 -p 2 -w -d $SCRATCH_MNT > /dev/null 2>&1 &
48 sleep 5
49 _scratch_shutdown -f
50 $KILLALL_PROG -q $FSSTRESS_PROG
51 wait
52 _scratch_unmount
53
54 # Initialize a dm-flakey device that will pass I/Os for 5s and fail thereafter.
55 _init_flakey
56 BLK_DEV_SIZE=`blockdev --getsz $SCRATCH_DEV`
57 FLAKEY_TABLE="0 $BLK_DEV_SIZE flakey $SCRATCH_DEV 0 5 180"
58 _load_flakey_table $FLAKEY_ALLOW_WRITES
59
60 # Set a 10s log recovery delay and mount the flakey device. This should allow
61 # initial writes to proceed (e.g., stale log block reset) and then let the
62 # flakey uptime timer expire such that I/Os will fail by the time log recovery
63 # starts.
64 echo 10 > /sys/fs/xfs/debug/log_recovery_delay
65
66 # The mount should fail due to dm-flakey. Note that this is dangerous on kernels
67 # without the xfs_buf log recovery race fixes.
68 _mount_flakey > /dev/null 2>&1
69
70 echo 0 > /sys/fs/xfs/debug/log_recovery_delay
71
72 _cleanup_flakey
73
74 # replay the log
75 _scratch_mount
76 _scratch_unmount
77
78 # success, all done
79 status=0
80 exit