Undoes mod: xfs-cmds:slinx:149090a
[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-2002 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     force_opts="-dsize=50m -lsize=2097152"
82     echo mkfs_xfs $force_opts $SCRATCH_DEV >>$seq.full
83     mkfs_xfs $force_opts $SCRATCH_DEV | _filter_mkfs >/dev/null 2>$tmp.mkfs
84     source $tmp.mkfs
85 }
86
87 _log_traffic()
88 {
89     count=$1
90     echo "*** generate log traffic"
91     
92     out=$SCRATCH_MNT/$$.tmp
93     
94     echo "   *** mount"
95     if ! mount -t xfs $SCRATCH_DEV $SCRATCH_MNT
96     then
97         echo "failed to mount $SCRATCH_DEV"
98         exit 1
99     fi
100
101     # having any quota enabled (acct/enfd) means extra log traffic - evil!
102     $here/src/feature -U $SCRATCH_DEV && \
103                 _notrun "Quota are enabled, test needs controlled log traffic"
104     $here/src/feature -G $SCRATCH_DEV && \
105                 _notrun "Quota are enabled, test needs controlled log traffic"
106  
107     echo "   *** fiddle"
108     while [ $count -ge 0 ]
109     do
110         touch $out 
111         rm $out
112         let "count = count - 1"
113     done
114     
115     echo "   *** unmount"
116     if ! umount $SCRATCH_DEV
117     then
118         echo "failed to unmount $SCRATCH_DEV"
119         exit 1
120     fi
121 }
122
123 _log_size()
124 {
125     xfs_logprint -tb $SCRATCH_DEV | $AWK_PROG '
126         /log device/ {  print $7}
127     '
128 }
129
130 _log_head()
131 {
132     xfs_logprint -tb $SCRATCH_DEV | $AWK_PROG '
133         /head:/ { print $5 }
134     '
135 }
136
137 # Get log stripe unit for v2 logs; if none specified,
138 # (or v1 log) just return "1" block
139
140 _log_sunit()
141 {
142     if [ $lsunit -eq 0 ]; then
143         echo $dbsize
144     else
145         expr $lsunit \* $dbsize
146     fi
147 }    
148
149 _after_log()
150 {
151     xfs_db -r $1 -c "sb" -c "print" | $AWK_PROG '
152         /logstart/  { logstart = $3 }
153         /logblocks/ { logblocks = $3 }
154         END {
155             print logstart + logblocks
156         }
157     '
158 }
159
160 _check_corrupt()
161 {
162     f="c6c6c6c6"
163     echo "*** check for corruption"
164     echo "expect $f..." >>$seq.full
165     xfs_db -r $1 -c "fsblock $2" -c "print" | head | tee -a $seq.full | \
166         grep -q -v "$f $f $f $f $f $f $f $f" && \
167             _fail "!!! block $2 corrupted!"
168 }
169
170 # get standard environment, filters and checks
171 . ./common.rc
172 . ./common.filter
173
174 # real QA test starts here
175
176 rm -f $seq.full
177
178 _require_scratch
179 _init
180
181 block=`_after_log $SCRATCH_DEV`
182 echo "fsblock after log = $block"               >>$seq.full
183 _check_corrupt $SCRATCH_DEV $block
184
185 size=`_log_size`
186 echo "log size = $size BB"                      >>$seq.full
187 head=`_log_head`
188 echo "log position = $head"                     >>$seq.full
189 lsunit=`_log_sunit`
190 echo "log sunit = $lsunit"                      >>$seq.full
191
192 [ $size -eq 4096 ] || \
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))"
196
197 echo "    lots of traffic"                      >>$seq.full
198 _log_traffic 850
199 head=`_log_head`
200 echo "log position = $head"                     >>$seq.full
201
202 [ $head -gt 3850 -a $head -lt 4050 ] || \
203     _fail "!!! unexpected log position $head"
204
205 for c in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
206 do
207     echo "   little traffic"            >>$seq.full
208     _log_traffic 2
209     head=`_log_head`
210     echo "log position = $head"         >>$seq.full
211     _check_corrupt $SCRATCH_DEV $block
212 done
213
214 [ $head -lt 1000 ] || \
215     _fail "!!! unexpected log position $head"
216
217 # success, all done
218 status=0
219 exit