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 2006 Sun Microsystems, Inc.  All rights reserved.
  24 # Use is subject to license terms.
  25 #
  26 # NFSv4 READ operation test - more negative tests
  27 #       verify SERVER errors returned with invalid read.
  28 
  29 # include all test enironment
  30 source READ.env
  31 
  32 # connect to the test server
  33 Connect
  34 
  35 # setting local variables
  36 set TNAME $argv0
  37 set bfh [get_fh "$BASEDIRS"]
  38 
  39 set hid "[pid][clock seconds]"
  40 set cid [getclientid $hid]
  41 if {$cid == -1} {
  42         putmsg stdout 0 "$TNAME: test setup - getclientid"
  43         putmsg stderr 0 "\t Test UNRESOLVED: unable to get clientid"
  44         exit $UNRESOLVED
  45 }
  46 
  47 
  48 # Test assertions 
  49 # --------------------------------------------------------------
  50 # b: Test READ w/OPEN,LOCK-1,LOCK-2,READ(LOCK-1-stateid), expect OLD_STATEID
  51 #
  52 proc assertion_b { Tfile } {
  53     global TNAME bfh PASS cid
  54 
  55     set expcode "OLD_STATEID"
  56     set ASSERTION \
  57         "READ w/OPEN,LOCK-1,LOCK-2,READ(LOCK-1-sid), expect $expcode"
  58     set tag "$TNAME{b}"
  59     putmsg stdout 0 "$tag: $ASSERTION"
  60     set owner "owner[pid]-b"
  61     # open a file to get the stateid
  62     set nfh [basic_open $bfh $Tfile 1 "$cid $owner" osid oseqid status]
  63     if {$nfh == -1} {
  64         putmsg stderr 0 "\t Test UNRESOLVED: basic_open failed, status=$status."
  65         return
  66     }
  67     # Set a lock on the file w/lower1
  68     set oseqid [expr $oseqid + 1]
  69     set lower1 "$owner-l1"
  70     set lseqid 1
  71     set res [compound {Putfh $nfh; 
  72         Lock 1 F 2 16 T $osid $lseqid {$oseqid $cid $lower1}}]
  73     if {$status !=  "OK"} {
  74         putmsg stderr 0 "\t Test UNRESOLVED: Lock1 failed, status=($status)"
  75         putmsg stderr 1 "\t   Res: $res"
  76         return
  77     }
  78     set lsid1 [lindex [lindex $res 1] 2]
  79     incr oseqid
  80     incr lseqid
  81     set res [compound {Putfh $nfh; 
  82         Lock 1 F 10 16 F $lsid1 $lseqid {$oseqid $cid $lower1}}]
  83     if {$status !=  "OK"} {
  84         putmsg stderr 0 "\t Test UNRESOLVED: Lock2 failed, status=($status)"
  85         putmsg stderr 1 "\t   Res: $res"
  86         return
  87     }
  88     # Now try to READ with Lock-stateid-1
  89     set res [compound {Putfh $nfh; Read $lsid1 0 64}]
  90     ckres "Read" $status $expcode $res $PASS
  91     set res [compound {Putfh $nfh; Close $oseqid $osid}]
  92 }
  93 
  94 
  95 # e: Read w/file opened WRITE only - expect OPENMODE
  96 #
  97 proc assertion_e { Tfile } {
  98     global TNAME bfh PASS cid
  99 
 100     set expcode "OPENMODE"
 101     set ASSERTION "Read w/file opened accsss=W, deny=0, expect $expcode"
 102     set tag "$TNAME{e}"
 103     putmsg stdout 0 "$tag: $ASSERTION"
 104 
 105     # open a RW file with WRITE only access:
 106     set oowner "[pid][expr [clock seconds] / 2]"
 107     set nfh [basic_open $bfh $Tfile 1 "$cid $oowner" \
 108         osid oseqid status 1 0 666 0 2]
 109     if {$nfh == -1} {
 110         putmsg stderr 0 "\t Test UNRESOLVED: basic_open failed, status=$status."
 111         return
 112     }
 113 
 114     # Now try to read this file:
 115     set res [compound {Putfh $nfh; Read $osid 0 10}]
 116     if { $status == "OK"} {
 117         # Some servers allow this, so must check another open w/deny=R
 118         set oowner2 "oowner2[pid]"
 119         set nfh2 [basic_open $bfh $Tfile 0 "$cid $oowner2" \
 120                 osid2 oseqid2 status 100 0 666 0 2 1]
 121         if {$nfh2 == -1} {
 122                 putmsg stderr 0 \
 123                     "\t Test UNRESOLVED: basic_open2 failed, status=$status."
 124                 incr oseqid
 125                 set res [compound {Putfh $nfh; Close $oseqid $osid}]
 126                 putmsg stderr 1 "Close1 res=$res"
 127                 return
 128         }
 129         # Now try to read this file:
 130         set res [compound {Putfh $nfh; Read $osid 0 10}]
 131         ckres "Read" $status $expcode $res $PASS
 132     } else {
 133         ckres "Read" $status $expcode $res $PASS
 134     }
 135 }
 136 
 137 
 138 # z: Read a file when lease expired - expect EXPIRED|STALE_STATEID
 139 #       (run last as it expires the lease)
 140 #
 141 proc assertion_z { Tfile } {
 142     global TNAME bfh PASS cid LEASE_TIME
 143 
 144     set expcode "EXPIRED|STALE_STATEID"
 145     set ASSERTION "Read a file when lease expired, expect $expcode"
 146     set tag "$TNAME{z}"
 147     putmsg stdout 0 "$tag: $ASSERTION"
 148     set leasetm $LEASE_TIME
 149     # open a file to get the stateid
 150     set owner "$tag-[pid]-zz"
 151     set nfh [basic_open $bfh $Tfile 0 "$cid $owner" osid oseqid status]
 152     if {$nfh == -1} {
 153         putmsg stderr 0 "\t Test UNRESOLVED: basic_open failed, status=$status."
 154         return
 155     }
 156     # wait for lease time to expired; then read
 157     putmsg stdout 1 "  wait for lease time to expire, then read"
 158     after [expr ($leasetm + 18) * 1000]
 159     set res [compound {Putfh $nfh; Read "$osid" 0 64}]
 160     ckres "Read" $status $expcode $res $PASS
 161 }
 162 
 163 
 164 # Start testing
 165 # --------------------------------------------------------------
 166 
 167 set TFileb "tfile-b.[pid]"
 168 assertion_b $TFileb
 169 set TFilee "tfile-e.[pid]"
 170 assertion_e $TFilee
 171 assertion_z $env(RWFILE)
 172 
 173 # Cleanup the temp file:
 174 set res [compound {Putfh $bfh; Remove $TFileb; Remove $TFilee}]
 175 if { "$status" != "OK" } {
 176         putmsg stderr 0 "\t WARNING: cleanup to remove tmp files failed"
 177         putmsg stderr 0 "\t          status=$status; please cleanup manually."
 178         putmsg stderr 1 "\t   res=($res)"
 179         putmsg stderr 1 "  "
 180         exit $WARNING
 181 }
 182 
 183 # --------------------------------------------------------------
 184 # disconnect and exit
 185 Disconnect
 186 exit $PASS