Ensure QA tests are run with all the mount options requested
[xfstests-dev.git] / common.rc
index 0cca139f3096d6702ea166374ff5f064185ebb21..5d248de1847346c703260bb8068ee0336d6c9575 100644 (file)
--- a/common.rc
+++ b/common.rc
@@ -1,7 +1,7 @@
 ##/bin/sh
 
 #
-# Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
+# Copyright (c) 2000-2003 Silicon Graphics, Inc.  All Rights Reserved.
 # 
 # This program is free software; you can redistribute it and/or modify it
 # under the terms of version 2 of the GNU General Public License as
@@ -39,22 +39,18 @@ then
     exit 1
 fi
 
+# make sure we have a standard umask
+umask 022
+
 # awk
 AWK_PROG=awk
 
-# ps
-PS_HAVE_BSD=false
-PS_ALL_FLAGS=-efw
-
-# host os
-PLATFORM=linux
-
 # extra parameters for fsstress
 FSSTRESS_AVOID="-f resvsp=0 -f unresvsp=0"
 
-export AWK_PROG PS_HAVE_BSD PS_ALL_FLAGS PLATFORM
+export AWK_PROG FSSTRESS_AVOID
 
-# we override mount so we can specify mount options
+# we override mount and mkfs.xfs so we can specify extra options
 
 mount()
 {
@@ -75,7 +71,79 @@ mount()
     esac
 }
 
