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