generic: test MADV_POPULATE_READ with IO errors
[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 . ./common/preamble
11 _begin_fstest aio dangerous enospc rw stress recoveryloop
12
13 fio_config=$tmp.fio
14
15 # Import common functions.
16 . ./common/filter
17 . ./common/fail_make_request
18 _supported_fs generic
19 _require_scratch
20 _require_block_device $SCRATCH_DEV
21 _require_fail_make_request
22
23 # Override the default cleanup function.
24 _cleanup()
25 {
26         kill $fs_pid $fio_pid &> /dev/null
27         _disallow_fail_make_request
28         cd /
29         rm -r -f $tmp.*
30 }
31
32 RUN_TIME=$((20+10*$TIME_FACTOR))
33 test -n "$SOAK_DURATION" && RUN_TIME="$SOAK_DURATION"
34 NUM_JOBS=$((4*LOAD_FACTOR))
35 BLK_DEV_SIZE=`blockdev --getsz $SCRATCH_DEV`
36 FILE_SIZE=$((BLK_DEV_SIZE * 512))
37
38 # Don't fail the test just because fio or fsstress dump cores
39 ulimit -c 0
40
41 cat >$fio_config <<EOF
42 ###########
43 # $seq test's fio activity
44 # Filenames derived from jobsname and jobid like follows:
45 # ${JOB_NAME}.${JOB_ID}.${ITERATION_ID}
46 [global]
47 ioengine=libaio
48 bs=4k
49 directory=${SCRATCH_MNT}
50 filesize=${FILE_SIZE}
51 size=9999T
52 continue_on_error=write
53 ignore_error=EIO,ENOSPC:EIO
54 error_dump=0
55
56 [stress_dio_aio_activity]
57 create_on_open=1
58 fallocate=none
59 iodepth=128*${LOAD_FACTOR}
60 direct=1
61 buffered=0
62 numjobs=${NUM_JOBS}
63 rw=randwrite
64 runtime=40+${RUN_TIME}
65 time_based
66
67 [stress_mmap_activity]
68 ioengine=mmap
69 create_on_open=0
70 fallocate=1
71 fdatasync=40960
72 filesize=8M
73 size=9999T
74 numjobs=${NUM_JOBS}
75 rw=randwrite
76 runtime=40+${RUN_TIME}
77 time_based
78
79 EOF
80
81 _require_fio $fio_config
82
83 # Disable all sync operations to get higher load
84 FSSTRESS_AVOID="$FSSTRESS_AVOID -ffsync=0 -fsync=0 -ffdatasync=0 -f setattr=1"
85
86 _workout()
87 {
88         out=$SCRATCH_MNT/fsstress.$$
89         args=`_scale_fsstress_args -p 1 -n999999999 -f setattr=0 $FSSTRESS_AVOID -d $out`
90         echo ""
91         echo "Start fsstress.."
92         echo ""
93         echo "fsstress $args" >> $seqres.full
94         $FSSTRESS_PROG $args > /dev/null 2>&1 &
95         fs_pid=$!
96         echo "Start fio.."
97         cat $fio_config >>  $seqres.full
98         $FIO_PROG $fio_config >> $seqres.full 2>&1 &
99         fio_pid=$!
100
101         # Let's it work for awhile, and force device failure
102         sleep $RUN_TIME
103         _start_fail_scratch_dev
104         # After device turns in to failed state filesystem may yet not know about
105         # that so buffered write(2) may succeed, but any integrity operations
106         # such as (sync, fsync, fdatasync, direct-io) should fail.
107         dd if=/dev/zero of=$SCRATCH_MNT/touch_failed_filesystem count=1 bs=4k conv=fsync \
108             >> $seqres.full 2>&1 && \
109             _fail "failed: still able to perform integrity fsync on $SCRATCH_MNT"
110
111         kill $fs_pid &> /dev/null
112         wait $fs_pid
113         wait $fio_pid
114         unset fs_pid
115         unset fio_pid
116
117         # We expect that broken FS still can be umounted
118         run_check _scratch_unmount
119         # Once filesystem was umounted no one is able to write to block device
120         # It is now safe to bring device back to normal state
121         _stop_fail_scratch_dev
122
123         # In order to check that filesystem is able to recover journal on mount(2)
124         # perform mount/umount, after that all errors should be fixed
125         _scratch_mount
126         run_check _scratch_unmount
127 }
128
129 # real QA test starts here
130
131 _scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
132 _scratch_mount
133 _allow_fail_make_request
134 _workout
135 status=$?
136 exit