fstests: move test group info to test files
[xfstests-dev.git] / tests / xfs / 438
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Huawei Technologies Co., Ltd. All Rights Reserved.
4 #
5 # FS QA Test No. 438
6 #
7 # Test for XFS umount hang problem caused by the unceasing push
8 # of dquot log item in AIL. Because xfs_qm_dqflush_done() will
9 # not be invoked, so each time xfsaild initiates the push,
10 # the push will return early after checking xfs_dqflock_nowait().
11 #
12 # xfs_qm_dqflush_done() should be invoked by xfs_buf_do_callbacks().
13 # However after the first write and the retried write of dquota buffer
14 # get the same IO error, XFS will let xfsaild to restart the write and
15 # xfs_buf_do_callbacks() will not be inovked.
16 #
17 # This test emulates the write error by using dm-flakey. The log
18 # area of the XFS filesystem is excluded from the range covered by
19 # dm-flakey, so the XFS will not be shutdown prematurely.
20 #
21 # Fixed by upstream commit 373b058 ("xfs: Properly retry failed dquot
22 # items in case of error during buffer writeback")
23 . ./common/preamble
24 _begin_fstest auto quick quota
25
26 # Override the default cleanup function.
27 _cleanup()
28 {
29         [ -z "${interval}" ] || \
30                 sysctl -w fs.xfs.xfssyncd_centisecs=${interval} >/dev/null 2>&1
31         cd /
32         rm -f $tmp.*
33         _unmount_flakey >/dev/null 2>&1
34         _cleanup_flakey > /dev/null 2>&1
35 }
36
37 # inject IO write error for the XFS filesystem except its log section
38 make_xfs_scratch_flakey_table()
39 {
40         local tgt=flakey
41         local opt="0 1 1 error_writes"
42         local dev=${SCRATCH_DEV}
43         local dev_sz=$(blockdev --getsz $dev)
44
45         # If using an external log device, just making the writing of
46         # entire data/metadata area fail forever.
47         if [ "${USE_EXTERNAL}" = "yes" -a ! -z "$SCRATCH_LOGDEV" ]; then
48                 echo "0 ${dev_sz} $tgt $dev 0 $opt"
49                 return
50         fi
51
52         local blk_sz=$(_scratch_xfs_get_sb_field blocksize)
53         local log_ofs=$(_scratch_xfs_get_sb_field logstart)
54         local log_sz=$(_scratch_xfs_get_sb_field logblocks)
55         local table=""
56         local ofs=0
57         local sz
58
59         log_ofs=$(_scratch_xfs_db -r -c "convert fsb ${log_ofs} bb" | \
60                           $AWK_PROG '{gsub("[()]", "", $2); print $2}')
61         let "log_sz *= blk_sz / 512"
62
63         # Add a flakey target for the area before the log section
64         # to make the data/metadata write fail forever
65         if [ "$ofs" -lt "${log_ofs}" ]; then
66                 let "sz = log_ofs - ofs"
67                 table="$ofs $sz $tgt $dev $ofs $opt"
68         fi
69
70         # Add a linear target for the log section, so the log write
71         # will work normally
72         table="$table\n${log_ofs} ${log_sz} linear $dev ${log_ofs}"
73
74         # Add a flakey target for the area after the log section
75         # to make the data/metadata write fail forever
76         let "ofs = log_ofs + log_sz"
77         if [ "$ofs" -lt "${dev_sz}" ]; then
78                 let "sz = dev_sz - ofs"
79                 table="$table\n$ofs $sz $tgt $dev $ofs $opt"
80         fi
81
82         echo -e $table
83 }
84
85 # Import common functions.
86 . ./common/dmflakey
87 . ./common/quota
88
89 _supported_fs xfs
90
91 # due to the injection of write IO error, the fs will be inconsistent
92 _require_scratch_nocheck
93 _require_flakey_with_error_writes
94 _require_user
95 _require_xfs_quota
96 _require_freeze
97
98 echo "Silence is golden"
99
100 _scratch_mkfs > $seqres.full 2>&1
101
102 # no error will be injected
103 _init_flakey
104 $DMSETUP_PROG info >> $seqres.full
105 $DMSETUP_PROG table >> $seqres.full
106
107 # save the old value for _cleanup()
108 interval=$(sysctl -n fs.xfs.xfssyncd_centisecs 2>/dev/null)
109 # shorten the time waiting for the push of ail items
110 sysctl -w fs.xfs.xfssyncd_centisecs=100 >> $seqres.full 2>&1
111
112 _qmount_option "usrquota"
113 _mount_flakey
114
115 # We need to set the quota limitation twice, and inject the write error
116 # after the second setting. If we try to inject the write error after
117 # the first setting, the initialization of the dquota buffer will get
118 # IO error and also be retried, and during the umount process the
119 # write will be ended, and xfs_qm_dqflush_done() will be inovked, and
120 # the umount will exit normally.
121 $XFS_QUOTA_PROG -x -c "limit -u isoft=500 $qa_user" $SCRATCH_MNT
122 $XFS_QUOTA_PROG -x -c "report -ih" $SCRATCH_MNT >> $seqres.full
123
124 # ensure the initialization of the dquota buffer is done
125 xfs_freeze -f $SCRATCH_MNT
126 xfs_freeze -u $SCRATCH_MNT
127
128 # inject write IO error
129 FLAKEY_TABLE_ERROR=$(make_xfs_scratch_flakey_table)
130 _load_flakey_table ${FLAKEY_ERROR_WRITES}
131 $DMSETUP_PROG info >> $seqres.full
132 $DMSETUP_PROG table >> $seqres.full
133
134 # update the dquota buffer
135 $XFS_QUOTA_PROG -x -c "limit -u isoft=400 $qa_user" $SCRATCH_MNT
136 $XFS_QUOTA_PROG -x -c "report -ih" $SCRATCH_MNT >> $seqres.full
137
138 sync
139
140 # wait for the push of the dquota log item in AIL and
141 # the completion of the retried write of dquota buffer
142 sleep 2
143
144 _unmount_flakey
145
146 _cleanup_flakey
147
148 # success, all done
149 status=0
150 exit