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