2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Huawei Technologies Co., Ltd. All Rights Reserved.
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().
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.
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.
21 # Fixed by upstream commit 373b058 ("xfs: Properly retry failed dquot
22 # items in case of error during buffer writeback")
24 _begin_fstest auto quick quota
26 # Override the default cleanup function.
29 [ -z "${interval}" ] || \
30 sysctl -w fs.xfs.xfssyncd_centisecs=${interval} >/dev/null 2>&1
33 _unmount_flakey >/dev/null 2>&1
34 _cleanup_flakey > /dev/null 2>&1
37 # inject IO write error for the XFS filesystem except its log section
38 make_xfs_scratch_flakey_table()
41 local opt="0 1 1 error_writes"
42 local dev=${SCRATCH_DEV}
43 local dev_sz=$(blockdev --getsz $dev)
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"
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)
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"
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"
70 # Add a linear target for the log section, so the log write
72 table="$table\n${log_ofs} ${log_sz} linear $dev ${log_ofs}"
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"
85 # Import common functions.
91 # due to the injection of write IO error, the fs will be inconsistent
92 _require_scratch_nocheck
93 _require_flakey_with_error_writes
98 echo "Silence is golden"
100 _scratch_mkfs > $seqres.full 2>&1
102 # no error will be injected
104 $DMSETUP_PROG info >> $seqres.full
105 $DMSETUP_PROG table >> $seqres.full
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
112 _qmount_option "usrquota"
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
124 # ensure the initialization of the dquota buffer is done
125 xfs_freeze -f $SCRATCH_MNT
126 xfs_freeze -u $SCRATCH_MNT
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
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
140 # wait for the push of the dquota log item in AIL and
141 # the completion of the retried write of dquota buffer