xfstests: use _notrun for tape checks
[xfstests-dev.git] / common / dump
1 ##/bin/bash
2 #
3 # Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation.
8 #
9 # This program is distributed in the hope that it would be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write the Free Software Foundation,
16 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17 #
18 #
19 # Functions useful for xfsdump/xfsrestore tests
20 #
21
22 # --- initializations ---
23 rm -f $seqres.full
24
25 if [ -n "$DEBUGDUMP" ]; then
26         _dump_debug=-v4
27         _restore_debug=-v4
28         _invutil_debug=-d
29
30         # Use dump/restore in qa directory (copy them here) for debugging
31         export PATH="$here:$PATH"
32         export __XFSDUMP_PROG="`set_prog_path xfsdump`"
33         export XFSDUMP_PROG="$__XFSDUMP_PROG -e"
34         export XFSRESTORE_PROG="`set_prog_path xfsrestore`"
35         export XFSINVUTIL_PROG="`set_prog_path xfsinvutil`"
36         [ -x $here/xfsdump ]    && echo "Using xfstests' xfsdump for debug"
37         [ -x $here/xfsrestore ] && echo "Using xfstests' xfsrestore for debug"
38         [ -x $here/xfsinvutil ] && echo "Using xfstests' xfsinvutil for debug"
39 fi
40
41 [ "$XFSDUMP_PROG" = "" ]    && _notrun "xfsdump not found"
42 [ "$XFSRESTORE_PROG" = "" ] && _notrun "xfsrestore not found"
43 [ "$XFSINVUTIL_PROG" = "" ] && _notrun "xfsinvutil not found"
44
45 # status returned for not run tests
46 NOTRUNSTS=2
47
48 # name those directories
49 dump_file=$tmp.dumpfile
50 # dump_file=$here/dumpfile #TEMP OVERRIDE DUMP FILE
51 dump_sdir=dumpdir
52 dump_dir=$SCRATCH_MNT/$dump_sdir
53 restore_sdir=restoredir
54 restore_dir=$SCRATCH_MNT/$restore_sdir
55 multi=3
56 dumptape=$TAPE_DEV
57 media_label="stress_tape_media"
58 session_label="stress_$seq"
59
60 nobody=4 # define this uid/gid as a number
61 do_quota_check=true # do quota check if quotas enabled
62
63 _need_to_be_root
64
65 # install our cleaner
66 trap "_cleanup; exit \$status" 0 1 2 3 15
67
68 # start inventory from a known base - move it aside for test
69 for dir in /var/xfsdump/inventory /var/lib/xfsdump/inventory; do
70     if [ -d $dir ]; then
71         [ -d $dir.$seq ] && rm -rf $dir.$seq
72         mv $dir $dir.$seq
73     fi
74 done
75
76 have_mtvariable=false
77 [ `uname` = "Linux" ] && have_mtvariable=true
78
79
80 _require_multi_stream()
81 {
82     $XFSDUMP_PROG -JF -f /dev/null -f /dev/null 2> /dev/null |
83     grep -q "too many -f arguments" &&
84     _notrun "xfsdump multi-stream support required"
85 }
86
87 _require_legacy_v2_format()
88 {
89     $XFSDUMP_PROG 2>&1 |
90     grep -q "generate format 2 dump" ||
91     _notrun "xfsdump -K option required"
92
93     $XFSRESTORE_PROG 2>&1 |
94     grep -q "force use of format 2 generation" ||
95     _notrun "xfsrestore -K option required"
96 }
97
98 #
99 # do a remote/local mt
100 #
101 _mt()
102 {
103     op=$1
104     if _isrmt; then
105         # REMOTE
106         _rmtdev=`echo $dumptape | $AWK_PROG -F: '{print $2}'`
107
108         if echo $dumptape | grep '@' >/dev/null; then
109             _spec=`echo $dumptape | $AWK_PROG -F: '{print $1}'`
110             _rmtuser=`echo $_spec | $AWK_PROG -F@ '{print $1}'`
111             _rmthost=`echo $_spec | $AWK_PROG -F@ '{print $2}'`
112             rsh -n -l $_rmtuser $_rmthost "mt -t $_rmtdev $op"
113         else
114             _rmthost=`echo $dumptape | $AWK_PROG -F: '{print $1}'`
115             rsh -n $_rmthost "mt -t $_rmtdev $op"
116         fi
117     else
118         #LOCAL
119         mt -t $dumptape $op
120     fi
121 }
122
123 _check_onl()
124 {
125     _limit=10
126     i=0
127     while [ $i -lt $_limit ]; do
128         echo "Checking online..." >>$seqres.full
129         if _mt status >$tmp.status 2>&1; then
130             break;
131         else
132             sleep 1
133         fi
134         let i=$i+1
135     done
136
137
138     if [ $i -eq $_limit ]; then
139         echo "ERROR: mt -f $dumptape failed"
140         cat $tmp.status
141
142         _notrun "mt -f $dumptape failed"
143     fi
144
145
146     if egrep -i 'onl|ready' $tmp.status | grep -iv 'not ready' >/dev/null; then
147         :
148     else
149         echo "ERROR: $dumptape is not online"
150         cat $tmp.status
151
152         _notrun "dumptape, $dumptape, is not online"
153     fi
154 }
155
156 _wait_tape()
157 {
158     echo "Wait for tape, $dumptape, ..." >>$seqres.full
159
160     i=0
161     while [ $i -lt 20 ]; do
162         echo "Checking status..." >>$seqres.full
163         if _mt status 2>&1 | tee -a $seqres.full | egrep -i "onl|ready" >/dev/null; then
164             break;
165         else
166             sleep 1
167         fi
168         let i=$i+1
169     done
170 }
171
172 #
173 # Keep trying so we know we really have rewound
174 #
175 _rewind()
176 {
177     echo "Initiate rewind..." >>$seqres.full
178     _wait_tape
179     _mt rewind >/dev/null
180     _wait_tape
181 }
182
183 #
184 # Do a custom erase because:
185 # (i) some machines don't support it
186 # (ii) some machines take forever to do it
187 #
188 _erase_soft()
189 {
190     echo "Erasing tape" | tee -a $seqres.full
191     _rewind
192     _mt weof 3
193     _rewind
194 }
195
196 _erase_hard()
197 {
198     echo "Erasing tape" | tee -a $seqres.full
199     _mt erase
200 }
201
202 _isrmt()
203 {
204     echo $dumptape | grep ':' >/dev/null
205 }
206
207 #
208 # Get tape ready
209 #
210 _set_variable()
211 {
212     $have_mtvariable || return
213
214     if _isrmt; then
215         :
216     else
217         # LOCAL
218         echo "Put scsi tape driver into variable block size mode"
219         mt -f $dumptape setblk 0
220     fi
221 }
222
223 _require_tape()
224 {
225     dumptape=$1
226
227     if [ -z "$dumptape" -o "@" == "$dumptape" ]; then
228         _notrun "No dump tape specified"
229     fi
230
231     _check_onl
232     _set_variable
233 }
234
235 _wipe_fs()
236 {
237     _require_scratch
238
239     _scratch_mkfs_xfs >>$seqres.full || _fail "mkfs failed"
240     _scratch_mount >>$seqres.full || _fail "mount failed"
241 }
242
243 #
244 # Cleanup created dirs and files
245 # Called by trap
246 #
247 _cleanup()
248 {
249     # Some tests include this before checking _supported_fs xfs
250     # and the sleeps & checks here get annoying
251     if [ "$FSTYP" != "xfs" ]; then
252        return
253     fi
254
255     cd $here
256     rm -f $tmp.*
257
258     if [ -n "$DEBUGDUMP" ]; then
259         # save it for inspection
260         for dir in /var/xfsdump/inventory /var/lib/xfsdump/inventory; do
261             [ -d $dir ] || continue
262             tar -cvf $seqres.inventory.tar $dir
263             ls -nR $dir >$seqres.inventory.ls
264         done
265     fi
266
267     # put inventory dir back
268     for dir in /var/xfsdump/inventory /var/lib/xfsdump/inventory; do
269         [ -d $dir.$seq ] || continue
270         rm -rf $dir             # get rid of new one
271         mv $dir.$seq $dir
272     done
273
274     if [ $status -ne $NOTRUNSTS ]; then
275         # Sleep added to stop _check_scratch_fs from complaining that the
276         # scratch_dev is still busy
277         sleep 10
278
279         _check_scratch_fs
280     fi
281 }
282
283 #
284 # ensure that bulkstat data will
285 # match with incore data
286 # by forcing disk data to be written out
287 #
288 _stable_fs()
289 {
290     _saveddir=`pwd`; cd /
291     umount $SCRATCH_MNT >>$seqres.full || _fail "unmount failed"
292     _scratch_mount >>$seqres.full || _fail "mount failed"
293     cd $_saveddir
294 }
295
296 #
297 # Run fsstress to create a mixture of
298 # files,dirs,links,symlinks
299 #
300 # Pinched from test 013.
301 #
302 _create_dumpdir_stress()
303 {
304     echo "Creating directory system to dump using fsstress."
305
306     _wipe_fs
307
308     _param="-f link=10 -f creat=10 -f mkdir=10 -f truncate=5 -f symlink=10"
309     _count=240
310     rm -rf $dump_dir
311     if ! mkdir $dump_dir; then
312         echo "    failed to mkdir $dump_dir"
313         status=1
314         exit
315     fi
316     echo ""
317     echo "-----------------------------------------------"
318     echo "fsstress : $_param"
319     echo "-----------------------------------------------"
320     if ! $here/ltp/fsstress $_param -s 1 $FSSTRESS_AVOID -n $_count -d $dump_dir >$tmp.out 2>&1
321     then
322         echo "    fsstress (count=$_count) returned $? - see $seqres.full"
323
324         echo "--------------------------------------"       >>$seqres.full
325         echo "output from fsstress:"                        >>$seqres.full
326         echo "--------------------------------------"       >>$seqres.full
327         cat $tmp.out                                        >>$seqres.full
328         status=1
329     fi
330
331     _stable_fs
332 }
333
334 _mk_fillconfig1()
335 {
336     cat <<End-of-File >$tmp.config
337 # pathname      size in bytes   owner   group
338 #
339 small           10      $nobody $nobody
340 big             102400  daemon  sys
341 sub/small       10      bin     bin
342 sub/big         102400  $nobody sys
343 #
344 sub/a           1       $nobody $nobody
345 sub/b           2       $nobody $nobody
346 sub/c           4       $nobody $nobody
347 sub/d           8       $nobody $nobody
348 sub/e           16      $nobody $nobody
349 sub/f           32      $nobody $nobody
350 sub/g           64      $nobody $nobody
351 sub/h           128     $nobody $nobody
352 sub/i           256     $nobody $nobody
353 sub/j           512     $nobody $nobody
354 sub/k           1024    $nobody $nobody
355 sub/l           2048    $nobody $nobody
356 sub/m           4096    $nobody $nobody
357 sub/n           8192    $nobody $nobody
358 #
359 sub/a00         100     $nobody $nobody
360 sub/b00         200     $nobody $nobody
361 sub/c00         400     $nobody $nobody
362 sub/d00         800     $nobody $nobody
363 sub/e00         1600    $nobody $nobody
364 sub/f00         3200    $nobody $nobody
365 sub/g00         6400    $nobody $nobody
366 sub/h00         12800   $nobody $nobody
367 sub/i00         25600   $nobody $nobody
368 sub/j00         51200   $nobody $nobody
369 sub/k00         102400  $nobody $nobody
370 sub/l00         204800  $nobody $nobody
371 sub/m00         409600  $nobody $nobody
372 sub/n00         819200  $nobody $nobody
373 #
374 sub/a000        1000    $nobody $nobody
375 sub/e000        16000   $nobody $nobody
376 sub/h000        128000  $nobody $nobody
377 sub/k000        1024000 $nobody $nobody
378 End-of-File
379 }
380
381 _mk_fillconfig2()
382 {
383     cat <<End-of-File >$tmp.config
384 # pathname      size in bytes
385 #
386 smalll          10      $nobody $nobody
387 biggg           102400  $nobody $nobody
388 sub/smalll      10      $nobody $nobody
389 sub/biggg       102400  $nobody $nobody
390 End-of-File
391 }
392
393 _mk_fillconfig_perm()
394 {
395     # dir_guid: ugo=rwx,g+s on dir is for IRIX chmod(1)
396
397     cat <<End-of-File >$tmp.config
398 # pathname      size/dir  user group mode
399 #
400 file_suid       10      $nobody $nobody 04777
401 file_guid       10      $nobody $nobody 02777
402 file_sticky     10      $nobody $nobody 01777
403 file_mix1       10      $nobody $nobody 761
404 file_mix2       10      $nobody $nobody 642
405 dir_suid        d       $nobody $nobody 04777
406 dir_guid        d       $nobody $nobody ugo=rwx,g+s
407 dir_sticky      d       $nobody $nobody 01777
408 dir_mix1        d       $nobody $nobody 761
409 dir_mix2        d       $nobody $nobody 642
410 End-of-File
411 }
412
413 _mk_fillconfig_ea()
414 {
415     cat <<End-of-File >$tmp.config
416 # pathname      size    user    group    perm   name value namespace
417 #
418 smalll          10      $nobody $nobody  777    attr1 some_text   user
419 biggg           102400  $nobody $nobody  777    attr2 some_text2  root
420 sub/smalll      10      $nobody $nobody  777    attr3 some_text3  user
421 sub/biggg       102400  $nobody $nobody  777    attr4 some_text4  root
422 dir             d       $nobody $nobody  777    attr5 dir_text    user
423 #
424 # Add more files so that there are more than the number
425 # of streams.
426 # There are bugs in dump/restore for # non-dir files < # streams
427 # It can be tested in another configuration.
428 # It is a pathalogical case.
429 #
430 sub/a           1       $nobody $nobody
431 sub/b           2       $nobody $nobody
432 sub/c           4       $nobody $nobody
433 sub/d           8       $nobody $nobody
434 sub/e           16      $nobody $nobody
435 sub/f           32      $nobody $nobody
436 sub/g           64      $nobody $nobody
437 sub/h           128     $nobody $nobody
438 sub/i           256     $nobody $nobody
439 sub/j           512     $nobody $nobody
440 sub/k           1024    $nobody $nobody
441 sub/l           2048    $nobody $nobody
442 sub/m           4096    $nobody $nobody
443 sub/n           8192    $nobody $nobody
444 End-of-File
445 }
446
447 #
448 # extended file attribute flags
449 #
450 _mk_fillconfig_xattr()
451 {
452     cat <<End-of-File >$tmp.config
453 # pathname      size    user    group    perm   name
454 #
455 xflag_realtime  10      $nobody $nobody  777    XFS_XFLAG_REALTIME
456 xflag_prealloc  10      $nobody $nobody  777    XFS_XFLAG_PREALLOC
457 xflag_immutable 10      $nobody $nobody  777    XFS_XFLAG_IMMUTABLE
458 xflag_append    10      $nobody $nobody  777    XFS_XFLAG_APPEND
459 xflag_sync      10      $nobody $nobody  777    XFS_XFLAG_SYNC
460 xflag_noatime   10      $nobody $nobody  777    XFS_XFLAG_NOATIME
461 xflag_nodump    10      $nobody $nobody  777    XFS_XFLAG_NODUMP
462 xflag_hasattr   10      $nobody $nobody  777    XFS_XFLAG_HASATTR
463 End-of-File
464 }
465
466 #
467 # Create a bunch of directories/files of different sizes
468 # filled with data.
469 #
470 # Pinched from test 001.
471 #
472 _do_create_dumpdir_fill()
473 {
474     echo "Creating directory system to dump using src/fill."
475
476     mkdir -p $dump_dir || _fail "cannot mkdir \"$dump_dir\""
477     cd $dump_dir
478
479     $verbose && echo -n "Setup "
480     sed -e '/^#/d' $tmp.config \
481     | while read file nbytes owner group perms ea_name ea_value namespace
482     do
483         if [ $nbytes = "d" ]; then
484             # create a directory
485             dir=$file
486             if [ ! -d $dir ]
487             then
488                 if mkdir $dir
489                 then
490                     :
491                 else
492                     $verbose && echo
493                     echo "Error: cannot mkdir \"$dir\""
494                     exit 1
495                 fi
496             fi
497         else
498             # create a directory/file
499             dir=`dirname $file`
500             if [ "$dir" != "." ]
501             then
502                 if [ ! -d $dir ]
503                 then
504                     if mkdir $dir
505                     then
506                         :
507                     else
508                         $verbose && echo
509                         echo "Error: cannot mkdir \"$dir\""
510                         exit 1
511                     fi
512                 fi
513             fi
514             rm -f $file
515             if $here/src/fill $file $file $nbytes
516             then
517                 :
518             else
519                 $verbose && echo
520                 echo "Error: cannot create \"$file\""
521                 exit 1
522             fi
523         fi
524         if [ -n "$owner" -a -n "$group" ]; then
525             chown $owner.$group $file
526         fi
527         if [ -n "$perms" ]; then
528             chmod $perms $file
529         fi
530
531         # extended attributes (EA)
532         if [ -n "$ea_name" -a -n "$ea_value" ]; then
533             if [ "X$namespace" = "Xroot" ]; then
534                 attr -R -s $ea_name -V $ea_value $file
535             else
536                 attr -s $ea_name -V $ea_value $file
537             fi
538         # extended file attribute flags - no value - NOT EAs
539         elif [ -n "$ea_name" -a -z "$ea_value" ]; then
540             # set the flag
541             # TODO XXX
542             # use xfs_io to send the ioctl
543             :
544         fi
545         $verbose && echo -n "."
546     done
547     $verbose && echo
548
549     cd $here
550 }
551
552 _mk_fillconfig_multi()
553 {
554     _mk_fillconfig1
555     cat <<End-of-File >>$tmp.config
556 # pathname      size in bytes
557 #
558 large000        8874368 $nobody $nobody
559 large111        2582912 $nobody $nobody
560 large222        7825792 $nobody $nobody
561 End-of-File
562 }
563
564 _create_dumpdir_largefile()
565 {
566     _wipe_fs
567     mkdir -p $dump_dir || _fail "cannot mkdir \"$dump_dir\""
568     _largesize=4294967297
569     _largefile=$dump_dir/largefile
570     echo "dd a largefile at offset $_largesize"
571     POSIXLY_CORRECT=yes \
572     dd if=/dev/zero of=$_largefile bs=1 seek=$_largesize count=10 2>&1
573     _stable_fs
574 }
575
576 _create_dumpdir_fill()
577 {
578     _wipe_fs
579     _mk_fillconfig1
580     _do_create_dumpdir_fill
581     _stable_fs
582 }
583
584 _create_dumpdir_fill2()
585 {
586     _wipe_fs
587     _mk_fillconfig2
588     _do_create_dumpdir_fill
589     _stable_fs
590 }
591
592 _create_dumpdir_fill_perm()
593 {
594     _wipe_fs
595     _mk_fillconfig_perm
596     _do_create_dumpdir_fill
597     _stable_fs
598 }
599
600 _create_dumpdir_fill_ea()
601 {
602     _wipe_fs
603     _mk_fillconfig_ea
604     _do_create_dumpdir_fill
605     _stable_fs
606 }
607
608 #
609 # Create enough files, and a few large enough files, so that
610 # some files are likely to be split across streams.
611 #
612 _create_dumpdir_fill_multi()
613 {
614     _wipe_fs
615     _mk_fillconfig_multi
616     _do_create_dumpdir_fill
617     _stable_fs
618 }
619
620 #
621 # Append a subset of the fill'ed files
622 # So we can see if just these get dumped on an incremental
623 #
624 _append_dumpdir_fill()
625 {
626     cd $dump_dir
627     cat <<End-of-File >$tmp.config
628 # pathname
629 #
630 small
631 sub/big
632 #
633 sub/a
634 sub/c
635 sub/e
636 End-of-File
637     sed -e '/^#/d' $tmp.config \
638     | while read file
639     do
640         echo 'Extra text' >>$file
641     done
642
643     cd $here
644     _stable_fs
645 }
646
647 _do_create_dump_symlinks()
648 {
649     echo "Creating directory system of symlinks to dump."
650
651     mkdir -p $dump_dir || _fail "cannot mkdir \"$dump_dir\""
652     cd $dump_dir
653
654     $verbose && echo -n "Setup "
655     sed -e '/^#/d' $tmp.config \
656     | while read file nbytes owner group owner2 group2 perms perms2
657     do
658         dir=`dirname $file`
659         if [ "$dir" != "." ]
660         then
661             if [ ! -d $dir ]
662             then
663                 if mkdir $dir
664                 then
665                     :
666                 else
667                     $verbose && echo
668                     echo "Error: cannot mkdir \"$dir\""
669                     exit 1
670                 fi
671             fi
672         fi
673         rm -f $file
674         touch $file
675
676         # Do chmod on symlink using umask.
677         # This won't do the right thing as it subtracts permissions.
678         # However, I don't care, as long as I get some different perms
679         # for testing.
680         if [ -n "$perms2" ]; then
681             omask=`umask`
682             umask $perms2
683         fi
684         ln -s $file $file-link
685         if [ -n "$perms2" ]; then
686             umask $omask
687         fi
688
689         if [ -n "$owner" -a -n "$group" ]; then
690             chown $owner.$group $file
691         fi
692         if [ -n "$owner" -a -n "$group" ]; then
693             chown -h $owner.$group $file-link
694         fi
695         if [ -n "$perms" ]; then
696             chmod $perms $file
697         fi
698         $verbose && echo -n "."
699     done
700     $verbose && echo
701
702     cd $here
703 }
704
705 _mk_symlink_config()
706 {
707     cat <<End-of-File >$tmp.config
708 # path  size    owner1  group1  owner2  group2  perm1   perm2
709 #
710 a       0       $nobody $nobody daemon  sys     124     421
711 b       0       daemon  sys     bin     bin     347     743
712 sub/a   0       bin     bin     $nobody sys     777     777
713 sub/b   0       $nobody sys     $nobody $nobody 367     763
714 End-of-File
715 }
716
717 _create_dumpdir_symlinks()
718 {
719     _wipe_fs
720     _mk_symlink_config
721     _do_create_dump_symlinks
722     _stable_fs
723 }
724
725 #
726 # create hardlinks of form $_fname, $_fname_h1 $_fname_h2 ...
727 #
728 _create_hardlinks()
729 {
730     _fname=$1
731     _numlinks=$2
732
733     touch $_fname
734     _j=1
735     while [ $_j -le $_numlinks ]; do
736         _suffix=_h$_j
737         _hardlink=$_fname$_suffix
738         echo "creating hardlink $_hardlink to $_fname"
739         ln $_fname $_hardlink
740         let _j=$_j+1
741     done
742 }
743
744 #
745 # create a set of hardlinks
746 # create hardlinks of form file1, file1_h1 file1_h2 ...
747 # create hardlinks of form file2, file2_h1 file2_h2 ...
748 # create hardlinks of form file3, file3_h1 file3_h2 ...
749 #
750 _create_hardset()
751 {
752     _numsets=$1
753     _i=1
754     while [ $_i -le $_numsets ]; do
755         _create_hardlinks file$_i 5
756         let _i=$_i+1
757     done
758 }
759
760
761 _modify_level()
762 {
763     _level=$1
764     echo "mod level $_level" >$dump_dir/file$_level
765 }
766
767 _create_dumpdir_hardlinks()
768 {
769     _numsets=$1
770     _wipe_fs
771     echo "Creating directory system of hardlinks to incrementally dump."
772
773     mkdir -p $dump_dir || _fail "cannot mkdir \"$dump_dir\""
774     cd $dump_dir
775
776     _create_hardset $_numsets
777
778     cd $here
779     _stable_fs
780 }
781
782 #
783 # Filter for ls
784 # Filter out times and dates on symlinks and char devices.
785 # Filter out size on directories because this can differ
786 # when transitioning to long inode numbers (ie. 64 bits).
787 #
788 _ls_filter()
789 {
790   $AWK_PROG '
791         /^l/ { date = $8; time = $7; sub(date,"DATE"); sub(time,"TIME"); print}
792         /^c/ { date = $9; time = $7; sub(date,"DATE"); sub(time,"TIME"); print}
793         /^d/ { size = $5; sub(size,"SIZE"); print}
794         {print}' \
795   | sed -e 's/total [0-9][0-9]*/total TOTAL/'
796 }
797
798 #
799 # Filtering of Irix character hwgraph device names
800 # e.g.
801 # chardev: /hw/node/xtalk/15/pci/0/scsi_ctlr/0/target/1/lun/0/disk/partition/4/char
802 # blkdev:  /dev/dsk/dks0d1s4
803 #
804 _filter_devchar()
805 {
806     $AWK_PROG '
807         /\/hw\/node/ {
808             sub(/\/hw.*scsi_ctlr\//,"/dev/dsk/dks")  # blah blah /dev/dsk/dks0/target/1/....
809             sub(/\/target\//,"d")                    # blah blah /dev/dsk/dks0d1/lun/0/disk.....
810             sub(/\/lun.*partition\//,"s")            # blah blah /dev/dsk/dks0d1s4/char
811             sub(/\/char/,"")                         # blah blah /dev/dsk/dks0d1s4
812         }
813         { print }
814     '
815 }
816
817
818 #
819 # Filter out the non-deterministic dump msgs from
820 # xfsdump and xfsrestore
821 #
822 _dump_filter_main()
823 {
824   _filter_devchar |\
825   sed \
826       -e "s#$__XFSDUMP_PROG#xfsdump#"                   \
827       -e "s#$XFSRESTORE_PROG#xfsrestore#"               \
828       -e "s#$XFSINVUTIL_PROG#xfsinvutil#"               \
829       -e "s/`hostname`/HOSTNAME/"                       \
830       -e "s#$SCRATCH_DEV#SCRATCH_DEV#"                  \
831       -e "s#$SCRATCH_RAWDEV#SCRATCH_DEV#"               \
832       -e "s#$dumptape#TAPE_DEV#"                        \
833       -e "s#$SCRATCH_MNT#SCRATCH_MNT#"                  \
834       -e "s#$dump_file#DUMP_FILE#"                      \
835       -e 's#/var/lib/xfsdump#/var/xfsdump#'             \
836       -e 's/session id:[        ]*[0-9a-f-]*/session id: ID/'  \
837       -e '/filesystem id:[      ]*[0-9a-f-]*/d'         \
838       -e 's/time:[      ].*/time: TIME/'                \
839       -e 's/date:[      ].*/date: DATE/'                \
840       -e 's/dump begun .*/dump begun DATE/'             \
841       -e 's/previously begun .*/previously begun DATE/' \
842       -e 's/[0-9][0-9]* seconds/SECS seconds/'          \
843       -e 's/restore.[0-9][0-9]*/restore.PID/'           \
844       -e 's/ino [0-9][0-9]*/ino INO/g'                  \
845       -e '/stream [0-9]:/s/offset [0-9][0-9]*/offset NUM/g'     \
846       -e '/: dump size/s/[0-9][0-9]*/NUM/'              \
847       -e '/dump size:/s/[0-9][0-9]*/NUM/'               \
848       -e '/dump size per stream:/s/[0-9][0-9]*/NUM/'    \
849       -e 's/\(media file size[   ]*\)[0-9][0-9]*/\1NUM/' \
850       -e 's/\(mfile size:[       ]*\)[0-9][0-9]*/\1NUM/' \
851       -e '/drive[        ]*[0-9][0-9]*:/d'              \
852       -e '/\/dev\/tty/d'                                \
853       -e '/inventory session uuid/d'                    \
854       -e '/ - Running single-threaded/d'                \
855       -e '/Mount point match/d'                         \
856       -e '/^.*I\/O metrics: .*$/d'                      \
857       -e 's/1048576/BLOCKSZ/'                           \
858       -e 's/2097152/BLOCKSZ/'                           \
859       -e 's/(pid[        ]*[1-9][0-9]*)/\(pid PID\)/'   \
860       -e '/version [3-9]\.[0-9]/d'                      \
861       -e 's/\/hw\/module.*$/SCRATCH_DEV/'               \
862       -e 's/xfsdump: ino map phase 1: .*/xfsdump: ino map <PHASES>/' \
863       -e '/xfsdump: ino map phase [2]/,1d'              \
864       -e '/xfsdump: ino map phase [3]/,1d'              \
865       -e '/xfsdump: ino map phase [4]/,1d'              \
866       -e '/xfsdump: ino map phase [5]/,1d'              \
867       -e 's/id:[[:space:]]*[0-9a-f]\{8\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{12\}/ID: ID/'                                              \
868       -e 's/\[y\/n\][- ]----------------------*/\[y\/n\]/'              \
869       -e '/skip attribute set/d'                                \
870   | perl -ne '
871         # filter out all the output between the lines "Dump Summary:"
872         # and "Dump Status:"
873         if ($_ =~ /(?:Dump|Restore) Summary/) {
874                 $skip = 1;
875         } elsif ($_ =~ /(?:Dump|Restore) Status/) {
876                 $skip = 0;
877         }
878         print if (! $skip);' \
879   | perl -ne '
880         # correct the file count if large scratch devices are being used
881         $skip = 0;
882         if ($_ =~ /(\S+) directories and (\S+) entries/) {
883                 $foo = $2;
884                 if ($ENV{'LARGE_SCRATCH_DEV'} && $foo > 0) {
885                         $foo -= 1;
886                 }
887                 printf("xfsrestore: %u directories and %u entries processed\n",
888                                                 $1, $foo);
889                 $skip = 1;
890         }
891         print if (! $skip);'
892 }
893
894 _dump_filter()
895 {
896    if $do_quota_check
897    then
898        _dump_filter_main | _check_quota_dumprestore | _check_quota_entries
899    else
900        _dump_filter_main
901    fi
902 }
903
904 _invutil_filter()
905 {
906   _dump_filter_main \
907   | sed \
908         -e 's/UUID[     ]*:[    ][0-9a-f-]*/UUID                :       ID/' \
909         -e 's/TIME OF DUMP[     ]*:.*/TIME OF DUMP      :       TIME/' \
910         -e 's/HOSTNAME:SCRATCH_MNT.*/HOSTNAME:SCRATCH_MNT/' \
911         -e 's#inventory/[0-9a-f-]*#inventory/UUID#' \
912
913 }
914
915
916 _dir_filter()
917 {
918   sed \
919     -e "s#$dump_file#DUMP_FILE#g"      \
920     -e "s#$SCRATCH_DEV#SCRATCH_DEV#"        \
921     -e "s#$SCRATCH_RAWDEV#SCRATCH_DEV#"    \
922     -e "s#$dumptape#TAPE_DEV#"         \
923     -e "s#$dump_dir#DUMP_DIR#g"       \
924     -e "s#$restore_dir#RESTORE_DIR#g" \
925     -e "s#$SCRATCH_MNT#SCRATCH_MNT#g"       \
926     -e "s#$dump_sdir#DUMP_SUBDIR#g"   \
927     -e "s#$restore_sdir#RESTORE_SUBDIR#g" \
928     -e "s#$$#PID#g" \
929     -e "/Only in SCRATCH_MNT: .use_space/d" \
930
931 }
932
933 #
934 # Parse xfsdump arguments.
935 # Note: requires a space between option letter and argument
936 #
937 _parse_dump_args()
938 {
939     OPTIND=0
940     dump_args=""
941     while [ $# -gt 0 ]
942     do
943         case $1
944         in
945         -f)
946             [ -z "$2" ] && _fail "missing argument for -f"
947             dumptape=$2
948             dump_file=$2
949             shift
950             ;;
951         -L)
952             [ -z "$2" ] && _fail "missing argument for -L"
953             session_label=$2
954             shift
955             ;;
956         --multi)
957             [ -z "$2" ] && _fail "missing argument for --multi"
958             multi=$2
959             shift
960             ;;
961         --check-quota)
962             do_quota_check=true
963             ;;
964         --no-check-quota)
965             do_quota_check=false
966             ;;
967         -o|-D|-F|-K)
968             dump_args="$dump_args $1"
969             ;;
970         -l|-d)
971             [ -z "$2" ] && _fail "missing argument for $1"
972             dump_args="$dump_args $1$2"
973             shift
974             ;;
975         *)
976             _fail "invalid argument to common.dump function: $1"
977             ;;
978         esac
979         shift
980     done
981 }
982
983 #
984 # Parse xfsrestore arguments.
985 # Note: requires a space between option letter and argument
986 #
987 _parse_restore_args()
988 {
989     OPTIND=0
990     restore_args=""
991     while [ $# -gt 0 ]
992     do
993         case $1
994         in
995         -f)
996             [ -z "$2" ] && _fail "missing argument for -f"
997             dumptape=$2
998             dump_file=$2
999             shift
1000             ;;
1001         -L)
1002             [ -z "$2" ] && _fail "missing argument for -L"
1003             session_label=$2
1004             shift
1005             ;;
1006         --multi)
1007             [ -z "$2" ] && _fail "missing argument for --multi"
1008             multi=$2
1009             shift
1010             ;;
1011         --check-quota)
1012             do_quota_check=true
1013             ;;
1014         --no-check-quota)
1015             do_quota_check=false
1016             ;;
1017         -K|-R)
1018             restore_args="$restore_args $1"
1019             ;;
1020         *)
1021             _fail "invalid argument to common.dump function: $1"
1022             ;;
1023         esac
1024         shift
1025     done
1026 }
1027
1028
1029 #
1030 # Dump a subdir
1031 #
1032 _do_dump_sub()
1033 {
1034     _parse_dump_args $*
1035
1036     echo "Dumping to tape..."
1037     opts="$_dump_debug$dump_args -s $dump_sdir -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
1038     echo "xfsdump $opts" | _dir_filter
1039     $XFSDUMP_PROG $opts 2>&1 | tee -a $seqres.full | _dump_filter
1040 }
1041
1042 #
1043 # Do dump to tape
1044 #
1045 _do_dump()
1046 {
1047     _parse_dump_args $*
1048
1049     echo "Dumping to tape..."
1050     opts="$_dump_debug$dump_args -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
1051     echo "xfsdump $opts" | _dir_filter
1052     $XFSDUMP_PROG $opts 2>&1 | tee -a $seqres.full | _dump_filter
1053 }
1054
1055
1056 #
1057 # Do full dump with -m
1058 #
1059 _do_dump_min()
1060 {
1061     _parse_dump_args $*
1062
1063     echo "Dumping to tape..."
1064     onemeg=1048576
1065     opts="$_dump_debug$dump_args -m -b $onemeg -l0 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
1066     echo "xfsdump $opts" | _dir_filter
1067     $XFSDUMP_PROG $opts 2>&1 | tee -a $seqres.full | _dump_filter
1068 }
1069
1070
1071 #
1072 # Do full dump to file
1073 #
1074 _do_dump_file()
1075 {
1076     _parse_dump_args $*
1077
1078     echo "Dumping to file..."
1079     opts="$_dump_debug$dump_args -f $dump_file -M $media_label -L $session_label $SCRATCH_MNT"
1080     echo "xfsdump $opts" | _dir_filter
1081     $XFSDUMP_PROG $opts 2>&1 | tee -a $seqres.full | _dump_filter
1082 }
1083
1084 #
1085 # Do full dump to multiple files
1086 #
1087 _do_dump_multi_file()
1088 {
1089     _parse_dump_args $*
1090
1091     multi_args=""
1092
1093     i=0
1094     while [ $i -lt $multi ]
1095     do
1096         multi_args="$multi_args -f $dump_file.$i -M $media_label.$i"
1097         let i=$i+1
1098     done
1099
1100     echo "Dumping to files..."
1101     opts="$_dump_debug$dump_args $multi_args -L $session_label $SCRATCH_MNT"
1102     echo "xfsdump $opts" | _dir_filter
1103     $XFSDUMP_PROG $opts 2>&1 | tee -a $seqres.full | _dump_filter
1104 }
1105
1106
1107 _prepare_restore_dir()
1108 {
1109     rm -rf $restore_dir
1110     mkdir $restore_dir || _fail "failed to mkdir $restore_dir"
1111 }
1112
1113
1114 #
1115 # Get tape ready and restore dir
1116 #
1117 _prepare_restore()
1118 {
1119     _prepare_restore_dir
1120
1121     echo "Rewinding tape"
1122     _rewind
1123 }
1124
1125 #
1126 # Restore the tape into $restore_dir
1127 #
1128 _do_restore()
1129 {
1130     _parse_restore_args $*
1131     _prepare_restore
1132
1133     echo "Restoring from tape..."
1134     opts="$_restore_debug$restore_args -f $dumptape  -L $session_label $restore_dir"
1135     echo "xfsrestore $opts" | _dir_filter
1136     $XFSRESTORE_PROG $opts 2>&1 | tee -a $seqres.full | _dump_filter
1137 }
1138
1139 #
1140 # Restore the tape into $restore_dir using -m
1141 #
1142 _do_restore_min()
1143 {
1144     _parse_restore_args $*
1145     _prepare_restore
1146
1147     echo "Restoring from tape..."
1148     onemeg=1048576
1149     opts="$_restore_debug$restore_args -m -b $onemeg -f $dumptape  -L $session_label $restore_dir"
1150     echo "xfsrestore $opts" | _dir_filter
1151     $XFSRESTORE_PROG $opts 2>&1 | tee -a $seqres.full | _dump_filter
1152 }
1153
1154 #
1155 # Restore the tape from a dump file
1156 #
1157 _do_restore_file()
1158 {
1159     _parse_restore_args $*
1160     _prepare_restore_dir
1161
1162     echo "Restoring from file..."
1163     opts="$_restore_debug$restore_args -f $dump_file  -L $session_label $restore_dir"
1164     echo "xfsrestore $opts" | _dir_filter
1165     $XFSRESTORE_PROG $opts 2>&1 | tee -a $seqres.full | _dump_filter
1166 }
1167
1168 #
1169 # Cumulative restore from a file
1170 # Must call _prepare_restore_dir before the first
1171 # (and only the first) call to this function.
1172 #
1173 _do_restore_file_cum()
1174 {
1175     _parse_restore_args $*
1176
1177     echo "Restoring cumumlative from file..."
1178     opts="$_restore_debug$restore_args -f $dump_file -r $restore_dir"
1179     echo "xfsrestore $opts" | _dir_filter
1180     $XFSRESTORE_PROG $opts 2>&1 | tee -a $seqres.full | _dump_filter
1181 }
1182
1183 _do_restore_toc()
1184 {
1185     _parse_restore_args $*
1186
1187     echo "Contents of dump ..."
1188     opts="$_restore_debug$restore_args -f $dump_file -t"
1189     echo "xfsrestore $opts" | _dir_filter
1190     cd $SCRATCH_MNT # for IRIX which needs xfs cwd
1191     $XFSRESTORE_PROG $opts 2>&1 | tee -a $seqres.full | _dump_filter_main |\
1192     _check_quota_file |\
1193     _check_quota_entries |\
1194     $AWK_PROG 'NF != 1 { print; next }
1195                {files = sprintf("%s\n%s", files, $1)}
1196                 END { print files | "sort" } '
1197     # the above awk code is to alpha sort only the output
1198     # of files (and not the verbose restore msgs)
1199     cd $here # put back
1200 }
1201
1202 #
1203 # Restore the tape from multiple dump files
1204 #
1205 _do_restore_multi_file()
1206 {
1207     _parse_restore_args $*
1208     _prepare_restore_dir
1209
1210     multi_args=""
1211
1212     i=0
1213     while [ $i -lt $multi ]
1214     do
1215         multi_args="$multi_args -f $dump_file.$i"
1216         let i=$i+1
1217     done
1218
1219     echo "Restoring from file..."
1220     opts="$_restore_debug$restore_args $multi_args -L $session_label $restore_dir"
1221     echo "xfsrestore $opts" | _dir_filter
1222     $XFSRESTORE_PROG $opts 2>&1 | tee -a $seqres.full | _dump_filter
1223 }
1224
1225 #
1226 # Do xfsdump piped into xfsrestore - xfsdump | xfsrestore
1227 # Pass dump options in $1 and restore options in $2, if required. e.g.:
1228 #     _do_dump_restore "-o -F" "-R"
1229 #     _do_dump_restore "" "-R"
1230 #
1231 # Use -s as we want to dump and restore to the same xfs partition
1232 #
1233 _do_dump_restore()
1234 {
1235     _parse_dump_args $1
1236     _parse_restore_args $2
1237     _prepare_restore_dir
1238     echo "xfsdump|xfsrestore ..."
1239     restore_opts="$_restore_debug$restore_args - $restore_dir"
1240     dump_opts="$_dump_debug$dump_args -s $dump_sdir - $SCRATCH_MNT"
1241     echo "xfsdump $dump_opts | xfsrestore $restore_opts" | _dir_filter
1242     $XFSDUMP_PROG $dump_opts 2>$tmp.dump.mlog | $XFSRESTORE_PROG $restore_opts 2>&1 | tee -a $seqres.full | _dump_filter
1243     _dump_filter <$tmp.dump.mlog
1244 }
1245
1246 #
1247 # Compare dumped subdirectory with restored dir
1248 # using ls -nR.
1249 # Thus no contents are compared but permissions, sizes,
1250 # owners, etc... are.
1251 #
1252 _ls_compare_sub()
1253 {
1254     #
1255     # verify we got back what we dumped
1256     #
1257     echo "Comparing listing of dump directory with restore directory"
1258     ls -nR $dump_dir | tee -a $seqres.full | _ls_filter >$tmp.dump_dir
1259     ls -nR $restore_dir/$dump_sdir | tee -a $seqres.full | _ls_filter \
1260     | sed -e "s#$restore_sdir\/##" >$tmp.restore_dir
1261
1262     diff -bcs $tmp.dump_dir $tmp.restore_dir | sed -e "s#$tmp#TMP#g"
1263 }
1264
1265 #
1266 # filter out the date fields
1267 #
1268 _ls_nodate_filter()
1269 {
1270     $AWK_PROG 'NF == 9 { print $1, $2, $3, $4, $9 }'
1271 }
1272
1273 #
1274 # _ls_compare_sub but don't compare dates
1275 _ls_nodate_compare_sub()
1276 {
1277     #
1278     # verify we got back what we dumped
1279     #
1280     echo "Comparing listing of dump directory with restore directory"
1281     ls -nR $dump_dir | tee -a $seqres.full | _ls_filter | _ls_nodate_filter >$tmp.dump_dir
1282     ls -nR $restore_dir/$dump_sdir | tee -a $seqres.full | _ls_filter \
1283     | _ls_nodate_filter | sed -e "s#$restore_sdir\/##" >$tmp.restore_dir
1284
1285     diff -bcs $tmp.dump_dir $tmp.restore_dir | sed -e "s#$tmp#TMP#g"
1286 }
1287
1288 #
1289 # Compare using recursive diff the files of the dumped
1290 # subdirectory.
1291 # This one will compare the contents.
1292 #
1293 _diff_compare_sub()
1294 {
1295     echo "Comparing dump directory with restore directory"
1296     diff -rs $dump_dir $restore_dir/$dump_sdir | _dir_filter
1297 }
1298
1299 _get_eas_on_path()
1300 {
1301     _path=$1
1302
1303 # Tim - this is the IRIX way...
1304     # find $_path -exec attr -l {} \; |\
1305     # awk '{print $9, $2}' |\
1306     # sed 's/["]//g' |\
1307     # sort |\
1308 # and this is now the Linux way...
1309     echo "User names"
1310     getfattr --absolute-names -Rh -m user $_path |\
1311     perl -wn -e '
1312         if (m/^# file: (\S+)/) { $file = $1 }
1313         elsif (m/^user\.(\w+)/) { print $file, " ",$1,"\n" }' |\
1314     sort |\
1315     while read file ea_name; do
1316         attr -g $ea_name $file
1317     done
1318
1319     if [ "$USE_ATTR_SECURE" = yes ]; then
1320         echo "Security names"
1321         getfattr --absolute-names -Rh -m security $_path |\
1322         perl -wn -e '
1323             if (m/^# file: (\S+)/) { $file = $1 }
1324             elsif (m/^security\.(\w+)/) { print $file, " ",$1,"\n" }' |\
1325         sort |\
1326         while read file ea_name; do
1327             attr -g $ea_name $file
1328         done
1329     fi
1330
1331     echo "Root names"
1332     getfattr --absolute-names -Rh -m trusted $_path |\
1333     perl -wn -e '
1334         if (m/^# file: (\S+)/) { $file = $1 }
1335         elsif (m/^trusted\.(\w+)/) { print $file, " ",$1,"\n" }' |\
1336     sort |\
1337     while read file ea_name; do
1338         attr -R -g $ea_name $file
1339     done
1340 }
1341
1342 #
1343 # Compare the extended attributes of the files/dirs
1344 # b/w the dumped and restore dirs.
1345 #
1346 #
1347 # Attribute "attr5" had a 8 byte value for /spare1/dump.5460/dir:
1348 # Attribute "attr5" had a 8 byte value for /spare1/restore.5460/dump.5460/dir:
1349 #
1350 _diff_compare_eas()
1351 {
1352     echo "Comparing dump directory with restore directory"
1353     echo "Looking at the extended attributes (EAs)"
1354     echo "EAs on dump"
1355     _get_eas_on_path $dump_dir | tee $seqres.ea1 | _dir_filter
1356     echo "EAs on restore"
1357     _get_eas_on_path $restore_dir/$dump_sdir \
1358     | sed -e "s#$restore_sdir\/##" \
1359     | tee $seqres.ea2 \
1360     | _dir_filter
1361     diff -s $seqres.ea1 $seqres.ea2
1362 }
1363
1364
1365 #
1366 # Compare using recursive diff the files of the dumped
1367 # filesystem
1368 #
1369 _diff_compare()
1370 {
1371     echo "Comparing dump directory with restore directory"
1372     diff -rs $SCRATCH_MNT $restore_dir | _dir_filter | _check_quota_diff
1373 }
1374
1375 #
1376 # Check out the dump inventory
1377 #
1378 _dump_inventory()
1379 {
1380     $XFSDUMP_PROG $_dump_debug -I | tee -a $seqres.full | _dump_filter_main
1381 }
1382
1383 #
1384 # Do the xfsinvutil cmd with debug and filters
1385 # Need to set variable: "$middate" to the invutil date
1386 #
1387 _do_invutil()
1388 {
1389     host=`hostname`
1390     echo "xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT \"$middate\" $*" >$seqres.full
1391     $XFSINVUTIL_PROG $_invutil_debug $* -M $host:$SCRATCH_MNT "$middate" \
1392     | tee -a $seqres.full | _invutil_filter
1393 }
1394
1395 #
1396 # ensure we can find the user quota msg if user quotas are on
1397 # ensure we can find the group quota msg if group quotas are on
1398 #
1399 _check_quota()
1400 {
1401     usermsg=$1
1402     groupmsg=$2
1403     projectmsg=$3
1404     uquota=0
1405     gquota=0
1406     pquota=0
1407     $here/src/feature -U $SCRATCH_DEV && uquota=1
1408     $here/src/feature -G $SCRATCH_DEV && gquota=1
1409     $here/src/feature -P $SCRATCH_DEV && pquota=1
1410
1411     $AWK_PROG -v uquota=$uquota -v gquota=$gquota -v pquota=$pquota \
1412               -v full=$seqres.full -v usermsg="$usermsg" \
1413               -v groupmsg="$groupmsg" -v projectmsg="$projectmsg" '
1414         $0 ~ projectmsg {
1415                         print "Found project quota:", $0 >>full
1416                         found_pquota = 1
1417                         if (!pquota) {
1418                             print "Found extra:", $0
1419                         }
1420                         next
1421         }
1422         $0 ~ groupmsg {
1423                         print "Found group quota:", $0 >>full
1424                         found_gquota = 1
1425                         if (!gquota) {
1426                             print "Found extra:", $0
1427                         }
1428                         next
1429         }
1430         $0 ~ usermsg {
1431                         print "Found user quota:", $0 >>full
1432                         found_uquota = 1
1433                         if (!uquota) {
1434                             print "Found extra:", $0
1435                         }
1436                         next
1437         }
1438                         { print }
1439         END {
1440                 if (uquota && !found_uquota) {
1441                     print "Missing user quota msg:", usermsg
1442                 }
1443                 if (gquota && !found_gquota) {
1444                     print "Missing group quota msg:", groupmsg
1445                 }
1446                 if (pquota && !found_pquota) {
1447                     print "Missing project quota msg:", projectmsg
1448                 }
1449         }
1450     '
1451 }
1452
1453 #
1454 # xfsrestore: 3 directories and 40 entries processed
1455 #   $5 = 40
1456 #   num entries needs to be reduced by num quota file(s)
1457 #
1458 _check_quota_entries()
1459 {
1460     uquota=0
1461     gquota=0
1462     pquota=0
1463     $here/src/feature -U $SCRATCH_DEV && uquota=1
1464     $here/src/feature -G $SCRATCH_DEV && gquota=1
1465     $here/src/feature -P $SCRATCH_DEV && pquota=1
1466     $AWK_PROG -v uquota=$uquota -v gquota=$gquota -v pquota=$pquota '
1467         /entries processed/ {
1468                 if (uquota) $5--
1469                 if (gquota) $5--
1470                 if (pquota) $5--
1471         }
1472         {print}'
1473 }
1474
1475 #
1476 # Look for:
1477 # xfsdump: saving user quota information for: SCRATCH_MNT
1478 # xfsdump: saving group quota information for: SCRATCH_MNT
1479 # xfsdump: saving project quota information for: SCRATCH_MNT
1480 # xfsrestore: user quota information written to ...'
1481 # xfsrestore: group quota information written to ...'
1482 # xfsrestore: project quota information written to ...'
1483 #
1484 # If on IRIX then look for:
1485 # xfsrestore: use 'edquota' to restore quotas
1486 # Else look for:
1487 # xfsrestore: use 'xfs_quota' to restore quotas
1488 #
1489 _check_quota_dumprestore()
1490 {
1491     if [ "$HOSTOS" == "IRIX" ]; then
1492         _check_quota 'user quota information' \
1493                      'group quota information' \
1494                      'project quota information' | \
1495         sed "/xfsrestore:.*use 'edquota' to restore quotas/d"
1496     else
1497         _check_quota 'user quota information' \
1498                      'group quota information' \
1499                      'project quota information' | \
1500         sed "/xfsrestore:.*use 'xfs_quota' to restore quotas/d"
1501     fi
1502 }
1503
1504 #
1505 # Look for:
1506 # Only in RESTORE_DIR: xfsdump_quotas
1507 # Only in RESTORE_DIR: xfsdump_quotas_group
1508 # Only in RESTORE_DIR: xfsdump_quotas_project
1509 #
1510 _check_quota_diff()
1511 {
1512    _check_quota 'Only in RESTORE_DIR: xfsdump_quotas' \
1513         'Only in RESTORE_DIR: xfsdump_quotas_group' \
1514         'Only in RESTORE_DIR: xfsdump_quotas_proj'
1515 }
1516
1517 #
1518 # Look for the quota file in the output
1519 # Ensure that it is there if it should be
1520 # Filter it out so that the output is always the same
1521 # even with no quotas
1522 #
1523 _check_quota_file()
1524 {
1525    _check_quota 'xfsdump_quotas' 'xfsdump_quotas_group' 'xfsdump_quotas_proj'
1526 }
1527
1528
1529 # make sure this script returns success
1530 /bin/true