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