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