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 process1 recovers after process2 attempts to lock 
  31 #    same file after server reboots, expect OK
  32 # b: Verify process1 recovers after process2 attempts to lock 
  33 #    same file after nfsd dies and restarts, 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 
  45 export RECOVERY_EXECUTE_PATH=$DIR
  46 export RECOVERY_STAT_PATH=$STF_SUITE/bin/
  47 
  48 prog=$STF_SUITE/bin/file_operator
  49 if [[ ! -x $prog ]]; then
  50         echo "$NAME: the executable program '$prog' not found."
  51         echo "\t Test UNINITIATED"
  52         exit $STF_UNINITIATED
  53 fi
  54 
  55 
  56 cd $MNTDIR
  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 wait_for_grace > /dev/null 2>&1
  61 
  62 TESTFILE="openfile.$$"
  63 
  64 
  65 function assertion_func
  66 {
  67    [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
  68 
  69    typeset actionType=$1
  70 
  71    # process1 locks file:
  72    $prog -W -c -u -o 4 -s $(expr $REBOOTIMER + 300) -L "1 0 0 0" -B "0 0 0" \
  73         $TESTFILE > $STF_TMPDIR/$NAME.out.$$ 2>&1 &
  74    pid1=$!
  75    wait_now 200 "grep \"got exclusive lock\" $STF_TMPDIR/$NAME.out.$$" > /dev/null 2>&1
  76    if (( $? != 0 )); then
  77         echo "$NAME: localhost did not have file locked?"
  78         cat $STF_TMPDIR/$NAME.out.$$
  79         kill $pid1 > /dev/null 2>&1
  80         rm -f $TESTFILE $STF_TMPDIR/$NAME.*.$$
  81         echo "\t Test FAIL" 
  82         return $STF_FAIL
  83    fi
  84 
  85    # Reboot SERVER to clear the blocking lock ...
  86    $DIR/isserverup $actionType > $STF_TMPDIR/$NAME.srv.$$ 2>&1
  87    if (( $? != 0 )); then
  88         echo "$NAME: $actionType on SERVER failed"
  89         cat $STF_TMPDIR/$NAME.srv.$$
  90         kill $pid1 > /dev/null 2>&1
  91         rm -f $TESTFILE $STF_TMPDIR/$NAME.*.$$
  92         echo "\t Test FAIL"
  93         return $STF_FAIL
  94    fi
  95 
  96    sleep 10
  97 
  98    # Now another process try to lock the same file:
  99    $prog -W -c -u -o 4 -s 30  -L "1 0 0 0" -B "0 0 -1" $TESTFILE \
 100         > $STF_TMPDIR/$NAME.out2.$$ 2>&1
 101 
 102    kill $pid1 > /dev/null 2>&1
 103    grep "unavailable" $STF_TMPDIR/$NAME.out2.$$ > /dev/null 2>&1
 104    if (( $? != 0 )); then
 105         echo "$NAME: $SERVER's reboot cleared localhost's locks"
 106         cat $STF_TMPDIR/$NAME.out2.$$
 107         rm -f $TESTFILE $STF_TMPDIR/$NAME.*.$$
 108         echo "\t Test FAIL"
 109         return $STF_FAIL
 110    fi
 111 
 112    rm -f $TESTFILE $STF_TMPDIR/$NAME.*.$$
 113    echo "\tTest PASS"
 114    return $STF_PASS
 115 }
 116 
 117 
 118 # Start main program here:
 119 # ----------------------------------------------------------------------
 120 
 121 ASSERTION_a="Verify process1 recovers after process2 attempts to lock \
 122         same file after server reboots, expect sucess"
 123 ASSERTION_b="Verify process1 recovers after process2 attempts to lock \
 124         same file after nfsd dies and restarts, expect sucess"
 125 
 126 echo "$NAME{a}: $ASSERTION_a"
 127 assertion_func "reboot"
 128 retcode=$?
 129 
 130 echo "$NAME{b}: $ASSERTION_b"
 131 assertion_func "reset-nfsd"
 132 retcode=$(($retcode+$?))
 133 
 134 (( $retcode == $STF_PASS )) && cleanup $STF_PASS || cleanup $STF_FAIL
 135