common.dump: filter out latest xfsdump version messages
[xfstests-dev.git] / common.dump
index 2ed5e100d144173205a5f2cea9c48df0879e8de3..e89dedcfe77d2d17fd36aad8bd58655ae61c10e7 100644 (file)
@@ -1,7 +1,21 @@
-#/bin/sh
+##/bin/bash
 #
 # Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.  All Rights Reserved.
 #
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#
+#
 # Functions useful for xfsdump/xfsrestore tests
 #
 
 rm -f $here/$seq.full
 
 if [ -n "$DEBUGDUMP" ]; then
-  _dump_debug=-v4
-  _restore_debug=-v4
-  _invutil_debug=-d
+       _dump_debug=-v4
+       _restore_debug=-v4
+       _invutil_debug=-d
+
+       # Use dump/restore in qa directory (copy them here) for debugging
+       export PATH="$here:$PATH"
+       export XFSDUMP_PROG="`set_prog_path xfsdump`"
+       export XFSRESTORE_PROG="`set_prog_path xfsrestore`"
+       export XFSINVUTIL_PROG="`set_prog_path xfsinvutil`"
+       [ -x $here/xfsdump ]    && echo "Using xfstests' xfsdump for debug"
+       [ -x $here/xfsrestore ] && echo "Using xfstests' xfsrestore for debug"
+       [ -x $here/xfsinvutil ] && echo "Using xfstests' xfsinvutil for debug"
 fi
 
-# Use dump/restore in qa directory for debugging
-PATH="$here:$PATH"
-export PATH
-#which xfsdump
-#which xfsrestore
-#which xfsinvutil
+[ "$XFSDUMP_PROG" = "" ]    && _notrun "xfsdump not found"
+[ "$XFSRESTORE_PROG" = "" ] && _notrun "xfsrestore not found"
+[ "$XFSINVUTIL_PROG" = "" ] && _notrun "xfsinvutil not found"
 
 # status returned for not run tests
 NOTRUNSTS=2
@@ -55,6 +75,25 @@ done
 have_mtvariable=false
 [ `uname` = "Linux" ] && have_mtvariable=true
 
+
+_require_multi_stream()
+{
+    $XFSDUMP_PROG -JF -f /dev/null -f /dev/null 2> /dev/null |
+    grep -q "too many -f arguments" &&
+    _notrun "xfsdump multi-stream support required"
+}
+
+_require_legacy_v2_format()
+{
+    $XFSDUMP_PROG 2>&1 |
+    grep -q "generate format 2 dump" ||
+    _notrun "xfsdump -K option required"
+
+    $XFSRESTORE_PROG 2>&1 |
+    grep -q "force use of format 2 generation" ||
+    _notrun "xfsrestore -K option required"
+}
+
 #
 # do a remote/local mt
 #
@@ -91,7 +130,7 @@ _check_onl()
        else
            sleep 1
        fi
-       i=`expr $i + 1`
+       let i=$i+1
     done
 
 
@@ -129,7 +168,7 @@ _wait_tape()
        else
            sleep 1
        fi
-       i=`expr $i + 1`
+       let i=$i+1
     done
 }
 
