Fix up 064 for quota checks.
[xfstests-dev.git] / common.dump
index 3962c30d935f5246fbdc0c95696e42ab55d24bf4..d7475edd044efbb71b568d2f1ccf70fee86557e9 100644 (file)
@@ -44,7 +44,7 @@ if [ -n "$DEBUGDUMP" ]; then
 fi
  
 # Use dump/restore in qa directory for debugging
-PATH=".:$PATH"
+PATH="$here:$PATH"
 export PATH
 #which xfsdump
 #which xfsrestore
@@ -463,13 +463,8 @@ _do_create_dumpdir_fill()
 {
     echo "Creating directory system to dump using src/fill."
 
-    if mkdir -p $dump_dir
-    then
-       :
-    else
-       echo "Error: cannot mkdir \"$dump_dir\""
-       exit 1
-    fi
+    mkdir -p $dump_dir ||\
+       _error "cannot mkdir \"$dump_dir\""
     cd $dump_dir
 
     $verbose && echo -n "Setup "
@@ -598,13 +593,8 @@ _do_create_dump_symlinks()
 {
     echo "Creating directory system of symlinks to dump."
 
-    if mkdir -p $dump_dir
-    then
-       :
-    else
-       echo "Error: cannot mkdir \"$dump_dir\""
-       exit 1
-    fi
+    mkdir -p $dump_dir ||\
+       _error "cannot mkdir \"$dump_dir\""
     cd $dump_dir
 
     $verbose && echo -n "Setup "
@@ -678,6 +668,64 @@ _create_dumpdir_symlinks()
     _stable_fs
 }      
 
+#
+# create hardlinks of form $_fname, $_fname_h1 $_fname_h2 ...
+#
+_create_hardlinks()
+{
+    _fname=$1  
+    _numlinks=$2
+
+    touch $_fname
+    _j=1
+    while [ $_j -le $_numlinks ]; do
+        _suffix=_h$_j
+       _hardlink=$_fname$_suffix
+       echo "creating hardlink $_hardlink to $_fname"
+       ln $_fname $_hardlink
+       _j=`expr $_j + 1`
+    done
+}
+
+#
+# create a set of hardlinks
+# create hardlinks of form file1, file1_h1 file1_h2 ...
+# create hardlinks of form file2, file2_h1 file2_h2 ...
+# create hardlinks of form file3, file3_h1 file3_h2 ...
+#
+_create_hardset()
+{
+    _numsets=$1
+    _i=1
+    while [ $_i -le $_numsets ]; do
+       _create_hardlinks file$_i 5
+       _i=`expr $_i + 1`
+    done
+}
+
+
+_modify_level()
+{
+    _level=$1
+    echo "mod level $_level" >$dump_dir/file$_level
+}
+
+_create_dumpdir_hardlinks()
+{
+    _numsets=$1
+    _wipe_fs
+    echo "Creating directory system of hardlinks to incrementally dump."
+
+    mkdir -p $dump_dir ||\
+       _error "cannot mkdir \"$dump_dir\""
+    cd $dump_dir
+
+    _create_hardset $_numsets
+
+    cd $here
+    _stable_fs
+}
+
 #
 # Filter for ls
 # Filter out dates on symlinks and char devices
@@ -772,6 +820,9 @@ _dir_filter()
 
 }
 
+#
+# Note: requires a space between option letter and argument 
+#
 _parse_args()
 {
     OPTIND=0
@@ -806,8 +857,13 @@ _parse_args()
         -Q)
             do_quota_check=false
             ;;
+        -l)
+            [ -z "$2" ] && _error "missing argument for -l"
+           dump_args="$dump_args -l$2"
+           shift
+            ;;
        *)
-            _error "invalid argument"
+            _error "invalid argument to common.dump function: $1"
             ;;
         esac
        shift
@@ -829,14 +885,14 @@ _do_dump_sub()
 }
 
 #
-# Do full level 0 dump
+# Do dump to tape
 #
 _do_dump()
 {
     _parse_args $*
 
     echo "Dumping to tape..."
-    opts="$_dump_debug$dump_args -l0 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
+    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 $seq.full | _dump_filter
 }
@@ -856,18 +912,6 @@ _do_dump_min()
     xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
 }
 
