Whamcloud - gitweb
b=13766
[fs/lustre-release.git] / lustre / tests / test-framework.sh
index 4b28769..0fa6898 100644 (file)
@@ -1,7 +1,7 @@
 #!/bin/bash
 # vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
 
-trap 'echo "test-framework exiting on error"' ERR
+trap 'print_summary && echo "test-framework exiting on error"' ERR
 set -e
 #set -x
 
@@ -10,6 +10,10 @@ export REFORMAT=${REFORMAT:-""}
 export VERBOSE=false
 export GMNALNID=${GMNALNID:-/usr/sbin/gmlndnid}
 export CATASTROPHE=${CATASTROPHE:-/proc/sys/lnet/catastrophe}
+export GSS=false
+export GSS_KRB5=false
+export GSS_PIPEFS=false
+export IDENTITY_UPCALL=false
 #export PDSH="pdsh -S -Rssh -w"
 
 # eg, assert_env LUSTRE MDSNODES OSTNODES CLIENTS
@@ -31,6 +35,38 @@ usage() {
     exit
 }
 
+print_summary () {
+    [ "$TESTSUITE" == "lfscktest" ] && return 0
+    [ -n "$ONLY" ] && echo "WARNING: ONLY is set to ${ONLY}."
+    local form="%-13s %-17s %s\n"
+    printf "$form" "status" "script" "skipped tests E(xcluded) S(low)"
+    echo "------------------------------------------------------------------------------------"
+    for O in $TESTSUITE_LIST; do
+        local skipped=""
+        local slow=""
+        local o=$(echo $O | tr "[:upper:]" "[:lower:]")
+        o=${o//_/-}
+        o=${o//tyn/tyN}
+        local log=${TMP}/${o}.log
+        [ -f $log ] && skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' | sed 's/test_//g')
+        [ -f $log ] && slow=$(grep SLOW $log | awk '{ printf " %s", $3 }' | sed 's/test_//g')
+        [ "${!O}" = "done" ] && \
+            printf "$form" "Done" "$O" "E=$skipped" && \
+            [ -n "$slow" ] && printf "$form" "-" "-" "S=$slow"
+
+    done
+
+    for O in $TESTSUITE_LIST; do
+        [ "${!O}" = "no" ] && \
+            printf "$form" "Skipped" "$O" ""
+    done
+
+    for O in $TESTSUITE_LIST; do
+        [ "${!O}" = "done" -o "${!O}" = "no" ] || \
+            printf "$form" "UNFINISHED" "$O" ""
+    done
+}
+
 init_test_env() {
     export LUSTRE=`absolute_path $LUSTRE`
     export TESTSUITE=`basename $0 .sh`
@@ -39,21 +75,36 @@ init_test_env() {
     [ -d /r ] && export ROOT=${ROOT:-/r}
     export TMP=${TMP:-$ROOT/tmp}
     export TESTSUITELOG=${TMP}/${TESTSUITE}.log
+    export HOSTNAME=${HOSTNAME:-`hostname`}
 
     export PATH=:$PATH:$LUSTRE/utils:$LUSTRE/utils/gss:$LUSTRE/tests
     export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
-    [ ! -f "$LCTL" ] && export LCTL=$(which lctl) 
+    [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
+    export LFS=${LFS:-"$LUSTRE/utils/lfs"}
+    [ ! -f "$LFS" ] && export LFS=$(which lfs)
+    export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
+    if [ ! -f "$L_GETIDENTITY" ]; then
+        if `which l_getidentity > /dev/null 2>&1`; then
+            export L_GETIDENTITY=$(which l_getidentity)
+        else
+            export L_GETIDENTITY=NONE
+        fi
+    fi
     export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
-    [ ! -f "$MKFS" ] && export MKFS=$(which mkfs.lustre) 
+    [ ! -f "$MKFS" ] && export MKFS=$(which mkfs.lustre)
     export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
-    [ ! -f "$TUNEFS" ] && export TUNEFS=$(which tunefs.lustre) 
+    [ ! -f "$TUNEFS" ] && export TUNEFS=$(which tunefs.lustre)
     export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
     export FSYTPE=${FSTYPE:-"ldiskfs"}
     export NAME=${NAME:-local}
     export LPROC=/proc/fs/lustre
     export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
+    [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] && \
+        export LGSSD=$(which lgssd)
     export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
+    [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd)
     export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
+    export DIR2
 
     if [ "$ACCEPTOR_PORT" ]; then
         export PORT_OPT="--port $ACCEPTOR_PORT"
@@ -62,17 +113,28 @@ init_test_env() {
     case "x$SEC" in
         xkrb5*)
             echo "Using GSS/krb5 ptlrpc security flavor"
-            export USING_KRB5="y"
+            GSS=true
+            GSS_KRB5=true
             ;;
     esac
 
-    # Paths on remote nodes, if different 
+    case "x$ID" in
+        xtrue)
+            IDENTITY_UPCALL=true
+            ;;
+        xfalse)
+            IDENTITY_UPCALL=false
+            ;;
+    esac
+
+    # Paths on remote nodes, if different
     export RLUSTRE=${RLUSTRE:-$LUSTRE}
     export RPWD=${RPWD:-$PWD}
+    export I_MOUNTED=${I_MOUNTED:-"no"}
 
     # command line
-    
-    while getopts "rvf:" opt $*; do 
+
+    while getopts "rvf:" opt $*; do
         case $opt in
             f) CONFIG=$OPTARG;;
             r) REFORMAT=--reformat;;
@@ -100,7 +162,7 @@ load_module() {
         # must be testing a "make install" or "rpm" installation
         # note failed to load ptlrpc_gss is considered not fatal
         if [ "$BASE" == "ptlrpc_gss" ]; then
-            modprobe $BASE $@ || echo "gss/krb5 is not supported"
+            modprobe $BASE $@ 2>/dev/null || echo "gss/krb5 is not supported"
         else
             modprobe $BASE $@
         fi
@@ -120,17 +182,17 @@ load_modules() {
 
     echo Loading modules from $LUSTRE
     load_module ../lnet/libcfs/libcfs
-    [ -z "$LNETOPTS" ] && \
-        LNETOPTS=$(awk '/^options lnet/ { print $0}' /etc/modprobe.conf | sed 's/^options lnet //g')
+    [ -f /etc/modprobe.conf ] && MODPROBECONF=/etc/modprobe.conf
+    [ -f /etc/modprobe.d/Lustre ] && MODPROBECONF=/etc/modprobe.d/Lustre
+    [ -z "$LNETOPTS" -a -n "$MODPROBECONF" ] && \
+        LNETOPTS=$(awk '/^options lnet/ { print $0}' $MODPROBECONF | sed 's/^options lnet //g')
     echo "lnet options: '$LNETOPTS'"
     # note that insmod will ignore anything in modprobe.conf
     load_module ../lnet/lnet/lnet $LNETOPTS
     LNETLND=${LNETLND:-"socklnd/ksocklnd"}
     load_module ../lnet/klnds/$LNETLND
-    [ "$FSTYPE" = "ldiskfs" ] && load_module ../ldiskfs/ldiskfs/ldiskfs
     load_module lvfs/lvfs
     load_module obdclass/obdclass
-    load_module lvfs/fsfilt_$FSTYPE
     load_module ptlrpc/ptlrpc
     load_module ptlrpc/gss/ptlrpc_gss
     # Now, some modules depend on lquota without USE_QUOTA check,
@@ -143,18 +205,27 @@ load_modules() {
     load_module mdc/mdc
     load_module osc/osc
     load_module lov/lov
-    load_module mds/mds
-    load_module mdd/mdd
-    load_module mdt/mdt
-    load_module cmm/cmm
-    load_module osd/osd
-    load_module ost/ost
-    load_module obdfilter/obdfilter
-    load_module llite/lustre
     load_module mgc/mgc
-    load_module mgs/mgs
-    rm -f $TMP/ogdb-`hostname`
-    $LCTL modules > $TMP/ogdb-`hostname`
+    if [ -z "$CLIENTONLY" ]; then
+        [ "$FSTYPE" = "ldiskfs" ] && load_module ../ldiskfs/ldiskfs/ldiskfs
+        load_module mgs/mgs
+        load_module mds/mds
+        load_module mdd/mdd
+        load_module mdt/mdt
+        load_module lvfs/fsfilt_$FSTYPE
+        load_module cmm/cmm
+        load_module osd/osd
+        load_module ost/ost
+        load_module obdfilter/obdfilter
+    fi
+
+    load_module llite/lustre
+    load_module llite/llite_lloop
+    rm -f $TMP/ogdb-$HOSTNAME
+    OGDB=$TMP
+    [ -d /r ] && OGDB="/r/tmp"
+    $LCTL modules > $OGDB/ogdb-$HOSTNAME
+
     # 'mount' doesn't look in $PATH, just sbin
     [ -f $LUSTRE/utils/mount.lustre ] && cp $LUSTRE/utils/mount.lustre /sbin/. || true
 }
@@ -188,6 +259,8 @@ wait_for_lnet() {
 }
 
 unload_modules() {
+    wait_exit_ST client # bug 12845
+
     lsmod | grep lnet > /dev/null && $LCTL dl && $LCTL dk $TMP/debug
     local MODULES=$($LCTL modules | awk '{ print $2 }')
     $RMMOD $MODULES > /dev/null 2>&1 || true
@@ -197,7 +270,7 @@ unload_modules() {
     MODULES=$($LCTL modules | awk '{ print $2 }')
     if [ -n "$MODULES" ]; then
     echo "Modules still loaded: "
-    echo $MODULES 
+    echo $MODULES
     if [ -e $LPROC ]; then
         echo "Lustre still loaded"
         cat $LPROC/devices || true
@@ -217,6 +290,7 @@ unload_modules() {
         echo "$LEAK_PORTALS" 1>&2
         mv $TMP/debug $TMP/debug-leak.`date +%s` || true
         echo "Memory leaks detected"
+       [ -n "$IGNORE_LEAK" ] && echo "ignoring leaks" && return 0
         return 254
     fi
     echo "modules unloaded."
@@ -245,7 +319,9 @@ start_gss_daemons() {
     # starting on MDT
     for num in `seq $MDSCOUNT`; do
         do_facet mds$num "$LSVCGSSD -v"
-        do_facet mds$num "$LGSSD -v"
+        if $GSS_PIPEFS; then
+            do_facet mds$num "$LGSSD -v"
+        fi
     done
     # starting on OSTs
     for num in `seq $OSTCOUNT`; do
@@ -253,7 +329,9 @@ start_gss_daemons() {
     done
     # starting on client
     # FIXME: is "client" the right facet name?
-    do_facet client "$LGSSD -v"
+    if $GSS_PIPEFS; then
+        do_facet client "$LGSSD -v"
+    fi
 
     # wait daemons entering "stable" status
     sleep 5
@@ -263,12 +341,16 @@ start_gss_daemons() {
     #
     for num in `seq $MDSCOUNT`; do
         check_gss_daemon_facet mds$num lsvcgssd
-        check_gss_daemon_facet mds$num lgssd
+        if $GSS_PIPEFS; then
+            check_gss_daemon_facet mds$num lgssd
+        fi
     done
     for num in `seq $OSTCOUNT`; do
         check_gss_daemon_facet ost$num lsvcgssd
     done
-    check_gss_daemon_facet client lgssd
+    if $GSS_PIPEFS; then
+        check_gss_daemon_facet client lgssd
+    fi
 }
 
 stop_gss_daemons() {
@@ -281,19 +363,14 @@ stop_gss_daemons() {
     send_sigint client lgssd
 }
 
-init_krb5_env() {
-    if [ ! -z $SEC ]; then
-        MDS_MOUNT_OPTS=$MDS_MOUNT_OPTS,sec=$SEC
-        OST_MOUNT_OPTS=$OST_MOUNT_OPTS,sec=$SEC
-    fi
-
-    if [ ! -z $USING_KRB5 ]; then
+init_gss() {
+    if $GSS; then
         start_gss_daemons
     fi
 }
 
-cleanup_krb5_env() {
-    if [ ! -z $USING_KRB5 ]; then
+cleanup_gss() {
+    if $GSS; then
         stop_gss_daemons
         # maybe cleanup credential cache?
     fi
@@ -314,7 +391,7 @@ ostdevlabel() {
 }
 
 # Facet functions
-# start facet device options 
+# start facet device options
 start() {
     facet=$1
     shift
@@ -322,12 +399,16 @@ start() {
     shift
     echo "Starting ${facet}: $@ ${device} ${MOUNT%/*}/${facet}"
     do_facet ${facet} mkdir -p ${MOUNT%/*}/${facet}
-    do_facet ${facet} mount -t lustre $@ ${device} ${MOUNT%/*}/${facet} 
+    do_facet ${facet} mount -t lustre $@ ${device} ${MOUNT%/*}/${facet}
     RC=${PIPESTATUS[0]}
     if [ $RC -ne 0 ]; then
-        echo mount -t lustre $@ ${device} ${MOUNT%/*}/${facet} 
+        echo mount -t lustre $@ ${device} ${MOUNT%/*}/${facet}
         echo Start of ${device} on ${facet} failed ${RC}
-    else 
+    else
+        do_facet ${facet} "sysctl -w lnet.debug=$PTLDEBUG; \
+        sysctl -w lnet.subsystem_debug=${SUBSYSTEM# }; \
+        sysctl -w lnet.debug_mb=${DEBUG_SIZE}"
+
         do_facet ${facet} sync
         label=$(do_facet ${facet} "e2label ${device}")
         [ -z "$label" ] && echo no label for ${device} && exit 1
@@ -354,24 +435,7 @@ stop() {
 
     # umount should block, but we should wait for unrelated obd's
     # like the MGS or MGC to also stop.
-    local WAIT=0
-    local INTERVAL=1
-    # conf-sanity 31 takes a long time cleanup
-    while [ $WAIT -lt 300 ]; do
-        running=$(do_facet ${facet} "[ -e $LPROC ] && grep ST' ' $LPROC/devices") || true
-        if [ -z "${running}" ]; then
-               return 0
-        fi
-        echo "waited $WAIT for${running}"
-        if [ $INTERVAL -lt 64 ]; then 
-            INTERVAL=$((INTERVAL + INTERVAL))
-        fi
-        sleep $INTERVAL
-        WAIT=$((WAIT + INTERVAL))
-    done
-    echo "service didn't stop after $WAIT seconds.  Still running:"
-    echo ${running}
-    exit 1
+    wait_exit_ST ${facet}
 }
 
 zconf_mount() {
@@ -388,12 +452,14 @@ zconf_mount() {
         exit 1
     fi
 
-    echo "Starting client: $OPTIONS $device $mnt" 
+    echo "Starting client: $OPTIONS $device $mnt"
     do_node $client mkdir -p $mnt
     do_node $client mount -t lustre $OPTIONS $device $mnt || return 1
 
-    do_node $client "sysctl -w lnet.debug=$PTLDEBUG; sysctl -w lnet.subsystem_debug=${SUBSYSTEM# }"
-    [ -d /r ] && $LCTL modules > /r/tmp/ogdb-`hostname`
+    do_node $client "sysctl -w lnet.debug=$PTLDEBUG;
+        sysctl -w lnet.subsystem_debug=${SUBSYSTEM# };
+        sysctl -w lnet.debug_mb=${DEBUG_SIZE}"
+    [ -d /r ] && $LCTL modules > /r/tmp/ogdb-$HOSTNAME
     return 0
 }
 
@@ -404,6 +470,7 @@ zconf_umount() {
     local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
     if [ $running -ne 0 ]; then
         echo "Stopping client $mnt (opts:$force)"
+        lsof | grep "$mnt" || true
         do_node $client umount $force $mnt
     fi
 }
@@ -412,7 +479,7 @@ shutdown_facet() {
     facet=$1
     if [ "$FAILURE_MODE" = HARD ]; then
         $POWER_DOWN `facet_active_host $facet`
-        sleep 2 
+        sleep 2
     elif [ "$FAILURE_MODE" = SOFT ]; then
         stop $facet
     fi
@@ -458,6 +525,24 @@ cleanup_check() {
     return 0
 }
 
+wait_delete_completed () {
+    local TOTALPREV=`awk 'BEGIN{total=0}; {total+=$1}; END{print total}' \
+            $LPROC/osc/*/kbytesavail`
+
+    local WAIT=0
+    local MAX_WAIT=20
+    while [ "$WAIT" -ne "$MAX_WAIT" ]; do
+        sleep 1
+        TOTAL=`awk 'BEGIN{total=0}; {total+=$1}; END{print total}' \
+            $LPROC/osc/*/kbytesavail`
+        [ "$TOTAL" -eq "$TOTALPREV" ] && break
+        echo "Waiting delete completed ... prev: $TOTALPREV current: $TOTAL "
+        TOTALPREV=$TOTAL
+        WAIT=$(( WAIT + 1))
+    done
+    echo "Delete completed."
+}
+
 wait_for_host() {
     HOST=$1
     check_network "$HOST" 900
@@ -470,6 +555,43 @@ wait_for() {
     wait_for_host $HOST
 }
 
+wait_mds_recovery_done () {
+    local timeout=`do_facet mds cat /proc/sys/lustre/timeout`
+#define OBD_RECOVERY_TIMEOUT (obd_timeout * 5 / 2)
+# as we are in process of changing obd_timeout in different ways
+# let's set MAX longer than that
+    MAX=$(( timeout * 4 ))
+    WAIT=0
+    while [ $WAIT -lt $MAX ]; do
+        STATUS=`do_facet mds grep status /proc/fs/lustre/mdt/*-MDT*/recovery_status`
+        echo $STATUS | grep COMPLETE && return 0
+        sleep 5
+        WAIT=$((WAIT + 5))
+        echo "Waiting $(($MAX - $WAIT)) secs for MDS recovery done"
+    done
+    echo "MDS recovery not done in $MAX sec"
+    return 1
+}
+
+wait_exit_ST () {
+    local facet=$1
+
+    local WAIT=0
+    local INTERVAL=1
+    # conf-sanity 31 takes a long time cleanup
+    while [ $WAIT -lt 300 ]; do
+        running=$(do_facet ${facet} "[ -e $LPROC ] && grep ST' ' $LPROC/devices") || true
+        [ -z "${running}" ] && return 0
+        echo "waited $WAIT for${running}"
+        [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
+        sleep $INTERVAL
+        WAIT=$((WAIT + INTERVAL))
+    done
+    echo "service didn't stop after $WAIT seconds.  Still running:"
+    echo ${running}
+    return 1
+}
+
 client_df() {
     # not every config has many clients
     if [ ! -z "$CLIENTS" ]; then
@@ -546,6 +668,11 @@ fail() {
     df $MOUNT || error "post-failover df: $?"
 }
 
+fail_nodf() {
+        local facet=$1
+        facet_failover $facet
+}
+
 fail_abort() {
     local facet=$1
     stop $facet
@@ -574,7 +701,7 @@ h2gm () {
 
 h2name_or_ip() {
     if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
-        echo $1"@$2" 
+        echo $1"@$2"
     fi
 }
 
@@ -637,7 +764,7 @@ facet_active() {
     fi
 
     active=${!activevar}
-    if [ -z "$active" ] ; then 
+    if [ -z "$active" ] ; then
         echo -n ${facet}
     else
         echo -n ${active}
@@ -648,7 +775,7 @@ facet_active_host() {
     local facet=$1
     local active=`facet_active $facet`
     if [ "$facet" == client ]; then
-        hostname
+        echo $HOSTNAME
     else
         echo `facet_host $active`
     fi
@@ -656,7 +783,7 @@ facet_active_host() {
 
 change_active() {
     local facet=$1
-    failover=${facet}failover 
+    failover=${facet}failover
     host=`facet_host $failover`
     [ -z "$host" ] && return
     curactive=`facet_active $facet`
@@ -674,8 +801,11 @@ do_node() {
     HOST=$1
     shift
     local myPDSH=$PDSH
-    if [ "$HOST" = "$(hostname)" ]; then
+    if [ "$HOST" = "$HOSTNAME" ]; then
         myPDSH="no_dsh"
+    elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
+        echo "cannot run remote command on $HOST with $myPDSH"
+        return 128
     fi
     if $VERBOSE; then
         echo "CMD: $HOST $@" >&2
@@ -728,10 +858,11 @@ stopall() {
     if [ $activemds != "mds1" ]; then
         fail mds1
     fi
-    
-    # assume client mount is local 
-    grep " $MOUNT " /proc/mounts && zconf_umount `hostname` $MOUNT $*
-    grep " $MOUNT2 " /proc/mounts && zconf_umount `hostname` $MOUNT2 $*
+
+    # assume client mount is local
+    grep " $MOUNT " /proc/mounts && zconf_umount $HOSTNAME $MOUNT $*
+    grep " $MOUNT2 " /proc/mounts && zconf_umount $HOSTNAME $MOUNT2 $*
+    [ "$CLIENTONLY" ] && return
     for num in `seq $MDSCOUNT`; do
         stop mds$num -f
     done
@@ -744,7 +875,7 @@ stopall() {
 cleanupall() {
     stopall $*
     unload_modules
-    cleanup_krb5_env
+    cleanup_gss
 }
 
 mdsmkfsopts()
@@ -756,6 +887,11 @@ mdsmkfsopts()
 formatall() {
     [ "$FSTYPE" ] && FSTYPE_OPT="--backfstype $FSTYPE"
 
+    if [ ! -z $SEC ]; then
+        MDS_MKFS_OPTS="$MDS_MKFS_OPTS --param srpc.flavor.default=$SEC"
+        OST_MKFS_OPTS="$OST_MKFS_OPTS --param srpc.flavor.default=$SEC"
+    fi
+
     stopall
     # We need ldiskfs here, may as well load them all
     load_modules
@@ -781,12 +917,43 @@ formatall() {
 }
 
 mount_client() {
-    grep " $1 " /proc/mounts || zconf_mount `hostname` $*
+    grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
+}
+
+# return value:
+# 0: success, the old identity set already.
+# 1: success, the old identity does not set.
+# 2: fail.
+switch_identity() {
+    local num=$1
+    local switch=$2
+    local j=`expr $num - 1`
+    local MDT="`do_facet mds$num ls -l $LPROC/mdt/ 2>/dev/null | grep MDT | awk '{print $9}' | grep $j$`"
+
+    if [ -z "$MDT" ]; then
+        return 2
+    fi
+
+    local old="`do_facet mds$num cat $LPROC/mdt/$MDT/identity_upcall`"
+
+    if [ $switch ]; then
+        do_facet mds$num "echo \"$L_GETIDENTITY\" > $LPROC/mdt/$MDT/identity_upcall"
+    else
+        do_facet mds$num "echo \"NONE\" > $LPROC/mdt/$MDT/identity_upcall"
+    fi
+
+    do_facet mds$num "echo \"-1\" > $LPROC/mdt/$MDT/identity_flush"
+
+    if [ $old = "NONE" ]; then
+        return 1
+    else
+        return 0
+    fi
 }
 
 setupall() {
     load_modules
-    init_krb5_env
+    init_gss
     if [ -z "$CLIENTONLY" ]; then
         echo "Setup mdts, osts"
         for num in `seq $MDSCOUNT`; do
@@ -794,6 +961,7 @@ setupall() {
             echo $REFORMAT | grep -q "reformat" \
             || do_facet mds$num "$TUNEFS --writeconf $DEVNAME"
             start mds$num $DEVNAME $MDS_MOUNT_OPTS
+            switch_identity $num $IDENTITY_UPCALL
         done
         for num in `seq $OSTCOUNT`; do
             DEVNAME=$(ostdevname $num)
@@ -808,8 +976,46 @@ setupall() {
     sleep 5
 }
 
+mounted_lustre_filesystems() {
+       awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
+}
+
+check_and_setup_lustre() {
+    MOUNTED="`mounted_lustre_filesystems`"
+    if [ -z "$MOUNTED" ]; then
+        [ "$REFORMAT" ] && formatall
+        setupall
+        MOUNTED="`mounted_lustre_filesystems`"
+        [ -z "$MOUNTED" ] && error "NAME=$NAME not mounted"
+        export I_MOUNTED=yes
+    fi
+    if [ "$ONLY" == "setup" ]; then
+        exit 0
+    fi
+}
+
+cleanup_and_setup_lustre() {
+    if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
+        sysctl -w lnet.debug=0 || true
+        cleanupall
+        if [ "$ONLY" == "cleanup" ]; then
+           exit 0
+        fi
+    fi
+    check_and_setup_lustre
+}
 
-####### 
+check_and_cleanup_lustre() {
+    if [ "`mount | grep $MOUNT`" ]; then
+        [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]*
+    fi
+    if [ "$I_MOUNTED" = "yes" ]; then
+        cleanupall -f || error "cleanup failed"
+    fi
+    unset I_MOUNTED
+}
+
+#######
 # General functions
 
 check_network() {
@@ -936,6 +1142,35 @@ cancel_lru_locks() {
     $LCTL mark "cancel_lru_locks $1 stop"
 }
 
+default_lru_size()
+{
+        NR_CPU=$(grep -c "processor" /proc/cpuinfo)
+        DEFAULT_LRU_SIZE=$((100 * NR_CPU))
+        echo "$DEFAULT_LRU_SIZE"
+}
+
+lru_resize_enable()
+{
+        NS=$1
+        test "x$NS" = "x" && NS="mdc"
+        for F in $LPROC/ldlm/namespaces/*$NS*/lru_size; do
+                D=$(dirname $F)
+                log "Enable lru resize for $(basename $D)"
+                echo "0" > $F
+        done
+}
+
+lru_resize_disable()
+{
+        NS=$1
+        test "x$NS" = "x" && NS="mdc"
+        for F in $LPROC/ldlm/namespaces/*$NS*/lru_size; do
+                D=$(dirname $F)
+                log "Disable lru resize for $(basename $D)"
+                DEFAULT_LRU_SIZE=$(default_lru_size)
+                echo "$DEFAULT_LRU_SIZE" > $F
+        done
+}
 
 pgcache_empty() {
     for a in /proc/fs/lustre/llite/*/dump_page_cache; do
@@ -948,26 +1183,46 @@ pgcache_empty() {
     return 0
 }
 
-FAIL_ON_ERROR=true
+debugsave() {
+    DEBUGSAVE="$(sysctl -n lnet.debug)"
+}
+
+debugrestore() {
+    [ -n "$DEBUGSAVE" ] && sysctl -w lnet.debug="${DEBUGSAVE}"
+    DEBUGSAVE=""
+}
+
+##################################
+# Test interface
 ##################################
-# Test interface 
+
 error() {
+    local FAIL_ON_ERROR=${FAIL_ON_ERROR:-true}
+    local TYPE=${TYPE:-"FAIL"}
     local ERRLOG
     sysctl -w lustre.fail_loc=0 2> /dev/null || true
-    log "${TESTSUITE} ${TESTNAME}: **** FAIL:" $@
+    log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
     ERRLOG=$TMP/lustre_${TESTSUITE}_${TESTNAME}.$(date +%s)
     echo "Dumping lctl log to $ERRLOG"
     # We need to dump the logs on all nodes
-    $LCTL dk $ERRLOG
-    [ ! "$mds_HOST" = "$(hostname)" ] && do_node $mds_HOST $LCTL dk $ERRLOG
-    [ ! "$ost_HOST" = "$(hostname)" -a ! "$ost_HOST" = "$mds_HOST" ] && do_node $ost_HOST $LCTL dk $ERRLOG
+    local NODES=$(nodes_list)
+    for NODE in $NODES; do
+        do_node $NODE $LCTL dk $ERRLOG
+    done
     debugrestore
-    [ "$TESTSUITELOG" ] && echo "$0: FAIL: $TESTNAME $@" >> $TESTSUITELOG
+    [ "$TESTSUITELOG" ] && echo "$0: ${TYPE}: $TESTNAME $@" >> $TESTSUITELOG
     if $FAIL_ON_ERROR; then
        exit 1
     fi
 }
 
+# use only if we are ignoring failures for this test, bugno required.
+# (like ALWAYS_EXCEPT, but run the test and ignore the results.)
+# e.g. error_ignore 5494 "your message"
+error_ignore() {
+    FAIL_ON_ERROR=false TYPE="IGNORE (bz$1)" error $2
+}
+
 skip () {
        log " SKIP: ${TESTSUITE} ${TESTNAME} $@"
        [ "$TESTSUITELOG" ] && echo "${TESTSUITE}: SKIP: $TESTNAME $@" >> $TESTSUITELOG
@@ -980,9 +1235,17 @@ build_test_filter() {
     done
     [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
         log "skipping tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
+    [ "$EXCEPT_SLOW" ] && \
+        log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
     for E in $EXCEPT $ALWAYS_EXCEPT; do
         eval EXCEPT_${E}=true
     done
+    for E in $EXCEPT_SLOW; do
+        eval EXCEPT_SLOW_${E}=true
+    done
+    for G in $GRANT_CHECK_LIST; do
+        eval GCHECK_ONLY_${G}=true
+       done
 }
 
 _basetest() {
@@ -1019,8 +1282,19 @@ run_test() {
         TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
         return 0
     fi
+    testname=EXCEPT_SLOW_$1
+    if [ ${!testname}x != x ]; then
+        TESTNAME=test_$1 skip "skipping SLOW test $1"
+        return 0
+    fi
+    testname=EXCEPT_SLOW_$base
+    if [ ${!testname}x != x ]; then
+        TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
+        return 0
+    fi
+
     run_one $1 "$2"
-    
+
     return $?
 }
 
@@ -1030,13 +1304,34 @@ equals_msg() {
 
     local suffixlen=$((${#EQUALS} - ${#msg}))
     [ $suffixlen -lt 5 ] && suffixlen=5
-    printf '===== %s %.*s\n' "$msg" $suffixlen $EQUALS
+    log `echo $(printf '===== %s %.*s\n' "$msg" $suffixlen $EQUALS)`
 }
 
 log() {
     echo "$*"
     lsmod | grep lnet > /dev/null || load_modules
-    $LCTL mark "$*" 2> /dev/null || true
+
+    local MSG="$*"
+    # Get rif of '
+    MSG=${MSG//\'/\\\'}
+    MSG=${MSG//\(/\\\(}
+    MSG=${MSG//\)/\\\)}
+    MSG=${MSG//\;/\\\;}
+    MSG=${MSG//\|/\\\|}
+    MSG=${MSG//\>/\\\>}
+    MSG=${MSG//\</\\\<}
+    local NODES=$(nodes_list)
+    for NODE in $NODES; do
+        do_node $NODE $LCTL mark "$MSG" 2> /dev/null || true
+    done
+}
+
+trace() {
+       log "STARTING: $*"
+       strace -o $TMP/$1.strace -ttt $*
+       RC=$?
+       log "FINISHED: $*: rc $RC"
+       return 1
 }
 
 pass() {
@@ -1049,14 +1344,23 @@ check_mds() {
     [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
 }
 
+reset_fail_loc () {
+    local myNODES=$(nodes_list)
+    local NODE
+
+    for NODE in $myNODES; do
+        do_node $NODE sysctl -w lustre.fail_loc=0 || true
+    done
+}
+
 run_one() {
     testnum=$1
     message=$2
     tfile=f${testnum}
-    tdir=d${base}
-
-    # Pretty tests run faster.
-    equals_msg $testnum: $message
+    export tdir=d0.${TESTSUITE}/d${base}
+    local SAVE_UMASK=`umask`
+    umask 0022
+    mkdir -p $DIR/$tdir
 
     BEFORE=`date +%s`
     log "== test $testnum: $message ============ `date +%H:%M:%S` ($BEFORE)"
@@ -1064,16 +1368,72 @@ run_one() {
     export TESTNAME=test_$testnum
     test_${testnum} || error "test_$testnum failed with $?"
     #check_mds
+    reset_fail_loc
+    check_grant ${testnum} || error "check_grant $testnum failed with $?"
     [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
         error "LBUG/LASSERT detected"
     pass "($((`date +%s` - $BEFORE))s)"
+    rmdir ${DIR}/$tdir >/dev/null 2>&1 || true
     unset TESTNAME
+    unset tdir
+    umask $SAVE_UMASK
+    cd $SAVE_PWD
+    $CLEANUP
 }
 
 canonical_path() {
     (cd `dirname $1`; echo $PWD/`basename $1`)
 }
 
+sync_clients() {
+    [ -d $DIR1 ] && cd $DIR1 && sync; sleep 1; sync
+    [ -d $DIR2 ] && cd $DIR2 && sync; sleep 1; sync
+       cd $SAVE_PWD
+}
+
+check_grant() {
+    export base=`basetest $1`
+    [ "$CHECK_GRANT" == "no" ] && return 0
+
+       testname=GCHECK_ONLY_${base}
+        [ ${!testname}x == x ] && return 0
+
+       echo -n "checking grant......"
+       cd $SAVE_PWD
+       # write some data to sync client lost_grant
+       rm -f $DIR1/${tfile}_check_grant_* 2>&1
+       for i in `seq $OSTCOUNT`; do
+               $LFS setstripe $DIR1/${tfile}_check_grant_$i -i $(($i -1)) -c 1
+               dd if=/dev/zero of=$DIR1/${tfile}_check_grant_$i bs=4k \
+                                             count=1 > /dev/null 2>&1
+       done
+       # sync all the data and make sure no pending data on server
+       sync_clients
+       
+       #get client grant and server grant
+       client_grant=0
+    for d in ${LPROC}/osc/*/cur_grant_bytes; do
+               client_grant=$((client_grant + `cat $d`))
+       done
+       server_grant=0
+       for d in ${LPROC}/obdfilter/*/tot_granted; do
+               server_grant=$((server_grant + `cat $d`))
+       done
+
+       # cleanup the check_grant file
+       for i in `seq $OSTCOUNT`; do
+               rm $DIR1/${tfile}_check_grant_$i
+       done
+
+       #check whether client grant == server grant
+       if [ $client_grant != $server_grant ]; then
+               echo "failed: client:${client_grant} server: ${server_grant}"
+               return 1
+       else
+               echo "pass"
+       fi
+}
+
 ########################
 # helper functions
 
@@ -1092,7 +1452,81 @@ remote_mds ()
     [ ! -e /proc/fs/lustre/mdt/*MDT* ]
 }
 
+remote_mds_nodsh()
+{
+    remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
+}
+
 remote_ost ()
 {
     [ $(grep -c obdfilter $LPROC/devices) -eq 0 ]
 }
+
+remote_ost_nodsh()
+{
+    remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
+}
+
+mdts_nodes () {
+    local MDSNODES=$(facet_host $SINGLEMDS)
+    local NODES_sort
+
+    # FIXME: Currenly we use only $SINGLEMDS,
+    # should be fixed when we will start to test cmd.
+    echo $MDSNODES
+    return
+
+    for num in `seq $MDSCOUNT`; do
+        local myMDS=$(facet_host mds$num)
+        MDSNODES="$MDSNODES $myMDS"
+    done
+    NODES_sort=$(for i in $MDSNODES; do echo $i; done | sort -u)
+
+    echo $NODES_sort
+}
+
+osts_nodes () {
+    local OSTNODES=$(facet_host ost1)
+    local NODES_sort
+
+    for num in `seq $OSTCOUNT`; do
+        local myOST=$(facet_host ost$num)
+        OSTNODES="$OSTNODES $myOST"
+    done
+    NODES_sort=$(for i in $OSTNODES; do echo $i; done | sort -u)
+
+    echo $NODES_sort
+}
+
+nodes_list () {
+    # FIXME. We need a list of clients
+    local myNODES=$HOSTNAME
+    local myNODES_sort
+
+    if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
+        myNODES="$myNODES $(osts_nodes) $(mdts_nodes)"
+    fi
+
+    myNODES_sort=$(for i in $myNODES; do echo $i; done | sort -u)
+
+    echo $myNODES_sort
+}
+
+is_patchless ()
+{
+    grep -q patchless $LPROC/version
+}
+
+check_runas_id() {
+    local myRUNAS_ID=$1
+    shift
+    local myRUNAS=$@
+    mkdir $DIR/d0_runas_test
+    chmod 0755 $DIR
+    chown $myRUNAS_ID:$myRUNAS_ID $DIR/d0_runas_test
+    $myRUNAS touch $DIR/d0_runas_test/f$$ || \
+        error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_ID.
+        Please set RUNAS_ID to some UID which exists on MDS and client or
+        add user $myRUNAS_ID:$myRUNAS_ID on these nodes."
+    rm -rf $DIR/d0_runas_test
+}