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.$$
  40         exit $retcode
  41 }
  42 
  43 echo "client a opens a file RDWR, get write delegation, then it modifies"
  44 echo "the file. client b stats the file after acregmax seconds, verify"
  45 echo "client b can get those changed attributes"
  46 
  47 CLNT2_TESTDIR=$1
  48 
  49 # create test file
  50 RUN_CHECK create_file_nodeleg $MNTDIR/testfile.$$ || cleanup $STF_UNRESOLVED
  51 
  52 # write test file over NFS, check delegation type
  53 $prog -W -c -d -o 4 -B "32768 10 -1" $MNTDIR/testfile.$$ \
  54         > $STF_TMPDIR/local.out.$$ 2>&1
  55 deleg_type=$(grep "return_delegation_type" $STF_TMPDIR/local.out.$$ \
  56         | nawk -F\= '{print $2'})
  57 if [[ $deleg_type -ne $WR ]]; then
  58         print -u2 "unexpected delegation type($deleg_type) when reading file"
  59         cleanup $STF_FAIL
  60 fi
  61 
  62 # stat the file on 2nd client
  63 RUN_CHECK RSH root $CLIENT2 "/usr/bin/stat -c %s,%Z $CLNT2_TESTDIR/testfile.$$" \
  64     > $STF_TMPDIR/stat.out || cleanup $STF_UNRESOLVED
  65 
  66 size=$(nawk -F\, '{print $1}' $STF_TMPDIR/stat.out)
  67 mtime=$(nawk -F\, '{print $2}' $STF_TMPDIR/stat.out)
  68 
  69 for i in 1 2 3; do
  70         sleep 2
  71         $prog -W -c -o 2 -B "10 1 -1" -d $MNTDIR/testfile.$$ \
  72                 > $STF_TMPDIR/$NAME.append.out.$$ 2>&1
  73         grep "completed successfully" $STF_TMPDIR/$NAME.append.out.$$ \
  74                 > /dev/null 2>&1
  75         if (( $? != 0 )); then
  76                 echo "client a failed to append data into the file"
  77                 rm -f $STF_TMPDIR/$NAME.append.out.$$
  78                 cleanup $STF_FAIL
  79         fi
  80 
  81         # 60 seconds is the default upper bound (see man mount_nfs -o acregmax)
  82         # plus 5 more to avoid a race with kernel cached attrs updates
  83         ti=0
  84         to=65
  85         inc=5
  86         while ((ti <= to)); do
  87             sleep $inc
  88             ti=$((ti + inc))
  89             RUN_CHECK RSH root $CLIENT2 "/usr/bin/stat -c %s,%Z $CLNT2_TESTDIR/testfile.$$" \
  90               > $STF_TMPDIR/stat.out || cleanup $STF_UNRESOLVED
  91             nsize=$(nawk -F\, '{print $1}' $STF_TMPDIR/stat.out)
  92             (( nsize == size + 10 )) && break
  93         done
  94 
  95         if (( nsize != size + 10 )); then
  96                 print -u2 "previous size : $size, current size: $nsize"
  97                 print -u2 "stat result on $CLIENT: ls -l $MNTDIR/testfile.$$"
  98                 ls -l $MNTDIR/testfile.$$ 1>&2
  99                 cleanup $STF_FAIL
 100         fi
 101 
 102         nmtime=$(nawk -F\, '{print $2}' $STF_TMPDIR/stat.out) 
 103         if (( nmtime <= mtime )); then
 104                 print -u2 "previous mtime : $mtime, current mtime: $nmtime"
 105                 print -u2 "stat result on $CLIENT: ls -l $MNTDIR/testfile.$$"
 106                 ls -l $MNTDIR/testfile.$$ 1>&2
 107                 cleanup $STF_FAIL
 108         fi
 109 
 110         size=$nsize
 111         mtime=$nmtime
 112 done
 113 
 114 # clean up 
 115 cleanup $STF_PASS