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