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 #
  29 # NFSv4 test to verify client can't mount after server unshareall
  30 #
  31 . ${STF_SUITE}/include/nfsgen.kshlib
  32 
  33 NAME=$(basename $0)
  34 
  35 [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] \
  36         && set -x
  37 
  38 DIR=$(dirname $0)
  39 
  40 # proc to check result and print out failure messages 
  41 # ckres rc message cat_file
  42 function ckres 
  43 {
  44     [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
  45     rc=$1
  46     msg=${2}
  47     cf=${3}
  48 
  49     if (( $rc != 0 )); then
  50         echo "\t Test STF_FAIL: $msg"
  51         [[ -f $cf ]] && cat $cf
  52     fi
  53     return $rc
  54 }
  55 
  56 # First check this test is not started before previous tests
  57 # grace period ends.
  58 echo "xxx" > $MNTDIR/wait_for_grace
  59 rm -rf $MNTDIR/wait_for_grace > /dev/null 2>&1
  60 
  61 TMPmnt=$ZONE_PATH/$NAME.$$
  62 mkdir -m 0777 -p $TMPmnt
  63 
  64 
  65 # Start test assertions here
  66 # ----------------------------------------------------------------------
  67 # a: Client tries to mount after server unshareall, expect fail
  68 function assertion_a 
  69 {
  70     [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
  71     ASSERTION="Client tries to mount after server unshareall"
  72     ASSERTION="$ASSERTION, expect fail"
  73     echo "$NAME{a}: $ASSERTION"
  74     # set SRVPATH be a "was" exported fs
  75     SRVPATH=$SHRDIR
  76 
  77     # First test it mount'ble from client
  78     mount -o vers=4,rw $SERVER:$SRVPATH $TMPmnt > $STF_TMPDIR/$NAME.mnt.$$ 2>&1
  79     ckres $? "mount <vers=4,rw $SERVER:$SRVPATH> failed" $STF_TMPDIR/$NAME.mnt.$$
  80     (( $? != 0 )) && return $STF_FAIL
  81 
  82     # verify the mount point is access'ble
  83     ls -lL $TMPmnt > $STF_TMPDIR/$NAME.ck.$$ 2>&1
  84     ckres $? "unable to access the mnt-point after unshare" $STF_TMPDIR/$NAME.ck.$$
  85     (( $? != 0 )) && return $STF_FAIL
  86 
  87     # umount it
  88     umount $TMPmnt > $STF_TMPDIR/$NAME.umnt.$$ 2>&1
  89     ckres $? "umount failed" $STF_TMPDIR/$NAME.umnt.$$
  90     (( $? != 0 )) && return $STF_FAIL
  91 
  92     # now have the SERVER to do an unshareall
  93     RSH root $SERVER "/usr/sbin/sharemgr stop -a" > $STF_TMPDIR/$NAME.srv.$$ 2>&1
  94     ckres $? "unshare $SRVPATH failed" $STF_TMPDIR/$NAME.srv.$$
  95     (( $? != 0 )) && return $STF_FAIL
  96 
  97     # and try to mount again with "/" and the original FS
  98     mount -o vers=4,ro $SERVER:/ $TMPmnt > $STF_TMPDIR/$NAME.mnt.$$ 2>&1
  99     if (( $? == 0 )); then 
 100         echo "\t Test STF_FAIL: mount <vers=4,ro $SERVER:/> did not fail"
 101         cat $STF_TMPDIR/$NAME.mnt.$$
 102         return $STF_FAIL
 103     fi
 104 
 105     mount -o vers=4,rw $SERVER:$SRVPATH $TMPmnt > $STF_TMPDIR/$NAME.mnt.$$ 2>&1
 106     if (( $? == 0 )); then 
 107         echo "\t Test STF_FAIL: mount <vers=4,ro $SERVER:$SRVPATH> did not fail"
 108         cat $STF_TMPDIR/$NAME.mnt.$$
 109         return $STF_FAIL
 110     fi
 111 
 112     # finally re-shareall in SERVER
 113     RSH root $SERVER "/usr/sbin/sharemgr start -a" > $STF_TMPDIR/$NAME.srv.$$ 2>&1
 114     ckres $? "shareall $SRVPATH failed" $STF_TMPDIR/$NAME.srv.$$
 115     (( $? != 0 )) && return $STF_FAIL
 116 
 117     RSH root $SERVER "/usr/bin/ksh ${SRV_TMPDIR}/recov_setserver -r" > $STF_TMPDIR/$NAME.srv.$$ 2>&1
 118     ckres $? "reshare $SHRDIR on $SERVER failed" $STF_TMPDIR/$NAME.srv.$$
 119     (( $? != 0 )) && return $STF_FAIL
 120 
 121     echo "\t Test PASS"
 122     return $STF_PASS
 123 }
 124 
 125 
 126 # Start main program here:
 127 # ----------------------------------------------------------------------
 128 
 129 assertion_a 
 130 (( $? == $STF_PASS )) && cleanup $STF_PASS "" "$TMPmnt $STF_TMPDIR/$NAME.*.$$" \
 131         || cleanup $STF_FAIL "" "$TMPmnt $STF_TMPDIR/$NAME.*.$$"
 132