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 # Setup the SERVER for stress test
  30 #
  31 
  32 NAME=$(basename $0)
  33 PROG=$0
  34 
  35 Usage="Usage: $NAME -s | -c | -t OPTARG | -h path\n
  36                 -s: to setup this host for stress test\n
  37                 -c: to cleanup the server for stress test\n
  38                 -t: to run stress_001/2/3/4 or cleanup_001/2\n
  39                 -h: to share/unshare path\n
  40 "
  41 if (( $# < 1 )); then
  42         echo $Usage
  43         exit 99
  44 fi
  45 
  46 # variables gotten from client system:
  47 STF_TMPDIR=STF_TMPDIR_from_client
  48 SHAREMNT_DEBUG=${SHAREMNT_DEBUG:-"SHAREMNT_DEBUG_from_client"}
  49 STRESS_TIMEOUT=STRESS_TIMEOUT_from_client
  50 NUM_SHARES=NUM_SHARES_from_client
  51 NUM_GROUPS=NUM_GROUPS_from_client
  52 NUM_ENTRYS=NUM_ENTRYS_from_client
  53 
  54 ZONENAME=$(zonename)
  55 NUM=$((NUM_GROUPS * NUM_ENTRYS))
  56 
  57 . $STF_TMPDIR/srv_config.vars
  58 
  59 # Include common STC utility functions
  60 if [[ -s $STC_GENUTILS/include/nfs-util.kshlib ]]; then
  61         . $STC_GENUTILS/include/nfs-util.kshlib
  62 else
  63         . $STF_TMPDIR/nfs-util.kshlib
  64 fi
  65 
  66 # cleanup function on all exit
  67 function cleanup {
  68         [[ :$SHAREMNT_DEBUG: == *:$NAME:* \
  69                 || :$SHAREMNT_DEBUG: == *:all:* ]] && set -x
  70 
  71         # Restore original /etc/dfs/dfstab files
  72         [[ $2 == "t" && -f /etc/dfs/dfstab.sharemnt.stress ]] && \
  73                 mv /etc/dfs/dfstab.sharemnt.stress /etc/dfs/dfstab
  74 
  75         rm -fr $STF_TMPDIR/*.$$
  76         exit $1
  77 }
  78 
  79 # do clean up of share groups forcibly
  80 function cleanup_sharemgr {
  81         [[ :$SHAREMNT_DEBUG: == *:$NAME:* \
  82                 || :$SHAREMNT_DEBUG: == *:all:* ]] && set -x
  83 
  84         sharemgr list -P nfs | grep "^shmgr_grp_" > $STF_TMPDIR/grp.out.$$
  85         typeset -i num=$(wc -l $STF_TMPDIR/grp.out.$$ | nawk '{print $1}')
  86         if (( $num > 0 )); then
  87                 while read agroup; do
  88                         sharemgr delete -f $agroup \
  89                                 >> $STF_TMPDIR/grp.del.$$ 2>&1 &
  90                 done < $STF_TMPDIR/grp.out.$$
  91         fi
  92         # wait for all delete commands in background to finish
  93         condition="! pgrep -z $ZONENAME -P $$ -x sharemgr > /dev/null"
  94         wait_now $STRESS_TIMEOUT "$condition" 3
  95         if (( $? != 0 )); then
  96                 echo "ERROR: timeout<$STRESS_TIMEOUT secs> for \c"
  97                 echo "deleting share groups..."
  98                 ps -efz $ZONENAME | grep "sharemgr"
  99                 cat $STF_TMPDIR/grp.del.$$
 100                 pkill -z $ZONENAME -P $$ -x sharemgr
 101         fi
 102         # check there is no any group more
 103         sharemgr list -P nfs | grep "^shmgr_grp_" > $STF_TMPDIR/grp.out.$$
 104         num=$(wc -l $STF_TMPDIR/grp.out.$$ | nawk '{print $1}')
 105         if (( $num > 0 )); then
 106                 echo "ERROR: Still find $num groups remained"
 107                 echo "\tyou need to cleanup them manually!"
 108                 cat $STF_TMPDIR/grp.out.$$
 109         fi
 110 
 111         cleanup 1
 112 }
 113 
 114 # Turn on debug info, if requested
 115 export STC_GENUTILS_DEBUG=$SHAREMNT_DEBUG
 116 [[ :$SHAREMNT_DEBUG: == *:$NAME:* \
 117         || :$SHAREMNT_DEBUG: == *:all:* ]] && set -x
 118 
 119 getopts sct:h: opt
 120 case $opt in
 121 s)
 122         if [[ ! -d $STRESSDIR ]]; then
 123                 mkdir -pm 0777 $STRESSDIR
 124                 (( $? != 0 )) && \
 125                         echo "could not create $STRESSDIR" && exit 1
 126         fi
 127 
 128         typeset -i i=0
 129         typeset -i j=$((NUM_SHARES + 1))
 130         (( $j < $NUM )) && j=$NUM
 131         while (( $i < $j )); do
 132                 mkdir -p $STRESSDIR/sharemnt_${i}_stress
 133 
 134                 # set up ZFS
 135                 if [[ -n $ZFSPOOL ]] && (( $i <= $NUM_SHARES )); then
 136                         create_zfs_fs $ZFSBASE $STRESSDIR/sharemnt_${i}_stress \
 137                                 > $STF_TMPDIR/zfs.out.$$ 2>&1
 138                         if (( $? != 0 )); then
 139                                 echo "$NAME: failed to create_zfs_fs \c"
 140                                 echo "$STRESSDIR/$sharemnt_${i}_stress"
 141                                 cat $STF_TMPDIR/zfs.out.$$
 142                                 cleanup 2
 143                         fi
 144                 fi
 145                 let i+=1
 146         done
 147         echo "Done - Setup OKAY"
 148         ;;
 149 t)
 150         # define share options with an array
 151         set -A SHOPT rw ro anon=0 nosuid ro=$CLIENT_S sec=sys
 152 
 153         # make sure there is no test dirs exported on server
 154         if [[ $OPTARG != cleanup* ]]; then
 155                 cat $SHARETAB | grep $STRESSDIR/sharemnt_ \
 156                         > $STF_TMPDIR/share.out.$$ 2>&1
 157                 if (( $? == 0 )); then
 158                         echo "ERROR: Some test dirs<$STRESSDIR/sharemnt_> \c"
 159                         echo " were exported before the testing, \c"
 160                         echo " please unshare them."
 161                         cat $STF_TMPDIR/share.out.$$
 162                         cleanup 1
 163                 fi
 164         fi
 165 
 166         case $OPTARG in
 167         stress_001)
 168                 mv /etc/dfs/dfstab /etc/dfs/dfstab.sharemnt.stress \
 169                         > $STF_TMPDIR/dfstab.backup.$$ 2>&1
 170                 if (( $? != 0 )); then
 171                         echo "ERROR: failed to backup /etc/dfs/dfstab"
 172                         cat $STF_TMPDIR/dfstab.backup.$$
 173                         cleanup 1 t
 174                 fi
 175 
 176                 typeset -i i=0
 177                 touch /etc/dfs/dfstab
 178                 while (( $i < $NUM_SHARES )); do
 179                         let k=i%6
 180                         echo "share -o ${SHOPT[$k]} $STRESSDIR/sharemnt_${i}_stress" \
 181                                 >> /etc/dfs/dfstab
 182                         let i+=1
 183                 done
 184                 entries=$(wc -l /etc/dfs/dfstab | nawk '{print $1}')
 185                 if (( $entries != $NUM_SHARES )); then
 186                         echo "ERROR: failed to add $NUM_SHARES entries in \c"
 187                         echo "/etc/dfs/dfstab, got $entries entries"
 188                         echo "======== /etc/dfs/dfstab ========="
 189                         cat /etc/dfs/dfstab
 190                         echo "===================================="
 191                         cleanup 1 t
 192                 fi
 193 
 194                 ksh "time shareall" > $STF_TMPDIR/time.out.$$ 2>&1
 195                 if (( $? != 0 )); then
 196                         echo "ERROR: shareall failed."
 197                         cat $STF_TMPDIR/time.out.$$
 198                         cat $SHARETAB
 199                         cleanup 1 t
 200                 fi
 201 
 202                 # check the filesystems are shared successfully
 203                 condition="(( \$(cat $SHARETAB \
 204                         | grep $STRESSDIR/sharemnt_ | wc -l \
 205                         | nawk '{print \$1}') == $NUM_SHARES ))"
 206                 wait_now 600 "$condition"
 207                 if (( $? != 0 )); then
 208                         num=$(cat $SHARETAB \
 209                                 | grep $STRESSDIR/sharemnt_ \
 210                                 | wc -l | nawk '{print $1}')
 211                         echo "ERROR: expected $NUM_SHARES entries in \c"
 212                         echo "$SHARETAB, but got $num entries"
 213                         echo "======== $SHARETAB ========="
 214                         cat $SHARETAB
 215                         echo "======== /etc/dfs/dfstab ========="
 216                         cat /etc/dfs/dfstab
 217                         echo "===================================="
 218                         cleanup 1 t
 219                 fi
 220 
 221                 # also check all filesystems are shared with correct options
 222                 i=0
 223                 while (( $i < $NUM_SHARES )); do
 224                         k=$((i % 6))
 225                         grep $STRESSDIR/sharemnt_${i}_stress $SHARETAB \
 226                                 > $STF_TMPDIR/share.out.$$ 2>&1
 227                         if (( $? != 0 )); then
 228                                 echo "ERROR: $STRESSDIR/sharemnt_${i}_stress \c"
 229                                 echo "wasn't shared"
 230                                 cleanup 1 t
 231                         fi
 232                         grep ${SHOPT[$k]} $STF_TMPDIR/share.out.$$ \
 233                                 > /dev/null 2>&1
 234                         if (( $? != 0 )); then
 235                                 echo "ERROR: $STRESSDIR/sharemnt_${i}_stress \c"
 236                                 echo "shared with incorrect option, expected \c"
 237                                 echo "${SHOPT[$k]}, but got :"
 238                                 cat $STF_TMPDIR/share.out.$$
 239                                 cleanup 1 t
 240                         fi
 241 
 242                         i=$((i+1))
 243                 done
 244 
 245                 echo "\nThe time of sharing $NUM_SHARES entries :"
 246                 cat $STF_TMPDIR/time.out.$$
 247         
 248                 ksh "time share -F nfs $STRESSDIR/sharemnt_${i}_stress" \
 249                         > $STF_TMPDIR/time.out.$$ 2>&1
 250                 if (( $? != 0 )); then
 251                         echo "ERROR: failed to share \c"
 252                         echo "$STRESSDIR/sharemnt_${i}_stress"
 253                         cat $STF_TMPDIR/time.out.$$
 254                         cleanup 1 t
 255                 fi
 256 
 257                 echo "\nThe time of sharing one more entry :"
 258                 cat $STF_TMPDIR/time.out.$$
 259                 echo " "
 260                 echo "$NAME: share testing complete - Result PASS"
 261 
 262                 cleanup 0 t
 263                 ;;
 264         stress_002)
 265                 mv /etc/dfs/dfstab /etc/dfs/dfstab.sharemnt.stress \
 266                         > $STF_TMPDIR/dfstab.backup.$$ 2>&1
 267                 if (( $? != 0 )); then
 268                         echo "ERROR: failed to backup /etc/dfs/dfstab"
 269                         cat $STF_TMPDIR/dfstab.backup.$$
 270                         cleanup 1 t
 271                 fi
 272                 touch /etc/dfs/dfstab
 273 
 274                 # set sharenfs to on, then all zfs are shared
 275                 ksh "time zfs set sharenfs=on $ZFSBASE" \
 276                         > $STF_TMPDIR/time.out.$$ 2>&1
 277                 if (( $? != 0 )); then
 278                         echo "ERROR: setting sharenfs=on failed."
 279                         cat $STF_TMPDIR/time.out.$$
 280                         cat $SHARETAB
 281                         cleanup 1 t
 282                 fi
 283 
 284                 # Normally, new created zfs are all shared, so we can
 285                 # get $NUM_SHARES + 1 entries. But for zfs, occasionally
 286                 # some entries are duplicated so here we only check if the
 287                 # shared number is more than $NUM_SHARES.
 288                 # The check is not enough due to the duplication,
 289                 # if there aren't $NUM_SHARES+1 entries directories exported,
 290                 # we still meet failures when mounting these dirs.
 291                 condition="(( \$(cat $SHARETAB \
 292                         | grep $STRESSDIR/sharemnt_ | wc -l \
 293                         | nawk '{print \$1}') > $NUM_SHARES ))"
 294                 wait_now 600 "$condition"
 295                 if (( $? != 0 )); then
 296                         expected=$((NUM_SHARES + 1))
 297                         num=$(cat $SHARETAB \
 298                                 | grep $STRESSDIR/sharemnt_ \
 299                                 | wc -l | nawk '{print $1}')
 300                         echo "ERROR: expected $expected entries in \c"
 301                         echo "$SHARETAB, but got $num entries"
 302                         echo "======== $SHARETAB ========="
 303                         cat $SHARETAB
 304                         echo "===================================="
 305                         cleanup 1 t
 306                 fi
 307 
 308                 echo "\nThe time of sharing $NUM_SHARES entries :"
 309                 cat $STF_TMPDIR/time.out.$$
 310 
 311                 unshare $STRESSDIR/sharemnt_0_stress \
 312                         > $STF_TMPDIR/unshare.out.$$ 2>&1
 313                 sleep 10
 314                 cat $SHARETAB | grep $STRESSDIR/sharemnt_0_stress \
 315                         > /dev/null 2>&1
 316                 if (( $? == 0 )); then
 317                         echo "ERROR: failed to unshare \c"
 318                         echo "$STRESSDIR/sharemnt_0_stress"
 319                         cat $STF_TMPDIR/unshare.out.$$
 320                         cleanup 1 t
 321                 fi
 322 
 323                 ksh "time share -F nfs $STRESSDIR/sharemnt_0_stress" \
 324                         > $STF_TMPDIR/time.out.$$ 2>&1
 325                 if (( $? != 0 )); then
 326                         echo "ERROR: failed to share \c"
 327                         echo "$STRESSDIR/sharemnt_0_stress"
 328                         cat $STF_TMPDIR/time.out.$$
 329                         cleanup 1 t
 330                 fi
 331 
 332                 echo "\nThe time of sharing one more entry :"
 333                 cat $STF_TMPDIR/time.out.$$
 334                 echo " "
 335                 echo "$NAME: share testing complete - Result PASS"
 336 
 337                 cleanup 0 t
 338                 ;;
 339         stress_003)
 340                 typeset -i i=0 k=0 j=0 num_in_grp=5 Total=200
 341                 while (( i < Total )); do
 342                         let k=i%6
 343                         $PROG -h ${SHOPT[$k]} $STRESSDIR/sharemnt_${i}_stress \
 344                                 >> $STF_TMPDIR/stress.out.$$ 2>&1 &
 345                         let i+=1
 346                         let j+=1
 347                         if (( j == num_in_grp || i == Total )); then
 348                                 j=0
 349                                 wait
 350                         fi
 351                 done
 352 
 353                 grep "ERROR:" $STF_TMPDIR/stress.out.$$ > /dev/null 2>&1
 354                 if (( $? == 0 )); then
 355                         echo "ERROR: some share/unshare failed."
 356                         cat $STF_TMPDIR/stress.out.$$
 357                         cleanup 1
 358                 fi
 359 
 360                 echo "$NAME: share/unshare testing complete - Result PASS"
 361                 cleanup 0
 362                 ;;
 363         stress_004)
 364                 # make sure there is no test group created on server
 365                 sharemgr list -P nfs | grep "^shmgr_grp_" \
 366                         > $STF_TMPDIR/grp.out.$$
 367                 num=$(wc -l $STF_TMPDIR/grp.out.$$ | nawk '{print $1}')
 368                 if (( $num > 0 )); then
 369                         echo "ERROR: $num test groups<shmgr_grp_> \c"
 370                         echo " were created before the testing, \c"
 371                         echo " please delete them."
 372                         cat $STF_TMPDIR/grp.out.$$
 373                         cleanup 1
 374                 fi
 375 
 376                 # step 1. create groups:
 377                 typeset -i i=0
 378                 while (( $i <= $NUM_GROUPS )); do
 379                         sharemgr create -P nfs shmgr_grp_$i \
 380                                 >> $STF_TMPDIR/grp.create.$$ 2>&1 &
 381                         i=$((i + 1))
 382                 done
 383                 # wait for all create commands in background to finish
 384                 condition="! pgrep -z $ZONENAME -P $$ -x sharemgr > /dev/null"
 385                 wait_now $STRESS_TIMEOUT "$condition" 3
 386                 if (( $? != 0 )); then
 387                         echo "ERROR: timeout<$STRESS_TIMEOUT secs> for \c"
 388                         echo "creating share groups..."
 389                         ps -efz $ZONENAME | grep "sharemgr"
 390                         cat $STF_TMPDIR/grp.create.$$
 391                         pkill -z $ZONENAME -P $$ -x sharemgr
 392                         cleanup_sharemgr
 393                 fi
 394                 # check number of created groups
 395                 sharemgr list -v -P nfs | grep "^shmgr_grp_" \
 396                         > $STF_TMPDIR/grp.out.$$
 397                 num=$(grep -w enabled $STF_TMPDIR/grp.out.$$ | wc -l \
 398                         | nawk '{print $1}')
 399                 expected=$((NUM_GROUPS + 1))
 400                 if (( $num != $expected )); then
 401                         echo "ERROR: sharemgr create group was unsuccessful"
 402                         echo "\tExpected to see $expected enabled groups, \c"
 403                         echo "but got $num"
 404                         cat $STF_TMPDIR/grp.out.$$
 405                         cleanup_sharemgr
 406                 fi
 407 
 408                 # step 2. add-share:
 409                 i=0
 410                 while (( $i < $NUM )); do
 411                         sharemgr add-share -s $STRESSDIR/sharemnt_${i}_stress \
 412                                 shmgr_grp_$NUM_GROUPS >> \
 413                                 $STF_TMPDIR/grp.addshr.$$ 2>&1 &
 414                         i=$((i + 1))
 415                 done
 416                 # wait for all add-share commands in background to finish
 417                 condition="! pgrep -z $ZONENAME -P $$ -x sharemgr > /dev/null"
 418                 wait_now $STRESS_TIMEOUT "$condition" 3
 419                 if (( $? != 0 )); then
 420                         echo "ERROR: timeout<$STRESS_TIMEOUT secs> for \c"
 421                         echo "adding share pathes to group..."
 422                         ps -efz $ZONENAME | grep "sharemgr"
 423                         cat $STF_TMPDIR/grp.addshr.$$
 424                         pkill -z $ZONENAME -P $$ -x sharemgr
 425                         cleanup_sharemgr
 426                 fi
 427                 # check number of entries in the last group
 428                 sharemgr show shmgr_grp_$NUM_GROUPS | grep -v \
 429                     "^shmgr_grp_$NUM_GROUPS" > $STF_TMPDIR/entry.out.$$
 430                 num=$(wc -l $STF_TMPDIR/entry.out.$$ | nawk '{print $1}')
 431                 if (( $num != $NUM )); then
 432                         echo "ERROR: sharemgr add-share was unsuccessful"
 433                         echo "\tExpected to see $NUM entries in the last \c"
 434                         echo "group, but got $num"
 435                         cat $STF_TMPDIR/entry.out.$$
 436                         cleanup_sharemgr
 437                 fi
 438                 # check number of shares
 439                 grep $STRESSDIR/sharemnt_ $SHARETAB > $STF_TMPDIR/share.out.$$
 440                 num=$(wc -l $STF_TMPDIR/share.out.$$ | nawk '{print $1}')
 441                 if (( $num != $NUM )); then
 442                         echo "ERROR: sharemgr add-share was unsuccessful"
 443                         echo "\tExpected to see $NUM shares, but got $num"
 444                         cat $STF_TMPDIR/share.out.$$
 445                         cleanup_sharemgr
 446                 fi
 447 
 448                 # step 3. move-share:
 449                 i=0
 450                 while (( $i < $NUM )); do
 451                         k=$((i % NUM_GROUPS))
 452                         sharemgr move-share -s $STRESSDIR/sharemnt_${i}_stress \
 453                                 shmgr_grp_$k >> $STF_TMPDIR/grp.mvshr.$$ 2>&1 &
 454                         i=$((i + 1))
 455                 done
 456                 # wait for all move-share commands in background to finish
 457                 condition="! pgrep -z $ZONENAME -P $$ -x sharemgr > /dev/null"
 458                 wait_now $STRESS_TIMEOUT "$condition" 3
 459                 if (( $? != 0 )); then
 460                         echo "ERROR: timeout<$STRESS_TIMEOUT secs> for \c"
 461                         echo "moving share pathes to different groups..."
 462                         ps -efz $ZONENAME | grep "sharemgr"
 463                         cat $STF_TMPDIR/grp.mvshr.$$
 464                         pkill -z $ZONENAME -P $$ -x sharemgr
 465                         cleanup_sharemgr
 466                 fi
 467                 # check number of entries in each group
 468                 i=0
 469                 while (( $i < $NUM_GROUPS )); do
 470                         sharemgr show shmgr_grp_$i | grep -v "^shmgr_grp_$i" \
 471                                 > $STF_TMPDIR/entry.out.$$
 472                         num=$(wc -l $STF_TMPDIR/entry.out.$$ | \
 473                             nawk '{print $1}')
 474                         if (( $num != $NUM_ENTRYS )); then
 475                             echo "ERROR: sharemgr move-share was unsuccessful"
 476                             echo "\tExpected to see $NUM_ENTRYS entries in \c"
 477                             echo "shmgr_grp_$i group, but got $num"
 478                             cat $STF_TMPDIR/entry.out.$$
 479                             cleanup_sharemgr
 480                         fi
 481                         i=$((i + 1))
 482                 done
 483                 # check there is no entry in the last group now
 484                 sharemgr show shmgr_grp_$NUM_GROUPS | grep -v \
 485                     "^shmgr_grp_$NUM_GROUPS" > $STF_TMPDIR/entry.out.$$
 486                 num=$(wc -l $STF_TMPDIR/entry.out.$$ | nawk '{print $1}')
 487                 if (( $num > 0 )); then
 488                         echo "ERROR: sharemgr move-share was unsuccessful"
 489                         echo "\tStill find $num entries in the last group"
 490                         cat $STF_TMPDIR/entry.out.$$
 491                         cleanup_sharemgr
 492                 fi
 493                 # check number of shares again
 494                 grep $STRESSDIR/sharemnt_ $SHARETAB > $STF_TMPDIR/share.out.$$
 495                 num=$(wc -l $STF_TMPDIR/share.out.$$ | nawk '{print $1}')
 496                 if (( $num != $NUM )); then
 497                         echo "ERROR: sharemgr move-share was unsuccessful"
 498                         echo "\tExpected to see $NUM shares, but got $num"
 499                         cat $STF_TMPDIR/share.out.$$
 500                         cleanup_sharemgr
 501                 fi
 502 
 503                 # step 4. set-share:
 504                 # NOTICE: -r resource-name is not checked due to bug 6654535,
 505                 # after this issue is resolved, we must enable this check
 506                 # again in the future.
 507                 i=0
 508                 while (( $i < $NUM )); do
 509                         k=$((i % NUM_GROUPS))
 510                         sharemgr set-share -d "directory $i" \
 511                                 -s $STRESSDIR/sharemnt_${i}_stress shmgr_grp_$k \
 512                                 >> $STF_TMPDIR/grp.setshr.$$ 2>&1 &
 513                         i=$((i + 1))
 514                 done
 515                 # wait for all set-share commands in background to finish
 516                 condition="! pgrep -z $ZONENAME -P $$ -x sharemgr > /dev/null"
 517                 wait_now $STRESS_TIMEOUT "$condition" 3
 518                 if (( $? != 0 )); then
 519                         echo "ERROR: timeout<$STRESS_TIMEOUT secs> for \c"
 520                         echo "setting entries' properties..."
 521                         ps -efz $ZONENAME | grep "sharemgr"
 522                         cat $STF_TMPDIR/grp.setshr.$$
 523                         pkill -z $ZONENAME -P $$ -x sharemgr
 524                         cleanup_sharemgr
 525                 fi
 526                 # check property of each entry
 527                 sharemgr show -v -P nfs > $STF_TMPDIR/entry.out.$$
 528                 i=0
 529                 while (( $i < $NUM ));do
 530                         grep "$STRESSDIR/sharemnt_${i}_stress" \
 531                             $STF_TMPDIR/entry.out.$$ | grep "directory $i" \
 532                             > /dev/null
 533                         if (( $? != 0 )); then
 534                             echo "ERROR: sharemgr set-share was unsuccessful"
 535                             echo "\tCannot find \"directory $i\" property \c"
 536                             echo "from $STRESSDIR/sharemnt_${i}_stress entry"
 537                             cat $STF_TMPDIR/entry.out.$$
 538                             cleanup_sharemgr
 539                         fi
 540                         i=$((i + 1))
 541                 done
 542 
 543                 # step 5. set groups:
 544                 i=0
 545                 while (( $i <= $NUM_GROUPS )); do
 546                         sharemgr set -P nfs -p anon="1234" shmgr_grp_$i
 547                                 >> $STF_TMPDIR/grp.set.$$ 2>&1 &
 548                         i=$((i + 1))
 549                 done
 550                 # wait for all set commands in background to finish
 551                 condition="! pgrep -z $ZONENAME -P $$ -x sharemgr > /dev/null"
 552                 wait_now $STRESS_TIMEOUT "$condition" 3
 553                 if (( $? != 0 )); then
 554                         echo "ERROR: timeout<$STRESS_TIMEOUT secs> for \c"
 555                         echo "setting groups' properties..."
 556                         ps -efz $ZONENAME | grep "sharemgr"
 557                         cat $STF_TMPDIR/grp.set.$$
 558                         pkill -z $ZONENAME -P $$ -x sharemgr
 559                         cleanup_sharemgr
 560                 fi
 561                 # check property of each group
 562                 i=0
 563                 while (( $i <= $NUM_GROUPS )); do
 564                         sharemgr show -p shmgr_grp_$i > $STF_TMPDIR/grp.prop.$$
 565                         grep "^shmgr_grp_$i " $STF_TMPDIR/grp.prop.$$ | grep \
 566                                 "nfs=(anon=\"1234\")" > /dev/null
 567                         if (( $? != 0 )); then
 568                             echo "ERROR: sharemgr set group was unsuccessful"
 569                             echo "\tCannot find nfs=(anon=\"1234\") property \c"
 570                             echo "from shmgr_grp_$i group"
 571                             cat $STF_TMPDIR/grp.prop.$$
 572                             cleanup_sharemgr
 573                         fi
 574                         i=$((i + 1))
 575                 done
 576                 # check property of each entry
 577                 grep $STRESSDIR/sharemnt_ $SHARETAB > $STF_TMPDIR/entry.prop.$$
 578                 i=0
 579                 while (( $i < $NUM ));do
 580                         grep "$STRESSDIR/sharemnt_${i}_stress" \
 581                             $STF_TMPDIR/entry.prop.$$ | grep "anon=1234" \
 582                             > /dev/null
 583                         if (( $? != 0 )); then
 584                             echo "ERROR: sharemgr set group was unsuccessful"
 585                             echo "\tCannot find \"anon=1234\" property \c"
 586                             echo "from $STRESSDIR/sharemnt_${i}_stress entry"
 587                             cat $STF_TMPDIR/entry.prop.$$
 588                             cleanup_sharemgr
 589                         fi
 590                         i=$((i + 1))
 591                 done
 592 
 593                 # step 6. unset groups:
 594                 i=0
 595                 while (( $i <= $NUM_GROUPS )); do
 596                         sharemgr unset -P nfs -p anon shmgr_grp_$i
 597                                 >> $STF_TMPDIR/grp.unset.$$ 2>&1 &
 598                         i=$((i + 1))
 599                 done
 600                 # wait for all unset commands in background to finish
 601                 condition="! pgrep -z $ZONENAME -P $$ -x sharemgr > /dev/null"
 602                 wait_now $STRESS_TIMEOUT "$condition" 3
 603                 if (( $? != 0 )); then
 604                         echo "ERROR: timeout<$STRESS_TIMEOUT secs> for \c"
 605                         echo "unsetting groups' properties..."
 606                         ps -efz $ZONENAME | grep "sharemgr"
 607                         cat $STF_TMPDIR/grp.unset.$$
 608                         pkill -z $ZONENAME -P $$ -x sharemgr
 609                         cleanup_sharemgr
 610                 fi
 611                 # check property of groups
 612                 sharemgr show -p -P nfs | grep "^shmgr_grp_" \
 613                         > $STF_TMPDIR/grp.prop.$$
 614                 grep -w anon $STF_TMPDIR/grp.prop.$$ > /dev/null
 615                 if (( $? == 0 )); then
 616                         echo "ERROR: sharemgr unset group was unsuccessful"
 617                         echo "\tStill find anon property from some groups"
 618                         cat $STF_TMPDIR/grp.prop.$$
 619                         cleanup_sharemgr
 620                 fi
 621                 # check property of entries
 622                 grep $STRESSDIR/sharemnt_ $SHARETAB > $STF_TMPDIR/entry.prop.$$
 623                 grep -w anon $STF_TMPDIR/entry.prop.$$ > /dev/null
 624                 if (( $? == 0 )); then
 625                         echo "ERROR: sharemgr unset group was unsuccessful"
 626                         echo "\tStill find anon property from some entries"
 627                         cat $STF_TMPDIR/entry.prop.$$
 628                         cleanup_sharemgr
 629                 fi
 630 
 631                 # step 7. disable groups:
 632                 sharemgr disable -va > $STF_TMPDIR/grp.disable.$$ 2>&1
 633                 if (( $? != 0 )); then
 634                         echo "ERROR: sharemgr disable was unsuccessful"
 635                         cat $STF_TMPDIR/grp.disable.$$
 636                         cleanup_sharemgr
 637                 fi
 638                 # check number of disabled groups
 639                 sharemgr list -v -P nfs | grep "^shmgr_grp_" \
 640                         > $STF_TMPDIR/grp.out.$$
 641                 num=$(grep -w disabled $STF_TMPDIR/grp.out.$$ | wc -l \
 642                         | nawk '{print $1}')
 643                 expected=$((NUM_GROUPS + 1))
 644                 if (( $num != $expected )); then
 645                         echo "ERROR: sharemgr disable was unsuccessful"
 646                         echo "\tExpected to see $expected disabled groups, \c"
 647                         echo "but got $num"
 648                         cat $STF_TMPDIR/grp.out.$$
 649                         cleanup_sharemgr
 650                 fi
 651                 # check there is no test dirs exported
 652                 grep $STRESSDIR/sharemnt_ $SHARETAB > $STF_TMPDIR/share.out.$$
 653                 num=$(wc -l $STF_TMPDIR/share.out.$$ | nawk '{print $1}')
 654                 if (( $num > 0 )); then
 655                         echo "ERROR: sharemgr disable was unsuccessful"
 656                         echo "\tStill find $num shared entries"
 657                         cat $STF_TMPDIR/share.out.$$
 658                         cleanup_sharemgr
 659                 fi
 660 
 661                 # step 8. enable groups:
 662                 sharemgr enable -va > $STF_TMPDIR/grp.enable.$$ 2>&1
 663                 if (( $? != 0 )); then
 664                         echo "ERROR: sharemgr enable was unsuccessful"
 665                         cat $STF_TMPDIR/grp.enable.$$
 666                         cleanup_sharemgr
 667                 fi
 668                 # check number of enabled groups
 669                 sharemgr list -v -P nfs | grep "^shmgr_grp_" \
 670                         > $STF_TMPDIR/grp.out.$$
 671                 num=$(grep -w enabled $STF_TMPDIR/grp.out.$$ | wc -l \
 672                         | nawk '{print $1}')
 673                 expected=$((NUM_GROUPS + 1))
 674                 if (( $num != $expected )); then
 675                         echo "ERROR: sharemgr enable was unsuccessful"
 676                         echo "\tExpected to see $expected enabled groups, \c"
 677                         echo "but got $num"
 678                         cat $STF_TMPDIR/grp.out.$$
 679                         cleanup_sharemgr
 680                 fi
 681                 # check number of shares again
 682                 grep $STRESSDIR/sharemnt_ $SHARETAB > $STF_TMPDIR/share.out.$$
 683                 num=$(wc -l $STF_TMPDIR/share.out.$$ | nawk '{print $1}')
 684                 if (( $num != $NUM )); then
 685                         echo "ERROR: sharemgr enable was unsuccessful"
 686                         echo "\tExpected to see $NUM shares, but got $num"
 687                         cat $STF_TMPDIR/share.out.$$
 688                         cleanup_sharemgr
 689                 fi
 690 
 691                 # step 9. remove-share:
 692                 i=$NUM
 693                 while (( $i >= 0 )); do
 694                         i=$((i - 1))
 695                         k=$((i % NUM_GROUPS))
 696                         sharemgr remove-share \
 697                                 -s $STRESSDIR/sharemnt_${i}_stress shmgr_grp_$k \
 698                                 >> $STF_TMPDIR/grp.rmvshr.$$ 2>&1 &
 699                 done
 700                 # wait for all remove-share commands in background to finish
 701                 condition="! pgrep -z $ZONENAME -P $$ -x sharemgr > /dev/null"
 702                 wait_now $STRESS_TIMEOUT "$condition" 3
 703                 if (( $? != 0 )); then
 704                         echo "ERROR: timeout<$STRESS_TIMEOUT secs> for \c"
 705                         echo "removing share pathes from groups..."
 706                         ps -efz $ZONENAME | grep "sharemgr"
 707                         cat $STF_TMPDIR/grp.rmvshr.$$
 708                         pkill -z $ZONENAME -P $$ -x sharemgr
 709                         cleanup_sharemgr
 710                 fi
 711                 # check number of entries in each group
 712                 i=0
 713                 while (( $i < $NUM_GROUPS )); do
 714                         sharemgr show shmgr_grp_$i | grep -v "^shmgr_grp_$i" \
 715                                 > $STF_TMPDIR/entry.out.$$
 716                         num=$(wc -l $STF_TMPDIR/entry.out.$$ | \
 717                             nawk '{print $1}')
 718                         if (( $num > 0 )); then
 719                             echo "ERROR: sharemgr remove-share was unsuccessful"
 720                             echo "\tStill find $num entries in shmgr_grp_$i"
 721                             cat $STF_TMPDIR/entry.out.$$
 722                             cleanup_sharemgr
 723                         fi
 724                         i=$((i + 1))
 725                 done
 726                 # check there is no test dirs exported any more
 727                 grep $STRESSDIR/sharemnt_ $SHARETAB > $STF_TMPDIR/share.out.$$
 728                 num=$(wc -l $STF_TMPDIR/share.out.$$ | nawk '{print $1}')
 729                 if (( $num > 0 )); then
 730                         echo "ERROR: sharemgr remove-share was unsuccessful"
 731                         echo "\tStill find $num shared entries"
 732                         cat $STF_TMPDIR/share.out.$$
 733                         cleanup_sharemgr
 734                 fi
 735 
 736                 # step 10. delete groups:
 737                 i=$NUM_GROUPS
 738                 while (( $i >= 0 )); do
 739                         sharemgr delete shmgr_grp_$i \
 740                                 >> $STF_TMPDIR/grp.delete.$$ 2>&1 &
 741                         i=$((i - 1))
 742                 done
 743                 # wait for all delete commands in background to finish
 744                 condition="! pgrep -z $ZONENAME -P $$ -x sharemgr > /dev/null"
 745                 wait_now $STRESS_TIMEOUT "$condition" 3
 746                 if (( $? != 0 )); then
 747                         echo "ERROR: timeout<$STRESS_TIMEOUT secs> for \c"
 748                         echo "deleting share groups..."
 749                         ps -efz $ZONENAME | grep "sharemgr"
 750                         cat $STF_TMPDIR/grp.delete.$$
 751                         pkill -z $ZONENAME -P $$ -x sharemgr
 752                         cleanup_sharemgr
 753                 fi
 754                 # check number of groups
 755                 sharemgr list -P nfs | grep "^shmgr_grp_" \
 756                         > $STF_TMPDIR/grp.out.$$
 757                 num=$(wc -l $STF_TMPDIR/grp.out.$$ | nawk '{print $1}')
 758                 if (( $num > 0 )); then
 759                         echo "ERROR: sharemgr delete group was unsuccessful"
 760                         echo "\tStill find $num groups remained"
 761                         cat $STF_TMPDIR/grp.out.$$
 762                         cleanup_sharemgr
 763                 fi
 764 
 765                 echo "$NAME: sharemgr testing complete - Result PASS"
 766                 cleanup 0
 767                 ;;
 768         cleanup_001)
 769                 [[ -f /etc/dfs/dfstab.sharemnt.stress ]] && \
 770                         mv /etc/dfs/dfstab.sharemnt.stress /etc/dfs/dfstab
 771                 unshareall > $STF_TMPDIR/unshare.out.$$ 2>&1
 772                 if (( $? != 0 )); then
 773                         echo "ERROR: failed to unshareall"
 774                         cat $STF_TMPDIR/unshare.out.$$
 775                         cleanup 1 t
 776                 fi
 777                 svcadm restart nfs/server
 778                 sleep 10
 779 
 780                 cleanup 0 t
 781                 ;;
 782         cleanup_002)
 783                 zfs set sharenfs=off $ZFSBASE > $STF_TMPDIR/time.out.$$ 2>&1
 784                 if (( $? != 0 )); then
 785                         echo "ERROR: setting sharenfs=off failed."
 786                         cat $STF_TMPDIR/time.out.$$
 787                         cleanup 1 t
 788                 fi
 789 
 790                 [[ -f /etc/dfs/dfstab.sharemnt.stress ]] && \
 791                         mv /etc/dfs/dfstab.sharemnt.stress /etc/dfs/dfstab
 792                 svcadm restart nfs/server
 793                 sleep 10
 794 
 795                 cleanup 0 t
 796                 ;;
 797         \?)
 798                 ;;
 799         esac
 800         ;;
 801 h)
 802         typeset opt=$OPTARG
 803         shift $((OPTIND - 1))
 804         typeset path=$1
 805         $MISCSHARE default share $path $opt
 806         if (( $? != 0 )); then
 807                 echo "ERROR: failed to share $path"
 808                 cleanup 1
 809         fi
 810         condition="grep -w $path $SHARETAB | grep -w $opt"
 811         wait_now 900 "$condition" 20
 812         if (( $? != 0 )); then
 813                 echo "ERROR: failed to find $path shared with $opt"
 814                 cleanup 1
 815         fi
 816         $MISCSHARE default unshare $path
 817         if (( $? != 0 )); then
 818                 echo "ERROR: failed to unshare $path"
 819                 cleanup 1
 820         fi
 821         grep -w $path $SHARETAB > /dev/null 2>&1
 822         if (( $? == 0 )); then
 823                 echo "ERROR: $path is still in $SHARETAB"
 824                 cleanup 1
 825         fi
 826         echo "Done with $path"
 827         ;;
 828 c)
 829         if [[ -n $ZFSPOOL ]]; then
 830                 i=0
 831                 while (( $i <= $NUM_SHARES )); do
 832                         Zfs=`zfs list | grep "$STRESSDIR/sharemnt_${i}_stress" \
 833                                 | nawk '{print $1}'`
 834                         if [[ -n $Zfs ]]; then
 835                                 zfs destroy -f $Zfs \
 836                                     > $STF_TMPDIR/cleanFS.out.$$ 2>&1
 837                                 if (( $? != 0 )); then
 838                                     echo "WARNING, unable to cleanup [$Zfs];"
 839                                     cat $STF_TMPDIR/cleanFS.out.$$
 840                                     echo "\t Please clean it up manually."
 841                                     cleanup 1
 842                                 fi
 843                         fi
 844                         i=$((i+1))
 845                 done
 846         fi
 847         rm -rf $STRESSDIR
 848 
 849         echo "Done - cleanup OKAY"
 850         ;;
 851 \?)
 852         echo $Usage
 853         exit 2
 854         ;;
 855 esac
 856 
 857 cleanup 0