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