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 # NFSv4 client name space test - mounting symlink
28 #
29
30 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
31
32 NAME=`basename $0`
33 CDIR=`pwd`
34 NSPC=`echo $NAME | sed 's/./ /g'`
35
36 # Source for common functions
37 . $TESTROOT/testsh
38
39 # check for root to run
40 is_root $NAME "NFSv4 name space tests (mount symlink)."
41
42 TMPmnt=$ZONE_PATH/$NAME.$$
43 mkdir -m 0777 -p $TMPmnt
44
45 allunsupp=0
46 is_cipso "vers=4" $SERVER
47 if [ $? -eq $CIPSO_NFSV4 ]; then
48 cipso_check_mntpaths $BASEDIR $TMPmnt
49 if [ $? -ne 0 ]; then
50 allunsupp=1
51 echo "$NAME: UNSUPPORTED"
52 echo "$NAME: CIPSO NFSv4 requires non-global zone mount dirs."
53 echo "$NSPC The server's BASEDIR and client's MNTPTR"
54 echo "$NSPC must contain path legs with matching"
55 echo "$NSPC non-global zone paths."
56 echo "$NSPC: Please try again ..."
57 fi
58 fi
59
60 # Start test assertions here
61 # ----------------------------------------------------------------------
62 # a: Verify mounting symlink dir in a shared FS, expect succeed
63 function assertion_a
64 {
65 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
66 ASSERTION="Mounting symlink dir in a shared FS"
67 ASSERTION="$ASSERTION, expect succeed"
68 echo "$NAME{a}: $ASSERTION"
69
70 if [ $allunsupp -eq 1 ]; then
71 echo "\t Test UNSUPPORTED"
72 return $FAIL
73 fi
74
75 # SRVPATH should be a symlink
76 SRVPATH=$BASEDIR/$SYMLDIR/dir2
77
78 # Test it with the mount on the $SRVPATH
79 mount -o vers=4,rw $SERVER:$SRVPATH $TMPmnt > $TMPDIR/$NAME.mnt.$$ 2>&1
80 ckreturn $? "mount <vers=4,rw $SERVER:$SRVPATH> failed" $TMPDIR/$NAME.mnt.$$
81 [ $? -ne 0 ] && return $FAIL
82
83 # verify the mount point is access'ble
84 ls -lL $TMPmnt > $TMPDIR/$NAME.ck.$$ 2>&1
85 ckreturn $? "unable to access the mnt-point after share" $TMPDIR/$NAME.ck.$$
86 [ $? -ne 0 ] && return $FAIL
87
88 # umount it
89 umount $TMPmnt > $TMPDIR/$NAME.umnt.$$ 2>&1
90 ckreturn $? "umount failed" $TMPDIR/$NAME.umnt.$$
91 [ $? -ne 0 ] && return $FAIL
92
93 echo "\t Test PASS"
94 }
95
96 # b: Verify mounting symlink file (w/no perm) in a shared FS, expect succeed
97 function assertion_b
98 {
99 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
100 ASSERTION="Mounting symlink file(w/no PERM) in shared FS"
101 ASSERTION="$ASSERTION, expect succeed"
102 echo "$NAME{b}: $ASSERTION"
103
104 if [ $allunsupp -eq 1 ]; then
105 echo "\t Test UNSUPPORTED"
106 return $FAIL
107 fi
108
109 # SRVPATH should be a symlink to a file with mode=0000
110 SRVPATH=$BASEDIR/$SYMNOPF
111
112 # Test it with the mount on the $SRVPATH
113 mount -o vers=4,rw $SERVER:$SRVPATH $TMPmnt > $TMPDIR/$NAME.mnt.$$ 2>&1
114 ckreturn $? "mount <vers=4,rw $SERVER:$SRVPATH> failed" $TMPDIR/$NAME.mnt.$$
115 [ $? -ne 0 ] && return $FAIL
116
117 # verify Getattr the mount point is correct
118 ls -l $TMPmnt > $TMPDIR/$NAME.ck.$$ 2>&1
119 ckreturn $? "unable to Getattr mnt-point after share" $TMPDIR/$NAME.ck.$$
120 [ $? -ne 0 ] && return $FAIL
121 Mode=`awk '{print $1}' $TMPDIR/$NAME.ck.$$`
122 if [[ $TestZFS = 1 ]]; then
123 # ACL/xattr is set for FNOPERM
124 expmode="----------+"
125 else
126 expmode="----------"
127 fi
128 if [ "$Mode" != $expmode ]; then
129 echo "\t Test FAIL: file mode is incorrect"
130 cat $TMPDIR/$NAME.ck.$$
131 umount $TMPmnt
132 return $FAIL
133 fi
134
135 # umount it
136 umount $TMPmnt > $TMPDIR/$NAME.umnt.$$ 2>&1
137 ckreturn $? "umount failed" $TMPDIR/$NAME.umnt.$$
138 [ $? -ne 0 ] && return $FAIL
139
140 echo "\t Test PASS"
141 }
142
143 # c: Verify mounting symlink to nosuchdir, expect fail
144 function assertion_c
145 {
146 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
147 ASSERTION="Mounting symlink to nosuch dir, expect fail"
148 echo "$NAME{c}: $ASSERTION"
149
150 if [ $allunsupp -eq 1 ]; then
151 echo "\t Test UNSUPPORTED"
152 return $FAIL
153 fi
154
155 # SRVPATH should be a symlink file
156 SRVPATH=$BASEDIR/syml_nodir
157
158 # Test it with the mount on the $SRVPATH, should fail
159 mount -o vers=4,rw $SERVER:$SRVPATH $TMPmnt > $TMPDIR/$NAME.mnt.$$ 2>&1
160 if [ $? -eq 0 ]; then
161 echo "\t Test FAIL: mounting <$SRVPATH> did not fail"
162 cat $TMPDIR/$NAME.mnt.$$
163 return $FAIL
164 fi
165
166 # verify the mount point is not NFS mounted
167 df -F nfs $TMPmnt > $TMPDIR/$NAME.ck.$$ 2>&1
168 if [ $? -eq 0 ]; then
169 echo "\t Test FAIL: mount point <$TMPmnt> should not be NFS"
170 cat $TMPDIR/$NAME.ck.$$
171 return $FAIL
172 fi
173
174 echo "\t Test PASS"
175 }
176
177 # d: Verify mounting symlink to out-of namespace dir(usr/lib), expect fail
178 function assertion_d
179 {
180 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
181 ASSERTION="Mounting symlink to out-of namespace dir(usr/lib), expect fail"
182 echo "$NAME{d}: $ASSERTION"
183
184 if [ $allunsupp -eq 1 ]; then
185 echo "\t Test UNSUPPORTED"
186 return $FAIL
187 fi
188
189 # SRVPATH should be a symlink file
190 SRVPATH=$BASEDIR/syml_outns
191
192 # Test it with the mount on the $SRVPATH, should fail
193 mount -o vers=4,rw $SERVER:$SRVPATH $TMPmnt > $TMPDIR/$NAME.mnt.$$ 2>&1
194 if [ $? -eq 0 ]; then
195 echo "\t Test FAIL: mounting <$SRVPATH> did not fail"
196 cat $TMPDIR/$NAME.mnt.$$
197 return $FAIL
198 fi
199
200 # verify the mount point is not NFS mounted
201 df -F nfs $TMPmnt > $TMPDIR/$NAME.ck.$$ 2>&1
202 if [ $? -eq 0 ]; then
203 echo "\t Test FAIL: mount point <$TMPmnt> should not be NFS"
204 cat $TMPDIR/$NAME.ck.$$
205 return $FAIL
206 fi
207
208 echo "\t Test PASS"
209 }
210
211 # e: Verify mounting symlink to file in unshared cross-mount, expect fail
212 # XXX this assertion may need to change when client cross-mount is available.
213 function assertion_e
214 {
215 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
216 ASSERTION="Mounting symlink to file in unshared cross-mnt, expect fail"
217 echo "$NAME{e}: $ASSERTION"
218
219 if [ $allunsupp -eq 1 ]; then
220 echo "\t Test UNSUPPORTED"
221 return $FAIL
222 fi
223
224 # SRVPATH should be a symlink file
225 SRVPATH=$BASEDIR/syml_nofile
226
227 # Test it with the mount on the $SRVPATH, should fail
228 mount -o vers=4,rw $SERVER:$SRVPATH $TMPmnt > $TMPDIR/$NAME.mnt.$$ 2>&1
229 if [ $? -eq 0 ]; then
230 echo "\t Test FAIL: mounting <$SRVPATH> did not fail"
231 cat $TMPDIR/$NAME.mnt.$$
232 return $FAIL
233 fi
234
235 # verify the mount point is not NFS mounted
236 df -F nfs $TMPmnt > $TMPDIR/$NAME.ck.$$ 2>&1
237 if [ $? -eq 0 ]; then
238 echo "\t Test FAIL: mount point should not be NFS"
239 cat $TMPDIR/$NAME.ck.$$
240 return $FAIL
241 fi
242
243 echo "\t Test PASS"
244 }
245
246 # h: Verify mounting symlink to another shared FS, expect succeed
247 function assertion_h
248 {
249 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
250 ASSERTION="Mounting symlink to another shared FS"
251 ASSERTION="$ASSERTION, expect succeed"
252 echo "$NAME{h}: $ASSERTION"
253
254 if [ $allunsupp -eq 1 ]; then
255 echo "\t Test UNSUPPORTED"
256 return $FAIL
257 fi
258
259 # SRVPATH should be a symlink
260 SRVPATH=$BASEDIR/syml_sh_fs
261
262 # Test it with the mount on the $SRVPATH
263 mount -o vers=4,rw $SERVER:$SRVPATH $TMPmnt > $TMPDIR/$NAME.mnt.$$ 2>&1
264 ckreturn $? "mount <vers=4,rw $SERVER:$SRVPATH> failed" $TMPDIR/$NAME.mnt.$$
265 [ $? -ne 0 ] && return $FAIL
266
267 # verify the mount point is access'ble
268 ls -lL $TMPmnt > $TMPDIR/$NAME.ck.$$ 2>&1
269 ckreturn $? "unable to access the mnt-point after share" $TMPDIR/$NAME.ck.$$
270 [ $? -ne 0 ] && return $FAIL
271
272 # umount it
273 umount $TMPmnt > $TMPDIR/$NAME.umnt.$$ 2>&1
274 ckreturn $? "umount failed" $TMPDIR/$NAME.umnt.$$
275 [ $? -ne 0 ] && return $FAIL
276
277 echo "\t Test PASS"
278 }
279
280 # i: Verify mounting symlink to a non-shared FS w/in shared node, expect succeed
281 # XXX this assertion may need to change when client cross-mount is available.
282 function assertion_i
283 {
284 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
285 ASSERTION="Mounting symlink to non-shared FS in shared node, expect succeed"
286 echo "$NAME{i}: $ASSERTION"
287
288 if [ $allunsupp -eq 1 ]; then
289 echo "\t Test UNSUPPORTED"
290 return $FAIL
291 fi
292
293 # SRVPATH should be a symlink file
294 SRVPATH=$BASEDIR/syml_nosh_fs
295
296 # Test it with the mount on the $SRVPATH, should OK as a dir
297 mount -o vers=4,rw $SERVER:$SRVPATH $TMPmnt > $TMPDIR/$NAME.mnt.$$ 2>&1
298 ckreturn $? "mount <vers=4,rw $SERVER:$SRVPATH> failed" $TMPDIR/$NAME.mnt.$$
299 [ $? -ne 0 ] && return $FAIL
300
301 # verify client can't create file in it
302 touch $TMPmnt/testfile.$$ > $TMPDIR/$NAME.ck.$$ 2>&1
303 if [ $? -eq 0 ]; then
304 echo "\t Test FAIL: mount point should not be writable"
305 cat $TMPDIR/$NAME.ck.$$
306 return $FAIL
307 fi
308
309 # umount it
310 umount $TMPmnt > $TMPDIR/$NAME.umnt.$$ 2>&1
311 ckreturn $? "umount failed" $TMPDIR/$NAME.umnt.$$
312 [ $? -ne 0 ] && return $FAIL
313
314 echo "\t Test PASS"
315 }
316
317 # m: Verify mounting symlink dir w/relative path, expect succeed
318 function assertion_m
319 {
320 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
321 ASSERTION="Mounting symlink dir with relative path"
322 ASSERTION="$ASSERTION, expect succeed"
323 echo "$NAME{m}: $ASSERTION"
324
325 if [ $allunsupp -eq 1 ]; then
326 echo "\t Test UNSUPPORTED"
327 return $FAIL
328 fi
329
330 # SRVPATH should be a symlink
331 SRVPATH=$BASEDIR/syml_dotd
332
333 # Test it with the mount on the $SRVPATH
334 mount -o vers=4,rw $SERVER:$SRVPATH $TMPmnt > $TMPDIR/$NAME.mnt.$$ 2>&1
335 ckreturn $? "mount <vers=4,rw $SERVER:$SRVPATH> failed" $TMPDIR/$NAME.mnt.$$
336 [ $? -ne 0 ] && return $FAIL
337
338 # verify the mount point is access'ble
339 ls -lL $TMPmnt > $TMPDIR/$NAME.ck.$$ 2>&1
340 ckreturn $? "unable to access the mnt-point after unshare" $TMPDIR/$NAME.ck.$$
341 [ $? -ne 0 ] && return $FAIL
342
343 # umount it
344 umount $TMPmnt > $TMPDIR/$NAME.umnt.$$ 2>&1
345 ckreturn $? "umount failed" $TMPDIR/$NAME.umnt.$$
346 [ $? -ne 0 ] && return $FAIL
347
348 echo "\t Test PASS"
349 }
350
351 # n: Verify mounting symlink file w/relative path (. & ..), expect succeed
352 function assertion_n
353 {
354 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
355 ASSERTION="Mounting symlink file w/relative path (. & ..)"
356 ASSERTION="$ASSERTION, expect succeed"
357 echo "$NAME{n}: $ASSERTION"
358
359 if [ $allunsupp -eq 1 ]; then
360 echo "\t Test UNSUPPORTED"
361 return $FAIL
362 fi
363
364 # SRVPATH should be a symlink
365 SRVPATH=$BASEDIR/syml_dotf
366
367 # Test it with the mount on the $SRVPATH
368 mount -o vers=4,rw $SERVER:$SRVPATH $TMPmnt > $TMPDIR/$NAME.mnt.$$ 2>&1
369 ckreturn $? "mount <vers=4,rw $SERVER:$SRVPATH> failed" $TMPDIR/$NAME.mnt.$$
370 [ $? -ne 0 ] && return $FAIL
371
372 # verify the mount point is access'ble
373 ls -lL $TMPmnt > $TMPDIR/$NAME.ck.$$ 2>&1
374 ckreturn $? "unable to access the mnt-point after unshare" $TMPDIR/$NAME.ck.$$
375 [ $? -ne 0 ] && return $FAIL
376
377 # umount it
378 umount $TMPmnt > $TMPDIR/$NAME.umnt.$$ 2>&1
379 ckreturn $? "umount failed" $TMPDIR/$NAME.umnt.$$
380 [ $? -ne 0 ] && return $FAIL
381
382 echo "\t Test PASS"
383 }
384
385 # o: Verify mounting symlink dir w/.. of shared inside shared FS, expect succeed
386 function assertion_o
387 {
388 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
389 ASSERTION="Mounting symlink dir w/.. of shared inside shared FS"
390 ASSERTION="$ASSERTION, expect succeed"
391 echo "$NAME{o}: $ASSERTION"
392
393 if [ $allunsupp -eq 1 ]; then
394 echo "\t Test UNSUPPORTED"
395 return $FAIL
396 fi
397
398 # SRVPATH should be a symlink
399 SRVPATH=$BASEDIR/syml_dotdot
400
401 # Test it with the mount on the $SRVPATH
402 mount -o vers=4,rw $SERVER:$SRVPATH $TMPmnt > $TMPDIR/$NAME.mnt.$$ 2>&1
403 ckreturn $? "mount <vers=4,rw $SERVER:$SRVPATH> failed" $TMPDIR/$NAME.mnt.$$
404 [ $? -ne 0 ] && return $FAIL
405
406 # verify the mount point is access'ble
407 ls -lL $TMPmnt > $TMPDIR/$NAME.ck.$$ 2>&1
408 ckreturn $? "unable to access the mnt-point after unshare" $TMPDIR/$NAME.ck.$$
409 [ $? -ne 0 ] && return $FAIL
410
411 # umount it
412 umount $TMPmnt > $TMPDIR/$NAME.umnt.$$ 2>&1
413 ckreturn $? "umount failed" $TMPDIR/$NAME.umnt.$$
414 [ $? -ne 0 ] && return $FAIL
415
416 echo "\t Test PASS"
417 }
418
419 # p: Verify mounting symlink to an absolute syml in shared FS, expect succeed
420 function assertion_p
421 {
422 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
423 ASSERTION="Mounting symlink to an absolute symlink in shared FS"
424 ASSERTION="$ASSERTION, expect succeed"
425 echo "$NAME{p}: $ASSERTION"
426
427 if [ $allunsupp -eq 1 ]; then
428 echo "\t Test UNSUPPORTED"
429 return $FAIL
430 fi
431
432 # SRVPATH should be a symlink
433 SRVPATH=$BASEDIR/symldir2
434
435 # Test it with the mount on the $SRVPATH
436 mount -o vers=4,rw $SERVER:$SRVPATH $TMPmnt > $TMPDIR/$NAME.mnt.$$ 2>&1
437 ckreturn $? "mount <vers=4,rw $SERVER:$SRVPATH> failed" $TMPDIR/$NAME.mnt.$$
438 [ $? -ne 0 ] && return $FAIL
439
440 # verify the mount point is access'ble
441 ls -lL $TMPmnt > $TMPDIR/$NAME.ck.$$ 2>&1
442 ckreturn $? "unable to access the mnt-point after unshare" $TMPDIR/$NAME.ck.$$
443 [ $? -ne 0 ] && return $FAIL
444
445 # umount it
446 umount $TMPmnt > $TMPDIR/$NAME.umnt.$$ 2>&1
447 ckreturn $? "umount failed" $TMPDIR/$NAME.umnt.$$
448 [ $? -ne 0 ] && return $FAIL
449
450 echo "\t Test PASS"
451 }
452
453 # Start main program here:
454 # ----------------------------------------------------------------------
455
456 assertion_a
457 [ $? -ne 0 ] && umount -f $TMPmnt > /dev/null 2>&1
458 assertion_b
459 [ $? -ne 0 ] && umount -f $TMPmnt > /dev/null 2>&1
460 assertion_c
461 [ $? -ne 0 ] && umount -f $TMPmnt > /dev/null 2>&1
462 assertion_d
463 [ $? -ne 0 ] && umount -f $TMPmnt > /dev/null 2>&1
464 assertion_e
465 [ $? -ne 0 ] && umount -f $TMPmnt > /dev/null 2>&1
466 assertion_h
467 [ $? -ne 0 ] && umount -f $TMPmnt > /dev/null 2>&1
468 assertion_i
469 [ $? -ne 0 ] && umount -f $TMPmnt > /dev/null 2>&1
470 assertion_m
471 [ $? -ne 0 ] && umount -f $TMPmnt > /dev/null 2>&1
472 assertion_n
473 [ $? -ne 0 ] && umount -f $TMPmnt > /dev/null 2>&1
474 assertion_o
475 [ $? -ne 0 ] && umount -f $TMPmnt > /dev/null 2>&1
476 assertion_p
477 [ $? -ne 0 ] && umount -f $TMPmnt > /dev/null 2>&1
478
479
480 # cleanup here
481 rmdir $TMPmnt
482 rm -f $TMPDIR/$NAME.*.$$
483
484 exit 0