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",
  83             # remount must use "vers=2|3";
  84             # if mount option contains "public" and "vers=2|3",
  85             # remount must use "public" and "vers=2|3" too,
  86             # otherwise, remount will fail.
  87             [[ (-n $urlflag || ,$Mntopts, == *,public,*) && \
  88                 ,$Mntopts, == @(*,vers=2,*|*,vers=3,*) ]] && \
  89                 newmntopt=$(echo $Mntopts | sed "s/ro/$remnt_opt/g")
  90             domount_check $urlflag $newmntopt $Shropt $ckdir
  91             do_rw_test
  92         fi
  93     else
  94         if [[ $Shropt == *anon=* ]]; then
  95             do_rw_test "ANON" $Shropt
  96         else
  97             do_rw_test "ANON" "nobody"
  98         fi
  99 
 100         set -A molist remount,ro ro,remount
 101         do_neg_mount_check ${molist[$((RANDOM % 2 ))]}
 102     fi
 103     unmount_check
 104 }
 105 
 106 USAGE="Usage: runtests Test_name Share_opt Mnt_opts"
 107 
 108 if (( $# < 3 )); then
 109         echo "$USAGE"
 110         exit $STF_UNRESOLVED
 111 fi
 112 
 113 typeset Tname=$1
 114 typeset Shropt=$2
 115 typeset Mntopts=$3
 116 
 117 # Check TX related info
 118 check_for_cipso "$SHRDIR" "$MNTDIR" "$Mntopts" || return $STF_UNSUPPORTED
 119 
 120 share_check "$Shropt"
 121 
 122 typeset -i ckro=0 shr_ro=0 mnt_ro=0
 123 shr_ro=$(echo "$Shropt" | \
 124         nawk -F\, '{for (i=1; i<=NF; i++) {if ($i ~ /^ro/) print i} }')
 125 mnt_ro=$(echo "$Mntopts" | \
 126         nawk -F\, '{for (i=1; i<=NF; i++) {if ($i ~ /^ro/) print i} }')
 127 ckro=$((shr_ro | mnt_ro))
 128 
 129 if [[ ,$Shropt, == *,public,* && ,$Mntopts, == *,public,* && \
 130         ,$Mntopts, != @(*,vers=2,*|*,vers=3,*) && \
 131         ! (,$Mntopts, == *,proto=udp,* && $Mntopts != *"vers"*) ]]; then
 132         domount_check "$Mntopts" "$Shropt" "/"
 133         automount_check "$Mntopts" "$Shropt" "BASIC" "/"
 134         do_others "/"
 135 else
 136         domount_check "$Mntopts" "$Shropt"
 137         automount_check "$Mntopts" "$Shropt" "BASIC"
 138         do_others
 139 fi
 140 
 141 # do url mount check
 142 if [[ ,$Shropt, == *,public,* ]]; then
 143         domount_check "URL" "$Mntopts" "$Shropt" "/"
 144         automount_check "URL" "$Mntopts" "$Shropt" "BASIC_URL" "/"
 145         do_others "URL" "/"
 146 else
 147         domount_check "URL" "$Mntopts" "$Shropt"
 148         automount_check "URL" "$Mntopts" "$Shropt" "BASIC_URL"
 149         do_others "URL"
 150 fi
 151 
 152 echo "$NAME: testing complete - Result PASS"
 153 cleanup $STF_PASS