Fix for external log/rt on the test device for auto-qa
[xfstests-dev.git] / common.rc
index f952d118e028c31003bc22bcef49120df36d8f38..47ee1e332e2aa964948dbd733ff51942340791cf 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,28 +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"
 
-# env variables for mem checking
-#EF_PROTECT_FREE=1 # efence
-#export EF_PROTECT_FREE
-# Not used because we get weird errors of form:
-# ElectricFence Exiting: mmap() failed: Cannot allocate memory
+export AWK_PROG FSSTRESS_AVOID
 
-export AWK_PROG PS_HAVE_BSD PS_ALL_FLAGS PLATFORM
-
-# we override mount so we can specify mount options
+# we override mount and mkfs.xfs so we can specify extra options
 
 mount()
 {
@@ -81,7 +71,77 @@ mount()
     esac
 }
 
-#
+_test_mount()
+{
+    TEST_OPTIONS=""
+    [ -z "$TEST_RTDEV" ] || TEST_OPTIONS="$TEST_OPTIONS -ortdev=$TEST_RTDEV"
+    [ -z "$TEST_LOGDEV" ] || TEST_OPTIONS="$TEST_OPTIONS -ologdev=$TEST_LOGDEV"
+    mount -t xfs $TEST_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 $* $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 $* $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()
 {
@@ -337,7 +397,6 @@ _fail()
 # 
 _require_scratch()
 {
-
     if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
     then
         _notrun "this test requires a valid \$SCRATCH_DEV"
@@ -357,34 +416,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
        :
@@ -393,7 +451,6 @@ _require_loop()
     fi
 }
 
-
 # check that a FS is mounted as XFS. if so, return mount point
 #
 _xfs_mounted()
@@ -416,9 +473,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 ]
@@ -440,7 +525,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
@@ -448,15 +533,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
     
@@ -473,7 +562,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)"
@@ -485,9 +575,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)"
@@ -500,7 +589,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)"
         
@@ -525,7 +614,7 @@ _check_fs()
         # 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
@@ -539,6 +628,22 @@ _check_fs()
     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
+}
+
 ################################################################################
 
 [ -d /usr/bsd ] && PATH=$PATH:/usr/bsd
@@ -555,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"
@@ -564,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