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 2008 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 #
29 # This test creates a big number of files on a directory X in the server.
30 # Then spawns a process that kills and restarts nfsmapid on the client.
31 # and creates a number of processes that do "ls -l" on test directory
32 # over nfs Simultaneously.
33 #
34
35 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
36
37 NAME=${0##*/}
38 CDIR=`pwd`
39
40 id | grep "0(root)" > /dev/null 2>&1
41 if [ $? -ne 0 ]; then
42 echo "$NAME{init}: Initialization"
43 echo "\t Test UNINITIATED: must be root to run testcase"
44 exit $UNINITIATED
45 fi
46
47 # Default of 1K iterations and 600 files and 10 processes
48 STRESS_LOOP=${1:-1000}
49 NUM_FILES=${2:-600}
50 NUM_PROC=${3:-10}
51
52 UIDMAPENV="./uid_proc"
53 UNINITIATED=6
54
55 # set up script running environment
56 if [ ! -f $UIDMAPENV ]; then
57 echo "$NAME: UIDMAPENV[$UIDMAPENV] not found; test UNINITIATED."
58 exit $UNINITIATED
59 fi
60 . $UIDMAPENV
61
62 # Also include common STC utility functions for SMF/Greenline
63 . $TESTROOT/libsmf.shlib
64
65 # This is the test directory for the files to be created/stat
66 MYTESTDIR="$MNTPTR/$NAME"
67
68 function cleanup
69 {
70 [ "$DEBUG" != "0" ] && set -x
71 (( $# >= 1 )) && ret=$1
72
73 # stop all child processes
74 n=0
75 while (( n < NUM_PROC ))
76 do
77 p="0${APIDs[$n]}"
78 (( p > 1 )) && kill ${APIDs[$n]} > /dev/null 2>&1
79 (( n = n + 1 ))
80 done
81
82 # remove compiled program
83 execute $SERVER root "cd $TMPDIR; rm -f create_mapid_files*" \
84 > /dev/null 2>&1
85
86 # remove test directory and tmp files
87 rm -rf $MYTESTDIR $TMPDIR/$NAME.*.$$ > /dev/null 2>&1
88
89 exit $ret
90 }
91
92
93 # Start main program here:
94 # ---------------------------------------------------------------------------
95 echo "$NAME{1}: looping ls tests in $MYTESTDIR,"
96 echo "\t while nfsmapid is being killed/restarted\n"
97 echo "\t START TIME: `date`\n"
98
99 # use the suite mounted directory to create the testdir
100 if [[ ! -d "$MYTESTDIR" ]]; then
101 mkdir -m 777 $MYTESTDIR> $TMPDIR/$NAME.mkdir.$$ 2>&1
102 if (( $? != 0 )); then
103 echo "\t Test UNINITIATED: cannot create test dir $MYTESTDIR"
104 cat $TMPDIR/$NAME.mkdir.$$
105 exit $UNINITIATED
106 fi
107 fi
108
109 # copy C program to server
110 rcp -p $CDIR/create_mapid_files.c $SERVER:$TMPDIR > $TMPDIR/$NAME.rcp.$$ 2>&1
111 if (( $? != 0 )); then
112 echo "\t Test UNINITIATED: cannot copy files to $SERVER:$TMPDIR"
113 echo "\tres = "
114 cat $TMPDIR/$NAME.rcp.$$
115 cleanup $UNINITIATED
116 fi
117
118 # compile the files creation program on the server
119 CS=$CC_SRV
120 cmd="cd $TMPDIR; $CS create_mapid_files.c -o create_mapid_files"
121 sh -c "$cmd"
122 scp $TMPDIR/create_mapid_files root@$SERVER:$TMPDIR > $TMPDIR/$NAME.rshcs.$$ 2>&1
123 if (( $? != 0 )); then
124 echo "\t Test UNINITIATED: \c"
125 echo "cannot scp to $SERVER:$TMPDIR/create_mapid_files"
126 echo "\tres = "
127 cat $TMPDIR/$NAME.rshcs.$$
128 cleanup $UNINITIATED
129 fi
130
131 cmd="cd $BASEDIR/$NAME; $TMPDIR/create_mapid_files -n $NUM_FILES"
132 [[ "$DEBUG" != "0" ]] && cmd="$cmd -d 1"
133 execute $SERVER root "$cmd" > $TMPDIR/$NAME.rshrun.$$ 2>&1
134 if [ "$?" != "0" ]; then
135 echo "\t Test UNINITIATED: \c"
136 echo "create_mapid_files cannot create files in"
137 echo "\t$SERVER:$BASEDIR/$NAME."
138 echo "\tres = "
139 cat $TMPDIR/$NAME.rshrun.$$
140 cleanup $UNINITIATED
141 fi
142
143 # name of the nfsmapid service
144 nfs_mapid="svc:/network/nfs/mapid:default"
145
146 # process to restart mapid service repeatedly on the background
147 (
148 logfile=$TMPDIR/$NAME.daemon_out.$$
149 exitfile=$TMPDIR/$NAME.daemon_exit.$$
150
151 while :
152 do
153 smf_fmri_transition_state do $nfs_mapid disabled 10 > $logfile
154 ckreturn $? "failed to disable mapid service" $logfile WARNING
155 sleep 6
156 smf_fmri_transition_state do $nfs_mapid online 10 > $logfile
157 ckreturn $? "failed to enable mapid service" $logfile WARNING
158 sleep 6
159 # if the file below is created, exit
160 if [[ -f $exitfile ]]; then
161 break
162 fi
163 done
164 rm -f $logfile $exitfile
165 )&
166 deamonMgmt_pid=$!
167
168 cd $MYTESTDIR
169
170 # Start the processes
171 n=0
172 while (( n < NUM_PROC ))
173 do
174 (
175 # repeat many ls -l over nfs
176 i=0
177 while (( i < STRESS_LOOP ))
178 do
179 echo "Process ${n} Loop ${i}"
180 ls -lR > $TMPDIR/$NAME.$n.out.$$ 2> $TMPDIR/$NAME.$n.err.$$
181 if [ $? -ne 0 ]; then
182 echo "ERROR: Could not ls -lR $MYTESTDIR, i=$i"
183 nlines=10
184 echo "\tlast $nlines lines printed were"
185 tail -$nlines $TMPDIR/$NAME.$n.out.$$
186 echo "\tstderr was"
187 cat $TMPDIR/$NAME.$n.err.$$
188 rm -f $TMPDIR/$NAME.$n.*.$$
189 else
190 rm -f $TMPDIR/$NAME.$n.*.$$
191 fi
192
193 (( i = i + 1 ))
194 done
195 ) > $TMPDIR/$NAME.$n.$$ 2>&1 &
196 APIDs[$n]=$!
197 (( n = n + 1 ))
198 done
199
200 cd $CDIR
201
202 # wait for all processes to be done, and check and print logs on errors
203 n=0
204 e=0
205 while (( n < NUM_PROC ))
206 do
207 wait ${APIDs[$n]}
208 grep ERROR $TMPDIR/$NAME.$n.$$ 2>&1 > /dev/null
209 if [ $? -eq 0 ]; then
210 cat $TMPDIR/$NAME.$n.$$
211 e=1
212 fi
213 rm -f $TMPDIR/$NAME.$n.$$
214 (( n = n + 1 ))
215 done
216 (( e != 0)) && echo "\t Test FAIL: error found from some process(es)"
217
218 touch $TMPDIR/$NAME.daemon_exit.$$
219 wait $deamonMgmt_pid
220
221 echo "\t Test PASS: test run completed successfully"
222 echo "\t END TIME: `date`\n"
223
224 cleanup $PASS