@@ -188,7 +227,7 @@ _require_tape()
 {
     dumptape=$1
 
-    if [ -z "$dumptape" ]; then
+    if [ -z "$dumptape" -o "@" == "$dumptape" ]; then
         echo "This test requires a dump tape - none was specified"
        echo "No dump tape specified" >$seq.notrun
        status=$NOTRUNSTS
@@ -213,6 +252,12 @@ _wipe_fs()
 #
 _cleanup()
 {
+    # Some tests include this before checking _supported_fs xfs
+    # and the sleeps & checks here get annoying
+    if [ "$FSTYP" != "xfs" ]; then
+       return
+    fi
+
     cd $here
     rm -f $tmp.*
 
@@ -267,7 +312,7 @@ _create_dumpdir_stress()
     _wipe_fs
 
     _param="-f link=10 -f creat=10 -f mkdir=10 -f truncate=5 -f symlink=10"
-    _count=200
+    _count=240
     rm -rf $dump_dir
     if ! mkdir $dump_dir; then
         echo "    failed to mkdir $dump_dir"
@@ -282,10 +327,10 @@ _create_dumpdir_stress()
     then
         echo "    fsstress (count=$_count) returned $? - see $here/$seq.full"
 
-        echo "--------------------------------------"       >>$here/$here/$seq.full
-        echo "output from fsstress:"                        >>$here/$here/$seq.full
-        echo "--------------------------------------"       >>$here/$here/$seq.full
-        cat $tmp.out                                        >>$here/$here/$seq.full
+        echo "--------------------------------------"       >>$here/$seq.full
+        echo "output from fsstress:"                        >>$here/$seq.full
+        echo "--------------------------------------"       >>$here/$seq.full
+        cat $tmp.out                                        >>$here/$seq.full
         status=1
     fi
 
@@ -510,6 +555,18 @@ _do_create_dumpdir_fill()
     cd $here
 }
 
+_mk_fillconfig_multi()
+{
+    _mk_fillconfig1
+    cat <<End-of-File >>$tmp.config
+# pathname     size in bytes
+#
+large000       8874368 $nobody $nobody
+large111       2582912 $nobody $nobody
+large222       7825792 $nobody $nobody
+End-of-File
+}
+
 _create_dumpdir_largefile()
 {
     _wipe_fs
@@ -554,6 +611,17 @@ _create_dumpdir_fill_ea()
     _stable_fs
 }
 
+#
+# Create enough files, and a few large enough files, so that
+# some files are likely to be split across streams.
+#
+_create_dumpdir_fill_multi()
+{
+    _wipe_fs
+    _mk_fillconfig_multi
+    _do_create_dumpdir_fill
+    _stable_fs
+}
 
 #
 # Append a subset of the fill'ed files
@@ -675,7 +743,7 @@ _create_hardlinks()
        _hardlink=$_fname$_suffix
        echo "creating hardlink $_hardlink to $_fname"
        ln $_fname $_hardlink
-       _j=`expr $_j + 1`
+       let _j=$_j+1
     done
 }
 
@@ -691,7 +759,7 @@ _create_hardset()
     _i=1
     while [ $_i -le $_numsets ]; do
        _create_hardlinks file$_i 5
-       _i=`expr $_i + 1`
+       let _i=$_i+1
     done
 }
 
@@ -761,6 +829,9 @@ _dump_filter_main()
 {
   _filter_devchar |\
   sed \
+      -e "s#$XFSDUMP_PROG#xfsdump#"                    \
+      -e "s#$XFSRESTORE_PROG#xfsrestore#"              \
+      -e "s#$XFSINVUTIL_PROG#xfsinvutil#"              \
       -e "s/`hostname`/HOSTNAME/"                      \
       -e "s#$SCRATCH_DEV#SCRATCH_DEV#"                 \
       -e "s#$SCRATCH_RAWDEV#SCRATCH_DEV#"              \
@@ -773,9 +844,11 @@ _dump_filter_main()
       -e 's/time:[     ].*/time: TIME/'                \
       -e 's/date:[     ].*/date: DATE/'                \
       -e 's/dump begun .*/dump begun DATE/'            \
+      -e 's/previously begun .*/previously begun DATE/'        \
       -e 's/[0-9][0-9]* seconds/SECS seconds/'         \
       -e 's/restore.[0-9][0-9]*/restore.PID/'          \
-      -e 's/ino [0-9][0-9]*/ino INO/'                  \
+      -e 's/ino [0-9][0-9]*/ino INO/g'                 \
+      -e '/stream [0-9]:/s/offset [0-9][0-9]*/offset NUM/g'    \
       -e '/: dump size/s/[0-9][0-9]*/NUM/'             \
       -e '/dump size:/s/[0-9][0-9]*/NUM/'              \
       -e '/dump size per stream:/s/[0-9][0-9]*/NUM/'   \
@@ -785,12 +858,18 @@ _dump_filter_main()
       -e '/\/dev\/tty/d'                               \
       -e '/inventory session uuid/d'                   \
       -e '/ - Running single-threaded/d'               \
+      -e '/Mount point match/d'                                \
       -e '/^.*I\/O metrics: .*$/d'                     \
       -e 's/1048576/BLOCKSZ/'                          \
       -e 's/2097152/BLOCKSZ/'                          \
       -e 's/(pid[       ]*[1-9][0-9]*)/\(pid PID\)/'   \
-      -e '/version 3\.0/d'                             \
+      -e '/version [3-9]\.[0-9]/d'                     \
       -e 's/\/hw\/module.*$/SCRATCH_DEV/'              \
+      -e 's/xfsdump: ino map phase 1: .*/xfsdump: ino map <PHASES>/' \
+      -e '/xfsdump: ino map phase [2]/,1d'             \
+      -e '/xfsdump: ino map phase [3]/,1d'             \
+      -e '/xfsdump: ino map phase [4]/,1d'             \
+      -e '/xfsdump: ino map phase [5]/,1d'             \
       -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/'                                             \
       -e 's/\[y\/n\][- ]----------------------*/\[y\/n\]/'             \
   | perl -ne '
@@ -827,7 +906,7 @@ _invutil_filter()
 _dir_filter()
 {
   sed \
-    -e "s#$dump_file#DUMP_FILE#"      \
+    -e "s#$dump_file#DUMP_FILE#g"      \
     -e "s#$SCRATCH_DEV#SCRATCH_DEV#"        \
     -e "s#$SCRATCH_RAWDEV#SCRATCH_DEV#"    \
     -e "s#$dumptape#TAPE_DEV#"         \
@@ -841,9 +920,10 @@ _dir_filter()
 }
 
 #
+# Parse xfsdump arguments.
 # Note: requires a space between option letter and argument
 #
-_parse_args()
+_parse_dump_args()
 {
     OPTIND=0
     dump_args=""
@@ -854,6 +934,7 @@ _parse_args()
         -f)
             [ -z "$2" ] && _fail "missing argument for -f"
            dumptape=$2
+           dump_file=$2
            shift
             ;;
         -L)
