generic: test deadlock on O_DIRECT|O_DSYNC
[xfstests-dev.git] / tests / generic / 299
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3
4 #
5 # FSQA Test No. 299
6 #
7 # AIO/DIO stress test
8 # Run random AIO/DIO activity and fallocate/truncate simultaneously
9 # Test will operate on huge sparsed files so ENOSPC is expected.
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 fio_config=$tmp.fio
18 status=1        # failure is the default!
19 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
20
21 # get standard environment, filters and checks
22 . ./common/rc
23 . ./common/filter
24
25 # real QA test starts here
26 _supported_fs generic
27 _supported_os Linux
28 _require_test
29 _require_scratch
30 _require_odirect
31 _require_block_device $SCRATCH_DEV
32
33 NUM_JOBS=$((4*LOAD_FACTOR))
34 BLK_DEV_SIZE=`blockdev --getsz $SCRATCH_DEV`
35 FILE_SIZE=$((BLK_DEV_SIZE * 512))
36
37 max_file_size=$(_get_max_file_size)
38 if [ $max_file_size -lt $FILE_SIZE ]; then
39         FILE_SIZE=$max_file_size
40 fi
41
42 cat >$fio_config <<EOF
43 ###########
44 # $seq test fio activity
45 # Filenames derived from jobsname and jobid like follows:
46 # ${JOB_NAME}.${JOB_ID}.${ITERATION_ID}
47 [global]
48 ioengine=libaio
49 bs=128k
50 directory=${SCRATCH_MNT}
51 filesize=${FILE_SIZE}
52 size=999G
53 iodepth=128*${LOAD_FACTOR}
54 continue_on_error=write
55 ignore_error=,ENOSPC
56 error_dump=0
57 create_on_open=1
58 fallocate=none
59 exitall=1
60
61 ## Perform direct aio, to files which may be truncated
62 ## by external task
63 [direct_aio]
64 direct=1
65 buffered=0
66 numjobs=${NUM_JOBS}
67 rw=randwrite
68 runtime=100*${TIME_FACTOR}
69 time_based
70
71 # Perform direct aio and verify data
72 # This test case should check use-after-free issues
73 [aio-dio-verifier]
74 numjobs=1
75 verify=crc32c-intel
76 verify_fatal=1
77 verify_dump=1
78 verify_backlog=1024
79 verify_async=4
80 verifysort=1
81 direct=1
82 bs=4k
83 rw=randrw
84 filename=aio-dio-verifier
85
86 # Perform buffered aio and verify data
87 # This test case should check use-after-free issues
88 [buffered-aio-verifier]
89 numjobs=1
90 verify=crc32c-intel
91 verify_fatal=1
92 verify_dump=1
93 verify_backlog=1024
94 verify_async=4
95 verifysort=1
96 direct=0
97 buffered=1
98 bs=4k
99 rw=randrw
100 filename=buffered-aio-verifier
101 EOF
102
103 rm -f $seqres.full
104
105 _require_fio $fio_config
106 _require_xfs_io_command "falloc"
107
108 _workout()
109 {
110         echo ""
111         echo "Run fio with random aio-dio pattern"
112         echo ""
113         cat $fio_config >>  $seqres.full
114         run_check $FIO_PROG $fio_config &
115         pid=$!
116         echo "Start fallocate/truncate loop"
117
118         for ((i=0; ; i++))
119         do
120             for ((k=1; k <= NUM_JOBS; k++))
121             do
122                 $XFS_IO_PROG -f -c "falloc 0 $FILE_SIZE" \
123                         $SCRATCH_MNT/direct_aio.$k.0 >> $seqres.full 2>&1
124             done
125             for ((k=1; k <= NUM_JOBS; k++))
126             do
127                 $XFS_IO_PROG -c "truncate  0" \
128                         $SCRATCH_MNT/direct_aio.$k.0 >> $seqres.full 2>&1
129             done
130             # Following like will check that pid is still run.
131             # Once fio exit we can stop fallocate/truncate loop
132             pgrep -f "$FIO_PROG" > /dev/null 2>&1 || break
133         done
134         wait $pid
135 }
136
137 _scratch_mkfs >> $seqres.full 2>&1
138 _scratch_mount
139
140 if ! _workout; then
141         _scratch_unmount 2>/dev/null
142         exit
143 fi
144
145 if ! _scratch_unmount; then
146         echo "failed to umount"
147         status=1
148         exit
149 fi
150 status=0
151 exit