-#
-# Do level 1 incremental dump
-#
-_do_dump_incremental()
-{
-    _parse_args $*
-
-    echo "Dumping incrementally to tape..."
-    opts="$_dump_debug$dump_args -l1 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
-    echo "xfsdump $opts" | _dir_filter  
-    xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
-}
 
 #
 # Do full dump to file
@@ -908,11 +952,8 @@ _do_dump_multi_file()
 _prepare_restore_dir()
 {
     rm -rf $restore_dir
-    if ! mkdir $restore_dir; then
-       echo "    failed to mkdir $restore_dir"
-       status=1
-       exit
-    fi
+    mkdir $restore_dir ||\
+       _error "failed to mkdir $restore_dir"
 }
 
 
@@ -937,7 +978,7 @@ _do_restore()
 
 
     echo "Restoring from tape..."
-    opts="$_restore_debug$dump_args -f $dumptape  -L $session_label $restore_dir"
+    opts="$_restore_debug -f $dumptape  -L $session_label $restore_dir"
     echo "xfsrestore $opts" | _dir_filter  
     xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
 }
@@ -952,7 +993,7 @@ _do_restore_min()
 
     echo "Restoring from tape..."
     onemeg=1048576
-    opts="$_restore_debug$dump_args -m -b $onemeg -f $dumptape  -L $session_label $restore_dir"
+    opts="$_restore_debug -m -b $onemeg -f $dumptape  -L $session_label $restore_dir"
     echo "xfsrestore $opts" | _dir_filter  
     xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
 }
@@ -966,11 +1007,44 @@ _do_restore_file()
     _prepare_restore_dir
 
     echo "Restoring from file..."
-    opts="$_restore_debug$dump_args -f $dump_file  -L $session_label $restore_dir"
+    opts="$_restore_debug -f $dump_file  -L $session_label $restore_dir"
     echo "xfsrestore $opts" | _dir_filter  
     xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
 }
 
+#
+# Cumulative restore from a file
+# Need to specify the dump level e.g. "-l 0"
+#
+_do_restore_file_cum()
+{
+    _parse_args $*
+    if echo $dump_args | grep '\-l0' >/dev/null; then
+       _prepare_restore_dir
+    fi
+
+    echo "Restoring cumumlative from file..."
+    opts="$_restore_debug -f $dump_file -r $restore_dir"
+    echo "xfsrestore $opts" | _dir_filter  
+    xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
+}
+
+_do_restore_toc()
+{
+    echo "Contents of dump ..."
+    opts="$_restore_debug -f $dump_file -t"
+    echo "xfsrestore $opts" | _dir_filter
+    cd $SCRATCH_MNT # for IRIX which needs xfs cwd
+    xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter_main |\
+    _check_quota_file |\
+    $AWK_PROG 'NF != 1 { print; next }
+              {files = sprintf("%s\n%s", files, $1)}
+               END { print files | "sort" } '
+    # the above awk code is to alpha sort only the output
+    # of files (and not the verbose restore msgs)
+    cd $here # put back
+}
+
 #
 # Restore the tape from multiple dump files
 #
@@ -989,7 +1063,7 @@ _do_restore_multi_file()
     done
 
     echo "Restoring from file..."
-    opts="$_restore_debug$dump_args $multi_args -L $session_label $restore_dir"
+    opts="$_restore_debug $multi_args -L $session_label $restore_dir"
     echo "xfsrestore $opts" | _dir_filter  
     xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
 }
@@ -1061,7 +1135,7 @@ _ls_nodate_compare_sub()
 _diff_compare_sub()
 {
     echo "Comparing dump directory with restore directory"
-    diff -rs $dump_dir $restore_dir/$dump_sdir | _dir_filter | _check_quota_diff
+    diff -rs $dump_dir $restore_dir/$dump_sdir | _dir_filter
 }
 
 _get_eas_on_path()
@@ -1071,6 +1145,7 @@ _get_eas_on_path()
     find $_path -exec attr -l {} \; |\
     awk '{print $9, $2}' |\
     sed 's/["]//g' |\
+    sort |\
     while read file ea_name; do
        attr -g $ea_name $file
     done
@@ -1130,32 +1205,32 @@ _do_invutil()
 }
 
 #
