f1eb5a2f100f8b05706219e0818967b874105c10
[xfstests-dev.git] / 018
1 #! /bin/sh
2 # XFS QA Test No. 018
3 #
4 # xfs_logprint test
5 # - extended to test for various log version 2 scenarios
6 # - tests 1 case of user/group quotas
7 #
8 #-----------------------------------------------------------------------
9 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
10
11 # This program is free software; you can redistribute it and/or modify it
12 # under the terms of version 2 of the GNU General Public License as
13 # published by the Free Software Foundation.
14
15 # This program is distributed in the hope that it would be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18
19 # Further, this software is distributed without any warranty that it is
20 # free of the rightful claim of any third person regarding infringement
21 # or the like.  Any license provided herein, whether implied or
22 # otherwise, applies only to this software file.  Patent licenses, if
23 # any, provided herein do not apply to combinations of this program with
24 # other software, or any other product whatsoever.
25
26 # You should have received a copy of the GNU General Public License along
27 # with this program; if not, write the Free Software Foundation, Inc., 59
28 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
29
30 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
31 # Mountain View, CA  94043, or:
32
33 # http://www.sgi.com 
34
35 # For further information regarding this notice, see: 
36
37 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
38 #-----------------------------------------------------------------------
39 #
40 # creator
41 owner=dxm@sgi.com
42
43 seq=`basename $0`
44 echo "QA output created by $seq"
45
46 here=`pwd`
47 tmp=/tmp/$$
48 status=0        # success is the default!
49
50 # get standard environment, filters and checks
51 . ./common.rc
52 . ./common.filter
53
54 _cleanup()
55 {
56     rm -f $tmp.*
57     if [ $status -eq 0 ]; then
58         # don't keep these files around unless something went wrong
59         rm $seq.trans* $seq.op* $seq.full
60     fi
61     echo "*** unmount"
62     umount $SCRATCH_MNT 2>/dev/null
63 }
64 trap "_cleanup; exit \$status" 0 1 2 3 15
65
66 _full()
67 {
68     echo ""            >>$seq.full      
69     echo "*** $* ***"  >>$seq.full
70     echo ""            >>$seq.full
71 }
72
73 # Handle the operations which get split over Log Record
74 # boundaries.
75 # Oper (379)..... flags: CONTINUE
76 # ...
77 # Oper (0)....... flags: WAS_CONT END
78 #
79 # or
80 #
81 # Oper (379)..... flags: none 
82 # ...
83 # Oper (0)....... flags: none 
84 #
85 _filter_opnum()
86 {
87     $AWK_PROG '
88 function extract_opnum(str) {
89         # e.g. "(379):" => "379"
90         gsub(/[():]/,"",str)
91         return str
92 }
93 BEGIN { 
94         opnum = -1
95         #debug = 1
96         }
97 /^Oper/ && debug {
98             printf "line = %s\n", $0
99         }
100 /^Oper/ {
101             was_cont = 0
102             prev_opnum = opnum
103             opnum = extract_opnum($2)
104         }
105 /^Oper/ && /flags: CONTINUE/ { 
106             $9 = "none" # overwrite CONTINUE flags
107             $2 = sprintf("(%d):", remember+opnum)       
108             remember += opnum
109             print
110             next        
111         }
112 /^Oper/ && /flags: WAS_CONT END/ {
113             # skip over was-continued op
114             # we assume there can be only 1
115             was_cont = 1
116             next        
117         }
118 (was_cont == 1) { 
119             # skip over any continued op stuff
120             next
121         }
122 /^Oper/ && /UNMOUNT/ {
123             remember = 0
124             opnum = -1
125             print
126             next
127         }
128 /^Oper/ && (opnum == 0) { 
129             # have operation 0 with NO continued op
130             remember += (prev_opnum+1)
131         }
132 /^Oper/ && debug { printf "line2 = %s, remember = %d, prev_opnum = %d\n", $0, remember, prev_opnum}
133 /^Oper/ && (remember > 0) {
134             # add in opnum accumulation from previous LRs 
135             $2 = sprintf("(%d):", remember+opnum)       
136             print
137             next
138         }
139         {print}
140     '
141 }
142
143 _filter_logprint()
144 {
145     sed '
146         s/data device: 0x[0-9a-f][0-9a-f]*/data device: <DEVICE>/;
147         s/log device: 0x[0-9a-f][0-9a-f]*/log device: <DEVICE>/;
148         s/log file: \".*\"/log device: <DEVICE>/;
149         s/daddr: [0-9][0-9]*/daddr: <DADDR>/;
150         s/length: [0-9][0-9]*/length: <LENGTH>/;
151         s/length: [0-9][0-9]*/length: <LENGTH>/;
152         s/^cycle num overwrites: .*$/cycle num overwrites: <TIDS>/;
153         s/tid: [0-9a-f][0-9a-f]*/tid: <TID>/;
154         s/tid:0x[0-9a-f][0-9a-f]*/tid:<TID>/;
155         s/q:0x[0-9a-f][0-9a-f]*/q:<Q>/;
156         s/a:0x[0-9a-f][0-9a-f]*/a:<A>/g;
157         s/blkno:0x[0-9a-f][0-9a-f]*/blkno:<BLKNO>/g;
158         s/blkno: [0-9][0-9]* (0x[0-9a-f]*)/blkno: <BLKNO> (<BLKNO>)/g;
159         s/blkno: [0-9][0-9]*/blkno: <BLKNO>/g;
160         s/boff: [0-9][0-9]*/boff: <BOFF>/g;
161         s/len: *[0-9][0-9]*/len:<LEN>/g;
162         /zeroed blocks/s/[0-9][0-9]*/<COUNT>/g;
163         /cleared blocks/s/[0-9][0-9]*/<COUNT>/g;
164         /log tail/s/[0-9][0-9]*/<COUNT>/g;
165         s/atime:[0-9a-fx]*  *mtime:[0-9a-fx]*  *ctime:[0-9a-fx]*/atime:<TIME>  mtime:<TIME>  ctime:<TIME>/;
166         s/atime 0x[0-9a-f]* mtime 0x[0-9a-f]* ctime 0x[0-9a-f]*/atime <TIME>  mtime <TIME>  ctime <TIME>/;
167         s/block [0-9][0-9]*/block <BLOCK>/;
168         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>/;
169         s/sunit: *[0-9][0-9]*  *swidth: *[0-9][0-9]*/sunit:<SUNIT> swidth:<SWIDTH>/;
170         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>/;
171         s/^uuid: *[0-9a-f-][0-9a-f-]* *format: *.*$/uuid: <UUID> format: <FORMAT>/;
172         /flushiter:/d;
173         /version:/,/h_size:/d;
174         /^---*/d;
175         /^===*/d;
176         /^~~~*/d;
177         /extended-header/d;
178         /LOG REC AT LSN/d;
179         /^[     ]*$/d;
180         s/  */ /g;
181         s/ $//;
182     ' \
183     | _fix_malloc
184 }
185
186 _check_log()
187 {
188     _full "clean_log : xfs_logprint"
189     _scratch_xfs_logprint -t | tee -a $seq.full \
190         | head | grep -q "<CLEAN>" || _fail "DIRTY LOG"
191 }
192
193 _print_operation()
194 {
195     raw=$seq.op.mnt$mnt.mkfs$mkfs.raw
196     filtered=$seq.op.mnt$mnt.mkfs$mkfs.filtered
197
198     echo "### xfs_logprint output ###" | tee $raw >$filtered
199     _scratch_xfs_logprint -c  2>&1 \
200     | tee -a $raw      \
201     | _filter_logprint \
202     | _filter_opnum    \
203     >>$filtered
204 }
205
206 # start at rec#2 "-s 2" so we skip over UMOUNT record which will always
207 # be a 512b single header at mkfs time
208 # and may not match with the FS mounted at a different LR size 
209 # => xlog_do_recovery_pass() can not handle the different hdr sizes
210 #    it assumes them all to be the same between the start..finish
211 # NB: On IRIX there is no UMOUNT record and so we could start from -s 0.
212
213 _print_transaction_inode()
214 {
215     raw=$seq.trans_inode.mnt$mnt.mkfs$mkfs.raw
216     filtered=$seq.trans_inode.mnt$mnt.mkfs$mkfs.filtered
217
218     echo "### xfs_logprint -t -i -s 2 output ###" | tee $raw >$filtered
219     _scratch_xfs_logprint -t -i -s 2 2>&1 \
220     | tee -a $raw      \
221     | _filter_logprint \
222     >>$filtered
223 }
224
225 _print_transaction_buf()
226 {
227     raw=$seq.trans_buf.mnt$mnt.mkfs$mkfs.raw
228     filtered=$seq.trans_buf.mnt$mnt.mkfs$mkfs.filtered
229
230     echo "### xfs_logprint -t -b -s 2 output ###" | tee $raw >$filtered
231     _scratch_xfs_logprint -t -b -s 2 2>&1 \
232     | tee -a $raw      \
233     | _filter_logprint \
234     >>$filtered
235 }
236
237
238 #
239 # will be run with different MKFS and MOUNT options
240 #
241 _mkfs_create_log()
242 {
243     _mkfs_opts=$1
244     _mnt_opts=$2
245
246     # create the FS
247     _full "mkfs"
248     extra_ops="-lsize=2000b $_mkfs_opts"
249     _scratch_mkfs_xfs $extra_ops >$tmp.mkfs0 2>&1
250     [ $? -ne 0 ] && \
251         _notrun "Cannot mkfs for this test using MKFS_OPTIONS specified: $MKFS_OPTIONS $extra_ops"
252
253     # check the mkfs settings
254     _filter_mkfs <$tmp.mkfs0 2>$tmp.mkfs
255     source $tmp.mkfs
256     [ $dbsize -eq 4096 ] \
257         || _notrun "Logprint test, tailored to 4K blocks ($dbsize in use)"
258     [ $isize -eq 256 ] \
259         || _notrun "Logprint test, tailored to 256b inodes ($isize in use)"
260
261     # mount the FS
262     _full " mount"
263     _scratch_mount $_mnt_opts >>$seq.full 2>&1 \
264         || _fail "mount failed: $_mnt_opts $MOUNT_OPTIONS"
265
266     # generate some log traffic - but not too much - life gets a little
267     # more complicated if the log wraps around. This traffic is
268     # pretty much arbitary, but could probably be made better than this.
269     touch $SCRATCH_MNT/{0,1,2,3,4,5,6,7,8,9}{0,1,2,3,4,5,6,7,8,9}
270         
271     # unmount the FS
272     _full "umount"
273     umount $SCRATCH_DEV >>$seq.full 2>&1 \
274         || _fail "umount failed"
275
276 }
277
278 _cmp_output()
279 {
280     echo "*** compare logprint: $1 with $2"
281     if ! diff $1 $2 >/dev/null; then
282         echo "FAILED: logprint output $1 differs to $2"
283         status=1
284     fi
285 }
286
287 _clear_opts()
288 {
289     # clear opts
290     # - remove the log options in mkfs
291     # - remove the log options in mount
292     # - remove the quota options in mount
293     # leave any other options given
294     MKFS_OPTIONS=`echo $MKFS_OPTIONS | sed -e 's/-l[ ]*[^ $]*//g'`
295     MOUNT_OPTIONS=`echo $MOUNT_OPTIONS |\
296             sed -e 's/logbsize=[^ ,]*,*//g' \
297                 -e 's/usrquota,*//g'        \
298                 -e 's/grpquota,*//g'        \
299                 -e 's/quota,*//g'           \
300                 -e 's/uqnoenforce,*//g'     \
301                 -e 's/gqnoenforce,*//g'     \
302                 -e 's/-o *$//g'             \
303                 -e 's/-o *-/-/g'            \
304                 `
305         
306     # export opts
307     export MKFS_OPTIONS
308     export MOUNT_OPTIONS
309 }
310
311 #
312 # Op data of different Log Record sizes will mean that data is
313 # split at different points and in op printing it will not
314 # try and decode the data which has been split up.
315 # So we do a special diff processing to complain of differences
316 # if no split is involved.
317 #
318 # Example diff with forms of:
319 # "Left over region from split log item"
320 # "Not printing rest of data"
321 #
322 #   2149c2149
323 #   < Left over region from split log item
324 #   ---
325 #   > BUF DATA
326 #   2888c2888,2889
327 #   < INODE: #regs: 3 Not printing rest of data
328 #   ---
329 #   > INODE: #regs: 3 ino: 0x80 flags: 0x5 dsize: 16
330 #   >  blkno: <BLKNO> len:<LEN> boff: <BOFF>
331 #
332 _process_op_diff()
333 {
334     $AWK_PROG <$1 '
335         BEGIN { num_splits = 1 }
336         /^[0-9]/ {
337
338                 # ensure cmd is a change op
339                 cmd = $1
340                 gsub(/[0-9][0-9]*/,"", cmd)
341                 gsub(/,/,"", cmd)
342                 if (cmd != "c") {
343                         print "bad diff cmd: ", $0
344                         exit 1
345                 }
346
347                 # ensure a split happened in previous difference
348                 if (num_splits != 1 && num_splits != 2) {
349                         print num_splits, " split(s) found prior to diff cmd: ", $0
350                         num_splits = 1 # shut-up end condition
351                         exit 1
352                 }
353                 num_splits = 0
354
355                 next
356         }
357         /Left over region/ || /Not printing rest/ { 
358                 num_splits++
359                 next
360         }
361         { next }
362         END { 
363                 if (num_splits != 1 && num_splits != 2) {
364                         print num_splits, " split(s) found prior to diff end"
365                         exit 1
366                 }
367         }
368     '
369     return $?
370 }
371
372 _cmp_op_output()
373 {
374     echo "*** compare logprint: $1 with $2"
375
376     diff $1 $2 >$filtered.diff
377     if ! _process_op_diff $filtered.diff
378     then
379         echo "FAILED: logprint output $1 differs to $2 considering splits"
380         status=1
381     fi
382 }
383
384
385 # real QA test starts here
386
387 # prelim
388 _require_scratch
389 rm -f $seq.trans* $seq.op* $seq.full
390 _clear_opts
391 echo "*** init FS"
392 umount $SCRATCH_DEV >/dev/null 2>&1
393
394 cat >$tmp.seq.params <<EOF
395 # mkfs-opt        mount-opt
396   -lversion=1     -ologbsize=32k
397   -lversion=2     -ologbsize=32k
398   -lversion=2     -ologbsize=64k
399   -lversion=2     -ologbsize=128k
400   -lversion=2     -ologbsize=256k
401 # NB: Stripe only affects LRs which weren't full when written out
402 #     So if we wrote out 32K LR then the stripe has no effect
403 #     In our case, it is likely that the LRs will be full but
404 #     it may no be the case in all QA environments where the LR
405 #     may be forced out early.
406 #  -lversion=2,su=4096 -ologbsize=32k
407 EOF
408
409 # do the work for various log params which
410 # should not effect the data content of the log
411 cat $tmp.seq.params \
412 | while read mkfs mnt
413 do
414     if [ "$mkfs" != "#" ]; then 
415         _mkfs_create_log $mkfs $mnt
416         _check_log
417
418         _print_operation
419         _cmp_op_output $seq.noquota.op $filtered
420
421         _print_transaction_inode
422         _cmp_output $seq.noquota.trans_inode $filtered
423
424         _print_transaction_buf
425         _cmp_output $seq.noquota.trans_buf $filtered
426     fi
427 done
428
429 # do a simple quota test to ensure DQUOT data is happening
430 mkfs="-lversion=1"
431 mnt="-ousrquota,grpquota"
432 _mkfs_create_log $mkfs $mnt
433 _check_log
434 _print_transaction_inode
435 _cmp_output $seq.ugquota.trans_inode $filtered
436
437 exit