@@ -861,26 +942,69 @@ _parse_args()
            session_label=$2
            shift
             ;;
-       -o)
-           dump_args="$dump_args -o"
+       --multi)
+            [ -z "$2" ] && _fail "missing argument for --multi"
+           multi=$2
+           shift
+           ;;
+        --check-quota)
+            do_quota_check=true
+            ;;
+        --no-check-quota)
+            do_quota_check=false
             ;;
-       -F)
-           dump_args="$dump_args -F"
+       -o|-D|-F|-K)
+           dump_args="$dump_args $1"
+            ;;
+        -l|-d)
+            [ -z "$2" ] && _fail "missing argument for $1"
+           dump_args="$dump_args $1$2"
+           shift
+            ;;
+       *)
+            _fail "invalid argument to common.dump function: $1"
+            ;;
+        esac
+       shift
+    done
+}
+
+#
+# Parse xfsrestore arguments.
+# Note: requires a space between option letter and argument
+#
+_parse_restore_args()
+{
+    OPTIND=0
+    restore_args=""
+    while [ $# -gt 0 ]
+    do
+        case $1
+        in
+        -f)
+            [ -z "$2" ] && _fail "missing argument for -f"
+           dumptape=$2
+           dump_file=$2
+           shift
+            ;;
+        -L)
+            [ -z "$2" ] && _fail "missing argument for -L"
+           session_label=$2
+           shift
             ;;
        --multi)
+            [ -z "$2" ] && _fail "missing argument for --multi"
            multi=$2
            shift
            ;;
-        -q)
+        --check-quota)
             do_quota_check=true
             ;;
-        -Q)
+        --no-check-quota)
             do_quota_check=false
             ;;
-        -l)
-            [ -z "$2" ] && _fail "missing argument for -l"
-           dump_args="$dump_args -l$2"
-           shift
+       -K|-R)
+           restore_args="$restore_args $1"
             ;;
        *)
             _fail "invalid argument to common.dump function: $1"
@@ -896,12 +1020,12 @@ _parse_args()
 #
 _do_dump_sub()
 {
-    _parse_args $*
+    _parse_dump_args $*
 
     echo "Dumping to tape..."
     opts="$_dump_debug$dump_args -s $dump_sdir -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
     echo "xfsdump $opts" | _dir_filter
-    xfsdump $opts 2>&1 | tee -a $here/$seq.full | _dump_filter
+    $XFSDUMP_PROG $opts 2>&1 | tee -a $here/$seq.full | _dump_filter
 }
 
 #
@@ -909,12 +1033,12 @@ _do_dump_sub()
 #
 _do_dump()
 {
-    _parse_args $*
+    _parse_dump_args $*
 
     echo "Dumping to tape..."
     opts="$_dump_debug$dump_args -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
     echo "xfsdump $opts" | _dir_filter
-    xfsdump $opts 2>&1 | tee -a $here/$seq.full | _dump_filter
+    $XFSDUMP_PROG $opts 2>&1 | tee -a $here/$seq.full | _dump_filter
 }
 
 
@@ -923,13 +1047,13 @@ _do_dump()
 #
 _do_dump_min()
 {
-    _parse_args $*
+    _parse_dump_args $*
 
     echo "Dumping to tape..."
     onemeg=1048576
     opts="$_dump_debug$dump_args -m -b $onemeg -l0 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
     echo "xfsdump $opts" | _dir_filter
-    xfsdump $opts 2>&1 | tee -a $here/$seq.full | _dump_filter
+    $XFSDUMP_PROG $opts 2>&1 | tee -a $here/$seq.full | _dump_filter
 }
 
 
