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 DIR=$(dirname $0)
  29 NAME=$(basename $0)
  30 configfile=$1
  31 #ZONE_PATH=${ZONE_PATH%%/}
  32 #STRESSDIR=${ZONE_PATH}${NFSSHRDIR}/stress
  33 #STRESSMNT=${ZONE_PATH}${NFSMNTDIR}/stress
  34 
  35 . $STF_SUITE/include/sharemnt.kshlib
  36 
  37 function cleanup {              # cleanup and exit
  38         [[ :$SHAREMNT_DEBUG: = *:${NAME}:* \
  39                 || :${SHAREMNT_DEBUG}: == *:all:* ]] && set -x
  40 
  41         rm -f $STF_TMPDIR/*.out.$$ $STF_TMPDIR/sharemnt.stress
  42         exit ${1}
  43 }
  44 
  45 # Turn on debug info, if requested
  46 export STC_GENUTILS_DEBUG=$STC_GENUTILS_DEBUG:$SHAREMNT_DEBUG
  47 [[ :$SHAREMNT_DEBUG: == *:$NAME:* \
  48         || :$SHAREMNT_DEBUG: == *:all:* ]] && set -x
  49 
  50 client_num=$(get_clients_num)
  51 if (( $? != 0 )); then
  52         echo "\n$NAME: RSH failed, $client_num"
  53         exit $STF_UNRESOLVED
  54 elif (( $client_num != 1 )); then
  55         echo "\n$NAME: multiple srv_shmnt files were found on the server."
  56         echo "\tthe stress tests don't support multiple clients\n"
  57         exit $STF_UNTESTED
  58 fi
  59 
  60 if [[ -z "$STRESS_TIMEOUT" ]]; then
  61         if (( $NUM_SHARES <= 2000 && \
  62                 $((NUM_GROUPS * NUM_ENTRYS)) <= 1000 )); then
  63                 let STRESS_TIMEOUT=60*60
  64         else
  65                 let STRESS_TIMEOUT=2*60*60
  66         fi
  67 fi
  68 
  69 #
  70 # Now setup the server..
  71 #
  72 # Firstly add environment variables to srv_setup script and
  73 # create a new script called server.stress which will be copied over to
  74 # the server:
  75 sed -e "s%STF_TMPDIR_from_client%${SRV_TMPDIR}%" \
  76         -e "s%STRESS_TIMEOUT_from_client%${STRESS_TIMEOUT}%" \
  77         -e "s%NUM_SHARES_from_client%${NUM_SHARES}%" \
  78         -e "s%NUM_GROUPS_from_client%${NUM_GROUPS}%" \
  79         -e "s%NUM_ENTRYS_from_client%${NUM_ENTRYS}%" \
  80         -e "s%SHAREMNT_DEBUG_from_client%${SHAREMNT_DEBUG}%" \
  81         $DIR/srv_setup > ${STF_TMPDIR}/sharemnt.stress \
  82         2> $STF_TMPDIR/sed.out.$$
  83 if (( $? != 0 )); then
  84         echo "$NAME: failed to create [sharemnt.stress] file."
  85         cat $STF_TMPDIR/sed.out.$$
  86         echo "PATH is $PATH"
  87         cleanup $STF_UNINITIATED
  88 fi
  89 
  90 #
  91 # copy srv_setup to server, which is called to do setup/cleanup.
  92 scp $STF_TMPDIR/sharemnt.stress root@$SERVER:$SRV_TMPDIR/sharemnt.stress \
  93         > $STF_TMPDIR/scp.out.$$ 2>&1
  94 if (( $? != 0 )); then
  95         echo "$NAME: failed to copy <srv_setup> to $SERVER:"
  96         cat $STF_TMPDIR/scp.out.$$
  97         cleanup $STF_FAIL
  98 fi
  99 
 100 # ..finally execute the script on the server.
 101 SRVDEBUG=$STC_GENUTILS_DEBUG:$SHAREMNT_DEBUG
 102 [[ :$SRVDEBUG: == *:RSH:* ]] && SRVDEBUG=all
 103 RSH root $SERVER \
 104         "export SHAREMNT_DEBUG=$SRVDEBUG; \
 105          F=$SRV_TMPDIR/sharemnt.stress; \
 106          chmod 0555 \$F && \$F -s" \
 107         > $STF_TMPDIR/rsh.out.$$ 2>&1
 108 rc=$?
 109 print_debug $STF_TMPDIR/rsh.out.$$
 110 grep "Done" $STF_TMPDIR/rsh.out.$$ > /dev/null 2>&1
 111 if [[ $? != 0 || $rc != 0 ]]; then
 112         echo "$NAME: run $SRV_TMPDIR/sharemnt.stress in $SERVER failed:"
 113         cat $STF_TMPDIR/rsh.out.$$
 114         cleanup $STF_FAIL
 115 fi
 116 
 117 # create some dirs as mount point in client.
 118 i=0
 119 while (( $i <= $NUM_SHARES )); do
 120         mkdir -p $STRESSMNT/mntdir_${i}_stress
 121         i=$((i+1))
 122 done
 123 
 124 # the stress test might need to increase STF_TIMEOUT
 125 # set STF_TIMEOUT and STRESS_TIMEOUT to stf configuration file
 126 let STF_TIMEOUT=${STRESS_TIMEOUT}*4
 127 echo "export STF_TIMEOUT=$STF_TIMEOUT" > $configfile
 128 echo "export STRESS_TIMEOUT=$STRESS_TIMEOUT" >> $configfile
 129 
 130 cleanup $STF_PASS