QA test updates - fixes for pquota, extsize, fsstress, and ensure mount options passe...
[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/data device: 0x[0-9a-f][0-9a-f]*/data device: <DEVICE>/;
99         s/log device: 0x[0-9a-f][0-9a-f]*/log device: <DEVICE>/;
100         s/log file: \".*\"/log device: <DEVICE>/;
101         s/daddr: [0-9][0-9]*/daddr: <DADDR>/;
102         s/length: [0-9][0-9]*/length: <LENGTH>/;
103         s/length: [0-9][0-9]*/length: <LENGTH>/;
104         s/^cycle num overwrites: .*$/cycle num overwrites: <TIDS>/;
105         s/tid: [0-9a-f][0-9a-f]*/tid: <TID>/;
106         s/tid:0x[0-9a-f][0-9a-f]*/tid:<TID>/;
107         s/q:0x[0-9a-f][0-9a-f]*/q:<Q>/;
108         s/a:0x[0-9a-f][0-9a-f]*/a:<A>/g;
109         s/blkno:0x[0-9a-f][0-9a-f]*/blkno:<BLKNO>/g;
110         s/blkno: [0-9][0-9]* (0x[0-9a-f]*)/blkno: <BLKNO> (<BLKNO>)/g;
111         s/blkno: [0-9][0-9]*/blkno: <BLKNO>/g;
112         s/boff: [0-9][0-9]*/boff: <BOFF>/g;
113         s/len: *[0-9][0-9]*/len:<LEN>/g;
114         /zeroed blocks/s/[0-9][0-9]*/<COUNT>/g;
115         /cleared blocks/d;
116         /log tail/s/[0-9][0-9]*/<COUNT>/g;
117         s/atime:[0-9a-fx]*  *mtime:[0-9a-fx]*  *ctime:[0-9a-fx]*/atime:<TIME>  mtime:<TIME>  ctime:<TIME>/;
118         s/atime 0x[0-9a-f]* mtime 0x[0-9a-f]* ctime 0x[0-9a-f]*/atime <TIME>  mtime <TIME>  ctime <TIME>/;
119         s/block [0-9][0-9]*/block <BLOCK>/;
120         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>/;
121         s/sunit: *[0-9][0-9]*  *swidth: *[0-9][0-9]*/sunit:<SUNIT> swidth:<SWIDTH>/;
122         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>/;
123         s/^uuid: *[0-9a-f-][0-9a-f-]* *format: *.*$/uuid: <UUID> format: <FORMAT>/;
124         /flushiter:/d;
125         /version:/,/h_size:/d;
126         /override tail/s/[0-9][0-9]*/<TAIL_BLK>/;
127         /^---*/d;
128         /^===*/d;
129         /^~~~*/d;
130         /extended-header/d;
131         /LOG REC AT LSN/d;
132         /DATA FORK EXTENTS/d;
133         s/BUF: cnt:[1-9][0-9]* total:[1-9][0-9]*.*/BUF: cnt:C total:T/;
134         s/INO: cnt:[1-9][0-9]* total:[1-9][0-9]*.*/INO: cnt:C total:T/;
135         s/#regs: *[1-9][0-9]*/#regs:R/;
136         /INODE:/s/flags:0x5/flags:0x1/g;
137         s/Oper ([0-9][0-9]*)/Oper (OPNUM)/;
138         /^[     ]*$/d;
139         s/  */ /g;
140         s/ $//;
141         s/newino: 0x[0-9a-f]*$/newino: <INO>/g
142         s/newino:0x[0-9a-f]*$/newino:<INO>/g
143         s/ino: 0x[0-9a-f]* flags:/ino: <INO> flags:/g
144         s/ino:0x[0-9a-f]* flags:/ino:<INO> flags:/g
145     '|\
146     awk '
147         # collapse BUF DATA group into 1 line
148         # for Oper data this can be over separate operations...ughh
149         /BUF DATA/ { 
150                 if (!buf_data) { # 1st one
151                     if (oper) { 
152                         print oper
153                         oper = 0
154                     }           
155                     print
156                 }
157                 buf_data = 1
158                 oper = 0 # wont need it now
159                 next
160         }
161         /^Oper/ { 
162                 # store it as we dont know if 2nd BUF DATA is to follow
163                 if (oper) {
164                     print oper
165                 }
166                 oper = $0
167                 next
168         }
169         /^TRANS/ && dummy_rec == 1 {
170                 # start printing again - dummy transaction over
171                 dummy_rec = 0
172         }
173         /DUMMY1/ {
174                 # filter out dummy transactions
175                 dummy_rec = 1
176                 next
177         }
178         {
179                 if (dummy_rec) {
180                     next
181                 }
182                 buf_data = 0
183                 if (oper) { # now we can print out oper
184                     print oper
185                     oper = 0    
186                 }
187                 print
188         }
189     '
190 }
191
192 _check_log()
193 {
194     _full "clean_log : xfs_logprint"
195     _scratch_xfs_logprint -t | tee -a $seq.full \
196         | head | grep -q "<CLEAN>" || _fail "DIRTY LOG"
197 }
198
199 _print_logstate()
200 {
201     _scratch_xfs_logprint -t | tee -a $seq.full >$tmp.logprint
202     if grep -q "<DIRTY>" $tmp.logprint; then
203         echo "dirty log"
204     fi
205     if grep -q "<CLEAN>" $tmp.logprint; then
206         echo "clean log"
207     fi
208 }
209
210 _print_operation()
211 {
212     mkdir $fulldir >/dev/null 2>&1
213     mntopt=`echo $MOUNT_OPTIONS | sed 's/ //g'`
214     mkfsopt=`echo $MKFS_OPTIONS | sed 's/ //g'`
215     raw=$fulldir/op.mnt$mntopt.mkfs$mkfsopt$sync_suffix.raw
216     filtered=$fulldir/op.mnt$mntopt.mkfs$mkfsopt$sync_suffix.filtered
217
218     echo "### xfs_logprint output ###" | tee $raw >$filtered
219     _scratch_xfs_logprint -c  2>&1 \
220     | tee -a $raw      \
221     | _filter_logprint \
222     | _filter_opnum    \
223     >>$filtered
224 }
225
226 # start at rec#2 "-s 2" so we skip over UMOUNT record which will always
227 # be a 512b single header at mkfs time
228 # and may not match with the FS mounted at a different LR size 
229 # => xlog_do_recovery_pass() can not handle the different hdr sizes
230 #    it assumes them all to be the same between the start..finish
231 # NB: On IRIX there is no UMOUNT record and so we could start from -s 0.
232
233 _print_transaction_inode()
234 {
235     _start=$1
236     mkdir $fulldir >/dev/null 2>&1
237     mntopt=`echo $MOUNT_OPTIONS | sed 's/ //g'`
238     mkfsopt=`echo $MKFS_OPTIONS | sed 's/ //g'`
239     raw=$fulldir/trans_inode.mnt$mntopt.mkfs$mkfsopt$sync_suffix.raw
240     filtered=$fulldir/trans_inode.mnt$mntopt.mkfs$mkfsopt$sync_suffix.filtered
241
242     echo "### xfs_logprint -t -i -s START output ###" | tee $raw >$filtered
243     _scratch_xfs_logprint -t -i -s $_start 2>&1 \
244     | tee -a $raw      \
245     | _filter_logprint \
246     >>$filtered
247 }
248
249 _print_transaction_buf()
250 {
251     _start=$1
252     mkdir $fulldir >/dev/null 2>&1
253     mntopt=`echo $MOUNT_OPTIONS | sed 's/ //g'`
254     mkfsopt=`echo $MKFS_OPTIONS | sed 's/ //g'`
255     raw=$fulldir/trans_buf.mnt$mntopt.mkfs$mkfsopt$sync_suffix.raw
256     filtered=$fulldir/trans_buf.mnt$mntopt.mkfs$mkfsopt$sync_suffix.filtered
257
258     echo "### xfs_logprint -t -b -s START output ###" | tee $raw >$filtered
259     _scratch_xfs_logprint -t -b -s $_start 2>&1 \
260     | tee -a $raw      \
261     | _filter_logprint \
262     >>$filtered
263 }
264
265 _mkfs_log()
266 {
267     # create the FS
268     _full "mkfs"
269     extra_ops="-l size=2000b"
270     _scratch_mkfs_xfs $extra_ops >>$seq.full 2>&1
271     if [ $? -ne 0 ] ; then 
272         _echofull "Cannot mkfs for this test using option specified: $MKFS_OPTIONS $extra_ops"
273         return 1
274     fi  
275
276     return 0
277 }
278
279
280 #
281 # mount fs and create some log traffic
282 #
283 _create_log()
284 {
285     # mount the FS
286     _full "mount"
287     _scratch_mount >>$seq.full 2>&1
288     if [ $? -ne 0 ] ; then 
289         _echofull "mount failed: $MOUNT_OPTIONS"
290         return 1
291     fi
292
293     # generate some log traffic - but not too much - life gets a little
294     # more complicated if the log wraps around. This traffic is
295     # pretty much arbitary, but could probably be made better than this.
296     touch $SCRATCH_MNT/{0,1,2,3,4,5,6,7,8,9}{0,1,2,3,4,5,6,7,8,9}
297         
298     # unmount the FS
299     _full "umount"
300     umount $SCRATCH_DEV >>$seq.full 2>&1
301     if [ $? -ne 0 ] ; then 
302         _echofull "umount failed"
303         return 1
304     fi
305
306     return 0
307 }
308
309 #
310 # mount fs and create some log traffic with sync'ing
311 #
312 _create_log_sync()
313 {
314     # mount the FS
315     _full " mount"
316     _scratch_mount >>$seq.full 2>&1
317     if [ $? -ne 0 ] ; then 
318         _echofull "mount failed: $MOUNT_OPTIONS"
319         return 1
320     fi
321
322     # generate some log traffic - but not too much
323     # add some syncs to get the log flushed to disk 
324     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
325         touch $file
326         sync
327     done
328
329     # unmount the FS
330     _full "umount"
331     umount $SCRATCH_DEV >>$seq.full 2>&1
332     if [ $? -ne 0 ] ; then 
333         _echofull "umount failed"
334         return 1
335     fi
336 }
337
338 _cmp_output()
339 {
340     echo "*** compare logprint: $1 with $2"
341     if ! diff $1 $2 >/dev/null; then
342         _fail "logprint output $1 differs to $2"
343     fi
344 }
345
346 #
347 # Op data of different Log Record sizes will mean that data is
348 # split at different points and in op printing it will not
349 # try and decode the data which has been split up.
350 # So we do a special diff processing to complain of differences
351 # if no split is involved.
352 #
353 # Example diff with forms of:
354 # "Left over region from split log item"
355 # "Not printing rest of data"
356 #
357 #   2149c2149
358 #   < Left over region from split log item
359 #   ---
360 #   > BUF DATA
361 #   2888c2888,2889
362 #   < INODE: #regs: 3 Not printing rest of data
363 #   ---
364 #   > INODE: #regs: 3 ino: 0x80 flags: 0x5 dsize: 16
365 #   >  blkno: <BLKNO> len:<LEN> boff: <BOFF>
366 #
367 _process_op_diff()
368 {
369     $AWK_PROG <$1 '
370         BEGIN { num_splits = 1; max_splits = 50 }
371         /^[0-9]/ {
372
373                 # ensure a split happened in previous difference
374                 if (num_splits < 1 || num_splits > max_splits) {
375                         print num_splits, " split(s) found prior to diff cmd: ", $0
376                         num_splits = 1 # shut-up end condition
377                         exit 1
378                 }
379                 num_splits = 0
380
381                 next
382         }
383         /Left over region/ || /Not printing rest/ { 
384                 num_splits++
385                 next
386         }
387         { next }
388         END { 
389                 if (num_splits < 1 || num_splits > max_splits) {
390                         print num_splits, " split(s) found prior to diff end"
391                         exit 1
392                 }
393         }
394     '
395     return $?
396 }
397
398 _cmp_op_output()
399 {
400     echo "*** compare logprint: $1 with $2"
401
402     diff $1 $2 >$filtered.diff
403     if ! _process_op_diff $filtered.diff
404     then
405         _fail "logprint output $1 differs to $2 considering splits"
406     fi
407 }
408
409 # return xfs log version of device
410 # e.g.
411 #   _log_version /dev/dsk/dks0d1s4
412 #
413 _log_version()
414 {
415     _dev=$1 
416     vers=`xfs_db -c 'sb 0' -c 'p versionnum' -r $_dev | $AWK_PROG '{print $3}'`
417     logver=`echo $vers | sed -e 's/0x[0-9a-f]\([0-9a-f]\)[0-9a-f][0-9a-f]/\1/'` 
418     if [ $logver = 4 -o $logver = 5 -o $logver = 6 -o $logver = 7 -o \
419          $logver = c -o $logver = d -o $logver = e -o $logver = f ]; then
420         echo 2
421     else
422         echo 1
423     fi
424 }
425
426 _require_v2log()
427 {
428     # test out mkfs to see if it supports "-l version=2"
429     export MKFS_OPTIONS="-l version=2"
430     if ! _scratch_mkfs_xfs $extra_ops >>$seq.full 2>&1; then
431         _notrun "mkfs does not support v2 logs"
432     fi
433
434     # test out mount to see if it mounts a v2 log fs
435     export MOUNT_OPTIONS="-o logbsize=32k"
436     if ! _scratch_mount >>$seq.full 2>&1; then
437         _notrun "mount/kernel does not support v2 logs"
438     fi
439
440     # check after unmount to see if it is clean
441     # i.e. it is not a 6.5.25 buggy version checking kernel
442     touch $SCRATCH_MNT/file
443     umount $SCRATCH_DEV >>$seq.full 2>&1
444     if _scratch_xfs_logprint -t | tee -a $seq.full \
445         | head | grep -q "<DIRTY>"; then
446         _notrun "kernel does not support v2 logs"
447     fi
448  
449     # otherwise presume it does support v2 logs...:)
450 }
451
452
453 # make sure this script returns success
454 /bin/true