xfsqa 185 shouldn't have uninitialised variables in the golden output
[xfstests-dev.git] / common.log
1 ##/bin/sh
2 #
3 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # common routines for log testing
6 # Created by dxm@sgi.com & tes@sgi.com
7 #
8
9 fulldir=$seq.fulldir
10 rm -rf $fulldir
11
12 _cleanup_logfiles()
13 {
14     if [ $status -eq 0 ]; then
15         # don't keep these files around unless something went wrong
16         rm -rf $fulldir
17     fi
18 }
19
20 _full()
21 {
22     echo ""            >>$seq.full      
23     echo "*** $* ***"  >>$seq.full
24     echo ""            >>$seq.full
25 }
26
27 _echofull()
28 {
29     echo ""            | tee -a $seq.full      
30     echo "*** $* ***"  | tee -a $seq.full
31     echo ""            | tee -a $seq.full
32 }
33
34 # Handle the operations which get split over Log Record
35 # boundaries.
36 # Oper (379)..... flags: CONTINUE
37 # ...
38 # Oper (0)....... flags: WAS_CONT END
39 #
40 # or
41 #
42 # Oper (379)..... flags: none 
43 # ...
44 # Oper (0)....... flags: none 
45 #
46 _filter_opnum()
47 {
48     $AWK_PROG '
49 BEGIN { 
50         debug = 0 
51         }
52 /^Oper/ && debug {
53             printf "line = %s\n", $0
54         }
55 /^Oper/ {
56             was_cont = 0
57         }
58 /^Oper/ && /flags: CONTINUE/ { 
59             # this will be the first op of split region
60             $9 = "none" # overwrite CONTINUE flags
61             print
62             print "Not printing rest"
63             was_cont = 1
64             next        
65         }
66 /^Oper/ && /flags: WAS_CONT END/ {
67             # this will be the last op of split region
68             # skip over was-continued op
69             # we assume there can be only 1
70             was_cont = 1
71             next        
72         }
73 (was_cont == 1) { 
74             # skip over any continued op stuff
75             next
76         }
77         {print}
78     '
79 }
80
81 #
82 # Filter out things that can change
83 # We have complexities which change when log is sync'ed at different
84 # times.
85 # Example1: DATA FORK EXTENTS
86 # These will not show up if inode is sync'ed sooner
87 #       /DATA FORK EXTENTS/d;
88 #       /INODE:/s/flags:0x5/flags:0x1/g;
89 # define XFS_ILOG_CORE   0x001   /* log standard inode fields */
90 # define XFS_ILOG_DEXT   0x004   /* log i_df.if_extents */
91 #
92 #
93
94 _filter_logprint()
95 {
96     _fix_malloc |\
97     sed '
98         s/ver:[0-9]/ver:<VERS>/;
99         s/version [0-9] format [0-9]/version <VERS> format <FORMAT>/;
100         s/data device: 0x[0-9a-f][0-9a-f]*/data device: <DEVICE>/;
101         s/log device: 0x[0-9a-f][0-9a-f]*/log device: <DEVICE>/;
102         s/log file: \".*\"/log device: <DEVICE>/;
103         s/daddr: [0-9][0-9]*/daddr: <DADDR>/;
104         s/length: [0-9][0-9]*/length: <LENGTH>/;
105         s/length: [0-9][0-9]*/length: <LENGTH>/;
106         s/^cycle num overwrites: .*$/cycle num overwrites: <TIDS>/;
107         s/tid: [0-9a-f][0-9a-f]*/tid: <TID>/;
108         s/tid:0x[0-9a-f][0-9a-f]*/tid:<TID>/;
109         s/q:0x[0-9a-f][0-9a-f]*/q:<Q>/;
110         s/a:0x[0-9a-f][0-9a-f]*/a:<A>/g;
111         s/blkno:0x[0-9a-f][0-9a-f]*/blkno:<BLKNO>/g;
112         s/blkno: *[0-9][0-9]* (0x[0-9a-f]*)/blkno: <BLKNO> (<BLKNO>)/g;
113         s/blkno: *[0-9][0-9]*/blkno: <BLKNO>/g;
114         s/boff: [0-9][0-9]*/boff: <BOFF>/g;
115         s/len: *[0-9][0-9]*/len:<LEN>/g;
116         /BUF:/s/[       ]*flags:.*$//;
117         /zeroed blocks/s/[0-9][0-9]*/<COUNT>/g;
118         /cleared blocks/d;
119         /log tail/s/[0-9][0-9]*/<COUNT>/g;
120         s/atime:[0-9a-fx]*  *mtime:[0-9a-fx]*  *ctime:[0-9a-fx]*/atime:<TIME>  mtime:<TIME>  ctime:<TIME>/;
121         s/atime 0x[0-9a-f]* mtime 0x[0-9a-f]* ctime 0x[0-9a-f]*/atime <TIME>  mtime <TIME>  ctime <TIME>/;
122         s/block [0-9][0-9]*/block <BLOCK>/;
123         s/icount: *[0-9][0-9]*  *ifree: *[0-9][0-9]*  *fdblks: *[0-9][0-9]*  *frext: *[0-9][0-9]*/icount:<COUNT> ifree:<FREE> fdblks:<BLOCKS> frext:<COUNT>/;
124         s/sunit: *[0-9][0-9]*  *swidth: *[0-9][0-9]*/sunit:<SUNIT> swidth:<SWIDTH>/;
125         s/1st: *[0-9][0-9]*  *last: *[0-9][0-9]*  *cnt: *[0-9][0-9]*  *freeblks: *[0-9][0-9]*  *longest: *[0-9][0-9]*/1st:<NUM> last:<NUM> cnt:<COUNT> freeblks:<COUNT> longest:<NUM>/;
126         s/^uuid: *[0-9a-f-][0-9a-f-]* *format: *.*$/uuid: <UUID> format: <FORMAT>/;
127         /flushiter:/d;
128         /version:/,/h_size:/d;
129         /override tail/s/[0-9][0-9]*/<TAIL_BLK>/;
130         /^---*/d;
131         /^===*/d;
132         /^~~~*/d;
133         /extended-header/d;
134         /LOG REC AT LSN/d;
135         /DATA FORK EXTENTS/d;
136         s/BUF: cnt:[1-9][0-9]* total:[1-9][0-9]*.*/BUF: cnt:C total:T/;
137         s/INO: cnt:[1-9][0-9]* total:[1-9][0-9]*.*/INO: cnt:C total:T/;
138         s/#regs: *[1-9][0-9]*/#regs:R/;
139         /INODE:/s/flags:0x5/flags:0x1/g;
140         s/Oper ([0-9][0-9]*)/Oper (OPNUM)/;
141         /^[     ]*$/d;
142         s/  */ /g;
143         s/ $//;
144         s/newino: 0x[0-9a-f]*$/newino: <INO>/g
145         s/newino:0x[0-9a-f]*$/newino:<INO>/g
146         s/ino: 0x[0-9a-f]* flags:/ino: <INO> flags:/g
147         s/ino:0x[0-9a-f]* flags:/ino:<INO> flags:/g
148     '|\
149     awk '
150         # collapse BUF DATA group into 1 line
151         # for Oper data this can be over separate operations...ughh
152         /BUF DATA/ { 
153                 if (!buf_data) { # 1st one
154                     if (oper) { 
155                         print oper
156                         oper = 0
157                     }           
158                     print
159                 }
160                 buf_data = 1
161                 oper = 0 # wont need it now
162                 next
163         }
164         /^Oper/ { 
165                 # store it as we dont know if 2nd BUF DATA is to follow
166                 if (oper) {
167                     print oper
168                 }
169                 oper = $0
170                 next
171         }
172         /^TRANS/ && dummy_rec == 1 {
173                 # start printing again - dummy transaction over
174                 dummy_rec = 0
175         }
176         /DUMMY1/ {
177                 # filter out dummy transactions
178                 dummy_rec = 1
179                 next
180         }
181         {
182                 if (dummy_rec) {
183                     next
184                 }
185                 buf_data = 0
186                 if (oper) { # now we can print out oper
187                     print oper
188                     oper = 0    
189                 }
190                 print
191         }
192     '
193 }
194
195 _check_log()
196 {
197     _full "clean_log : xfs_logprint"
198     _scratch_xfs_logprint -t | tee -a $seq.full \
199         | head | grep -q "<CLEAN>" || _fail "DIRTY LOG"
200 }
201
202 _print_logstate()
203 {
204     _scratch_xfs_logprint -t | tee -a $seq.full >$tmp.logprint
205     if grep -q "<DIRTY>" $tmp.logprint; then
206         echo "dirty log"
207     fi
208     if grep -q "<CLEAN>" $tmp.logprint; then
209         echo "clean log"
210     fi
211 }
212
213 _print_operation()
214 {
215     mkdir $fulldir >/dev/null 2>&1
216     mntopt=`echo $MOUNT_OPTIONS | sed 's/ //g'`
217     mkfsopt=`echo $MKFS_OPTIONS | sed 's/ //g'`
218     raw=$fulldir/op.mnt$mntopt.mkfs$mkfsopt$sync_suffix.raw
219     filtered=$fulldir/op.mnt$mntopt.mkfs$mkfsopt$sync_suffix.filtered
220
221     echo "### xfs_logprint output ###" | tee $raw >$filtered
222     _scratch_xfs_logprint -c  2>&1 \
223     | tee -a $raw      \
224     | _filter_logprint \
225     | _filter_opnum    \
226     >>$filtered
227 }
228
229 # start at rec#2 "-s 2" so we skip over UMOUNT record which will always
230 # be a 512b single header at mkfs time
231 # and may not match with the FS mounted at a different LR size 
232 # => xlog_do_recovery_pass() can not handle the different hdr sizes
233 #    it assumes them all to be the same between the start..finish
234 # NB: On IRIX there is no UMOUNT record and so we could start from -s 0.
235
236 _print_transaction_inode()
237 {
238     _start=$1
239     mkdir $fulldir >/dev/null 2>&1
240     mntopt=`echo $MOUNT_OPTIONS | sed 's/ //g'`
241     mkfsopt=`echo $MKFS_OPTIONS | sed 's/ //g'`
242     raw=$fulldir/trans_inode.mnt$mntopt.mkfs$mkfsopt$sync_suffix.raw
243     filtered=$fulldir/trans_inode.mnt$mntopt.mkfs$mkfsopt$sync_suffix.filtered
244
245     echo "### xfs_logprint -t -i -s START output ###" | tee $raw >$filtered
246     _scratch_xfs_logprint -t -i -s $_start 2>&1 \
247     | tee -a $raw      \
248     | _filter_logprint \
249     >>$filtered
250 }
251
252 _print_transaction_buf()
253 {
254     _start=$1
255     mkdir $fulldir >/dev/null 2>&1
256     mntopt=`echo $MOUNT_OPTIONS | sed 's/ //g'`
257     mkfsopt=`echo $MKFS_OPTIONS | sed 's/ //g'`
258     raw=$fulldir/trans_buf.mnt$mntopt.mkfs$mkfsopt$sync_suffix.raw
259     filtered=$fulldir/trans_buf.mnt$mntopt.mkfs$mkfsopt$sync_suffix.filtered
260
261     echo "### xfs_logprint -t -b -s START output ###" | tee $raw >$filtered
262     _scratch_xfs_logprint -t -b -s $_start 2>&1 \
263     | tee -a $raw      \
264     | _filter_logprint \
265     >>$filtered
266 }
267
268 _mkfs_log()
269 {
270     # create the FS
271     # mkfs options to append to log size otion can be specified ($*)
272     export MKFS_OPTIONS="-l size=2000b $*"
273     _full "mkfs"
274     _scratch_mkfs_xfs >>$seq.full 2>&1
275     if [ $? -ne 0 ] ; then 
276         _echofull "Cannot mkfs for this test using option specified: $MKFS_OPTIONS"
277         return 1
278     fi  
279
280     return 0
281 }
282
283
284 #
285 # mount fs and create some log traffic
286 #
287 _create_log()
288 {
289     # mount the FS
290     _full "mount"
291     _scratch_mount >>$seq.full 2>&1
292     if [ $? -ne 0 ] ; then 
293         _echofull "mount failed: $MOUNT_OPTIONS"
294         return 1
295     fi
296
297     # generate some log traffic - but not too much - life gets a little
298     # more complicated if the log wraps around. This traffic is
299     # pretty much arbitary, but could probably be made better than this.
300     touch $SCRATCH_MNT/{0,1,2,3,4,5,6,7,8,9}{0,1,2,3,4,5,6,7,8,9}
301         
302     # unmount the FS
303     _full "umount"
304     umount $SCRATCH_DEV >>$seq.full 2>&1
305     if [ $? -ne 0 ] ; then 
306         _echofull "umount failed"
307         return 1
308     fi
309
310     return 0
311 }
312
313 #
314 # mount fs and create some log traffic with sync'ing
315 #
316 _create_log_sync()
317 {
318     # mount the FS
319     _full " mount"
320     _scratch_mount >>$seq.full 2>&1
321     if [ $? -ne 0 ] ; then 
322         _echofull "mount failed: $MOUNT_OPTIONS"
323         return 1
324     fi
325
326     # generate some log traffic - but not too much
327     # add some syncs to get the log flushed to disk 
328     for file in $SCRATCH_MNT/{0,1,2,3,4,5,6,7,8,9}{0,1,2,3,4,5,6,7,8,9}; do
329         touch $file
330         sync
331     done
332
333     # unmount the FS
334     _full "umount"
335     umount $SCRATCH_DEV >>$seq.full 2>&1
336     if [ $? -ne 0 ] ; then 
337         _echofull "umount failed"
338         return 1
339     fi
340 }
341
342 _cmp_output()
343 {
344     echo "*** compare logprint: $1 with $2"
345     if ! diff $1 $2 >/dev/null; then
346         _fail "logprint output $1 differs to $2"
347     fi
348 }
349
350 #
351 # Op data of different Log Record sizes will mean that data is
352 # split at different points and in op printing it will not
353 # try and decode the data which has been split up.
354 # So we do a special diff processing to complain of differences
355 # if no split is involved.
356 #
357 # Example diff with forms of:
358 # "Left over region from split log item"
359 # "Not printing rest of data"
360 #
361 #   2149c2149
362 #   < Left over region from split log item
363 #   ---
364 #   > BUF DATA
365 #   2888c2888,2889
366 #   < INODE: #regs: 3 Not printing rest of data
367 #   ---
368 #   > INODE: #regs: 3 ino: 0x80 flags: 0x5 dsize: 16
369 #   >  blkno: <BLKNO> len:<LEN> boff: <BOFF>
370 #
371 _process_op_diff()
372 {
373     $AWK_PROG <$1 '
374         BEGIN { num_splits = 1; max_splits = 50 }
375         /^[0-9]/ {
376
377                 # ensure a split happened in previous difference
378                 if (num_splits < 1 || num_splits > max_splits) {
379                         print num_splits, " split(s) found prior to diff cmd: ", $0
380                         num_splits = 1 # shut-up end condition
381                         exit 1
382                 }
383                 num_splits = 0
384
385                 next
386         }
387         /Left over region/ || /Not printing rest/ { 
388                 num_splits++
389                 next
390         }
391         { next }
392         END { 
393                 if (num_splits < 1 || num_splits > max_splits) {
394                         print num_splits, " split(s) found prior to diff end"
395                         exit 1
396                 }
397         }
398     '
399     return $?
400 }
401
402 _cmp_op_output()
403 {
404     echo "*** compare logprint: $1 with $2"
405
406     diff $1 $2 >$filtered.diff
407     if ! _process_op_diff $filtered.diff
408     then
409         _fail "logprint output $1 differs to $2 considering splits"
410     fi
411 }
412
413 # return xfs log version of device
414 # e.g.
415 #   _log_version /dev/dsk/dks0d1s4
416 #
417 _log_version()
418 {
419     _dev=$1 
420     vers=`xfs_db -c 'sb 0' -c 'p versionnum' -r $_dev | $AWK_PROG '{print $3}'`
421     logver=`echo $vers | sed -e 's/0x[0-9a-f]\([0-9a-f]\)[0-9a-f][0-9a-f]/\1/'` 
422     if [ $logver = 4 -o $logver = 5 -o $logver = 6 -o $logver = 7 -o \
423          $logver = c -o $logver = d -o $logver = e -o $logver = f ]; then
424         echo 2
425     else
426         echo 1
427     fi
428 }
429
430 _require_v2log()
431 {
432     # test out mkfs to see if it supports "-l version=2"
433     export MKFS_OPTIONS="-l version=2"
434     if ! _scratch_mkfs_xfs >>$seq.full 2>&1; then
435         _notrun "mkfs does not support v2 logs"
436     fi
437
438     # test out mount to see if it mounts a v2 log fs
439     export MOUNT_OPTIONS="-o logbsize=32k"
440     if ! _scratch_mount >>$seq.full 2>&1; then
441         _notrun "mount/kernel does not support v2 logs"
442     fi
443
444     # check after unmount to see if it is clean
445     # i.e. it is not a 6.5.25 buggy version checking kernel
446     touch $SCRATCH_MNT/file
447     umount $SCRATCH_DEV >>$seq.full 2>&1
448     if _scratch_xfs_logprint -t | tee -a $seq.full \
449         | head | grep -q "<DIRTY>"; then
450         _notrun "kernel does not support v2 logs"
451     fi
452  
453     # otherwise presume it does support v2 logs...:)
454 }
455
456
457 # make sure this script returns success
458 /bin/true