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 "*** determine log size"
49 local dsize="-d size=${sz_mb}m"
50 local lsize="-l size=$(_scratch_find_xfs_min_logblocks $dsize)b"
51 local force_opts="$dsize $lsize"
52 _scratch_mkfs_xfs $force_opts >> $seqres.full 2>&1
54 # set log_size and log_size_bb globally
55 log_size_bb=`_log_size`
56 log_size=$((log_size_bb * 512))
57 echo "log_size_bb = $log_size_bb log_size = $log_size" >> $seqres.full
59 echo "*** reset partition"
60 $here/src/devzero -b 2048 -n $sz_mb -v 198 $SCRATCH_DEV # write 0xc6
63 # Do not discard blocks as we check for patterns in free space.
65 # First, make sure that mkfs supports '-K' option by using its
66 # dry run (-N option) and then add it to the force_opts.
68 if _scratch_mkfs_xfs -N -K $force_opts >/dev/null 2>&1; then
69 force_opts="-K $force_opts"
71 echo mkfs_xfs $force_opts $SCRATCH_DEV >>$seqres.full
72 _scratch_mkfs_xfs $force_opts >$tmp.mkfs0 2>&1
74 _notrun "Cannot mkfs for this test using MKFS_OPTIONS specified"
75 _filter_mkfs <$tmp.mkfs0 >/dev/null 2>$tmp.mkfs
77 [ $logsunit -ne 0 ] && \
78 _notrun "Cannot run this test using log MKFS_OPTIONS specified"
80 # quotas generate extra log traffic so force it off
81 _qmount_option noquota
87 echo "*** generate log traffic"
89 out=$SCRATCH_MNT/$$.tmp
92 if ! _try_scratch_mount
94 echo "failed to mount $SCRATCH_DEV"
98 # having any quota enabled (acct/enfd) means extra log traffic - evil!
99 $here/src/feature -U $SCRATCH_DEV && \
100 _notrun "UQuota are enabled, test needs controlled log traffic"
101 $here/src/feature -G $SCRATCH_DEV && \
102 _notrun "GQuota are enabled, test needs controlled log traffic"
103 $here/src/feature -P $SCRATCH_DEV && \
104 _notrun "PQuota are enabled, test needs controlled log traffic"
107 while [ $count -ge 0 ]
113 let "count = count - 1"
117 if ! _scratch_unmount
119 echo "failed to unmount $SCRATCH_DEV"
126 _scratch_xfs_logprint -tb | $AWK_PROG '
127 /log file: / || /log device: / { print $7}
133 _scratch_xfs_logprint -tb | $AWK_PROG '
138 # Get log stripe unit for v2 logs; if none specified,
139 # (or v1 log) just return "1" block
143 if [ ${lsunit:-0} -eq 0 ]; then
146 expr $lsunit \* $dbsize
152 xfs_db -r $1 -c "sb" -c "print" | $AWK_PROG '
153 /logstart/ { logstart = $3 }
154 /logblocks/ { logblocks = $3 }
156 print logstart + logblocks
164 echo "*** check for corruption"
165 echo "expect $f..." >>$seqres.full
166 xfs_db -r -c "fsblock $2" -c "print" $1 | head | tee -a $seqres.full | \
167 grep -q -v "$f $f $f $f $f $f $f $f" && \
168 _fail "!!! block $2 corrupted!"
171 # get standard environment, filters and checks
176 # real QA test starts here
185 block=`_after_log $SCRATCH_DEV`
186 echo "fsblock after log = $block" >>$seqres.full
187 _check_corrupt $SCRATCH_DEV $block
189 actual_log_size=`_log_size`
190 echo "log size = $actual_log_size BB" >>$seqres.full
192 echo "log position = $head" >>$seqres.full
194 echo "log sunit = $lsunit" >>$seqres.full
197 [ $actual_log_size -eq $log_size_bb ] || \
198 _fail "!!! unexpected log size $size"
199 [ $head -eq 2 -o $head -eq $((lsunit/512)) ] || \
200 _fail "!!! unexpected initial log position $head vs. $((lsunit/512))"
202 # Step 1: Run 200 ops to estimate how how many log blocks are used for each op.
203 # Ignore the fact that it will also include an unmount record; this should be
205 echo " lots of traffic for sampling" >>$seqres.full
207 _log_traffic $sample_size_ops
209 num_blocks=`expr $head1 - $head`
210 blocks_per_op=`echo "scale=3; $num_blocks / $sample_size_ops" | bc`
211 echo "log position = $head1; old log position: $head" >> $seqres.full
212 echo "blocks_per_op = $blocks_per_op" >>$seqres.full
214 # Step 2: Quickly advance the log from wherever step 1 left us to the point
215 # where the log is now 80% full on its first cycle.
217 # Estimate the number of ops needed to get the log head close to but not past
218 # near_end_min for a single mount. We'd rather fall short and have to step our
219 # way closer to the end than run past the end, so our target for this second
220 # step is to fill 80% of the first cycle of the log.
221 num_expected_ops=$(( 8 * $(echo "$log_size_bb / $blocks_per_op" | bc) / 10))
222 echo "num_expected_ops = $num_expected_ops" >>$seqres.full
224 # Compute the number of ops needed to get from wherever we are right now in
225 # the log cycle to the 80% point.
226 num_expected_to_go=`echo "$num_expected_ops - $sample_size_ops" | bc`
227 echo "num_expected_to_go = $num_expected_to_go" >>$seqres.full
229 echo " lots more traffic" >>$seqres.full
230 _log_traffic $num_expected_to_go
232 echo "log position = $head" >>$seqres.full
234 # Step 3: Gradually advance log traffic to get us from wherever step 2 left us
235 # to the point where the log is within approximately 20 ops of wrapping into
238 # Since this is a log wrapping test, it's critical to push the log head to the
239 # point where it will wrap around within twenty rounds of ops. Compute the
240 # expected value of the log head when we get to this point. This "/ 1" piece
241 # tricks bc into printing integer numbers.
242 near_end_min=$(echo "$log_size_bb - (20 * $blocks_per_op / 1)" | bc)
243 echo "near_end_min = $near_end_min" >>$seqres.full
245 # Step us (in batches of 10 ops) to our goal.
246 while [ $head -lt $near_end_min ]; do
247 echo " bump traffic from $head towards $near_end_min" >> $seqres.full
248 _log_traffic 10 > /dev/null 2>&1
252 [ $head -gt $near_end_min -a $head -lt $log_size_bb ] || \
253 _fail "!!! unexpected near end log position $head"
255 # Step 4: Try to wrap the log, checking for corruption with each advance.
256 # This is the functionality that we're actually trying to test. We will try
257 # 40 ops (in batches of 2) to try to wrap the log.
260 echo " little traffic" >>$seqres.full
263 echo "log position = $head" >>$seqres.full
264 _check_corrupt $SCRATCH_DEV $block
267 [ $head -lt 1000 ] || \
268 _fail "!!! unexpected wrapped log position $head"