-#
+_test_mount()
+{
+    TEST_OPTIONS=""
+    [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
+        TEST_OPTIONS="$TEST_OPTIONS -ortdev=$TEST_RTDEV"
+    [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
+        TEST_OPTIONS="$TEST_OPTIONS -ologdev=$TEST_LOGDEV"
+    mount -t xfs $TEST_OPTIONS $MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
+}
+
+_scratch_mount_options()
+{
+    SCRATCH_OPTIONS=""
+    [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
+        SCRATCH_OPTIONS="$SCRATCH_OPTIONS -ortdev=$SCRATCH_RTDEV"
+    [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
+        SCRATCH_OPTIONS="$SCRATCH_OPTIONS -ologdev=$SCRATCH_LOGDEV"
+    echo $SCRATCH_OPTIONS $MOUNT_OPTIONS $* $SCRATCH_DEV $SCRATCH_MNT
+}
+
+_scratch_mount()
+{
+    SCRATCH_OPTIONS=""
+    [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
+        SCRATCH_OPTIONS="$SCRATCH_OPTIONS -ortdev=$SCRATCH_RTDEV"
+    [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
+        SCRATCH_OPTIONS="$SCRATCH_OPTIONS -ologdev=$SCRATCH_LOGDEV"
+    mount -t xfs $SCRATCH_OPTIONS $MOUNT_OPTIONS $* $SCRATCH_DEV $SCRATCH_MNT
+}
+
+_scratch_mkfs_options()
+{
+    SCRATCH_OPTIONS=""
+    [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
+        SCRATCH_OPTIONS="$SCRATCH_OPTIONS -rrtdev=$SCRATCH_RTDEV"
+    [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
+        SCRATCH_OPTIONS="$SCRATCH_OPTIONS -llogdev=$SCRATCH_LOGDEV"
+    echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
+}
+
+_scratch_mkfs_xfs()
+{
+    SCRATCH_OPTIONS=""
+    [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
+        SCRATCH_OPTIONS="$SCRATCH_OPTIONS -rrtdev=$SCRATCH_RTDEV"
+    [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
+        SCRATCH_OPTIONS="$SCRATCH_OPTIONS -llogdev=$SCRATCH_LOGDEV"
+    /sbin/mkfs.xfs -f $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
+}
+
+_scratch_xfs_db_options()
+{
+    SCRATCH_OPTIONS=""
+    [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
+        SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
+    echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
+}
+
+_scratch_xfs_logprint()
+{
+    SCRATCH_OPTIONS=""
+    [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
+        SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
+    /usr/sbin/xfs_logprint $SCRATCH_OPTIONS $* $SCRATCH_DEV
+}
+
+_scratch_xfs_repair()
+{
+    SCRATCH_OPTIONS=""
+    [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
+        SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
+    /sbin/xfs_repair $SCRATCH_OPTIONS $* $SCRATCH_DEV
+}
 
 _get_pids_by_name()
 {
@@ -262,11 +330,57 @@ _is_block_dev()
     [ -b $1 ] && src/lstat64 $1 | $AWK_PROG '/Device type:/ { print $9 }'
 }
 
+# Do a command, log it to $seq.full, optionally test return status
+# and die if command fails. If called with one argument _do executes the
+# command, logs it, and returns its exit status. With two arguments _do
+# first prints the message passed in the first argument, and then "done"
+# or "fail" depending on the return status of the command passed in the
+# second argument. If the command fails and the variable _do_die_on_error
+# is set to "always" or the two argument form is used and _do_die_on_error
+# is set to "message_only" _do will print an error message to
+# $seq.out and exit.
+
+_do()
+{
+  if [ $# -eq 1 ]; then
+    _cmd=$1
+  elif [ $# -eq 2 ]; then
+    _note=$1
+    _cmd=$2
+    echo -n "$_note... "
+  else
+    echo "Usage: _do [note] cmd" 1>&2
+    status=1; exit
+  fi
+
+  (eval "echo '---' \"$_cmd\"") >>$seq.full
+  (eval "$_cmd") >$tmp._out 2>&1; ret=$?
+  cat $tmp._out | _fix_malloc >>$seq.full
+  if [ $# -eq 2 ]; then
+    if [ $ret -eq 0 ]; then
+      echo "done"
+    else
+      echo "fail"
+    fi
+  fi
+  if [ $ret -ne 0  ] \
+     && [ "$_do_die_on_error" = "always" \
+        -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
+  then
+      [ $# -ne 2 ] && echo
+      eval "echo \"$_cmd\" failed \(returned $ret\): see $seq.full"
+      status=1; exit
+  fi
+
+  return $ret
+}
+
 # bail out, setting up .notrun file
 # 
 _notrun()
 {
     echo "$*" >$seq.notrun
+    echo "$seq not run: $*"
     status=0
     exit
 }
@@ -285,7 +399,6 @@ _fail()
 # 
 _require_scratch()
 {
-
     if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
     then
         _notrun "this test requires a valid \$SCRATCH_DEV"
@@ -305,34 +418,33 @@ _require_scratch()
             echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
             exit 1
         fi
-        
         # and then unmount it
-    
         if ! umount $SCRATCH_DEV
         then
             echo "failed to unmount $SCRATCH_DEV"
             exit 1
         fi
     fi
-    
-    # should be ok now
-
 }
 
 # this test needs a logdev 
 # 
 _require_logdev()
 {
-    if [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ]
-    then
+    [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
         _notrun "This test requires a valid \$SCRATCH_LOGDEV" 
-    fi
+    [ "$USE_EXTERNAL" != yes ] && \
+        _notrun "This test requires USE_EXTERNAL to be enabled"
+
+    # ensure its not mounted
+    umount $SCRATCH_LOGDEV 2>/dev/null
 }
 
 # this test requires loopback device support
 # 
 _require_loop()
 {
+    modprobe loop >/dev/null 2>&1
     if grep loop /proc/devices >/dev/null 2>&1
     then
        :
@@ -341,7 +453,6 @@ _require_loop()
     fi
 }
 
-
 # check that a FS is mounted as XFS. if so, return mount point
 #
 _xfs_mounted()
@@ -364,9 +475,37 @@ _xfs_mounted()
     fi
 }
 
+
+# setup the .out file link, depending on which form of quota is
+# enabled as this often influences how the test output appears.
+# [NB: SCRATCH_DEV must be mounted for this to work]
+# 
+_setup_seq_out()
+{
+    # this lets us phase use of this into the dump/restore tests easier...
+    [ -f $seq.ugquota -a -f $seq.noquota -a $seq.usrquota -a $seq.grpquota ] \
+       || return
+
+    rm -f $seq.out
+    if src/feature -U $SCRATCH_DEV
+    then
+       if src/feature -G $SCRATCH_DEV
+       then
+           ln $seq.ugquota $seq.out
+       else
+           ln $seq.usrquota $seq.out
+       fi
+    elif src/feature -G $SCRATCH_DEV
+    then
+       ln $seq.grpquota $seq.out
+    else
+       ln $seq.noquota $seq.out
+    fi
+}
+
+
 # remount a FS to a new mode (ro or rw)
 #
-
 _remount()
 {
     if [ $# -ne 2 ]
@@ -388,7 +527,7 @@ _remount()
 
 }
 
-# run xfs_check on a FS. 
+# run xfs_check and friends on a FS. 
 #
 # if the filesystem is mounted, it's either remounted ro before being
 # checked or it's unmounted and then remounted
@@ -396,15 +535,19 @@ _remount()
 
 USE_REMOUNT=0
 
-_check_fs()
+_check_filesystem()
 {
-    if [ $# -ne 1 ]
+    if [ $# -ne 1 -a $# -ne 2 ]
     then
-       echo "Usage: _check_fs device" 1>&2
+       echo "Usage: _check_fs device [logdevice]" 1>&2
        exit 1
     fi
     
     device=$1
+    if [ $# -eq 2 -a "$2" != "" ]; then
+               extra_log_options="-l$2"
+        extra_mount_options="-ologdev=$2"
+    fi
     type=`_fs_type $device`
     ok=1
     
@@ -421,7 +564,8 @@ _check_fs()
         fi
     fi
 
-    xfs_logprint -t $device 2>&1 | tee $tmp.fs_check | grep -q "<CLEAN>"
+    /usr/sbin/xfs_logprint -t $device $extra_log_options 2>&1 \
+                | tee $tmp.fs_check | grep -q "<CLEAN>"
     if [ $? -ne 0 ]
     then
         echo "_check_fs: filesystem on $device has dirty log (see $seq.full)"
@@ -433,9 +577,8 @@ _check_fs()
         
         ok=0
     fi
-        
-    
-    xfs_check $device 2>&1 | _fix_malloc >$tmp.fs_check 
+
+    /usr/sbin/xfs_check $device 2>&1 | _fix_malloc >$tmp.fs_check 
     if [ -s $tmp.fs_check ]
     then
         echo "_check_fs: filesystem on $device is inconsistent (c) (see $seq.full)"
@@ -448,7 +591,7 @@ _check_fs()
         ok=0
     fi
     
-    if ! xfs_repair -n $device >$tmp.fs_check 2>&1
+    if ! /sbin/xfs_repair -n $device $extra_log_options >$tmp.fs_check 2>&1
     then
         echo "_check_fs: filesystem on $device is inconsistent (r) (see $seq.full)"
         
@@ -466,14 +609,12 @@ _check_fs()
         echo "*** mount output ***"                             >>$seq.full
         mount                                                   >>$seq.full
         echo "*** end mount output"                             >>$seq.full
-    fi
-    
-    if [ "$type" = "xfs" ]
+    elif [ "$type" = "xfs" ]
     then
         # mounted... 
         if [ $USE_REMOUNT -eq 0 ]
         then
-            if ! mount -t xfs $device $mountpoint
+            if ! mount -t xfs $extra_mount_options $device $mountpoint
             then
                 echo "!!! failed to remount $device on $mountpoint"
                 ok=0
@@ -484,7 +625,23 @@ _check_fs()
     fi
     
     [ $ok -eq 0 ] && exit 1
-    
+    return 0    
+}
+
+_check_test_fs()
+{
+    TEST_LOG=""
+    [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
+        TEST_LOG="$TEST_LOGDEV"
+    _check_filesystem $TEST_DEV $TEST_LOG
+}
+
+_check_scratch_fs()
+{
+    SCRATCH_LOG=""
+    [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
+        SCRATCH_LOG="$SCRATCH_LOGDEV"
+    _check_filesystem $SCRATCH_DEV $SCRATCH_LOG
 }
 
 ################################################################################
@@ -503,6 +660,17 @@ then
         exit 1
     fi
     
+    # if $TEST_DEV is not mounted, mount it now as XFS
+    if [ -z "`_fs_type $TEST_DEV`" ]
+    then
+        # $TEST_DEV is not mounted
+        if ! _test_mount
+        then
+            echo "common.rc: could not mount $TEST_DEV on $TEST_DIR"
+            exit 1
+        fi
+    fi
+    
     if [ "`_fs_type $TEST_DEV`" != "xfs" ]
     then
         echo "common.rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED XFS filesystem"
@@ -512,7 +680,7 @@ then
 
 fi
 
-# check for some required biunaries on our $PATH
+# check for some required binaries on our $PATH
 #
 for exec in mkfs.xfs xfs_logprint xfs_check xfs_repair xfs_db
 do