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 write to same file and stat it, expect OK
  32 # b: Verify client recovers on write op; after nfsd dies and
  33 #    restarts try to write to same file and stat it, 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 # used to export EXECUTION path
  46 export RECOVERY_EXECUTE_PATH=$DIR
  47 export RECOVERY_STAT_PATH=$STF_SUITE/bin/
  48 
  49 # Global variables
  50 prog=$STF_SUITE/bin/file_operator
  51 
  52 TESTFILE="openfile.$$"
  53 
  54 if [[ ! -x $prog ]]; then
  55         echo "$NAME: the executible program '$prog' not found."
  56         echo "\t Test FAIL"
  57         return $STF_FAIL
  58 fi
  59 
  60 # First check this test is not started before previous tests
  61 # grace period ends.
  62 echo "xxx" > $MNTDIR/wait_for_grace
  63 rm -rf $MNTDIR/wait_for_grace > /dev/null 2>&1
  64 
  65 # Start test
  66 # --------------------------------------------------------------------
  67 function assertion_func
  68 {
  69    [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
  70    actionType=$1
  71 
  72    # start a process to open and write data info a file
  73    # it also read those data back for check after server reboot or
  74    # nfsd restart on server
  75    $prog -W -o 4 -e $RANDOM -B "32768 1024 1024" $MNTDIR/$TESTFILE > \
  76         $STF_TMPDIR/$NAME.out.$$ 2>&1 &
  77    pid=$!
  78 
  79    # wait untill prog wrote all data into the file
  80    wait_now 200 "grep \"I am ready\" $STF_TMPDIR/$NAME.out.$$" \
  81         > /dev/null 2>&1
  82    if (( $? != 0 )); then
  83         echo "$NAME: client failed to write 32MB data into $STF_TMPDIR/$NAME.out.$$ \
  84                 in 200 seconds"
  85         cat $STF_TMPDIR/$NAME.out.$$
  86         kill $pid
  87         rm -f $MNTDIR/$TESTFILE* $STF_TMPDIR/$NAME.*
  88         echo "\t Test FAIL"
  89         return $STF_FAIL
  90    fi
  91 
  92   # reboot server or restart nfsd on server
  93   $DIR/isserverup $actionType > $STF_TMPDIR/$NAME.reboot.$$ 2>&1
  94   if (( $? != 0 )); then
  95         echo "$NAME: failed to reboot $SERVER"
  96         cat $STF_TMPDIR/$NAME.reboot.$$
  97         kill $pid
  98         rm -f $MNTDIR/$TESTFILE* $STF_TMPDIR/$NAME.*
  99         echo "\t Test FAIL"
 100         return $STF_FAIL
 101   fi
 102 
 103    # kill first write process
 104    kill $pid
 105 
 106    # recovery: the second open and write on same file should succeed 
 107    # after reboot.
 108    # successfully
 109    $prog -W -o 4 -e $RANDOM -B "32768 1024 -1" $MNTDIR/$TESTFILE > \
 110         $STF_TMPDIR/$NAME.out2.$$ 2>&1
 111    if (( $? != 0 )); then
 112         echo "$NAME: the client didn't recover from write op \
 113                 after server reboot..."
 114         cat $STF_TMPDIR/$NAME.out2.$$
 115         rm -f $STF_TMPDIR/$NAME.*
 116         echo "\t Test FAIL"
 117         return $STF_FAIL
 118    fi
 119 
 120    # Verify the stat attributes of the test file are the same
 121    # for both opens
 122    nawk '/^st_/ && ! /st_[cm]time/ && ! /^st_bl/ {print}' \
 123    $STF_TMPDIR/$NAME.out.$$ > $STF_TMPDIR/$NAME.stat.$$ 2>&1
 124    if (( $? != 0 )); then
 125         echo "$NAME: nawk failed to get stat info after \
 126                 the 1rst open and write before server reboot..."
 127         cat $STF_TMPDIR/$NAME.stat.$$
 128         rm -f $STF_TMPDIR/$NAME.*
 129         echo "\t Test FAIL"
 130         return $STF_FAIL
 131    fi
 132 
 133    nawk '/^st_/ && ! /st_[cm]time/ && ! /^st_bl/ {print}' \
 134    $STF_TMPDIR/$NAME.out2.$$ > $STF_TMPDIR/$NAME.stat2.$$ 2>&1
 135    if (( $? != 0 )); then
 136         echo "$NAME: stat failed to get stat info after \ 
 137                 the 2nd open and write after server reboot..."
 138         cat $STF_TMPDIR/$NAME.stat2.$$
 139         rm -f $STF_TMPDIR/$NAME.*
 140         echo "\t Test FAIL"
 141         return $STF_FAIL
 142    fi
 143 
 144    diff $STF_TMPDIR/$NAME.stat.$$ $STF_TMPDIR/$NAME.stat2.$$ > \
 145    $STF_TMPDIR/$NAME.diff.$$ 2>&1
 146    if (( $? != 0 )); then
 147         echo "$NAME: Differences in stat files found"
 148         cat $STF_TMPDIR/$NAME.diff.$$
 149         rm -f $STF_TMPDIR/$NAME.*
 150         echo "\t Test FAIL"
 151         return $STF_FAIL
 152    fi
 153 
 154    # cleanup test and tmpfiles
 155    rm -f $STF_TMPDIR/$NAME.*
 156    rm -f $MNTDIR/$TESTFILE
 157    # after cleanup and before start of test case b
 158    sleep 1
 159 
 160    echo "\tTest PASS"
 161    return $STF_PASS
 162 }
 163 
 164 
 165 # Start main program here:
 166 # ----------------------------------------------------------------------
 167 ASSERTION="Verify client recovers on write op; after server reboots \
 168         try to write to same file and stat it, expect sucess"
 169 ASSERTION_b="Verify client recovers on write op; after nfsd dies and \
 170         restarts try to write to same file and stat it, expect sucess"
 171 
 172 echo "$NAME{a}: $ASSERTION"
 173 assertion_func "reboot"
 174 retcode=$?
 175 
 176 echo "$NAME{b}: $ASSERTION"
 177 assertion_func "reset-nfsd"
 178 retcode=$(($retcode+$?))
 179 
 180 (( $retcode == $STF_PASS )) && cleanup $STF_PASS || cleanup $STF_FAIL