4 # test end of log overwrite bug #796141
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved.
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #-----------------------------------------------------------------------
30 # create a new FS, mostly fill the log. Then wrap the log back to the
31 # start bit by bit to force wiping of stale blocks near the end of the
32 # log. Check the block after the log ends to check for corruption
35 # - given we're only touching a single inode, the block after the
36 # log which is in the middle ag should never be touched.
37 # if it changes, we assume the log is writing over it
41 echo "QA output created by $seq"
47 trap "_cleanup; exit \$status" 0 1 2 3 15
54 umount $SCRATCH_MNT 2>/dev/null
59 sed -e 's/[0-9][0-9]*\.\.[0-9][0-9]*/BLOCKRANGE/g'
64 echo "*** reset partition"
65 $here/src/devzero -b 2048 -n 50 -v 198 $SCRATCH_DEV
67 force_opts="-dsize=50m -lsize=$log_size"
68 echo mkfs_xfs $force_opts $SCRATCH_DEV >>$seq.full
69 _scratch_mkfs_xfs $force_opts >$tmp.mkfs0 2>&1
71 _notrun "Cannot mkfs for this test using MKFS_OPTIONS specified"
72 _filter_mkfs <$tmp.mkfs0 >/dev/null 2>$tmp.mkfs
74 [ $logsunit -ne 0 ] && \
75 _notrun "Cannot run this test using log MKFS_OPTIONS specified"
81 echo "*** generate log traffic"
83 out=$SCRATCH_MNT/$$.tmp
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 ]
105 let "count = count - 1"
109 if ! umount $SCRATCH_DEV
111 echo "failed to unmount $SCRATCH_DEV"
118 _scratch_xfs_logprint -tb | $AWK_PROG '
119 /log file: / || /log device: / { print $7}
125 _scratch_xfs_logprint -tb | $AWK_PROG '
130 # Get log stripe unit for v2 logs; if none specified,
131 # (or v1 log) just return "1" block
135 if [ ${lsunit:-0} -eq 0 ]; then
138 expr $lsunit \* $dbsize
144 xfs_db -r $1 -c "sb" -c "print" | $AWK_PROG '
145 /logstart/ { logstart = $3 }
146 /logblocks/ { logblocks = $3 }
148 print logstart + logblocks
156 echo "*** check for corruption"
157 echo "expect $f..." >>$seq.full
158 xfs_db -r -c "fsblock $2" -c "print" $1 | head | tee -a $seq.full | \
159 grep -q -v "$f $f $f $f $f $f $f $f" && \
160 _fail "!!! block $2 corrupted!"
163 # get standard environment, filters and checks
167 # real QA test starts here
175 log_size_bb=`expr $log_size / 512`
180 block=`_after_log $SCRATCH_DEV`
181 echo "fsblock after log = $block" >>$seq.full
182 _check_corrupt $SCRATCH_DEV $block
184 actual_log_size=`_log_size`
185 echo "log size = $actual_log_size BB" >>$seq.full
187 echo "log position = $head" >>$seq.full
189 echo "log sunit = $lsunit" >>$seq.full
192 [ $actual_log_size -eq $log_size_bb ] || \
193 _fail "!!! unexpected log size $size"
194 [ $head -eq 2 -o $head -eq $((lsunit/512)) ] || \
195 _fail "!!! unexpected initial log position $head vs. $((lsunit/512))"
197 # find how how many blocks per op for 100 ops
198 # ignore the fact that it will also include an unmount record etc...
199 # this should be small overall
200 echo " lots of traffic for sampling" >>$seq.full
202 _log_traffic $sample_size_ops
204 num_blocks=`expr $head1 - $head`
205 blocks_per_op=`echo "scale=3; $num_blocks / $sample_size_ops" | bc`
206 echo "blocks_per_op = $blocks_per_op" >>$seq.full
207 num_expected_ops=`echo "$log_size_bb / $blocks_per_op" | bc`
208 echo "num_expected_ops = $num_expected_ops" >>$seq.full
209 num_expected_to_go=`echo "$num_expected_ops - $sample_size_ops" | bc`
210 echo "num_expected_to_go = $num_expected_to_go" >>$seq.full
212 echo " lots more traffic" >>$seq.full
213 _log_traffic $num_expected_to_go
215 echo "log position = $head" >>$seq.full
218 near_end_min=`echo "0.95 * $log_size_bb" | bc | sed 's/\..*//'`
219 echo "near_end_min = $near_end_min" >>$seq.full
221 [ $head -gt $near_end_min -a $head -lt $log_size_bb ] || \
222 _fail "!!! unexpected near end log position $head"
226 echo " little traffic" >>$seq.full
229 echo "log position = $head" >>$seq.full
230 _check_corrupt $SCRATCH_DEV $block
233 [ $head -lt 1000 ] || \
234 _fail "!!! unexpected wrapped log position $head"