1 #
   2 # CDDL HEADER START
   3 #
   4 # The contents of this file are subject to the terms of the
   5 # Common Development and Distribution License (the "License").
   6 # You may not use this file except in compliance with the License.
   7 #
   8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9 # or http://www.opensolaris.org/os/licensing.
  10 # See the License for the specific language governing permissions
  11 # and limitations under the License.
  12 #
  13 # When distributing Covered Code, include this CDDL HEADER in each
  14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15 # If applicable, add the following below this CDDL HEADER, with the
  16 # fields enclosed by brackets "[]" replaced with your own identifying
  17 # information: Portions Copyright [yyyy] [name of copyright owner]
  18 #
  19 # CDDL HEADER END
  20 #
  21 
  22 #
  23 # Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24 # Use is subject to license terms.
  25 #
  26 
  27 . ${STF_SUITE}/include/nfsgen.kshlib
  28 
  29 export PATH=$PATH:${STF_SUITE}/tests/delegation/bin/${STF_EXECUTE_MODE}
  30 export RD=1
  31 export WR=2
  32 export NONE=0
  33 
  34 if [[ :$NFSGEN_DEBUG: = *:C_UTILITY:* \
  35                 || :${NFSGEN_DEBUG}: = *:all:* ]]; then
  36         DEBUGOPT="-D"
  37 fi
  38 
  39 C_OPTS="$MMAPOPT $DEBUGOPT"
  40 
  41 # Description
  42 #       A function to create a file. The function is special in that 
  43 #       client won't get RD or WR delegation after the file is created.
  44 # Usage:
  45 #       create_file_nodeleg <pathname>
  46 # Return:
  47 #       0 on success, 1 on error
  48 function create_file_nodeleg {
  49         NAME=create_file_nodeleg
  50         [[ :$NFSGEN_DEBUG: = *:${NAME}:* \
  51                 || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
  52 
  53         dir=$(dirname $1)
  54         file=$(basename $1)
  55         RUN_CHECK "echo '#123456789' > $dir/$file.tmp1" || return 1
  56         RUN_CHECK mkfile 1m $dir/$file.tmp2 || return 1
  57         RUN_CHECK "cat $dir/$file.tmp1 $dir/$file.tmp2 > $dir/$file.tmp" \
  58             ||return 1
  59         RUN_CHECK rm -f $dir/$file.tmp1 $dir/$file.tmp2
  60         RUN_CHECK chmod 777 $dir/$file.tmp
  61         RUN_CHECK mv $dir/$file.tmp $dir/$file || return 1
  62 }
  63 
  64 # Description
  65 #       A function to copy a file. The function is special in that 
  66 #       client won't get RD or WR delegation after the file is created.
  67 # Usage:
  68 #       copy_file_nodeleg <pathname>
  69 # Return:
  70 #       0 on success, 1 on error
  71 function copy_file_nodeleg {
  72         NAME=copy_file_nodeleg
  73         [[ :$NFSGEN_DEBUG: = *:${NAME}:* \
  74                 || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
  75 
  76         src=$1
  77         dst=$2
  78         dst_dir=$(dirname $dst)
  79         dst_file=$(basename $dst)
  80 
  81         RUN_CHECK cp -p $src $dst_dir/$dst_file.tmp || return 1
  82         RUN_CHECK mv $dst_dir/$dst_file.tmp $dst || return 1
  83 }
  84 
  85 # Description
  86 #       A function to get and save current rfsreqcnt_v4 statistic number
  87 # Usage:
  88 #       save_rfsreqcntv4 <opname>
  89 # Return:
  90 #       0 on success, 1 on error
  91 function save_rfsreqcntv4 {
  92         NAME=save_rfsreqcntv4
  93         [[ :$NFSGEN_DEBUG: = *:${NAME}:* \
  94                 || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
  95 
  96         typeset opname=$1
  97         typeset n=$(kstat -m nfs -n rfsreqcnt_v$TESTVERS -s $opname \
  98             | grep $opname | awk '{print $2}')
  99         if [[ -z $n ]]; then
 100                 print -u2 "failed to get $opname kstat statistic"
 101                 return 1
 102         fi
 103         echo $n
 104 }
 105 
 106 # Description
 107 #       A function to get rfsreqcnt_v4 statistic number and check
 108 #       it is larger than the value passed.
 109 # Usage:
 110 #       check_rfsreqcntv4_larger <opname> <old_value>
 111 # Return:
 112 #       0 on success, 1 on error
 113 function check_rfsreqcntv4_larger {
 114         NAME=check_rfsreqcntv4_larger
 115         [[ :$NFSGEN_DEBUG: = *:${NAME}:* \
 116                 || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
 117 
 118         typeset opname=$1
 119         typeset oldval=$2
 120         typeset newval=$(kstat -m nfs -n rfsreqcnt_v$TESTVERS -s $opname \
 121             | grep $opname | awk '{print $2}')
 122 
 123         if [[ -z $newval ]]; then
 124                 print -u2 "failed to get $opname kstat number"
 125                 return 1
 126         fi
 127 
 128         if (( newval > oldval )); then
 129                 return 0
 130         else
 131                 print -u2 "$opname statistic(Previous:$oldval Current: $newval)"
 132                 return 1
 133         fi
 134 }
 135 
 136 # Description
 137 #       A function to get rfsreqcnt_v4 statistic number and check
 138 #       it is equal to the value passed.
 139 # Usage:
 140 #       check_rfsreqcntv4_equal <opname> <old_value>
 141 # Return:
 142 #       0 on success, 1 on error
 143 function check_rfsreqcntv4_equal {
 144         NAME=check_rfsreqcntv4_equal
 145         [[ :$NFSGEN_DEBUG: = *:${NAME}:* \
 146                 || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
 147 
 148         typeset opname=$1
 149         typeset oldval=$2
 150         typeset newval=$(kstat -m nfs -n rfsreqcnt_v$TESTVERS -s $opname \
 151             | grep $opname | awk '{print $2}')
 152 
 153         if [[ -z $newval ]]; then
 154                 print -u2 "failed to get $opname kstat number"
 155                 return 1
 156         fi
 157 
 158         if (( newval == oldval )); then
 159                 return 0
 160         else
 161                 print -u2 "$opname statistic(Previous:$oldval Current: $newval)"
 162                 return 1
 163         fi
 164 }
 165 
 166 # Description
 167 #       A function to get and save current nfs4_callback_stats statistic number
 168 # Usage:
 169 #       save_nfs4callback <opname>
 170 # Return:
 171 #       0 on success, 1 on error
 172 function save_nfs4callback {
 173         NAME=save_nfs4callback
 174         [[ :$NFSGEN_DEBUG: = *:${NAME}:* \
 175                 || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
 176 
 177         typeset opname=$1
 178         typeset n=$(kstat -m nfs -n nfs4_callback_stats -s $opname \
 179             | grep $opname | awk '{print $2}')
 180         if [[ -z $n ]]; then
 181                 print -u2 "failed to get $opname kstat statistic"
 182                 return 1
 183         fi
 184         echo $n
 185 }
 186 
 187 # Description
 188 #       A function to get nfs4_callback_stats statistic number and check
 189 #       it is equal to the value passed.
 190 # Usage:
 191 #       check_nfs4callback_equal <opname> <old_value>
 192 # Return:
 193 #       0 on success, 1 on error
 194 function check_nfs4callback_equal {
 195         NAME=check_nfs4callback_equal
 196         [[ :$NFSGEN_DEBUG: = *:${NAME}:* \
 197                 || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
 198 
 199         typeset opname=$1
 200         typeset oldval=$2
 201         typeset newval=$(kstat -m nfs -n nfs4_callback_stats -s $opname \
 202             | grep $opname | awk '{print $2}')
 203 
 204         if [[ -z $newval ]]; then
 205                 print -u2 "failed to get $opname kstat number"
 206                 return 1
 207         fi
 208 
 209         if (( newval == oldval )); then
 210                 return 0
 211         else
 212                 print -u2 "$opname statistic(Previous:$oldval Current: $newval)"
 213                 return 1
 214         fi
 215 }
 216 
 217