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