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 # Setup the SERVER for testing sharetab.
29
30 NAME=$(basename $0)
31
32 Usage="Usage: $NAME -s | -c | -i | -a | -m | -r phase\n
33 -s: setup this host for sharetab test\n
34 -c: cleanup\n
35 -i: initial check\n
36 -a: access test\n
37 -m: mountd test\n
38 -r: reboot test\n
39 phase: 1. prepare the file; 2. compare the files\n
40 "
41 # -z: zfs test\n
42 # -u: zfs unshare test\n
43 if (( $# < 1 )); then
44 echo $Usage
45 exit 99
46 fi
47
48 # variables gotten from client system:
49 STF_TMPDIR=STF_TMPDIR_from_client
50 SHAREMNT_DEBUG=${SHAREMNT_DEBUG:-"SHAREMNT_DEBUG_from_client"}
51
52 . $STF_TMPDIR/srv_config.vars
53
54 # Include common STC utility functions for SMF
55 if [[ -s $STC_GENUTILS/include/libsmf.shlib ]]; then
56 . $STC_GENUTILS/include/libsmf.shlib
57 . $STC_GENUTILS/include/nfs-smf.kshlib
58 else
59 . $STF_TMPDIR/libsmf.shlib
60 . $STF_TMPDIR/nfs-smf.kshlib
61 fi
62 . $STF_TMPDIR/sharemnt.kshlib
63
64 # Turn on debug info, if requested
65 export STC_GENUTILS_DEBUG=$SHAREMNT_DEBUG
66 [[ :$SHAREMNT_DEBUG: == *:$NAME:* \
67 || :$SHAREMNT_DEBUG: == *:all:* ]] && set -x
68
69 # share is not supported in non-global zone
70 ck_zone "This test is not supported since share cannot run in non-global zone."
71
72 typeset var1 var2
73
74 # cleanup function on all exit
75 function cleanup {
76 [[ :$SHAREMNT_DEBUG: == *:$NAME:* \
77 || :$SHAREMNT_DEBUG: == *:all:* ]] && set -x
78
79 #zfs unallow bin share,sharenfs $SHARETABDIR >/dev/null 2>&1
80 rm -fr $STF_TMPDIR/$NAME.*.$$
81 exit $1
82 }
83
84 # Timeout (in seconds) for SMF commands to complete
85 SMF_TIMEOUT=60
86
87 getopts sciamr: opt
88 case $opt in
89 s)
90 if [[ ! -d $SHARETABDIR ]]; then
91 mkdir -pm 0777 $SHARETABDIR
92 [[ $? != 0 ]] && \
93 echo "could not create $SHARETABDIR" && exit 1
94 fi
95
96 rm -rf $SHARETABDIR/dir?
97 mkdir -m 0777 $SHARETABDIR/dir1 > /dev/null 2>&1
98 mkdir -m 0777 $SHARETABDIR/dir2 > /dev/null 2>&1
99 mkdir -m 0777 $SHARETABDIR/dir3 > /dev/null 2>&1
100 [[ ! -w $SHARETABDIR/dir1 || ! -w $SHARETABDIR/dir2 || ! -w $SHARETABDIR/dir3 ]] && \
101 echo "can not create dir1/dir2/dir3 under $SHARETABDIR" && \
102 cleanup 1
103
104 # set up ZFS
105 if [[ -n $ZFSPOOL ]]; then
106 create_zfs_fs $ZFSBASE $SHARETABDIR/dir1 > $STF_TMPDIR/$NAME.zfs.$$ 2>&1
107 if [[ $? != 0 ]]; then
108 echo "$NAME: failed to create_zfs_fs $SHARETABDIR/dir1"
109 cat $STF_TMPDIR/$NAME.zfs.$$
110 cleanup 99
111 fi
112 print_debug $STF_TMPDIR/$NAME.zfs.$$
113
114 create_zfs_fs $ZFSBASE $SHARETABDIR/dir2 > $STF_TMPDIR/$NAME.zfs.$$ 2>&1
115 if [[ $? != 0 ]]; then
116 echo "$NAME: failed to create_zfs_fs $SHARETABDIR/dir2"
117 cat $STF_TMPDIR/$NAME.zfs.$$
118 cleanup 99
119 fi
120 print_debug $STF_TMPDIR/$NAME.zfs.$$
121 fi
122 echo "$SHARETABDIR/dir1 share -F nfs -o rw $SHARETABDIR/dir1" \
123 > $STF_TMPDIR/$NAME.cn.$$
124 echo "$SHARETABDIR/dir2 share -F nfs -o rw $SHARETABDIR/dir2" \
125 >> $STF_TMPDIR/$NAME.cn.$$
126 nfs_smf_setup "file" $STF_TMPDIR/$NAME.cn.$$ $SMF_TIMEOUT \
127 > $STF_TMPDIR/$NAME.shr.$$ 2>&1
128 if [[ $? != 0 ]]; then
129 echo "\n$NAME: failed to share path"
130 cat $STF_TMPDIR/$NAME.shr.$$
131 cleanup 1
132 fi
133 print_debug $STF_TMPDIR/$NAME.shr.$$
134 sleep 5
135
136 echo "Done - sharetab setup PASS"
137 ;;
138 c)
139 echo "$SHARETABDIR/dir1" > $STF_TMPDIR/$NAME.cn.$$
140 echo "$SHARETABDIR/dir2" >> $STF_TMPDIR/$NAME.cn.$$
141 nfs_smf_clean $STF_TMPDIR/$NAME.cn.$$ $SMF_TIMEOUT
142 unshare $SHARETABDIR/dir3 > /dev/null 2>&1
143 sleep 5
144
145 if [[ -n $ZFSPOOL ]]; then
146 typeset Zfs=""
147 for Zfs in $(zfs list | grep "$SHARETABDIR" | awk '{print $1}'); do
148 zfs destroy -f $Zfs > $STF_TMPDIR/$NAME.cleanFS.$$ 2>&1
149 if (( $? != 0 )); then
150 echo "WARNING: unable to cleanup [$Zfs];"
151 cat $STF_TMPDIR/$NAME.cleanFS.$$
152 echo "\t Please clean it up manually."
153 cleanup 2
154 fi
155 done
156 fi
157
158 rm -rf $STF_TMPDIR/sharemnt.shtab $SHARETABDIR
159 echo "Done - sharetab cleanup PASS"
160 ;;
161 i)
162 # fs check
163 rval=$(df -F sharefs 2> $STF_TMPDIR/$NAME.df.$$)
164 if [[ $? != 0 ]]; then
165 echo "\n$NAME: failed to get the status of sharefs"
166 cat $STF_TMPDIR/$NAME.df.$$
167 cleanup 2
168 fi
169
170 # mount point check
171 rval=$(echo $rval | awk '{print $1}')
172 if [[ $rval != $SHARETAB ]]; then
173 echo "\n$NAME: the mount point <$rval> is not expected <$SHARETAB>"
174 cleanup 2
175 fi
176
177 # SHARETAB check
178 [[ ! -f $SHARETAB ]] && \
179 echo "\n$NAME: test failed for $SHARETAB does not exist" && \
180 cleanup 2
181
182 rm -f $SHARETAB
183 [[ ! -f $SHARETAB ]] && \
184 echo "\n$NAME: test failed for $SHARETAB can be removed." && \
185 cleanup 2
186
187 # umount check
188 # non-empty SHARETAB can not be umounted
189 umount $SHARETAB > $STF_TMPDIR/$NAME.mnt.$$ 2>&1
190 rval=$(df -F sharefs | awk '{print $1}')
191 if [[ $rval != $SHARETAB ]]; then
192 echo "\n$NAME: test failed for <$SHARETAB> is umounted."
193 cat $STF_TMPDIR/$NAME.mnt.$$
194 cleanup 2
195 fi
196 unshareall > $STF_TMPDIR/$NAME.unshare.$$ 2>&1
197 if [[ $? != 0 ]]; then
198 echo "\n$NAME: failed to unshareall"
199 cat $STF_TMPDIR/$NAME.unshare.$$
200 cleanup 2
201 fi
202 if [[ -s $SHARETAB ]]; then
203 echo "\n$NAME: test failed for $SHARETAB is not empty."
204 echo "\tafter unsharell:"
205 cat $SHARETAB
206 cleanup 2
207 fi
208 # empty SHARETAB can be umounted
209 umount $SHARETAB > $STF_TMPDIR/$NAME.mnt.$$ 2>&1
210 rval=$(df -F sharefs)
211 if [[ -n $rval ]]; then
212 echo "\n$NAME: test failed for <$SHARETAB> is still mounted."
213 echo "\t$rval"
214 cat $STF_TMPDIR/$NAME.mnt.$$
215 cleanup 2
216 fi
217 sharemgr add-share -s $SHARETABDIR/dir3 default > $STF_TMPDIR/$NAME.shr.$$ 2>&1
218 if [[ $? != 0 ]]; then
219 echo "\n$NAME: failed to add-share $SHARETABDIR/dir3."
220 cat $STF_TMPDIR/$NAME.shr.$$
221 cleanup 2
222 fi
223 rval=$(share)
224 if [[ -n $rval ]]; then
225 echo "\n$NAME: test failed for non-empty output of share."
226 echo "\t$rval"
227 cleanup 2
228 fi
229 sharemgr show default | tr -d ' ' | \
230 grep -ws $SHARETABDIR/dir3 > /dev/null
231 if [[ $? != 0 ]]; then
232 echo "\n$NAME: sharemgr failed to find $SHARETABDIR/dir3."
233 cleanup 2
234 fi
235 # get it back
236 mount -F sharefs sharefs $SHARETAB > $STF_TMPDIR/$NAME.mnt.$$ 2>&1
237 if [[ $? != 0 ]]; then
238 echo "\n$NAME: failed to mount $SHARETAB back."
239 cat $STF_TMPDIR/$NAME.mnt.$$
240 cleanup 2
241 fi
242 grep -ws $SHARETABDIR/dir3 $SHARETAB > /dev/null
243 if [[ $? != 0 ]]; then
244 echo "\n$NAME: failed to find $SHARETABDIR/dir3 in $SHARETAB."
245 cleanup 2
246 fi
247 shareall > $STF_TMPDIR/$NAME.shr.$$ 2>&1
248 if [[ $? != 0 ]]; then
249 echo "\n$NAME: failed to shareall"
250 cat $STF_TMPDIR/$NAME.shr.$$
251 cleanup 2
252 fi
253 for i in 1 2 3; do
254 grep -ws $SHARETABDIR/dir$i $SHARETAB
255 if [[ $? != 0 ]]; then
256 echo "\n$NAME: failed to find $SHARETABDIR/dir$i in $SHARETAB."
257 cleanup 2
258 fi
259 done
260 sharemgr remove-share -s $SHARETABDIR/dir3 default \
261 > $STF_TMPDIR/$NAME.shr.$$ 2>&1
262 if [[ $? != 0 ]]; then
263 echo "\n$NAME: failed to remove-share $SHARETABDIR/dir3."
264 cat $STF_TMPDIR/$NAME.shr.$$
265 cleanup 2
266 fi
267
268 # readonly check
269 var1=$(/usr/bin/sum $SHARETAB)
270 echo readonly >> $SHARETAB 2>/dev/null
271 var2=$(/usr/bin/sum $SHARETAB)
272 if [[ $var1 != $var2 || $? != 0 ]]; then
273 echo "\n$NAME: test failed for $SHARETAB is changed"
274 cat $SHARETAB
275 cleanup 1
276 fi
277
278 # chmod check
279 chmod -f 777 $SHARETAB
280 var1=$(ls -l $SHARETAB | awk '{print $1}')
281 if [[ $var1 != "-r--r--r--" || $? != 0 ]]; then
282 echo "\n$NAME: test failed for the permissions mode"
283 echo "\t of $SHARETAB is wrong"
284 ls -l $SHARETAB
285 cleanup 1
286 fi
287
288 # acl check
289 var1=$(ls -v $SHARETAB | /usr/bin/sum)
290 if [[ -n $ZFSBASE ]]; then
291 chmod A+user:root:write_data:allow $SHARETAB >/dev/null 2>&1
292 else
293 chmod A+user:root:rw- $SHARETAB >/dev/null 2>&1
294 fi
295 rc=$?
296 var2=$(ls -v $SHARETAB | /usr/bin/sum)
297 if [[ $var1 != $var2 || $rc == 0 ]]; then
298 echo "\n$NAME: test failed for the ACL mode of"
299 echo "\t $SHARETAB is changed"
300 ls -v $SHARETAB
301 cleanup 1
302 fi
303
304 echo "Done - sharetab initial check PASS"
305 ;;
306 a)
307 # Access /etc/dfs/sharetab as end user.
308 echo "Access $SHARETAB as end user ... \c"
309 var1=$(/usr/bin/sum $SHARETAB)
310 var2=$(su bin -c "/usr/bin/sum $SHARETAB")
311 if [[ $var1 != $var2 || $? != 0 ]]; then
312 echo "\n$NAME: the user of bin got a different $SHARETAB -"
313 echo "\t $var2, root got $var1"
314 cat $SHARETAB
315 cleanup 1
316 fi
317
318 echo "OK"
319
320 echo "Done - sharetab access test PASS"
321 ;;
322 m)
323 # Change the state of mountd, verify the consistence of
324 # /etc/dfs/sharetab.
325 echo "Disable mountd and check $SHARETAB ... \c"
326 /usr/sbin/svcadm refresh $SRV_FMRI
327 sleep 5
328 typeset pid1 pid2
329 pid1=$(pgrep -z global -x mountd)
330 if [[ $? != 0 || -z $pid1 ]]; then
331 echo "\n$NAME: failed to get mountd"
332 cleanup 1
333 fi
334 var1=$(/usr/bin/sum $SHARETAB)
335 pstop $pid1
336 if [[ $? != 0 ]]; then
337 echo "\n$NAME: failed to stop mountd"
338 cleanup 1
339 fi
340 var2=$(/usr/bin/sum $SHARETAB)
341 if [[ $var1 != $var2 ]]; then
342 echo "\n$NAME: test failed for $SHARETAB changed"
343 echo "\tafter mountd is stopped, $var1 to $var2"
344 cat $SHARETAB
345 cleanup 1
346 fi
347 echo "OK"
348
349 echo "Resume mountd and check $SHARETAB ... \c"
350 prun $pid1
351 if [[ $? != 0 ]]; then
352 echo "\n$NAME: failed to resume mountd"
353 cleanup 1
354 fi
355 var2=$(/usr/bin/sum $SHARETAB)
356 if [[ $var1 != $var2 ]]; then
357 echo "\n$NAME: test failed for $SHARETAB change"
358 echo "\tafter mountd is resumed, $var1 to $var2"
359 cat $SHARETAB
360 cleanup 1
361 fi
362 echo "OK"
363
364 echo "Restart mountd and check $SHARETAB ... \c"
365 share $SHARETABDIR/dir3 > $STF_TMPDIR/$NAME.shr.$$ 2>&1
366 if [[ $? != 0 ]]; then
367 echo "\n$NAME: failed to share $SHARETABDIR/dir3"
368 cat $STF_TMPDIR/$NAME.shr.$$
369 cleanup 1
370 fi
371 sleep 5
372 var2=$(/usr/bin/sum $SHARETAB)
373 if [[ $var1 == $var2 ]]; then
374 echo "\n$NAME: test failed for $SHARETAB is not updated"
375 echo "\tafter $SHARETABDIR/dir3 is shared"
376 cat $SHARETAB
377 cleanup 1
378 fi
379 kill -9 $pid1
380
381 sleep 10 # wait for mountd
382 pid2=$(pgrep -z global -x mountd)
383 if [[ $? != 0 || -z $pid2 || $pid1 == $pid2 ]]; then
384 echo "\n$NAME: failed to restart mountd"
385 cleanup 1
386 fi
387 # Note: no in-kernel sharetab, after killing mountd, manual share lost
388 var2=$(/usr/bin/sum $SHARETAB)
389 if [[ $var1 != $var2 ]]; then
390 echo "\n$NAME: $SHARETAB changed after mountd is restarted"
391 echo "\t $var1 to $var2"
392 cat $SHARETAB
393 cleanup 1
394 fi
395 echo "OK"
396
397 echo "Done - sharetab mountd test PASS"
398 ;;
399 r)
400 case $OPTARG in
401 1)
402 # Test SHARETAB is consistent after the machine reboots
403 # prepare for reboot
404 echo "backup $SHARETAB and ready to reboot... \c"
405 cp -f $SHARETAB $STF_TMPDIR/_SHARETAB \
406 > $STF_TMPDIR/$NAME.shr.$$ 2>&1
407 if [[ $? != 0 ]]; then
408 echo "\n$NAME: failed to backup $SHARETAB"
409 cat $STF_TMPDIR/$NAME.shr.$$
410 rm -f $STF_TMPDIR/_SHARETAB
411 cleanup 1
412 fi
413 echo "OK"
414
415 echo "Done - $SHARETAB prepare PASS for reboot"
416 reboot
417 ;;
418 2)
419 # check the consistence of /etc/dfs/sharetab
420 echo "reboot and check $SHARETAB ... \c"
421 diff $SHARETAB $STF_TMPDIR/_SHARETAB
422 if [[ $? != 0 ]]; then
423 echo "\n$NAME: $SHARETAB is inconsistent after reboot"
424 echo "--- before reboot ---"
425 cat $STF_TMPDIR/_SHARETAB
426 echo "--- after reboot ---"
427 cat $SHARETAB
428 rm -f $STF_TMPDIR/_SHARETAB
429 cleanup 1
430 fi
431 echo "OK"
432 rm -f $STF_TMPDIR/_SHARETAB
433
434 echo "Done - $SHARETAB test PASS after reboot"
435 ;;
436 \?)
437 cleanup 2
438 ;;
439 esac
440
441 ;;
442 z)
443 # zfs delegation has dependency on sharetab, ;-)
444 # This section will not run until zfs delegation putback
445 # and maybe some codes need update
446 # share zfs as end user
447 echo "zfs share test ... \c"
448 zfs allow bin share,sharenfs $SHARETABDIR
449 typeset Zfs=""
450 Zfs=$(zfs list | grep "$SHARETABDIR/dir" | awk '{print $1}')
451 [[ -z $Zfs ]] && echo "\n$NAME: Can not test zfs share" && cleanup 1
452
453 su bin -c "zfs share $SHARETABDIR/dir1"
454 su bin -c "zfs share $SHARETABDIR/dir2"
455 grep -w "$SHARETABDIR/dir1" $SHARETAB > /dev/null 2>&1
456 [[ $? != 0 ]] && \
457 echo "\n$NAME: failed to share $SHARETABDIR/dir1" && cleanup 1
458 grep -w "$SHARETABDIR/dir2" $SHARETAB > /dev/null 2>&1
459 [[ $? != 0 ]] && \
460 echo "\n$NAME: failed to share $SHARETABDIR/dir2" && cleanup 1
461
462 echo "OK"
463 echo "Done - sharetab zfs share PASS"
464 ;;
465 u)
466 # zfs delegation has dependency on sharetab, ;-)
467 # This section will not run until zfs delegation putback
468 # and maybe some codes need update
469 # unshare zfs as end user
470 echo "zfs unshare test ... \c"
471 su bin -c "zfs unshare $SHARETABDIR/dir1"
472 su bin -c "zfs unshare $SHARETABDIR/dir2"
473 grep -w "$SHARETABDIR/dir" $SHARETAB > /dev/null 2>&1
474 [[ $? != 0 ]] && \
475 echo "\n$NAME: failed to unshare $SHARETABDIR/dir" && cleanup 1
476
477 echo "OK"
478 echo "Done - sharetab zfs unshare PASS"
479 ;;
480 \?)
481 echo $Usage
482 exit 2
483 ;;
484
485 esac
486
487 cleanup 0