fsx/fsstress: round blocksize properly
[xfstests-dev.git] / tests / generic / 019
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3
4 #
5 # FSQA Test No. generic/019
6 #
7 # Run fsstress and fio(dio/aio and mmap) and simulate disk failure
8 # check filesystem consistency at the end.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 fio_config=$tmp.fio
17 status=1        # failure is the default!
18
19 # get standard environment, filters and checks
20 . ./common/rc
21 . ./common/filter
22 _supported_fs generic
23 _require_scratch
24 _require_block_device $SCRATCH_DEV
25 _require_fail_make_request
26
27 SYSFS_BDEV=`_sysfs_dev $SCRATCH_DEV`
28
29 allow_fail_make_request()
30 {
31     echo "Allow global fail_make_request feature"
32     echo 100 > $DEBUGFS_MNT/fail_make_request/probability
33     echo 9999999 > $DEBUGFS_MNT/fail_make_request/times
34     echo 0 >  /sys/kernel/debug/fail_make_request/verbose
35 }
36
37 disallow_fail_make_request()
38 {
39     echo "Disallow global fail_make_request feature"
40     echo 0 > $DEBUGFS_MNT/fail_make_request/probability
41     echo 0 > $DEBUGFS_MNT/fail_make_request/times
42 }
43
44 start_fail_scratch_dev()
45 {
46     echo "Force SCRATCH_DEV device failure"
47     echo " echo 1 > $SYSFS_BDEV/make-it-fail" >> $seqres.full
48     echo 1 > $SYSFS_BDEV/make-it-fail
49 }
50
51 stop_fail_scratch_dev()
52 {
53     echo "Make SCRATCH_DEV device operable again"
54     echo " echo 0 > $SYSFS_BDEV/make-it-fail" >> $seqres.full
55     echo 0 > $SYSFS_BDEV/make-it-fail
56 }
57
58 _cleanup()
59 {
60     poweron_scratch_dev
61     disallow_fail_make_request
62     rm -f $tmp.*
63 }
64 trap "_cleanup; exit \$status" 1 2 3 15
65
66 RUN_TIME=$((20+10*$TIME_FACTOR))
67 NUM_JOBS=$((4*LOAD_FACTOR))
68 BLK_DEV_SIZE=`blockdev --getsz $SCRATCH_DEV`
69 FILE_SIZE=$((BLK_DEV_SIZE * 512))
70
71 cat >$fio_config <<EOF
72 ###########
73 # $seq test's fio activity
74 # Filenames derived from jobsname and jobid like follows:
75 # ${JOB_NAME}.${JOB_ID}.${ITERATION_ID}
76 [global]
77 ioengine=libaio
78 bs=4k
79 directory=${SCRATCH_MNT}
80 filesize=${FILE_SIZE}
81 size=9999T
82 continue_on_error=write
83 ignore_error=EIO,ENOSPC:EIO
84 error_dump=0
85
86 [stress_dio_aio_activity]
87 create_on_open=1
88 fallocate=none
89 iodepth=128*${LOAD_FACTOR}
90 direct=1
91 buffered=0
92 numjobs=${NUM_JOBS}
93 rw=randwrite
94 runtime=40+${RUN_TIME}
95 time_based
96
97 [stress_mmap_activity]
98 ioengine=mmap
99 create_on_open=0
100 fallocate=1
101 fdatasync=40960
102 filesize=8M
103 size=9999T
104 numjobs=${NUM_JOBS}
105 rw=randwrite
106 runtime=40+${RUN_TIME}
107 time_based
108
109 EOF
110
111 _require_fio $fio_config
112
113 # Disable all sync operations to get higher load
114 FSSTRESS_AVOID="$FSSTRESS_AVOID -ffsync=0 -fsync=0 -ffdatasync=0 -f setattr=1"
115
116 _workout()
117 {
118         out=$SCRATCH_MNT/fsstress.$$
119         args=`_scale_fsstress_args -p 1 -n999999999 -f setattr=0 $FSSTRESS_AVOID -d $out`
120         echo ""
121         echo "Start fsstress.."
122         echo ""
123         echo "fsstress $args" >> $seqres.full
124         $FSSTRESS_PROG $args > /dev/null 2>&1 &
125         fs_pid=$!
126         echo "Start fio.."
127         cat $fio_config >>  $seqres.full
128         $FIO_PROG $fio_config >> $seqres.full 2>&1 &
129         fio_pid=$!
130
131         # Let's it work for awhile, and force device failure
132         sleep $RUN_TIME
133         start_fail_scratch_dev
134         # After device turns in to failed state filesystem may yet not know about
135         # that so buffered write(2) may succeed, but any integrity operations
136         # such as (sync, fsync, fdatasync, direct-io) should fail.
137         dd if=/dev/zero of=$SCRATCH_MNT/touch_failed_filesystem count=1 bs=4k conv=fsync \
138             >> $seqres.full 2>&1 && \
139             _fail "failed: still able to perform integrity fsync on $SCRATCH_MNT"
140
141         kill $fs_pid &> /dev/null
142         wait $fs_pid
143         wait $fio_pid
144
145         # We expect that broken FS still can be umounted
146         run_check _scratch_unmount
147         # Once filesystem was umounted no one is able to write to block device
148         # It is now safe to bring device back to normal state
149         stop_fail_scratch_dev
150
151         # In order to check that filesystem is able to recover journal on mount(2)
152         # perform mount/umount, after that all errors should be fixed
153         _scratch_mount
154         run_check _scratch_unmount
155 }
156
157 # real QA test starts here
158
159 rm -f $seqres.full
160 _scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
161 _scratch_mount
162 allow_fail_make_request
163 _workout
164 status=$?
165 disallow_fail_make_request
166 exit