1 #! /usr/bin/ksh -p
   2 #
   3 # CDDL HEADER START
   4 #
   5 # The contents of this file are subject to the terms of the
   6 # Common Development and Distribution License (the "License").
   7 # You may not use this file except in compliance with the License.
   8 #
   9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10 # or http://www.opensolaris.org/os/licensing.
  11 # See the License for the specific language governing permissions
  12 # and limitations under the License.
  13 #
  14 # When distributing Covered Code, include this CDDL HEADER in each
  15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16 # If applicable, add the following below this CDDL HEADER, with the
  17 # fields enclosed by brackets "[]" replaced with your own identifying
  18 # information: Portions Copyright [yyyy] [name of copyright owner]
  19 #
  20 # CDDL HEADER END
  21 #
  22 
  23 #
  24 # Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  25 # Use is subject to license terms.
  26 #
  27 
  28 NAME=$(basename $0)
  29 
  30 . $STF_SUITE/include/sharemnt.kshlib
  31 . $STC_GENUTILS/include/nfs-tx.kshlib
  32 
  33 export STC_GENUTILS_DEBUG=$STC_GENUTILS_DEBUG:$SHAREMNT_DEBUG
  34 [[ :$SHAREMNT_DEBUG: == *:${NAME}:* \
  35         || :${SHAREMNT_DEBUG}: == *:all:* ]] && set -x
  36 
  37 ################################################################################
  38 #
  39 # __stc_assertion_start
  40 #
  41 # ID: runtests
  42 #
  43 # DESCRIPTION:
  44 #   For each log tag in nfslog.conf, combine different nfs version.
  45 #   Do some simple rw operation and verify the operation is logged.
  46 #
  47 # STRATEGY:
  48 #   1. Call domount_check to mount test filesystem and verify
  49 #   2. Call do_rw_test script to test in the mounted filesystem
  50 #   3. Call unmount_check to umount and check the filesystem is umounted
  51 #   4. Call test_nfslogd to verify logging. 
  52 #
  53 # TESTABILITY: explicit
  54 #
  55 # TEST_AUTOMATION_LEVEL: automated
  56 #
  57 # __stc_assertion_end
  58 #
  59 ################################################################################
  60 
  61 USAGE="Usage: runtests Test_name Log_tag Share_opt Mnt_opts"
  62 
  63 if (( $# < 4 )); then
  64         echo "$USAGE"
  65         exit $STF_UNRESOLVED
  66 fi
  67 
  68 typeset Tname=$1
  69 typeset Tag=$2
  70 typeset Shropt=$3
  71 typeset Mntopts=$4
  72 typeset Lock_Dir=/var/tmp/sharemnt_lock
  73 
  74 is_cipso "$Mntopts" "$SERVER"
  75 run_result=$?
  76 if (( $run_result == 3 )); then
  77         echo "$NAME: UNSUPPORTED"
  78         echo "\tCurrently nfslogd only support NFSv2 and NFSv3, "
  79         echo "\tNFSv4 testing with Trusted Extensions is not supported" 
  80         exit $STF_UNSUPPORTED
  81 elif (( $run_result == 1 )); then
  82         echo "$NAME: UNSUPPORTED"
  83         echo "\tCurrently only NFSv3 and NFSv4 are supported under TX"
  84         exit $STF_UNSUPPORTED
  85 fi
  86 
  87 # make sure nfslogd is running on server before test start
  88 SRVDEBUG=$SHAREMNT_DEBUG
  89 [[ :$SHAREMNT_DEBUG: == *:RSH:* ]] && SRVDEBUG=all
  90 RSH root $SERVER \
  91     "export SHAREMNT_DEBUG=$SRVDEBUG; \
  92     ksh $SRV_TMPDIR/sharemnt.nfslogd -C" \
  93     > $STF_TMPDIR/rsh.out.$$ 2>&1
  94 if (( $? != 0 )); then
  95     echo "\n$Tname: run $SRV_TMPDIR/sharemnt.nfslogd in $SERVER failed:"
  96     cat $STF_TMPDIR/rsh.out.$$
  97     cleanup $STF_FAIL
  98 else
  99         print_debug $STF_TMPDIR/rsh.out.$$
 100 fi
 101 
 102 # The function returns the content of lock file on server.
 103 function read_lock_file {
 104         typeset lockfile=$1
 105 
 106         value=$(RSH root $SERVER "cat $Lock_Dir/$lockfile" 2>/dev/null)
 107         if (( $? != 0 )); then
 108                 echo "\n$Tname: failed to read lock file<$Lock_Dir/$lockfile"
 109                 echo $value
 110                 cleanup $STF_UNINITIATED
 111         fi
 112 
 113         echo $value
 114 }
 115 
 116 # get the number of client
 117 client_num=$(read_lock_file ".stf_unconfigure")
 118 
 119 Timeout=$((1800*$client_num))
 120 interval=$((5*$client_num))
 121 do_exec=0
 122 waited_time=0
 123 while (( $waited_time <= $Timeout )); do
 124         ref_exec=$(read_lock_file ".stf_execute")
 125         if [[ $ref_exec == 0 ]]; then
 126                 # write pid to lock file and occupy the lock.
 127                 RSH root $SERVER \
 128                         "echo ${CLIENT_S}_$$ > $Lock_Dir/.stf_execute; sync" \
 129                         > $STF_TMPDIR/rsh.out.$$ 2>&1
 130                 if (( $? != 0 )); then
 131                         echo "\n$Tname: failed to write lock file"
 132                         cat $STF_TMPDIR/rsh.out.$$
 133                         cleanup $STF_UNINITIATED
 134                 fi
 135 
 136                 # make sure to release the lock
 137                 # If there are mutiple clients, sleep for a while to let other
 138                 # clients get the lock and have a chance to be scheduled.
 139                 trap "RSH root $SERVER \"echo 0 > $Lock_Dir/.stf_execute\" && \
 140                         sync && [[ $client_num != 1 ]] && \
 141                         sleep $((interval+7))" \
 142                         0 1 2 15
 143 
 144                 # make sure that other clients do not overwrite the lock file
 145                 if (( $client_num != 1 )); then
 146                         sleep 3
 147                         ref_exec=$(read_lock_file ".stf_execute")
 148                         [[ $ref_exec != ${CLIENT_S}_$$ ]] && continue
 149                 fi
 150 
 151                 do_exec=1
 152                 break
 153         else
 154                 sleep $interval
 155                 waited_time=$((waited_time + $interval))
 156         fi
 157 done
 158 
 159 if (( $do_exec == 0 )); then
 160         echo "\n$TNAME: The case can not get the lock after sleep $Timeout secs"
 161         cleanup $STF_UNINITIATED
 162 fi
 163 
 164 share_check "$Shropt" "$NFSLOGDDIR"
 165 domount_check "$Mntopts" "$Shropt" "$NFSLOGDDIR"
 166 do_rw_test "tfile.$$"
 167 unmount_check
 168 
 169 echo "Verify write operations logged correctly in logfile ... \c"
 170 sleep 5
 171 SRVDEBUG=$SHAREMNT_DEBUG
 172 [[ :$SHAREMNT_DEBUG: == *:RSH:* ]] && SRVDEBUG=all
 173 RSH root $SERVER \
 174     "export SHAREMNT_DEBUG=$SRVDEBUG; \
 175     ksh $SRV_TMPDIR/test_nfslogd $Tname tfile.$$ $Tag 1 1 1 ${SHAREMNT_DEBUG}" \
 176     > $STF_TMPDIR/rsh.out.$$ 2>&1
 177 if (( $? != 0 )); then
 178     echo "\n$Tname: run $SRV_TMPDIR/test_nfslogd in $SERVER failed:"
 179     cat $STF_TMPDIR/rsh.out.$$
 180     cleanup $STF_FAIL
 181 else
 182         print_debug $STF_TMPDIR/rsh.out.$$
 183     echo "OK"
 184 fi
 185 
 186 echo "$Tname: testing complete - Result PASS"
 187 cleanup $STF_PASS