2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved.
7 # test end of log overwrite bug #796141
12 # create a new FS, mostly fill the log. Then wrap the log back to the
13 # start bit by bit to force wiping of stale blocks near the end of the
14 # log. Check the block after the log ends to check for corruption
17 # - given we're only touching a single inode, the block after the
18 # log which is in the middle ag should never be touched.
19 # if it changes, we assume the log is writing over it
23 seqres=$RESULT_DIR/$seq
24 echo "QA output created by $seq"
30 trap "_cleanup; exit \$status" 0 1 2 3 15
37 _scratch_unmount 2>/dev/null
42 sed -e 's/[0-9][0-9]*\.\.[0-9][0-9]*/BLOCKRANGE/g'
47 echo "*** reset partition"
48 $here/src/devzero -b 2048 -n 50 -v 198 $SCRATCH_DEV
50 force_opts="-dsize=50m -lsize=$log_size"
52 # Do not discard blocks as we check for patterns in free space.
54 # First, make sure that mkfs supports '-K' option by using its
55 # dry run (-N option) and then add it to the force_opts.
57 if _scratch_mkfs_xfs -N -K $force_opts >/dev/null 2>&1; then
58 force_opts="-K $force_opts"
60 echo mkfs_xfs $force_opts $SCRATCH_DEV >>$seqres.full
61 _scratch_mkfs_xfs $force_opts >$tmp.mkfs0 2>&1
63 _notrun "Cannot mkfs for this test using MKFS_OPTIONS specified"
64 _filter_mkfs <$tmp.mkfs0 >/dev/null 2>$tmp.mkfs
66 [ $logsunit -ne 0 ] && \
67 _notrun "Cannot run this test using log MKFS_OPTIONS specified"
73 echo "*** generate log traffic"
75 out=$SCRATCH_MNT/$$.tmp
78 if ! _try_scratch_mount
80 echo "failed to mount $SCRATCH_DEV"
84 # having any quota enabled (acct/enfd) means extra log traffic - evil!
85 $here/src/feature -U $SCRATCH_DEV && \
86 _notrun "UQuota are enabled, test needs controlled log traffic"
87 $here/src/feature -G $SCRATCH_DEV && \
88 _notrun "GQuota are enabled, test needs controlled log traffic"
89 $here/src/feature -P $SCRATCH_DEV && \
90 _notrun "PQuota are enabled, test needs controlled log traffic"
93 while [ $count -ge 0 ]
99 let "count = count - 1"
103 if ! _scratch_unmount
105 echo "failed to unmount $SCRATCH_DEV"
112 _scratch_xfs_logprint -tb | $AWK_PROG '
113 /log file: / || /log device: / { print $7}
119 _scratch_xfs_logprint -tb | $AWK_PROG '
124 # Get log stripe unit for v2 logs; if none specified,
125 # (or v1 log) just return "1" block
129 if [ ${lsunit:-0} -eq 0 ]; then
132 expr $lsunit \* $dbsize
138 xfs_db -r $1 -c "sb" -c "print" | $AWK_PROG '
139 /logstart/ { logstart = $3 }
140 /logblocks/ { logblocks = $3 }
142 print logstart + logblocks
150 echo "*** check for corruption"
151 echo "expect $f..." >>$seqres.full
152 xfs_db -r -c "fsblock $2" -c "print" $1 | head | tee -a $seqres.full | \
153 grep -q -v "$f $f $f $f $f $f $f $f" && \
154 _fail "!!! block $2 corrupted!"
157 # get standard environment, filters and checks
161 # real QA test starts here
169 log_size_bb=`expr $log_size / 512`
174 block=`_after_log $SCRATCH_DEV`
175 echo "fsblock after log = $block" >>$seqres.full
176 _check_corrupt $SCRATCH_DEV $block
178 actual_log_size=`_log_size`
179 echo "log size = $actual_log_size BB" >>$seqres.full
181 echo "log position = $head" >>$seqres.full
183 echo "log sunit = $lsunit" >>$seqres.full
186 [ $actual_log_size -eq $log_size_bb ] || \
187 _fail "!!! unexpected log size $size"
188 [ $head -eq 2 -o $head -eq $((lsunit/512)) ] || \
189 _fail "!!! unexpected initial log position $head vs. $((lsunit/512))"
191 # find how how many blocks per op for 100 ops
192 # ignore the fact that it will also include an unmount record etc...
193 # this should be small overall
194 echo " lots of traffic for sampling" >>$seqres.full
196 _log_traffic $sample_size_ops
198 num_blocks=`expr $head1 - $head`
199 blocks_per_op=`echo "scale=3; $num_blocks / $sample_size_ops" | bc`
200 echo "blocks_per_op = $blocks_per_op" >>$seqres.full
201 num_expected_ops=`echo "$log_size_bb / $blocks_per_op" | bc`
202 echo "num_expected_ops = $num_expected_ops" >>$seqres.full
203 num_expected_to_go=`echo "$num_expected_ops - $sample_size_ops" | bc`
204 echo "num_expected_to_go = $num_expected_to_go" >>$seqres.full
206 echo " lots more traffic" >>$seqres.full
207 _log_traffic $num_expected_to_go
209 echo "log position = $head" >>$seqres.full
212 near_end_min=`echo "0.95 * $log_size_bb" | bc | sed 's/\..*//'`
213 echo "near_end_min = $near_end_min" >>$seqres.full
215 [ $head -gt $near_end_min -a $head -lt $log_size_bb ] || \
216 _fail "!!! unexpected near end log position $head"
220 echo " little traffic" >>$seqres.full
223 echo "log position = $head" >>$seqres.full
224 _check_corrupt $SCRATCH_DEV $block
227 [ $head -lt 1000 ] || \
228 _fail "!!! unexpected wrapped log position $head"