-# Look for:
-# xfsdump: saving user quota information for: SCRATCH_MNT
-# xfsdump: saving group quota information for: SCRATCH_MNT
-# xfsrestore: user quota information written to ...'
-# xfsrestore: group quota information written to ...'
+# ensure we can find the user quota msg if user quotas are on
+# ensure we can find the group quota msg if group quotas are on
 #
-_check_quota_dumprestore()
+_check_quota()
 {
+    usermsg=$1 
+    groupmsg=$2 
     uquota=0
     gquota=0 
-    src/feature -U $SCRATCH_DEV && uquota=1
-    src/feature -G $SCRATCH_DEV && gquota=1
+    $here/src/feature -U $SCRATCH_DEV && uquota=1
+    $here/src/feature -G $SCRATCH_DEV && gquota=1
 
-    $AWK_PROG -v uquota=$uquota -v gquota=$gquota -v full=$seq.full '
-       /user quota information/ {
-                       print "Found user quota:", $0 >>full
-                       found_uquota = 1
-                       if (!uquota) {
+    $AWK_PROG -v uquota=$uquota -v gquota=$gquota -v full=$seq.full \
+              -v usermsg=$usermsg -v groupmsg=$groupmsg '
+       $0 ~ groupmsg {
+                       print "Found group quota:", $0 >>full
+                       found_gquota = 1
+                       if (!gquota) {
                            print "Found extra:", $0
                        }
                        next
        }
-       /group quota information/ {
-                       print "Found group quota:", $0 >>full
-                       found_gquota = 1
-                       if (!gquota) {
+       $0 ~ usermsg {
+                       print "Found user quota:", $0 >>full
+                       found_uquota = 1
+                       if (!uquota) {
                            print "Found extra:", $0
                        }
                        next
@@ -1163,53 +1238,48 @@ _check_quota_dumprestore()
                        { print }
        END {
                if (uquota && !found_uquota) {
-                   print "Missing saving/restoring uquota msg"
+                   print "Missing: ", usermsg
                }
                if (gquota && !found_gquota) {
-                   print "Missing saving/restoring gquota msg"
+                   print "Missing: ", groupmsg
                }
        }
     '
 }
 
+#
+# Look for:
+# xfsdump: saving user quota information for: SCRATCH_MNT
+# xfsdump: saving group quota information for: SCRATCH_MNT
+# xfsrestore: user quota information written to ...'
+# xfsrestore: group quota information written to ...'
+#
+_check_quota_dumprestore()
+{
+   _check_quota 'user quota information' \
+                'group quota information'
+}
+
 #
 # Look for:
 # Only in RESTORE_DIR: xfsdump_quotas
 # Only in RESTORE_DIR: xfsdump_quotas_group
 #
-
 _check_quota_diff()
 {
-    uquota=0
-    gquota=0 
-    src/feature -U $SCRATCH_DEV && uquota=1
-    src/feature -G $SCRATCH_DEV && gquota=1
+   _check_quota 'Only in RESTORE_DIR: xfsdump_quotas' \
+       'Only in RESTORE_DIR: xfsdump_quotas_group' 
+}
 
-    $AWK_PROG -v uquota=$uquota -v gquota=$gquota '
-       /Only in RESTORE_DIR: xfsdump_quotas_group/ {
-                       found_gquota = 1
-                       if (!gquota) {
-                           print "Found extra:", $0
-                       }
-                       next
-       }
-       /Only in RESTORE_DIR: xfsdump_quotas/ {
-                       found_uquota = 1
-                       if (!uquota) {
-                           print "Found extra:", $0
-                       }
-                       next
-       }
-                       { print }
-       END {
-               if (uquota && !found_uquota) {
-                   print "Missing xfsdump_quotas msg"
-               }
-               if (gquota && !found_gquota) {
-                   print "Missing xfsdump_quotas_group msg"
-               }
-       }
-    '
+#
+# Look for the quota file in the output
+# Ensure that it is there if it should be
+# Filter it out so that the output is always the same
+# even with no quotas
+#
+_check_quota_file()
+{
+   _check_quota 'xfsdump_quotas' 'xfsdump_quotas_group'
 }
 
 # make sure this script returns success