@@ -938,12 +1062,12 @@ _do_dump_min()
 #
 _do_dump_file()
 {
-    _parse_args $*
+    _parse_dump_args $*
 
     echo "Dumping to file..."
     opts="$_dump_debug$dump_args -f $dump_file -M $media_label -L $session_label $SCRATCH_MNT"
     echo "xfsdump $opts" | _dir_filter
-    xfsdump $opts 2>&1 | tee -a $here/$seq.full | _dump_filter
+    $XFSDUMP_PROG $opts 2>&1 | tee -a $here/$seq.full | _dump_filter
 }
 
 #
@@ -951,7 +1075,7 @@ _do_dump_file()
 #
 _do_dump_multi_file()
 {
-    _parse_args "$@"
+    _parse_dump_args $*
 
     multi_args=""
 
@@ -959,13 +1083,13 @@ _do_dump_multi_file()
     while [ $i -lt $multi ]
     do
        multi_args="$multi_args -f $dump_file.$i -M $media_label.$i"
-       i=`expr $i + 1`
+       let i=$i+1
     done
 
     echo "Dumping to files..."
     opts="$_dump_debug$dump_args $multi_args -L $session_label $SCRATCH_MNT"
     echo "xfsdump $opts" | _dir_filter
-    xfsdump $opts 2>&1 | tee -a $here/$seq.full | _dump_filter
+    $XFSDUMP_PROG $opts 2>&1 | tee -a $here/$seq.full | _dump_filter
 }
 
 
@@ -992,14 +1116,13 @@ _prepare_restore()
 #
 _do_restore()
 {
-    _parse_args $*
+    _parse_restore_args $*
     _prepare_restore
 
-
     echo "Restoring from tape..."
-    opts="$_restore_debug -f $dumptape  -L $session_label $restore_dir"
+    opts="$_restore_debug$restore_args -f $dumptape  -L $session_label $restore_dir"
     echo "xfsrestore $opts" | _dir_filter
-    xfsrestore $opts 2>&1 | tee -a $here/$seq.full | _dump_filter
+    $XFSRESTORE_PROG $opts 2>&1 | tee -a $here/$seq.full | _dump_filter
 }
 
 #
@@ -1007,14 +1130,14 @@ _do_restore()
 #
 _do_restore_min()
 {
-    _parse_args $*
+    _parse_restore_args $*
     _prepare_restore
 
     echo "Restoring from tape..."
     onemeg=1048576
-    opts="$_restore_debug -m -b $onemeg -f $dumptape  -L $session_label $restore_dir"
+    opts="$_restore_debug$restore_args -m -b $onemeg -f $dumptape  -L $session_label $restore_dir"
     echo "xfsrestore $opts" | _dir_filter
-    xfsrestore $opts 2>&1 | tee -a $here/$seq.full | _dump_filter
+    $XFSRESTORE_PROG $opts 2>&1 | tee -a $here/$seq.full | _dump_filter
 }
 
 #
@@ -1022,39 +1145,39 @@ _do_restore_min()
 #
 _do_restore_file()
 {
-    _parse_args $*
+    _parse_restore_args $*
     _prepare_restore_dir
 
     echo "Restoring from file..."
-    opts="$_restore_debug -f $dump_file  -L $session_label $restore_dir"
+    opts="$_restore_debug$restore_args -f $dump_file  -L $session_label $restore_dir"
     echo "xfsrestore $opts" | _dir_filter
-    xfsrestore $opts 2>&1 | tee -a $here/$seq.full | _dump_filter
+    $XFSRESTORE_PROG $opts 2>&1 | tee -a $here/$seq.full | _dump_filter
 }
 
 #
 # Cumulative restore from a file
