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