common/rc: factor out _scratch_xfs_[get|set]_sb_field
[xfstests-dev.git] / tests / xfs / 264
1 #! /bin/bash
2 # FS QA Test 264
3 #
4 # Test XFS EIO error handling configuration. Stop XFS from retrying
5 # to writeback forever when hit EIO.
6 #
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2016 Red Hat, Inc.  All Rights Reserved.
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 seq=`basename $0`
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
28
29 here=`pwd`
30 tmp=/tmp/$$
31 status=1        # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
33
34 _cleanup()
35 {
36         cd /
37         rm -f $tmp.*
38         _dmerror_cleanup
39 }
40
41 # get standard environment, filters and checks
42 . ./common/rc
43 . ./common/filter
44 . ./common/dmerror
45
46 # remove previous $seqres.full before test
47 rm -f $seqres.full
48
49 # real QA test starts here
50 _supported_fs xfs
51 _supported_os Linux
52 _require_scratch
53 _require_dm_target error
54 _require_fs_sysfs error/fail_at_unmount
55 _require_fs_sysfs error/metadata/EIO/max_retries
56 _require_fs_sysfs error/metadata/EIO/retry_timeout_seconds
57
58 _scratch_mkfs >> $seqres.full 2>&1
59 _dmerror_init
60
61 do_test()
62 {
63         local attr="$1"
64         local num=0
65
66         _dmerror_mount
67         _reset_xfs_sysfs_error_handling $DMERROR_DEV
68         # Disable fail_at_unmount before test EIO error handling
69         _set_fs_sysfs_attr $DMERROR_DEV error/fail_at_unmount 0
70         echo -n "error/fail_at_unmount="
71         _get_fs_sysfs_attr $DMERROR_DEV error/fail_at_unmount
72
73         _set_fs_sysfs_attr $DMERROR_DEV $attr 1
74         num=`_get_fs_sysfs_attr $DMERROR_DEV $attr`
75         echo "$attr=$num"
76         # _fail the test if we fail to set $attr to 1, because the test
77         # probably will hang in such case and block subsequent tests.
78         if [ "$num" != "1" ]; then
79                 _fail "Failed to set $attr: 1"
80         fi
81
82         # start a metadata-intensive workload, but no data allocation operation.
83         # Because uncompleted new space allocation I/Os may cause XFS to shutdown
84         # after loading error table.
85         $FSSTRESS_PROG -z -n 5000 -p 10 \
86                        -f creat=10 \
87                        -f resvsp=1 \
88                        -f truncate=1 \
89                        -f punch=1 \
90                        -f chown=5 \
91                        -f mkdir=5 \
92                        -f rmdir=1 \
93                        -f mknod=1 \
94                        -f unlink=1 \
95                        -f symlink=1 \
96                        -f rename=1 \
97                        -d $SCRATCH_MNT/fsstress >> $seqres.full 2>&1
98
99         # Loading error table without "--nolockfs" option. Because "--nolockfs"
100         # won't freeze fs, then some running I/Os may cause XFS to shutdown
101         # prematurely. That's not what we want to test.
102         _dmerror_load_error_table lockfs
103         _dmerror_unmount
104
105         # Mount again to replay log after loading working table, so we have a
106         # consistent XFS after test.
107         _dmerror_load_working_table
108         _dmerror_mount
109         _dmerror_unmount
110 }
111
112 #### Test EIO/max_retries ####
113 # Set EIO/max_retries a limited number(>-1), then even if fail_at_unmount=0,
114 # the test won't hang.
115 echo "=== Test EIO/max_retries ==="
116 do_test error/metadata/EIO/max_retries
117
118 #### Test EIO/retry_timeout_seconds ####
119 # Set EIO/retry_timeout_seconds to a limited number(>0), then even if
120 # fail_at_unmount=0, the test won't hang.
121 echo "=== Test EIO/retry_timeout_seconds ==="
122 do_test error/metadata/EIO/retry_timeout_seconds
123
124 # success, all done
125 status=0
126 exit