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