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 seqres=$RESULT_DIR/$seq
25 echo "QA output created by $seq"
29 status=1 # failure is the default!
30 trap "_cleanup; exit \$status" 0 1 2 3 15
34 [ -z "${interval}" ] || \
35 sysctl -w fs.xfs.xfssyncd_centisecs=${interval} >/dev/null 2>&1
38 _unmount_flakey >/dev/null 2>&1
39 _cleanup_flakey > /dev/null 2>&1
42 # inject IO write error for the XFS filesystem except its log section
43 make_xfs_scratch_flakey_table()
46 local opt="0 1 1 error_writes"
47 local dev=${SCRATCH_DEV}
48 local dev_sz=$(blockdev --getsz $dev)
50 # If using an external log device, just making the writing of
51 # entire data/metadata area fail forever.
52 if [ "${USE_EXTERNAL}" = "yes" -a ! -z "$SCRATCH_LOGDEV" ]; then
53 echo "0 ${dev_sz} $tgt $dev 0 $opt"
57 local blk_sz=$(_scratch_xfs_get_sb_field blocksize)
58 local log_ofs=$(_scratch_xfs_get_sb_field logstart)
59 local log_sz=$(_scratch_xfs_get_sb_field logblocks)
64 log_ofs=$(_scratch_xfs_db -r -c "convert fsb ${log_ofs} bb" | \
65 $AWK_PROG '{gsub("[()]", "", $2); print $2}')
66 let "log_sz *= blk_sz / 512"
68 # Add a flakey target for the area before the log section
69 # to make the data/metadata write fail forever
70 if [ "$ofs" -lt "${log_ofs}" ]; then
71 let "sz = log_ofs - ofs"
72 table="$ofs $sz $tgt $dev $ofs $opt"
75 # Add a linear target for the log section, so the log write
77 table="$table\n${log_ofs} ${log_sz} linear $dev ${log_ofs}"
79 # Add a flakey target for the area after the log section
80 # to make the data/metadata write fail forever
81 let "ofs = log_ofs + log_sz"
82 if [ "$ofs" -lt "${dev_sz}" ]; then
83 let "sz = dev_sz - ofs"
84 table="$table\n$ofs $sz $tgt $dev $ofs $opt"
90 # get standard environment, filters and checks
97 # due to the injection of write IO error, the fs will be inconsistent
98 _require_scratch_nocheck
99 _require_flakey_with_error_writes
106 echo "Silence is golden"
108 _scratch_mkfs > $seqres.full 2>&1
110 # no error will be injected
112 $DMSETUP_PROG info >> $seqres.full
113 $DMSETUP_PROG table >> $seqres.full
115 # save the old value for _cleanup()
116 interval=$(sysctl -n fs.xfs.xfssyncd_centisecs 2>/dev/null)
117 # shorten the time waiting for the push of ail items
118 sysctl -w fs.xfs.xfssyncd_centisecs=100 >> $seqres.full 2>&1
120 _qmount_option "usrquota"
123 # We need to set the quota limitation twice, and inject the write error
124 # after the second setting. If we try to inject the write error after
125 # the first setting, the initialization of the dquota buffer will get
126 # IO error and also be retried, and during the umount process the
127 # write will be ended, and xfs_qm_dqflush_done() will be inovked, and
128 # the umount will exit normally.
129 $XFS_QUOTA_PROG -x -c "limit -u isoft=500 $qa_user" $SCRATCH_MNT
130 $XFS_QUOTA_PROG -x -c "report -ih" $SCRATCH_MNT >> $seqres.full
132 # ensure the initialization of the dquota buffer is done
133 xfs_freeze -f $SCRATCH_MNT
134 xfs_freeze -u $SCRATCH_MNT
136 # inject write IO error
137 FLAKEY_TABLE_ERROR=$(make_xfs_scratch_flakey_table)
138 _load_flakey_table ${FLAKEY_ERROR_WRITES}
139 $DMSETUP_PROG info >> $seqres.full
140 $DMSETUP_PROG table >> $seqres.full
142 # update the dquota buffer
143 $XFS_QUOTA_PROG -x -c "limit -u isoft=400 $qa_user" $SCRATCH_MNT
144 $XFS_QUOTA_PROG -x -c "report -ih" $SCRATCH_MNT >> $seqres.full
148 # wait for the push of the dquota log item in AIL and
149 # the completion of the retried write of dquota buffer