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