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 NAME=$(basename $0)
29
30 . $STF_SUITE/include/sharemnt.kshlib
31 . $STC_GENUTILS/include/nfs-tx.kshlib
32
33 export STC_GENUTILS_DEBUG=$STC_GENUTILS_DEBUG:$SHAREMNT_DEBUG
34 [[ :$SHAREMNT_DEBUG: == *:${NAME}:* \
35 || :${SHAREMNT_DEBUG}: == *:all:* ]] && set -x
36
37 ################################################################################
38 #
39 # __stc_assertion_start
40 #
41 # ID: runtests
42 #
43 # DESCRIPTION:
44 # For each SHROPT, go through the MNTOPT and mount the SERVER's filesystems
45 # Do some simple rw/ro testing
46 #
47 # STRATEGY:
48 # 1. Call domount_check to mount test filesystem and verify
49 # 2. Call do_rw|ro_test script if needed for testing in the mounted filesystem
50 # 3. Call unmount_check to umount and check the filesystem is umounted
51 #
52 # TESTABILITY: explicit
53 #
54 # TEST_AUTOMATION_LEVEL: automated
55 #
56 # __stc_assertion_end
57 #
58 ################################################################################
59
60 # Function to do ro|rw|remount testing in the NFS mount point
61 # Usage: do_others [URL] [check_dir]
62 #
63 function do_others {
64 typeset Fname=do_others
65 [[ :$SHAREMNT_DEBUG: == *:${NAME}:* \
66 || :${SHAREMNT_DEBUG}: == *:all:* ]] && set -x
67
68 typeset urlflag=""
69 if [[ $1 == URL ]]; then
70 urlflag="URL"
71 shift
72 fi
73 typeset ckdir="$*"
74
75 if (( $ckro > 0 )); then
76 do_ro_test
77
78 if (( $shr_ro == 0 )); then
79 set -A molist remount remount,rw rw,remount
80 typeset remnt_opt=${molist[$((RANDOM % 3 ))]}
81 typeset newmntopt=$remnt_opt
82 # if mount with URL format and "vers=2|3", remount must use "vers=2|3";
83 # if mount option contains "public" and "vers=2|3", remount must
84 # use "public" and "vers=2|3" too, otherwise, remount will fail.
85 [[ (-n $urlflag || ,$Mntopts, == *,public,*) && \
86 ,$Mntopts, == @(*,vers=2,*|*,vers=3,*) ]] && \
87 newmntopt=$(echo $Mntopts | sed "s/ro/$remnt_opt/g")
88 domount_check $urlflag $newmntopt $Shropt $ckdir
89 do_rw_test
90 fi
91 else
92 if [[ $Shropt == *anon=* ]]; then
93 do_rw_test "ANON" $Shropt
94 else
95 do_rw_test "ANON" "nobody"
96 fi
97
98 set -A molist remount,ro ro,remount
99 do_neg_mount_check ${molist[$((RANDOM % 2 ))]}
100 fi
101 unmount_check
102 }
103
104 USAGE="Usage: runtests Test_name Share_opt Mnt_opts"
105
106 if (( $# < 3 )); then
107 echo "$USAGE"
108 exit $STF_UNRESOLVED
109 fi
110
111 typeset Tname=$1
112 typeset Shropt=$2
113 typeset Mntopts=$3
114
115 # Check TX related info
116 check_for_cipso "$SHRDIR" "$MNTDIR" "$Mntopts" || return $STF_UNSUPPORTED
117
118 share_check "$Shropt"
119
120 typeset -i ckro=0 shr_ro=0 mnt_ro=0
121 shr_ro=$(echo "$Shropt" | \
122 nawk -F\, '{for (i=1; i<=NF; i++) {if ($i ~ /^ro/) print i} }')
123 mnt_ro=$(echo "$Mntopts" | \
124 nawk -F\, '{for (i=1; i<=NF; i++) {if ($i ~ /^ro/) print i} }')
125 ckro=$((shr_ro | mnt_ro))
126
127 if [[ ,$Shropt, == *,public,* && ,$Mntopts, == *,public,* && \
128 ,$Mntopts, != @(*,vers=2,*|*,vers=3,*) && \
129 ! (,$Mntopts, == *,proto=udp,* && $Mntopts != *"vers"*) ]]; then
130 domount_check "$Mntopts" "$Shropt" "/"
131 automount_check "$Mntopts" "$Shropt" "BASIC" "/"
132 do_others "/"
133 else
134 domount_check "$Mntopts" "$Shropt"
135 automount_check "$Mntopts" "$Shropt" "BASIC"
136 do_others
137 fi
138
139 # do url mount check
140 if [[ ,$Shropt, == *,public,* ]]; then
141 domount_check "URL" "$Mntopts" "$Shropt" "/"
142 automount_check "URL" "$Mntopts" "$Shropt" "BASIC_URL" "/"
143 do_others "URL" "/"
144 else
145 domount_check "URL" "$Mntopts" "$Shropt"
146 automount_check "URL" "$Mntopts" "$Shropt" "BASIC_URL"
147 do_others "URL"
148 fi
149
150 echo "$NAME: testing complete - Result PASS"
151 cleanup $STF_PASS