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 _begin_fstest rw auto quick
25 # Override the default cleanup function.
31 _scratch_unmount 2>/dev/null
36 sed -e 's/[0-9][0-9]*\.\.[0-9][0-9]*/BLOCKRANGE/g'
41 echo "*** determine log size"
43 local dsize="-d size=${sz_mb}m"
44 local lsize="-l size=$(_scratch_find_xfs_min_logblocks $dsize)b"
45 local force_opts="$dsize $lsize"
46 _scratch_mkfs_xfs $force_opts >> $seqres.full 2>&1
48 # set log_size and log_size_bb globally
49 log_size_bb=`_log_size`
50 log_size=$((log_size_bb * 512))
51 echo "log_size_bb = $log_size_bb log_size = $log_size" >> $seqres.full
53 echo "*** reset partition"
54 $here/src/devzero -b 2048 -n $sz_mb -v 198 $SCRATCH_DEV # write 0xc6
57 # Do not discard blocks as we check for patterns in free space.
59 # First, make sure that mkfs supports '-K' option by using its
60 # dry run (-N option) and then add it to the force_opts.
62 if _scratch_mkfs_xfs -N -K $force_opts >/dev/null 2>&1; then
63 force_opts="-K $force_opts"
65 echo mkfs_xfs $force_opts $SCRATCH_DEV >>$seqres.full
66 _scratch_mkfs_xfs $force_opts >$tmp.mkfs0 2>&1
68 _notrun "Cannot mkfs for this test using MKFS_OPTIONS specified"
69 _filter_mkfs <$tmp.mkfs0 >/dev/null 2>$tmp.mkfs
71 [ $logsunit -ne 0 ] && \
72 _notrun "Cannot run this test using log MKFS_OPTIONS specified"
74 # quotas generate extra log traffic so force it off
75 _qmount_option noquota
81 echo "*** generate log traffic"
83 out=$SCRATCH_MNT/$$.tmp
86 if ! _try_scratch_mount
88 echo "failed to mount $SCRATCH_DEV"
92 # having any quota enabled (acct/enfd) means extra log traffic - evil!
93 $here/src/feature -U $SCRATCH_DEV && \
94 _notrun "UQuota are enabled, test needs controlled log traffic"
95 $here/src/feature -G $SCRATCH_DEV && \
96 _notrun "GQuota are enabled, test needs controlled log traffic"
97 $here/src/feature -P $SCRATCH_DEV && \
98 _notrun "PQuota are enabled, test needs controlled log traffic"
101 while [ $count -ge 0 ]
107 let "count = count - 1"
111 if ! _scratch_unmount
113 echo "failed to unmount $SCRATCH_DEV"
120 _scratch_xfs_logprint -tb | $AWK_PROG '
121 /log file: / || /log device: / { print $7}
127 _scratch_xfs_logprint -tb | $AWK_PROG '
132 # Get log stripe unit for v2 logs; if none specified,
133 # (or v1 log) just return "1" block
137 if [ ${lsunit:-0} -eq 0 ]; then
140 expr $lsunit \* $dbsize
146 _scratch_xfs_db -r -c "sb" -c "print" | $AWK_PROG '
147 /logstart/ { logstart = $3 }
148 /logblocks/ { logblocks = $3 }
150 print logstart + logblocks
158 echo "*** check for corruption"
159 echo "expect $f..." >>$seqres.full
160 _scratch_xfs_db -r -c "fsblock $2" -c "print" | head | tee -a $seqres.full | \
161 grep -q -v "$f $f $f $f $f $f $f $f" && \
162 _fail "!!! block $2 corrupted!"
165 # Import common functions.
169 # real QA test starts here
175 block=`_after_log $SCRATCH_DEV`
176 echo "fsblock after log = $block" >>$seqres.full
177 _check_corrupt $SCRATCH_DEV $block
179 actual_log_size=`_log_size`
180 echo "log size = $actual_log_size BB" >>$seqres.full
182 echo "log position = $head" >>$seqres.full
184 echo "log sunit = $lsunit" >>$seqres.full
187 [ $actual_log_size -eq $log_size_bb ] || \
188 _fail "!!! unexpected log size $size"
189 [ $head -eq 2 -o $head -eq $((lsunit/512)) ] || \
190 _fail "!!! unexpected initial log position $head vs. $((lsunit/512))"
192 # Step 1: Run 200 ops to estimate how how many log blocks are used for each op.
193 # Ignore the fact that it will also include an unmount record; this should be
195 echo " lots of traffic for sampling" >>$seqres.full
197 _log_traffic $sample_size_ops
199 num_blocks=`expr $head1 - $head`
200 blocks_per_op=`echo "scale=3; $num_blocks / $sample_size_ops" | bc`
201 echo "log position = $head1; old log position: $head" >> $seqres.full
202 echo "blocks_per_op = $blocks_per_op" >>$seqres.full
204 # Step 2: Quickly advance the log from wherever step 1 left us to the point
205 # where the log is now 80% full on its first cycle.
207 # Estimate the number of ops needed to get the log head close to but not past
208 # near_end_min for a single mount. We'd rather fall short and have to step our
209 # way closer to the end than run past the end, so our target for this second
210 # step is to fill 80% of the first cycle of the log.
211 num_expected_ops=$(( 8 * $(echo "$log_size_bb / $blocks_per_op" | bc) / 10))
212 echo "num_expected_ops = $num_expected_ops" >>$seqres.full
214 # Compute the number of ops needed to get from wherever we are right now in
215 # the log cycle to the 80% point.
216 num_expected_to_go=`echo "$num_expected_ops - $sample_size_ops" | bc`
217 echo "num_expected_to_go = $num_expected_to_go" >>$seqres.full
219 echo " lots more traffic" >>$seqres.full
220 _log_traffic $num_expected_to_go
222 echo "log position = $head" >>$seqres.full
224 # Step 3: Gradually advance log traffic to get us from wherever step 2 left us
225 # to the point where the log is within approximately 20 ops of wrapping into
228 # Since this is a log wrapping test, it's critical to push the log head to the
229 # point where it will wrap around within twenty rounds of ops. Compute the
230 # expected value of the log head when we get to this point. This "/ 1" piece
231 # tricks bc into printing integer numbers.
232 near_end_min=$(echo "$log_size_bb - (20 * $blocks_per_op / 1)" | bc)
233 echo "near_end_min = $near_end_min" >>$seqres.full
235 # Step us (in batches of 10 ops) to our goal.
236 while [ $head -lt $near_end_min ]; do
237 echo " bump traffic from $head towards $near_end_min" >> $seqres.full
238 _log_traffic 10 > /dev/null 2>&1
242 [ $head -gt $near_end_min -a $head -lt $log_size_bb ] || \
243 _fail "!!! unexpected near end log position $head"
245 # Step 4: Try to wrap the log, checking for corruption with each advance.
246 # This is the functionality that we're actually trying to test. We will try
247 # 40 ops (in batches of 2) to try to wrap the log.
250 echo " little traffic" >>$seqres.full
253 echo "log position = $head" >>$seqres.full
254 _check_corrupt $SCRATCH_DEV $block
257 [ $head -lt 1000 ] || \
258 _fail "!!! unexpected wrapped log position $head"