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 # Share a file for each SHROPT, then go through the MNTOPT and mount
45 # this file from SERVER's filesystems and do some simple rw/ro testing
46 #
47 # STRATEGY:
48 # 1. Share a file from server's filesystem
49 # 2. Call domount_check and automount_check to mount test file and verify
50 # 3. Call do_rw|ro_test script if needed for testing in the mounted file
51 # 4. Call unmount_check to umount and check the file is umounted
52 #
53 # TESTABILITY: explicit
54 #
55 # TEST_AUTOMATION_LEVEL: automated
56 #
57 # __stc_assertion_end
58 #
59 ################################################################################
60
61 # Function to do rw testing in the NFS mount point that's mounted from a "file"
62 # Usage: do_rw_file [check_dir]
63 #
64 function do_rw_file {
65 typeset Fname=do_rw_file
66 [[ :$SHAREMNT_DEBUG: == *:${NAME}:* \
67 || :${SHAREMNT_DEBUG}: == *:all:* ]] && set -x
68
69 typeset ckDIR=$1
70 [[ -z $ckDIR ]] && ckDIR=$MNTDIR
71
72 echo "Doing READ/WRITE testing at <$ckDIR> file ..."
73 typeset TData="READ/WRITE tests at $ckDIR file"
74
75 file $ckDIR > $STF_TMPDIR/file.out.$$ 2>&1
76 grep 'ksh script' $STF_TMPDIR/file.out.$$ > /dev/null 2>&1
77 if (( $? != 0 )); then
78 echo "$Fname: checking file-type to $ckDIR failed"
79 echo "\texpected=<ksh script>, got:"
80 cat $STF_TMPDIR/file.out.$$
81 cleanup $STF_FAIL
82 fi
83
84 echo "$TData" >> $ckDIR 2> $STF_TMPDIR/wr.out.$$
85 if (( $? != 0 )); then
86 echo "$Fname: APPEND/WRITE to $ckDIR failed"
87 cat $STF_TMPDIR/wr.out.$$
88 cleanup $STF_FAIL
89 fi
90 ckData=$(tail -1 $ckDIR)
91 if [[ "$ckData" != "$TData" ]]; then
92 echo "$Fname: READ file $ckDIR failed"
93 echo "\texpect=$<$TData>"
94 echo "\tgot=$<$ckData>"
95 cleanup $STF_FAIL
96 fi
97 echo "OK"
98 }
99
100 # Function to do ro testing in the mount point that's mounted from a "file"
101 # Usage: do_rw_file [check_dir]
102 #
103 function do_ro_file {
104 typeset Fname=do_ro_file
105 [[ :$SHAREMNT_DEBUG: == *:${NAME}:* \
106 || :${SHAREMNT_DEBUG}: == *:all:* ]] && set -x
107
108 typeset ckDIR=$1
109 [[ -z $ckDIR ]] && ckDIR=$MNTDIR
110
111 echo "Doing READ ONLY testing at <$ckDIR> file ..."
112
113 ls -ld $ckDIR > $STF_TMPDIR/lsd.out.$$ 2>&1
114 grep "^d" $STF_TMPDIR/lsd.out.$$ > /dev/null 2>&1
115 if (( $? == 0 )); then
116 echo "$Fname: checking listing of $ckDIR failed"
117 echo "\tit listed as a directory?"
118 cat $STF_TMPDIR/lsd.out.$$
119 cleanup $STF_FAIL
120 fi
121 # check ACL if it's not 'rootfile'
122 if [[ ,$Shropt, != *,anon=0,* ]]; then
123 ls -v $ckDIR > $STF_TMPDIR/lsv.out.$$ 2>&1
124 if [[ ,$Mntopts, == @(*,vers=2,*|*,vers=3,*) ]]; then
125 # NFSv3,v2 use POSIX acl, check differently
126 grep "user" $STF_TMPDIR/lsv.out.$$ | \
127 grep ":r--" > /dev/null 2>&1
128 else
129 grep "owner" $STF_TMPDIR/lsv.out.$$ | grep \
130 "write_data" | grep ":deny" > /dev/null 2>&1
131 fi
132 if (( $? != 0 )); then
133 echo "$Fname: checking ACL of $ckDIR failed"
134 echo "\texpected: <owner deny write_data>|<user:r-->"
135 cat $STF_TMPDIR/lsv.out.$$
136 cleanup $STF_FAIL
137 fi
138 fi
139 # append data to file should fail
140 echo "Trying to write into <$ckDIR> file" >> $ckDIR \
141 2> $STF_TMPDIR/write.out.$$
142 if (( $? == 0 )); then
143 echo "$Fname: trying to write into <$ckDIR> file succeeded"
144 echo "\tit should be READ ONLY"
145 cat $STF_TMPDIR/lsd.out.$$
146 cleanup $STF_FAIL
147 fi
148 echo "OK"
149 }
150
151 USAGE="Usage: runtests Test_name Share_opt Mnt_opts"
152
153 if (( $# < 3 )); then
154 echo "$USAGE"
155 exit $STF_UNINITIATED
156 fi
157
158 typeset Tname=$1
159 typeset Shropt=$2
160 typeset Mntopts=$3
161
162 # Check TX related info
163 check_for_cipso "$SHRDIR" "$MNTDIR" "$Mntopts" || return $STF_UNSUPPORTED
164
165 # set the ReadOnly flag based on share/mount options
166 typeset -i ckro=0 shr_ro=0 mnt_ro=0
167 shr_ro=$(echo "$Shropt" | \
168 nawk -F\, '{for (i=1; i<=NF; i++) {if ($i ~ /^ro/) print i} }')
169 mnt_ro=$(echo "$Mntopts" | \
170 nawk -F\, '{for (i=1; i<=NF; i++) {if ($i ~ /^ro/) print i} }')
171 ckro=$((shr_ro | mnt_ro))
172
173 # first unshare the file from last run, just in case
174 RSH root $SERVER \
175 "export SHAREMNT_DEBUG=$SRVDEBUG; \
176 $SRV_TMPDIR/srv_setup -u $SHRDIR" > $STF_TMPDIR/rsh.out.$$ 2>&1
177 if (( $? != 0 )); then
178 echo "$NAME: failed to unshare <$SHRDIR>"
179 cat $STF_TMPDIR/rsh.out.$$ > /dev/null 2>&1
180 cleanup $STF_UNRESOLVED
181 fi
182
183 # Now set the test file for share in server, for share_check
184 if [[ ,$Shropt, == *,anon=0,* ]]; then
185 NEW_SHRDIR=$SHRDIR/rootfile
186 else
187 (( ckro > 0 )) && \
188 NEW_SHRDIR=$SHRDIR/rofile || \
189 NEW_SHRDIR=$SHRDIR/rwfile
190 fi
191 share_check "$Shropt" $NEW_SHRDIR
192
193 typeset isURL=""
194 if [[ ,$Shropt, == *,public,* ]]; then
195 # NFSv3,v2 cannot mount public root as file; thus use full path
196 # And skip NFSv4,public for now because of CR 6504516
197 if [[ ,$Mntopts, == @(*,vers=2,*|*,vers=3,*) ]]; then
198 NEW_SHRDIR="/$NEW_SHRDIR"
199 else
200 # NEW_SHRDIR="/"
201 echo "\tCurrently it can't test mounting NFS/URL with NFSv4"
202 echo "\tdue to CR 6504516. Test should be re-enabled once"
203 echo "\tthe bug is fixed"
204 cleanup $STF_UNTESTED
205 fi
206 isURL=URL
207 fi
208
209 # Then do the rw/ro check for both manual mount and automount
210 domount_check $isURL "$Mntopts" "$Shropt" $NEW_SHRDIR
211 nfsstat -m $MNTDIR
212 (( ckro > 0 )) && do_ro_file || do_rw_file
213
214 automount_check $isURL "$Mntopts" "$Shropt" "BASIC_URL" "$NEW_SHRDIR"
215 mntPTR=$(grep "$Mntopts" $STF_TMPDIR/auto_indirect.shmnt | awk '{print $1}')
216 mntPTR=/AUTO_shmnt/$mntPTR
217 nfsstat -m $mntPTR
218 (( ckro > 0 )) && do_ro_file $mntPTR || do_rw_file $mntPTR
219
220 # Finally umount it
221 unmount_check
222
223 echo "$NAME: testing complete - Result PASS"
224 cleanup $STF_PASS