srcdiff produces slightly different output now, so update QA test
[xfstests-dev.git] / 016
1 #! /bin/sh
2 # XFS QA Test No. 016
3 #
4 # test end of log overwrite bug #796141
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2000-2003 Silicon Graphics, Inc.  All Rights Reserved.
8
9 # This program is free software; you can redistribute it and/or modify it
10 # under the terms of version 2 of the GNU General Public License as
11 # published by the Free Software Foundation.
12
13 # This program is distributed in the hope that it would be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
17 # Further, this software is distributed without any warranty that it is
18 # free of the rightful claim of any third person regarding infringement
19 # or the like.  Any license provided herein, whether implied or
20 # otherwise, applies only to this software file.  Patent licenses, if
21 # any, provided herein do not apply to combinations of this program with
22 # other software, or any other product whatsoever.
23
24 # You should have received a copy of the GNU General Public License along
25 # with this program; if not, write the Free Software Foundation, Inc., 59
26 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
27
28 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
29 # Mountain View, CA  94043, or:
30
31 # http://www.sgi.com 
32
33 # For further information regarding this notice, see: 
34
35 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
36 #-----------------------------------------------------------------------
37 #
38 # creator
39 owner=dxm@sgi.com
40
41 #
42 # pv 796141
43 #
44 # create a new FS, mostly fill the log. Then wrap the log back to the
45 # start bit by bit to force wiping of stale blocks near the end of the
46 # log. Check the block after the log ends to check for corruption
47 #
48 # assumptions : 
49 #    - given we're only touching a single inode, the block after the
50 #      log which is in the middle ag should never be touched.
51 #      if it changes, we assume the log is writing over it
52 #
53
54 seq=`basename $0`
55 echo "QA output created by $seq"
56
57 here=`pwd`
58 tmp=/tmp/$$
59 status=1
60
61 trap "_cleanup; exit \$status" 0 1 2 3 15
62
63 _cleanup()
64 {
65     rm -f $tmp.*
66     echo "*** unmount"
67     umount $SCRATCH_MNT 2>/dev/null
68 }
69
70 _block_filter()
71 {
72     sed -e 's/[0-9][0-9]*\.\.[0-9][0-9]*/BLOCKRANGE/g'
73 }
74
75 _init()
76 {
77     echo "*** reset partition"
78     $here/src/devzero -b 2048 -n 50 -v 198 $SCRATCH_DEV
79     echo "*** mkfs"
80     force_opts="-dsize=50m -lsize=2097152"
81     echo mkfs_xfs $force_opts $SCRATCH_DEV >>$seq.full
82     _scratch_mkfs_xfs $force_opts >$tmp.mkfs0 2>&1
83     [ $? -ne 0 ] && \
84         _notrun "Cannot mkfs for this test using MKFS_OPTIONS specified"
85     _filter_mkfs <$tmp.mkfs0 >/dev/null 2>$tmp.mkfs
86     source $tmp.mkfs
87 }
88
89 _log_traffic()
90 {
91     count=$1
92     echo "*** generate log traffic"
93     
94     out=$SCRATCH_MNT/$$.tmp
95     
96     echo "   *** mount"
97     if ! _scratch_mount
98     then
99         echo "failed to mount $SCRATCH_DEV"
100         exit 1
101     fi
102
103     # having any quota enabled (acct/enfd) means extra log traffic - evil!
104     $here/src/feature -U $SCRATCH_DEV && \
105                 _notrun "Quota are enabled, test needs controlled log traffic"
106     $here/src/feature -G $SCRATCH_DEV && \
107                 _notrun "Quota are enabled, test needs controlled log traffic"
108  
109     echo "   *** fiddle"
110     while [ $count -ge 0 ]
111     do
112         touch $out 
113         rm $out
114         let "count = count - 1"
115     done
116     
117     echo "   *** unmount"
118     if ! umount $SCRATCH_DEV
119     then
120         echo "failed to unmount $SCRATCH_DEV"
121         exit 1
122     fi
123 }
124
125 _log_size()
126 {
127     _scratch_xfs_logprint -tb | $AWK_PROG '
128         /log file: / || /log device: / { print $7}
129     '
130 }
131
132 _log_head()
133 {
134     _scratch_xfs_logprint -tb | $AWK_PROG '
135         /head:/ { print $5 }
136     '
137 }
138
139 # Get log stripe unit for v2 logs; if none specified,
140 # (or v1 log) just return "1" block
141
142 _log_sunit()
143 {
144     if [ ${lsunit:-0} -eq 0 ]; then
145         echo $dbsize
146     else
147         expr $lsunit \* $dbsize
148     fi
149 }    
150
151 _after_log()
152 {
153     xfs_db -r $1 -c "sb" -c "print" | $AWK_PROG '
154         /logstart/  { logstart = $3 }
155         /logblocks/ { logblocks = $3 }
156         END {
157             print logstart + logblocks
158         }
159     '
160 }
161
162 _check_corrupt()
163 {
164     f="c6c6c6c6"
165     echo "*** check for corruption"
166     echo "expect $f..." >>$seq.full
167     xfs_db -r $1 -c "fsblock $2" -c "print" | head | tee -a $seq.full | \
168         grep -q -v "$f $f $f $f $f $f $f $f" && \
169             _fail "!!! block $2 corrupted!"
170 }
171
172 # get standard environment, filters and checks
173 . ./common.rc
174 . ./common.filter
175
176 # real QA test starts here
177
178 rm -f $seq.full
179
180 _require_scratch
181 _init
182
183 block=`_after_log $SCRATCH_DEV`
184 echo "fsblock after log = $block"               >>$seq.full
185 _check_corrupt $SCRATCH_DEV $block
186
187 size=`_log_size`
188 echo "log size = $size BB"                      >>$seq.full
189 head=`_log_head`
190 echo "log position = $head"                     >>$seq.full
191 lsunit=`_log_sunit`
192 echo "log sunit = $lsunit"                      >>$seq.full
193
194 [ $size -eq 4096 ] || \
195     _fail "!!! unexpected log size $size"
196 [ $head -eq 2 -o $head -eq $((lsunit/512)) ] || \
197     _fail "!!! unexpected initial log position $head vs. $((lsunit/512))"
198
199 echo "    lots of traffic"                      >>$seq.full
200 _log_traffic 850
201 head=`_log_head`
202 echo "log position = $head"                     >>$seq.full
203
204 [ $head -gt 3850 -a $head -lt 4050 ] || \
205     _fail "!!! unexpected log position $head"
206
207 for c in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
208 do
209     echo "   little traffic"            >>$seq.full
210     _log_traffic 2
211     head=`_log_head`
212     echo "log position = $head"         >>$seq.full
213     _check_corrupt $SCRATCH_DEV $block
214 done
215
216 [ $head -lt 1000 ] || \
217     _fail "!!! unexpected log position $head"
218
219 # success, all done
220 status=0
221 exit