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 # the file is designed for "no claim_deleg_cur" tests. It is
  29 # called in the following way: 
  30 # 
  31 #   nodelegclaim <testfile> <cmd1> <deleg_type1> <cmd2> <deleg_type2> \
  32 #       <remote_cmd>
  33 #
  34 # the script will first create $testfile, and then execute $cmd1
  35 # and verify the expected delegation type, and then execute $cmd2 and
  36 # verify the expected delegation type. Then it runs a remote command 
  37 # on client B and verifies it triger delegation callback. Then it checks
  38 # there is no claim_deleg_cur. 
  39 
  40 . ${STF_SUITE}/include/nfsgen.kshlib
  41 . ${STF_SUITE}/tests/delegation/include/delegation.kshlib
  42 
  43 NAME=$(basename $0)
  44 [[ :$_NFS_STF_DEBUG: = *:${NAME}:* \
  45         || :${_NFS_STF_DEBUG}: = *:all:* ]] && set -x
  46 
  47 function cleanup {
  48         retcode=$1
  49         pkill file_operator
  50         rm -f $testfile $STF_TMPDIR/$NAME.cmd.*
  51         exit $retcode
  52 }
  53 
  54 testfile=$1
  55 cmd1=$2
  56 dtype1=$3
  57 cmd2=$4
  58 dtype2=$5
  59 remote_cmd=$6
  60 typeset pid
  61 
  62 # create test file
  63 RUN_CHECK create_file_nodeleg $testfile || cleanup $STF_UNRESOLVED
  64 
  65 # run command 1, check delegation type
  66 eval $cmd1 > $STF_TMPDIR/$NAME.cmd.1.$$ 2>&1
  67 deleg_type=$(grep "return_delegation_type" $STF_TMPDIR/$NAME.cmd.1.$$ \
  68         | nawk -F\= '{print $2'})
  69 if [[ $deleg_type -ne $dtype1 ]]; then
  70         print -u2 "unexpected delegation type($deleg_type) when reading file"
  71         cat $STF_TMPDIR/$NAME.cmd.1.$$
  72         cleanup $STF_FAIL
  73 fi
  74 
  75 # save current open and close statistic
  76 prev_claim=$(save_nfs4callback claim_cur) || cleanup $STF_UNRESOLVED
  77 
  78 # run command 2, check delegation type
  79 eval $cmd2 > $STF_TMPDIR/$NAME.cmd.2.$$ 2>&1
  80 deleg_type=$(grep "return_delegation_type" $STF_TMPDIR/$NAME.cmd.2.$$ \
  81         | nawk -F\= '{print $2'})
  82 if [[ $deleg_type -ne $dtype2 ]]; then
  83         print -u2 "unexpected delegation type($deleg_type) when reading file"
  84         cat $STF_TMPDIR/$NAME.cmd.2.$$
  85         cleanup $STF_FAIL
  86 fi
  87 
  88 # save current delegreturn op statistic
  89 prev_delegreturn=$(save_rfsreqcntv4 delegreturn) || cleanup $STF_UNRESOLVED
  90 
  91 # execute command 2 on 2nd client
  92 RSH root $CLIENT2 "$remote_cmd" > $STF_TMPDIR/$NAME.cmd.3.$$ 2>&1
  93 if (( $? != 0 )); then
  94         printf -u2 "failed to execute \"$remoted_cmd\" on $CLIENT2"
  95         cat $STF_TMPDIR/$NAME.cmd.3.$$
  96         cleanup $STF_FAIL
  97 fi
  98 
  99 
 100 # check delegreturn op statistic
 101 RUN_CHECK check_rfsreqcntv4_larger delegreturn $prev_delegreturn \
 102     || cleanup $STF_FAIL
 103 
 104 # check open and close op statistic
 105 RUN_CHECK check_nfs4callback_equal claim_cur $prev_claim || cleanup $STF_FAIL
 106 
 107 # clean up 
 108 cleanup $STF_PASS