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