-# Need to specify the dump level e.g. "-l 0"
+# Must call _prepare_restore_dir before the first
+# (and only the first) call to this function.
 #
 _do_restore_file_cum()
 {
-    _parse_args $*
-    if echo $dump_args | grep '\-l0' >/dev/null; then
-       _prepare_restore_dir
-    fi
+    _parse_restore_args $*
 
     echo "Restoring cumumlative from file..."
-    opts="$_restore_debug -f $dump_file -r $restore_dir"
+    opts="$_restore_debug$restore_args -f $dump_file -r $restore_dir"
     echo "xfsrestore $opts" | _dir_filter
-    xfsrestore $opts 2>&1 | tee -a $here/$seq.full | _dump_filter
+    $XFSRESTORE_PROG $opts 2>&1 | tee -a $here/$seq.full | _dump_filter
 }
 
 _do_restore_toc()
 {
+    _parse_restore_args $*
+
     echo "Contents of dump ..."
-    opts="$_restore_debug -f $dump_file -t"
+    opts="$_restore_debug$restore_args -f $dump_file -t"
     echo "xfsrestore $opts" | _dir_filter
     cd $SCRATCH_MNT # for IRIX which needs xfs cwd
-    xfsrestore $opts 2>&1 | tee -a $here/$seq.full | _dump_filter_main |\
+    $XFSRESTORE_PROG $opts 2>&1 | tee -a $here/$seq.full | _dump_filter_main |\
     _check_quota_file |\
     _check_quota_entries |\
     $AWK_PROG 'NF != 1 { print; next }
@@ -1070,7 +1193,7 @@ _do_restore_toc()
 #
 _do_restore_multi_file()
 {
-    _parse_args "$@"
+    _parse_restore_args $*
     _prepare_restore_dir
 
     multi_args=""
@@ -1079,29 +1202,33 @@ _do_restore_multi_file()
     while [ $i -lt $multi ]
     do
        multi_args="$multi_args -f $dump_file.$i"
-       i=`expr $i + 1`
+       let i=$i+1
     done
 
     echo "Restoring from file..."
-    opts="$_restore_debug $multi_args -L $session_label $restore_dir"
+    opts="$_restore_debug$restore_args $multi_args -L $session_label $restore_dir"
     echo "xfsrestore $opts" | _dir_filter
-    xfsrestore $opts 2>&1 | tee -a $here/$seq.full | _dump_filter
+    $XFSRESTORE_PROG $opts 2>&1 | tee -a $here/$seq.full | _dump_filter
 }
 
 #
 # Do xfsdump piped into xfsrestore - xfsdump | xfsrestore
+# Pass dump options in $1 and restore options in $2, if required. e.g.:
+#     _do_dump_restore "-o -F" "-R"
+#     _do_dump_restore "" "-R"
 #
 # Use -s as we want to dump and restore to the same xfs partition
 #
 _do_dump_restore()
 {
-    _parse_args $*
+    _parse_dump_args $1
+    _parse_restore_args $2
     _prepare_restore_dir
     echo "xfsdump|xfsrestore ..."
-    restore_opts="$_restore_debug - $restore_dir"
+    restore_opts="$_restore_debug$restore_args - $restore_dir"
     dump_opts="$_dump_debug$dump_args -s $dump_sdir - $SCRATCH_MNT"
     echo "xfsdump $dump_opts | xfsrestore $restore_opts" | _dir_filter
-    xfsdump $dump_opts 2>$tmp.dump.mlog | xfsrestore $restore_opts 2>&1 | tee -a $here/$seq.full | _dump_filter
+    $XFSDUMP_PROG $dump_opts 2>$tmp.dump.mlog | $XFSRESTORE_PROG $restore_opts 2>&1 | tee -a $here/$seq.full | _dump_filter
     _dump_filter <$tmp.dump.mlog
 }
 
@@ -1239,7 +1366,7 @@ _diff_compare()
 #
 _dump_inventory()
 {
-    xfsdump $_dump_debug -I | tee -a $here/$seq.full | _dump_filter_main
+    $XFSDUMP_PROG $_dump_debug -I | tee -a $here/$seq.full | _dump_filter_main
 }
 
 #
@@ -1250,7 +1377,7 @@ _do_invutil()
 {
     host=`hostname`
     echo "xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT \"$middate\" $*" >$here/$seq.full
-    xfsinvutil $_invutil_debug $* -M $host:$SCRATCH_MNT "$middate" \
+    $XFSINVUTIL_PROG $_invutil_debug $* -M $host:$SCRATCH_MNT "$middate" \
     | tee -a $here/$seq.full | _invutil_filter
 }
 
@@ -1345,6 +1472,8 @@ _check_quota_entries()
 #
 # If on IRIX then look for:
 # xfsrestore: use 'edquota' to restore quotas
+# Else look for:
+# xfsrestore: use 'xfs_quota' to restore quotas
 #
 _check_quota_dumprestore()
 {
@@ -1356,7 +1485,8 @@ _check_quota_dumprestore()
     else
        _check_quota 'user quota information' \
                     'group quota information' \
-                    'project quota information'
+                    'project quota information' | \
+       sed "/xfsrestore:.*use 'xfs_quota' to restore quotas/d"
     fi
 }