Home | History | Annotate | Download | only in sharemnt
      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 # ident	"@(#)configure.ksh	1.18	09/08/11 SMI"
     28 #
     29 
     30 DIR=$(dirname $0)
     31 NAME=$(basename $0)
     32 
     33 # Directory for tmp files
     34 STF_TMPDIR=${STF_TMPDIR:-$STF_CONFIG}
     35 STF_TMPDIR=$STF_TMPDIR/TMPDIR_$(date "+%Y-%m-%d-%H-%M-%S" | sed 's/-//g')
     36 mkdir -m 0777 -p $STF_TMPDIR
     37 
     38 . $STF_SUITE/include/sharemnt.kshlib
     39 . $STC_GENUTILS/include/libsmf.shlib
     40 . $STC_GENUTILS/include/nfs-tx.kshlib
     41 . $STC_GENUTILS/include/nfs-smf.kshlib
     42 
     43 # Turn on debug info, if requested
     44 export STC_GENUTILS_DEBUG=$STC_GENUTILS_DEBUG:$SHAREMNT_DEBUG
     45 [[ :$SHAREMNT_DEBUG: == *:${NAME}:* \
     46 	|| :${SHAREMNT_DEBUG}: == *:all:* ]] && set -x
     47 
     48 CLIENT=${CLIENT:-$(hostname)}
     49 clt_ip=$(getent ipnodes $CLIENT | head -1 | awk '{print $1}')
     50 srv_ip=$(getent ipnodes $SERVER | head -1 | awk '{print $1}')
     51 if [[ $clt_ip == $srv_ip ]]; then
     52 	echo "$NAME: SERVER<$SERVER> can't be set to \c"
     53 	echo "the same as localhost."
     54 	exit $STF_UNINITIATED
     55 fi
     56 
     57 SERVER_S=$(getent ipnodes $srv_ip | head -1 | awk '{print $NF}')
     58 if (( $? != 0 )); then
     59 	echo "$NAME: Can't get SERVER's name on $CLIENT"
     60 	exit $STF_UNINITIATED
     61 fi
     62 ping $SERVER_S > $STF_TMPDIR/ping.out.$$ 2>&1
     63 if (( $? != 0 )); then
     64 	echo "$NAME: SERVER<$SERVER_S> not responding to pings:"
     65 	cat $STF_TMPDIR/ping.out.$$
     66 	rm -f $STF_TMPDIR/ping.out.$$
     67 	exit $STF_UNINITIATED
     68 fi
     69 
     70 CLIENT_S=$(get_hostname_remote $clt_ip $SERVER_S)
     71 if (( $? != 0 )); then
     72 	echo "$NAME: Can't get CLIENT's name on $SERVER"
     73 	exit $STF_UNINITIATED
     74 fi
     75 
     76 TUID01=$(get_free_uid $SERVER)
     77 (( $? != 0 )) && echo "$NAME: Can't get a unused uid" && exit $STF_UNINITIATED
     78 TUSER01="SM"$TUID01 # SM is Share-Mount for short
     79 # Unique name for client used on server
     80 TCLIENT=$CLIENT_S"."$clt_ip
     81 
     82 function cleanup {	# cleanup and exit
     83 	[[ :$SHAREMNT_DEBUG: == *:${NAME}:* \
     84 		|| :${SHAREMNT_DEBUG}: == *:all:* ]] && set -x
     85 
     86 	rm -f $STF_TMPDIR/*.out.$$ $STF_TMPDIR/srv_setup
     87 	exit ${1}
     88 }
     89 
     90 configfile=$1
     91 export ZONE_PATH=${ZONE_PATH%%/}
     92 # Path for SERVER to test
     93 export BASEDIR=${ZONE_PATH}${NFSSHRDIR}
     94 export TESTDIR=${ZONE_PATH}${NFSSHRDIR}/$TCLIENT
     95 # Path for SERVER to share
     96 export SHRDIR=$TESTDIR/common
     97 # Path for sharetab to share
     98 export SHARETABDIR=$TESTDIR/sharetab
     99 # Path for nfslogd to share
    100 export NFSLOGDDIR=$TESTDIR/nfslogd
    101 # Path for stress test
    102 export STRESSDIR=$TESTDIR/stress
    103 # Path for localhost to mount
    104 export MNTDIR=$ZONE_PATH$NFSMNTDIR/common
    105 # Path for stress test to mount
    106 export STRESSMNT=$ZONE_PATH$NFSMNTDIR/stress
    107 # Path for others to share
    108 export OTHERDIR=$TESTDIR/others
    109 # Path for misc_opts to share
    110 export QUOTADIR=$TESTDIR/misc_opts_quota
    111 # Path for automount to mount
    112 export AUTOIND=$ZONE_PATH$AUTOIND
    113 export CLIENT=$CLIENT
    114 export CLIENT_S=$CLIENT_S
    115 export SERVER_S=$SERVER_S
    116 # Testing Group for SERVER to test
    117 export TESTGRP=${TESTGRP:-"shmnt_grp"}
    118 export TUID01=$TUID01
    119 export TUSER01=$TUSER01
    120 export STF_TMPDIR=$STF_TMPDIR
    121 export SRV_TMPDIR=/var/tmp/TMPDIR_shmnt_$TCLIENT # must be fixed dir
    122 
    123 # also write path variable to $configfile
    124 cat >> $configfile <<-EOF
    125 export ZONE_PATH=$ZONE_PATH
    126 export BASEDIR=$BASEDIR
    127 export TESTDIR=$TESTDIR
    128 export SHRDIR=$SHRDIR
    129 export NFSLOGDDIR=$NFSLOGDDIR
    130 export STRESSDIR=$STRESSDIR
    131 export MNTDIR=$MNTDIR
    132 export STRESSMNT=$STRESSMNT
    133 export AUTOIND=$AUTOIND
    134 export OTHERDIR=$OTHERDIR
    135 export QUOTADIR=$QUOTADIR
    136 export SHARETABDIR=$SHARETABDIR
    137 export CLIENT=$CLIENT
    138 export CLIENT_S=$CLIENT_S
    139 export SERVER_S=$SERVER_S
    140 export TESTGRP=$TESTGRP
    141 export TUID01=$TUID01
    142 export TUSER01=$TUSER01
    143 export STF_TMPDIR=$STF_TMPDIR
    144 export SRV_TMPDIR=$SRV_TMPDIR
    145 export STC_GENUTILS=$STC_GENUTILS
    146 EOF
    147 (( $? != 0 )) && echo "Could not write to $configfile file" && \
    148 	exit $STF_UNINITIATED
    149 
    150 #
    151 # create srv_config.vars
    152 #
    153 cat >> $STF_TMPDIR/srv_config.vars <<-EOF
    154 export PATH=/usr/sbin:/usr/bin:/usr/lib/nfs:$SRV_TMPDIR:$STC_GENUTILS/bin:\$PATH
    155 export STC_GENUTILS=$STC_GENUTILS
    156 export STF_TMPDIR=$SRV_TMPDIR
    157 export CLIENT_S=$CLIENT_S
    158 export BASEDIR=$BASEDIR
    159 export TESTDIR=$TESTDIR
    160 export SHRDIR=$SHRDIR
    161 export NFSLOGDDIR=$NFSLOGDDIR
    162 export SHARETABDIR=$SHARETABDIR
    163 export OTHERDIR=$OTHERDIR
    164 export QUOTADIR=$QUOTADIR
    165 export STRESSDIR=$STRESSDIR
    166 export TESTGRP=$TESTGRP
    167 export TUID01=$TUID01
    168 export TUSER01=$TUSER01
    169 export TUSER_UTAG=$TUSER_UTAG
    170 export SRV_FMRI="svc:/network/nfs/server:default"
    171 export LCK_FMRI="svc:/network/nfs/nlockmgr:default"
    172 export STAT_FMRI="svc:/network/nfs/status:default"
    173 export QUOTA_FMRI="svc:/network/nfs/rquota:default"
    174 export SMF_TIMEOUT=60
    175 export SHARETAB="/etc/dfs/sharetab"
    176 export MISCSHARE=$SRV_TMPDIR/miscshare
    177 EOF
    178 
    179 #
    180 # Now setup the server..
    181 #
    182 # Check TX related info
    183 check_for_cipso "$TESTDIR" "$MNTDIR" "$MNTOPT" || return $STF_UNSUPPORTED
    184 
    185 #
    186 # create SRV_TMPDIR on server
    187 #
    188 RSH root $SERVER \
    189 	"rm -rf $SRV_TMPDIR; \
    190 	 mkdir -pm 0777 $SRV_TMPDIR"
    191 	> $STF_TMPDIR/rsh.out.$$ 2>&1
    192 if (( $? != 0 )); then
    193 	echo "$NAME: failed to create <$SRV_TMPDIR> on $SERVER:"
    194 	cat $STF_TMPDIR/rsh.out.$$
    195 	cleanup $STF_UNINITIATED
    196 fi
    197 
    198 
    199 #
    200 # add environment variables to srv_setup script and
    201 # create a new script called srv_setup which will be copied over to
    202 # the server:
    203 #
    204 sed -e "s%STF_TMPDIR_from_client%${SRV_TMPDIR}%" \
    205 	-e "s%SHAREMNT_DEBUG_from_client%${SHAREMNT_DEBUG}%" \
    206 	$DIR/srv_setup.ksh > ${STF_TMPDIR}/srv_setup \
    207 	2> $STF_TMPDIR/sed.out.$$
    208 if (( $? != 0 )); then
    209 	echo "$NAME: failed to create [srv_setup] file."
    210 	cat $STF_TMPDIR/sed.out.$$
    211 	echo "PATH is $PATH"
    212 	cleanup $STF_UNINITIATED
    213 fi
    214 
    215 # setup miscshare on server
    216 sed -e "s%STF_TMPDIR_from_client%${SRV_TMPDIR}%" \
    217 	-e "s%SHAREMNT_DEBUG_from_client%${SHAREMNT_DEBUG}%" \
    218 	$STF_SUITE/bin/miscshare > $STF_TMPDIR/miscshare \
    219 	2> $STF_TMPDIR/sed.out.$$
    220 if (( $? != 0 )); then
    221 	echo "$NAME: failed to create [miscshare] file."
    222 	cat $STF_TMPDIR/sed.out.$$
    223 	echo "PATH is $PATH"
    224 	cleanup $STF_UNINITIATED
    225 fi
    226 chmod 0555 $STF_TMPDIR/miscshare
    227 
    228 # remove stf.kshlib from sharemnt.kshlib as it is not necessary on server
    229 sed '/stf.kshlib/d' $STF_SUITE/include/sharemnt.kshlib > \
    230 	$STF_TMPDIR/sharemnt.kshlib 2> $STF_TMPDIR/sed.out.$$
    231 if (( $? != 0 )); then
    232 	echo "$NAME: failed to create [sharemnt.kshlib] file."
    233 	cat $STF_TMPDIR/sed.out.$$
    234 	echo "PATH is $PATH"
    235 	cleanup $STF_UNINITIATED
    236 fi
    237 
    238 if RSH root $SERVER "[[ ! -s $STC_GENUTILS/include/nfs-util.kshlib ]]"; then
    239 	server_files="\
    240 		$STC_GENUTILS/bin/stc_genutils \
    241 		$STC_GENUTILS/include/nfs-util.kshlib \
    242 		$STC_GENUTILS/include/nfs-smf.kshlib \
    243 		$STC_GENUTILS/include/libsmf.shlib"
    244 fi
    245 server_files="$server_files \
    246 	$STF_TMPDIR/sharemnt.kshlib \
    247 	$STF_TMPDIR/srv_config.vars \
    248 	$STF_TMPDIR/srv_setup \
    249 	$STF_TMPDIR/miscshare"
    250 rcp -p $server_files $SERVER:$SRV_TMPDIR > $STF_TMPDIR/rcp.out.$$ 2>&1
    251 if (( $? != 0 )); then
    252 	echo "$NAME: failed to copy <$server_files> to $SERVER:"
    253 	cat $SRV_TMPDIR/rcp.out.$$
    254 	cleanup $STF_FAIL
    255 fi
    256 
    257 # ..finally execute the script on the server.
    258 SRVDEBUG=$STC_GENUTILS_DEBUG:$SHAREMNT_DEBUG
    259 [[ :$SRVDEBUG: == *:RSH:* ]] && SRVDEBUG=all
    260 RSH root $SERVER \
    261 	"export SHAREMNT_DEBUG=$SRVDEBUG; \
    262 	 F=$SRV_TMPDIR/srv_setup; \
    263 	 chmod 0555 \$F && \$F -s" \
    264 	> $STF_TMPDIR/rsh.out.$$ 2> $STF_TMPDIR/rsh.err.$$
    265 rc=$?
    266 print_debug $STF_TMPDIR/rsh.err.$$
    267 grep "Done" $STF_TMPDIR/rsh.out.$$ > /dev/null 2>&1
    268 if (( $? != 0 || $rc != 0 )); then
    269 	echo "$NAME: run $SRV_TMPDIR/srv_setup in $SERVER failed:"
    270 	cat $STF_TMPDIR/rsh.out.$$
    271 	cat $STF_TMPDIR/rsh.err.$$
    272 	cleanup $STF_FAIL
    273 fi
    274 
    275 fs_info=$(egrep '^SRV_FS=' $STF_TMPDIR/rsh.out.$$ | awk -F= '{print $2}')
    276 fs_type=$(echo $fs_info | awk '{print $1}')
    277 if [[ $fs_type == zfs ]]; then
    278 	ZFSPOOL=$(echo $fs_info | awk '{print $2}')
    279 	echo "ZFSPOOL=$ZFSPOOL; export ZFSPOOL" >> $configfile
    280 fi
    281 
    282 # Now setup the client
    283 
    284 # set NFSMAPID_DOMAIN
    285 NFSMAPID_DOMAIN=$(egrep '^SRV_NFSMAPID_DOMAIN=' $STF_TMPDIR/rsh.out.$$ \
    286 					| awk -F= '{print $2}')
    287 set_nfs_property nfsmapid_domain $NFSMAPID_DOMAIN $1 \
    288 	>$STF_TMPDIR/mapid.out.$$ 2>&1
    289 if (( $? != 0 )); then
    290 	echo "$NAME: failed to set nfsmapid_domain"
    291 	cat $STF_TMPDIR/mapid.out.$$
    292 	cleanup $STF_FAIL
    293 fi
    294 print_debug $STF_TMPDIR/mapid.out.$$
    295 
    296 #
    297 # We set the auto_enable property of all the NFS services to "false" to
    298 # ensure that they are not silenty re-enabled after we have disabled
    299 # them.
    300 #
    301 # Note svc:/network/nfs/client does not have an auto_enable property.
    302 #
    303 set_fmri_svcprop $STF_CONFIG/svc_prop.orig $SERVICES
    304 if (( $? != 0 )); then
    305 	echo "$NAME: failed to set auto_enable property for <$SERVICES>"
    306 	cleanup $STF_UNINITIATED
    307 fi
    308 
    309 #
    310 # Mount the NFS directory with specified options
    311 #
    312 [[ ! -d $MNTDIR ]] && mkdir -pm 0777 $MNTDIR > /dev/null 2>&1
    313 umount -f $MNTDIR > /dev/null 2>&1
    314 mount -o ${MNTOPT} ${SERVER}:${SHRDIR} $MNTDIR > $STF_TMPDIR/mnt.out.$$ 2>&1
    315 if (( $? != 0 )); then
    316 	echo "$NAME: client<$CLIENT> failed to mount ${SERVER}:${SHRDIR}."
    317 	cat $STF_TMPDIR/mnt.out.$$
    318 	cleanup $STF_FAIL
    319 fi
    320 
    321 # Ensure that we do not start the tests until the server is responding
    322 # properly (i.e. is not in grace etc)
    323 #
    324 echo "This is a rofile for sharemnt Testing" > $MNTDIR/rofile 2>&1
    325 if (( $? != 0 )); then
    326 	echo "$NAME: client<$CLIENT> failed to create <$MNTDIR/rofile> file"
    327 	cat $MNTDIR/rofile
    328 	cleanup $STF_UNRESOLVED
    329 fi
    330 chmod 444 $MNTDIR/rofile
    331 
    332 # Prepare client's automount maps as well
    333 #
    334 if [[ ! -f $STF_CONFIG/auto_master.shmnt.orig ]]; then
    335 	cp -p /etc/auto_master $STF_CONFIG/auto_master.shmnt.orig \
    336 		2> $STF_TMPDIR/cp.out.$$
    337 	if (( $? != 0 )); then
    338 		echo "$NAME: client<$CLIENT> failed to save auto_master file"
    339 		cat $STF_TMPDIR/cp.out.$$
    340 		cleanup $STF_UNRESOLVED
    341 	fi
    342 fi
    343 egrep -v "shmnt|sharemnt" $STF_CONFIG/auto_master.shmnt.orig > /etc/auto_master
    344 echo "##\n# Added for testing sharemnt tests\n#" >> /etc/auto_master
    345 echo "/- $STF_TMPDIR/auto_direct.shmnt" >> /etc/auto_master
    346 echo "$AUTOIND $STF_TMPDIR/auto_indirect.shmnt" >> /etc/auto_master
    347 echo "# this file is used for direct auto-map of sharemnt tests" \
    348 	> $STF_TMPDIR/auto_direct.shmnt
    349 echo "# this file is used for indirect auto-map of sharemnt tests" \
    350 	> $STF_TMPDIR/auto_indirect.shmnt
    351 
    352 smf_fmri_transition_state "do" $AUTO_FMRI "restart" 60 \
    353 	> $STF_TMPDIR/smf.out.$$ 2>&1
    354 if (( $? != 0 )); then
    355 	echo "$NAME: client<$CLIENT> failed to restart autofs service"
    356 	cat $STF_TMPDIR/smf.out.$$
    357 	cleanup $STF_FAIL
    358 fi
    359 print_debug $STF_TMPDIR/smf.out.$$
    360 
    361 # create test user
    362 useradd -u $TUID01 -c $TUSER_UTAG -d /tmp $TUSER01 \
    363 	>$STF_TMPDIR/useradd.out.$$ 2>&1
    364 ckresult $? "$NAME: failed to add $TUSER01" $STF_TMPDIR/useradd.out.$$ \
    365 	|| cleanup $STF_FAIL
    366 
    367 # verify the RDMA connection if TESTRDMA=yes
    368 echo $TESTRDMA | grep -i no > /dev/null 2>&1
    369 if (( $? != 0 )); then
    370 	# user wants to test NFS/RDMA
    371 	nfsstat -m $MNTDIR > $STF_TMPDIR/nstat.out.$$ 2>&1
    372 	grep 'Flags:' $STF_TMPDIR/nstat.out.$$ | grep 'proto=rdma' > /dev/null 2>&1
    373 	if (( $? != 0 )); then
    374 		echo "$NAME: WARNING:"
    375 		echo "\t TESTRDMA=<$TESTRDMA>, but client didn't mount <proto=rdma>"
    376 		echo "\t nfsstat -m $MNTDIR got:"
    377 		cat $STF_TMPDIR/nstat.out.$$
    378 		echo "\t No <proto=rdma> will be generated and run."
    379 		echo "export TESTRDMA=no" >> $configfile
    380 	else
    381 		echo "export TESTRDMA=yes" >> $configfile
    382 	fi
    383 fi
    384 
    385 cleanup $STF_PASS
    386