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 . ${STF_SUITE}/include/nfsgen.kshlib
  29 . ${STF_SUITE}/tests/delegation/include/delegation.kshlib
  30 
  31 NAME=$(basename $0)
  32 typeset prog=$STF_SUITE/bin/file_operator
  33 
  34 [[ :$NFSGEN_DEBUG: = *:${NAME}:* \
  35         || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
  36 
  37 function cleanup {
  38         retcode=$1
  39         rm -f $MNTDIR/testfile.$$ $STF_TMPDIR/file_operator.*.$$
  40         exit $retcode
  41 }
  42 
  43 echo "open a file RDONLY, get read delegation"
  44 echo "then reopen the file RDWR, get write delegation"
  45 
  46 # create test file
  47 RUN_CHECK create_file_nodeleg $MNTDIR/testfile.$$ || cleanup $STF_UNRESOLVED
  48 
  49 # read test file over NFS, check delegation type
  50 $prog -R -c -d -o 0 -B "1 1 -1" $MNTDIR/testfile.$$ \
  51         > $STF_TMPDIR/file_operator.outR.$$ 2>&1
  52 deleg_type=$(grep "return_delegation_type" $STF_TMPDIR/file_operator.outR.$$ \
  53         | nawk -F\= '{print $2'})
  54 if [[ $deleg_type -ne $RD ]]; then
  55         print -u2 "unexpected delegation type($deleg_type) when reading file"
  56         cleanup $STF_FAIL
  57 fi
  58 
  59 # write test file over NFS, check delegation type
  60 $prog -W -c -d -o 4 -B "1 1 -1" $MNTDIR/testfile.$$ \
  61         > $STF_TMPDIR/file_operator.outW.$$ 2>&1
  62 deleg_type=$(grep "return_delegation_type" $STF_TMPDIR/file_operator.outW.$$ \
  63         | nawk -F\= '{print $2'})
  64 
  65 if [[ $deleg_type -ne $WR ]]; then
  66         print -u2 "unexpected delegation type($deleg_type) when writing file"
  67         cleanup $STF_FAIL
  68 fi
  69 
  70 # clean up 
  71 cleanup $STF_PASS