changes to fold xfs_support code back into XFS (the other sgi projects
[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     rm -f $tmp.*
67     echo "*** unmount"
68     umount $SCRATCH_MNT 2>/dev/null
69 }
70
71 _block_filter()
72 {
73     sed -e 's/[0-9][0-9]*\.\.[0-9][0-9]*/BLOCKRANGE/g'
74 }
75
76 _init()
77 {
78     echo "*** reset partition"
79     $here/src/devzero -b 2048 -n 50 -v 198 $SCRATCH_DEV
80     echo "*** mkfs"
81     lsize=2097152
82     dsize=50m
83     echo mkfs_xfs -dsize=$dsize -lsize=$lsize $SCRATCH_DEV >>$seq.full
84     if ! mkfs_xfs -dsize=$dsize -lsize=$lsize $SCRATCH_DEV >>$seq.full 2>&1
85     then
86         echo "failed to mkfs $SCRATCH_DEV" >>$seq.full
87         _notrun "mkfs cannot create scratch fs, probably too small log"
88         exit 1
89     fi
90 }
91
92 _log_traffic()
93 {
94     count=$1
95     echo "*** generate log traffic"
96     
97     out=$SCRATCH_MNT/$$.tmp
98     
99     echo "   *** mount"
100     if ! mount -t xfs $SCRATCH_DEV $SCRATCH_MNT
101     then
102         echo "failed to mount $SCRATCH_DEV"
103         exit 1
104     fi
105
106     # having any quota enabled (acct/enfd) means extra log traffic - evil!
107     $here/src/feature -U $SCRATCH_DEV && \
108                 _notrun "Quota are enabled, test needs controlled log traffic"
109     $here/src/feature -G $SCRATCH_DEV && \
110                 _notrun "Quota are enabled, test needs controlled log traffic"
111  
112     echo "   *** fiddle"
113     while [ $count -ge 0 ]
114     do
115         touch $out 
116         rm $out
117         let "count = count - 1"
118     done
119     
120     echo "   *** unmount"
121     if ! umount $SCRATCH_DEV
122     then
123         echo "failed to unmount $SCRATCH_DEV"
124         exit 1
125     fi
126 }
127
128 _log_size()
129 {
130     xfs_logprint -tb $SCRATCH_DEV | $AWK_PROG '
131         /log device/ {  print $7}
132     '
133 }
134
135 _log_head()
136 {
137     xfs_logprint -tb $SCRATCH_DEV | $AWK_PROG '
138         /head:/ { print $5 }
139     '
140 }
141
142 _after_log()
143 {
144     xfs_db -r $1 -c "sb" -c "print" | $AWK_PROG '
145         /logstart/  { logstart = $3 }
146         /logblocks/ { logblocks = $3 }
147         END {
148             print logstart + logblocks
149         }
150     '
151 }
152
153 _check_corrupt()
154 {
155     f="c6c6c6c6"
156     echo "*** check for corruption"
157     echo "expect $f..." >>$seq.full
158     xfs_db -r $1 -c "fsblock $2" -c "print" | head | tee -a $seq.full | \
159         grep -q -v "$f $f $f $f $f $f $f $f" && \
160             _fail "!!! block $2 corrupted!"
161 }
162
163 # get standard environment, filters and checks
164 . ./common.rc
165 . ./common.filter
166
167 # real QA test starts here
168
169 rm -f $seq.full
170
171 _require_scratch
172 _init
173
174 block=`_after_log $SCRATCH_DEV`
175 echo "fsblock after log = $block"               >>$seq.full
176 _check_corrupt $SCRATCH_DEV $block
177
178 size=`_log_size`
179 echo "log size = $size BB"                      >>$seq.full
180 head=`_log_head`
181 echo "log position = $head"                     >>$seq.full
182
183 [ $size -eq 4096 ] || \
184     _fail "!!! unexpected log size $size"
185 [ $head -eq 2 ] || \
186     _fail "!!! unexpected initial log position $head"
187
188 echo "    lots of traffic"                      >>$seq.full
189 _log_traffic 850
190 head=`_log_head`
191 echo "log position = $head"                     >>$seq.full
192
193 [ $head -gt 3850 -a $head -lt 4050 ] || \
194     _fail "!!! unexpected log position $head"
195
196 for c in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
197 do
198     echo "   little traffic"            >>$seq.full
199     _log_traffic 2
200     head=`_log_head`
201     echo "log position = $head"         >>$seq.full
202     _check_corrupt $SCRATCH_DEV $block
203 done
204
205 [ $head -lt 1000 ] || \
206     _fail "!!! unexpected log position $head"
207
208 # success, all done
209 status=0
210 exit