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: shrmnt_optchk
  42 #
  43 # DESCRIPTION:
  44 #   For the mount and export the SERVER's filesystems with
  45 #   other options, including share: public, anon, nosuid;
  46 #   mount: public, rsize, wsize, quota|noquota, intr|nointr
  47 #
  48 # STRATEGY:
  49 #   verify the share and mount/automount behaviors
  50 #
  51 # TESTABILITY: explicit
  52 #
  53 # TEST_AUTOMATION_LEVEL: automated
  54 #
  55 # __stc_assertion_end
  56 #
  57 ################################################################################
  58 
  59 # Function to do interrupt test when mounting fs
  60 #   Usage: do_intr_test mnt_opt
  61 #
  62 function do_intr_test {
  63         typeset Fname=do_intr_test
  64         [[ :$SHAREMNT_DEBUG: == *:${NAME}:* \
  65                 || :$SHAREMNT_DEBUG: == *:$Fname:* \
  66                 || :${SHAREMNT_DEBUG}: == *:all:* ]] && set -x
  67         set -o monitor
  68         typeset mntopt="$*"
  69 
  70         echo "Doing intr access testing at $MNTDIR ... \c"
  71 
  72         # disable the nfs/server
  73         typeset fmri="svc:/network/nfs/server:default"
  74         typeset SRVDEBUG=$STC_GENUTILS_DEBUG:$SHAREMNT_DEBUG
  75         [[ :$SRVDEBUG: == *:RSH:* ]] && SRVDEBUG=all
  76         RSH root $SERVER \
  77                 "export SHAREMNT_DEBUG=$SRVDEBUG; \
  78                 $SRV_TMPDIR/srv_setup -f disable $fmri" \
  79                 > $STF_TMPDIR/rsh.out.$$ 2>&1
  80         rc=$?
  81         [[ :$SRVDEBUG: == *:all:* ]] && cat $STF_TMPDIR/rsh.out.$$
  82         grep "Done" $STF_TMPDIR/rsh.out.$$ > /dev/null 2>&1
  83         if [[ $? != 0 || $rc != 0 ]]; then
  84                 echo "\n$Fname: Failed to disable nfs/server running on $SERVER"
  85                 cat $STF_TMPDIR/rsh.out.$$
  86                 cleanup $STF_FAIL
  87         fi
  88 
  89         # try to kill the hung cat process with INT signal
  90         cat $MNTDIR/rofile > /dev/null 2>&1 &
  91         typeset -i app_pid=$!
  92         /usr/bin/kill -INT $app_pid > /dev/null 2>&1
  93         pgrep cat | grep -w $app_pid > /dev/null 2>&1
  94         typeset -i res=$?
  95         if (( $res == 0 )); then
  96                 kill -9 $app_pid > /dev/null 2>&1
  97                 wait_now 120 "! pgrep cat | grep -w $app_pid > /dev/null 2>&1" 3
  98         fi
  99 
 100         # enable the nfs/server
 101         RSH root $SERVER \
 102                 "export SHAREMNT_DEBUG=$SRVDEBUG; \
 103                 $SRV_TMPDIR/srv_setup -f enable $fmri" \
 104                 > $STF_TMPDIR/rsh.out.$$ 2>&1
 105         rc=$?
 106         [[ :$SRVDEBUG: == *:all:* ]] && cat $STF_TMPDIR/rsh.out.$$
 107         grep "Done" $STF_TMPDIR/rsh.out.$$ > /dev/null 2>&1
 108         if [[ $? != 0 || $rc != 0 ]]; then
 109                 echo "\n$Fname: Failed to enable nfs/server running on $SERVER"
 110                 cat $STF_TMPDIR/rsh.out.$$
 111                 cleanup $STF_FAIL
 112         fi
 113 
 114         # check whether the hung process was/wasn't killed as expected
 115         typeset -i exp_res=1
 116         [[ $mntopt == *nointr* ]] && exp_res=0
 117         if (( $res != $exp_res )); then
 118                 echo "\n$Fname: cat is not as expected, \c"
 119                 (( $res == 0 )) && echo "it is not interruptted" \
 120                         || echo "it is interruptted"
 121                 cleanup $STF_FAIL
 122         fi
 123 
 124         echo "OK"
 125 }
 126 
 127 
 128 # Function to do set uid/gid test
 129 #   Usage: do_sid_test shr_opt
 130 #
 131 function do_sid_test {
 132         typeset Fname=do_sid_test
 133         [[ :$SHAREMNT_DEBUG: == *:${NAME}:* \
 134                 || :$SHAREMNT_DEBUG: == *:$Fname:* \
 135                 || :${SHAREMNT_DEBUG}: == *:all:* ]] && set -x
 136         typeset shropt="$*"
 137         typeset is_sid="set"
 138         typeset exp_sid="set"
 139         [[ $shropt == *nosuid* ]] && exp_sid="not set"
 140         typeset tfile="$MNTDIR/$Fname.out.$$"
 141 
 142         echo "Doing suid testing at $MNTDIR ... \c"
 143 
 144         # create a file and set access permission
 145         rm -f $tfile
 146         touch $tfile
 147         chmod 777 $tfile
 148         typeset perm=$(ls -l $tfile | awk '{print $1}')
 149         if [[ $perm != "-rwxrwxrwx" ]]; then
 150                 echo "\n$Fname: Failed to create $tfile with \c"
 151                 echo "the permission of rwx"
 152                 ls -l $tfile
 153                 rm -f $tfile
 154                 cleanup $STF_FAIL
 155         fi
 156 
 157         # try to enable the file's setuid mode bits and verify
 158         chmod u+s $tfile
 159         [[ ! -u $tfile ]] && is_sid="not set"
 160         if [[ $is_sid != $exp_sid ]]; then
 161                 echo "\n$Fname: the setuid bit is not expected, it is $is_sid"
 162                 ls -l $tfile
 163                 rm -f $tfile
 164                 cleanup $STF_FAIL
 165         fi
 166 
 167         # try to enable the file's setgid mode bits and verify
 168         chmod g+s $tfile
 169         [[ ! -g $tfile ]] && is_sid="not set"
 170         if [[ $is_sid != $exp_sid ]]; then
 171                 echo "\n$Fname: the setgid bit is not expected, it is $is_sid"
 172                 ls -l $tfile
 173                 rm -f $tfile
 174                 cleanup $STF_FAIL
 175         fi
 176 
 177         echo "OK"
 178         rm -f $tfile
 179 }
 180 
 181 # Function to check read/write buffer size
 182 #   Usage: do_rwsize_test mnt_dir mnt_opt
 183 #
 184 function do_rwsize_test {
 185         typeset Fname=do_rwsize_test
 186         [[ :$SHAREMNT_DEBUG: == *:${NAME}:* \
 187                 || :$SHAREMNT_DEBUG: == *:$Fname:* \
 188                 || :${SHAREMNT_DEBUG}: == *:all:* ]] && set -x
 189         typeset mntdir=$1
 190         typeset mntopt=$2
 191 
 192         echo "Doing rsize/wsize check at $mntdir ... \c"
 193         nfsstat -m $mntdir > $STF_TMPDIR/nstat.out.$$ 2>&1
 194         if (( $? != 0 )); then
 195                 echo "\n$Fname: nfsstat $mntdir failed"
 196                 cat $STF_TMPDIR/nstat.out.$$
 197                 cleanup $STF_UNRESOLVED
 198         fi
 199 
 200         typeset -i rsize wsize default_size
 201         typeset MNT_STAT=$(grep "^ Flags:" $STF_TMPDIR/nstat.out.$$ \
 202                 | awk '{print $2}')
 203 
 204         # set initial expected size
 205         for opt in $(echo $mntopt | sed 's/,/ /g'); do
 206                 case $opt in
 207                 rsize=*|wsize=*)
 208                         eval $opt
 209                         ;;
 210                 esac
 211         done
 212 
 213         # get the default size for different nfs version
 214         case $MNT_STAT in
 215         vers=2*)
 216                 default_size=8192 #8K
 217                 ;;
 218         vers=3*)
 219                 default_size=32768 #32K
 220                 ;;
 221         *)
 222                 default_size=1048576 #1M
 223                 ;;
 224         esac
 225 
 226         # set real expected size
 227         (( rsize == 0 || rsize > default_size )) && rsize=default_size
 228         (( wsize == 0 || wsize > default_size )) && wsize=default_size
 229         typeset expt="rsize=$rsize,wsize=$wsize"
 230 
 231         if [[ ,$MNT_STAT, != *,$expt,* ]]; then
 232                 echo "\n$Fname: didn't get correct rsize/wsize \c"
 233                 echo "with mntopt<$mntopt>, expected: $expt"
 234                 cat $STF_TMPDIR/nstat.out.$$
 235                 cleanup $STF_FAIL
 236         fi
 237 
 238         echo "OK"
 239 }
 240 
 241 # Function to check fs quota
 242 #   Usage: do_quota_test mnt_opt
 243 #
 244 function do_quota_test {
 245         typeset Fname=do_quota_test
 246         [[ :$SHAREMNT_DEBUG: == *:${NAME}:* \
 247                 || :$SHAREMNT_DEBUG: == *:$Fname:* \
 248                 || :${SHAREMNT_DEBUG}: == *:all:* ]] && set -x
 249         typeset mntopt=$1
 250 
 251         echo "Doing quota check ... \c"
 252 
 253         # try to make a file with greater size than quota allowed and
 254         # expect to see quota exceed if ZFS
 255         if [[ -n $ZFSPOOL ]]; then
 256                 /usr/sbin/mkfile 3m $MNTDIR/file 2>&1 | \
 257                     grep "Disc quota exceeded" > /dev/null 2>&1
 258                 if (( $? != 0 )); then
 259                         echo "\n$Fname: disk quota is not in effect"
 260                         rm -f $MNTDIR/file*
 261                         cleanup $STF_FAIL
 262                 fi
 263                 echo "OK"
 264                 rm -f $MNTDIR/file*
 265                 return
 266         fi
 267 
 268         # try to make a file with greater size than quota allowed with
 269         # $TUSER01 and expect to see quota exceed
 270         su $TUSER01 -c "/usr/sbin/mkfile 11k $MNTDIR/file" 2>&1 | \
 271                 grep "Disc quota exceeded" > /dev/null 2>&1
 272         if (( $? != 0 )); then
 273                 echo "\n$Fname: disk quota is not in effect"
 274                 rm -f $MNTDIR/file*
 275                 cleanup $STF_FAIL
 276         fi
 277         rm -f $MNTDIR/file*
 278 
 279         # try to make more files than limited number with $TUSER01 and
 280         # expect to see quota exceed too
 281         su $TUSER01 -c "/usr/sbin/mkfile 1k $MNTDIR/file1 $MNTDIR/file2 \
 282                 $MNTDIR/file3 $MNTDIR/file4" 2>&1
 283         if (( $? != 0 )); then
 284                 echo "\n$Fname: expect to create 4 files, but failed"
 285                 quota -v $TUSER01
 286                 rm -f $MNTDIR/file*
 287                 cleanup $STF_FAIL
 288         fi
 289         su $TUSER01 -c "/usr/sbin/mkfile 1k $MNTDIR/file5" 2>&1 | \
 290                 grep "Disc quota exceeded" > /dev/null 2>&1
 291         if (( $? != 0 )); then
 292                 echo "\n$Fname: file quota is not in effect"
 293                 rm -f $MNTDIR/file*
 294                 cleanup $STF_FAIL
 295         fi
 296 
 297         # check quota of $TUSER01
 298         quota -v $TUSER01 > $STF_TMPDIR/quota.out.$$ 2>&1
 299         if (( $? != 0 )); then
 300                 echo "\n$Fname: quota -v $TUSER01 failed"
 301                 cat $STF_TMPDIR/quota.out.$$
 302                 rm -f $MNTDIR/file*
 303                 cleanup $STF_FAIL
 304         fi
 305 
 306         typeset out=$(grep "$MNTDIR" $STF_TMPDIR/quota.out.$$)
 307         if [[ ,$mntopt, != *,noquota,* ]]; then
 308                 if [[ $out != $MNTDIR ]]; then
 309                         echo "\n$Fname: quota failed"
 310                         cat $STF_TMPDIR/quota.out.$$
 311                         rm -f $MNTDIR/file*
 312                         cleanup $STF_FAIL
 313                 fi
 314                 out=$(tail -1 $STF_TMPDIR/quota.out.$$ | awk '{print $3,$6}')
 315                 if [[ $out != "10 5" ]]; then
 316                         echo "\n$Fname: didn't get correct quota"
 317                         cat $STF_TMPDIR/quota.out.$$
 318                         rm -f $MNTDIR/file*
 319                         cleanup $STF_FAIL
 320                 fi
 321         fi
 322 
 323         echo "OK"
 324         rm -f $MNTDIR/file*
 325 }
 326 
 327 function check_for_quotadir {
 328         typeset Fname=check_for_quotadir
 329         [[ :$SHAREMNT_DEBUG: == *:${NAME}:* \
 330                 || :$SHAREMNT_DEBUG: == *:$Fname:* \
 331                 || :${SHAREMNT_DEBUG}: == *:all:* ]] && set -x
 332 
 333         typeset quota_dir=$1
 334         if [[ -n $ZFSPOOL ]]; then
 335                 #
 336                 # If quoda_dir is based on UFS, and server is rebooted,
 337                 # setup for quota_dir via LOFI will be lost;
 338                 # If quota_dir is based on ZFS, even if server is rebooted, 
 339                 # setup for quota_dir via zfs is always there.
 340                 #
 341                 return 0
 342         fi
 343 
 344         RSH root $SERVER \
 345                 "/bin/df -n /dev/lofi/* | grep ${quota_dir}:" \
 346                 > /dev/null 2>&1
 347         if (( $? != 0 )); then
 348                 echo "$NAME: current test is based on UFS,"
 349                 echo "setup for quota test at<$quota_dir> not found"
 350                 return 1
 351         fi
 352 
 353         return 0
 354 }
 355 
 356 typeset Tname=$1
 357 typeset opt1=$2
 358 typeset opt2=$3
 359 
 360 case $Tname in
 361 MNT_INTR*)
 362         check_for_cipso "$SHRDIR" "$MNTDIR" "$opt1" || return $STF_UNSUPPORTED
 363         share_check "rw"
 364         domount_check $opt1
 365         do_intr_test $opt1
 366         ;;
 367 SH_SUID*)
 368         check_for_cipso "$SHRDIR" "$MNTDIR" "$opt2" || return $STF_UNSUPPORTED
 369         [[ $opt1 == "nosuid" ]] && share_check $opt1 || share_check "rw"
 370         domount_check $opt2
 371         automount_check $opt2
 372         do_sid_test $opt1
 373         ;;
 374 MNT_SIZE*)
 375         check_for_cipso "$SHRDIR" "$MNTDIR" "$opt1" || return $STF_UNSUPPORTED
 376         share_check "rw"
 377         domount_check $opt1
 378         automount_check $opt1
 379         do_rwsize_test $MNTDIR $opt1
 380         ;;
 381 MNT_QUOTA*)
 382         check_for_cipso "$QUOTADIR" "$MNTDIR" "$opt1" || \
 383             return $STF_UNSUPPORTED
 384         check_for_quotadir "$QUOTADIR" || return $STF_UNTESTED
 385         share_check "rw" $QUOTADIR
 386         domount_check "$opt1" "rw" $QUOTADIR
 387         automount_check "$opt1" "rw" "QUOTA" $QUOTADIR
 388         do_quota_test "$opt1"
 389         ;;
 390 *)
 391         echo "$Tname: error - it is unreachable - Result FAIL"
 392         exit $STF_UNRESOLVED
 393         ;;
 394 esac
 395 
 396 unmount_check
 397 
 398 echo "$NAME: testing complete - Result PASS"
 399 cleanup $STF_PASS