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 client recovery:
  30 # a: Verify client recovers on write op after server reboots; 
  31 # try to close after reboot, expect OK
  32 # b: Verify client recovers on write op after after nfsd dies and
  33 # and restarts; try to close after nfsd restart, expect OK
  34 #
  35 
  36 . ${STF_SUITE}/include/nfsgen.kshlib
  37 
  38 NAME=$(basename $0)
  39 
  40 [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
  41 
  42 DIR=$(dirname $0)
  43 PATH=/usr/bin:$PATH
  44 prog=$STF_SUITE/bin/file_operator
  45 
  46 export RECOVERY_EXECUTE_PATH=$DIR
  47 export RECOVERY_STAT_PATH=$STF_SUITE/bin/
  48 
  49 TESTFILE="openfile.$$"
  50 
  51 if [[ ! -x $prog ]]; then
  52         echo "$NAME: the executible program '$prog' not found."
  53         echo "\t Test FAIL"
  54         return $STF_FAIL
  55 fi
  56 
  57 # First check this test is not started before previous tests 
  58 # grace period ends.
  59 echo "xxx" > $MNTDIR/wait_for_grace
  60 rm -rf $MNTDIR/wait_for_grace > /dev/null 2>&1
  61 
  62 # Start test
  63 # --------------------------------------------------------------------
  64 function assertion_func 
  65 {
  66    [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
  67    actionType=$1
  68 
  69    # start a process to open and write data info a file
  70    # it also read those data back for check after server reboot or
  71    # nfsd restart on server
  72    $prog -c -W -o 4 -e $RANDOM -B "32768 1024 1024" $MNTDIR/$TESTFILE > \
  73    $STF_TMPDIR/$NAME.out.$$ 2>&1 &
  74    pid=$!
  75 
  76    # wait untill prog wrote all data into the file
  77    wait_now 200 "grep \"I am ready\" $STF_TMPDIR/$NAME.out.$$" \
  78    > /dev/null 2>&1
  79    if (( $? != 0 )); then
  80         echo "$NAME: client failed to write 32MB data into $STF_TMPDIR/$NAME.out.$$ \
  81                 in 200 seconds"
  82         cat $STF_TMPDIR/$NAME.out.$$
  83         kill $pid
  84         rm -f $MNTDIR/$TESTFILE* $STF_TMPDIR/$NAME.*
  85         echo "\t Test FAIL"
  86         return $STF_FAIL
  87   fi
  88 
  89   # reboot server or restart nfsd on server
  90   $DIR/isserverup $actionType > $STF_TMPDIR/$NAME.reboot.$$ 2>&1
  91   if (( $? != 0 )); then
  92         echo "$NAME: failed to reboot $SERVER"
  93         cat $STF_TMPDIR/$NAME.reboot.$$
  94         kill $pid
  95         rm -f $MNTDIR/$TESTFILE* $STF_TMPDIR/$NAME.*
  96         echo "\t Test FAIL"
  97         return $STF_FAIL
  98   fi
  99 
 100   # signal the test program to read data back
 101   kill -16 $pid
 102 
 103   wait $pid
 104   if (( $? != 0 )); then
 105         echo "wait the process with pid=$pid failed"
 106         echo "\t Test FAIL"
 107         kill $pid
 108         rm -f $MNTDIR/$TESTFILE* $STF_TMPDIR/$NAME.*
 109         return $STF_FAIL
 110   fi
 111 
 112    rm -f $MNTDIR/$TESTFILE* $STF_TMPDIR/$NAME.*
 113    echo "\tTest PASS"
 114    return $STF_PASS
 115 }
 116 
 117 
 118 # Start main program here:
 119 # ----------------------------------------------------------------------
 120 ASSERTION_a="Verify client recovers on write op after server reboot; \
 121         try to close after reboot, expect sucess"
 122 ASSERTION_b="Verify client recovers on write op after after nfsd dies and \
 123         and restarts; try to close after nfsd restart, expect sucess"
 124 
 125 echo "$NAME{a}: $ASSERTION"
 126 assertion_func "reboot"
 127 retcode=$?
 128 
 129 echo "$NAME{b}: $ASSERTION"
 130 assertion_func "reset-nfsd"
 131 retcode=$(($retcode+$?))
 132 
 133 (( $retcode == $STF_PASS )) && cleanup $STF_PASS || cleanup $STF_FAIL