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 LOCK, LOCKT, LOCKU operation test - negative tests
  27 #       Verify server returns correct errors with negative requests.
  28 
  29 # include all test enironment
  30 source LOCKsid.env
  31 set OPEN4_RESULT_LOCKTYPE_POSIX 4
  32 
  33 # connect to the test server
  34 Connect
  35 
  36 # setting local variables
  37 set TNAME $argv0
  38 set bfh [get_fh $BASEDIRS]
  39 set hid "[pid]-[expr int([expr [expr rand()] * 100000000])]"
  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 set TFILE "$TNAME.[pid]"
  47 
  48 # Start testing
  49 # --------------------------------------------------------------
  50 # First open a file w/access=READ for the lock tests
  51 putmsg stdout 0 \
  52   "  ** Now Open/create ($TFILE)) w/access=R for following assertions(a,b):"
  53 set open_owner "[pid][clock seconds]"
  54 set oseqid 10
  55 set tag "$TNAME-OPEN"
  56 set res [compound {Putfh $bfh; Open $oseqid 1 0 "$cid $open_owner" \
  57         {1 0 {{mode 0644}}} {0 $TFILE}; Getfh}]
  58 if {$status != "OK"} {
  59         putmsg stdout 0 "$TNAME: test setup - OPEN file for access=READ"
  60         putmsg stderr 0 \
  61                 "\t Test UNRESOLVED: unable to Open ($TFILE) for read"
  62         putmsg stderr 0 "\t\t  Assertions(a,b) will not run"
  63         putmsg stderr 1 "\t Res=($res)."
  64         exit $UNRESOLVED
  65 }
  66 
  67 set osid [lindex [lindex $res 1] 2]
  68 set rflags [lindex [lindex $res 1] 4] 
  69 set nfh [lindex [lindex $res 2] 2]
  70 # do open_confirm if needed, e.g. rflags has OPEN4_RESULT_CONFIRM set
  71 if {[expr $rflags & $OPEN4_RESULT_CONFIRM] == $OPEN4_RESULT_CONFIRM} {
  72         set oseqid [expr $oseqid + 1]
  73         set res [compound {Putfh $nfh; Open_confirm $osid $oseqid}]
  74         if {$status != "OK"} {
  75                 putmsg stdout 0 "$TNAME: test setup - OPEN_CONFIRM"
  76                 putmsg stderr 0 "\t Test UNRESOLVED: unable to Open_confirm"
  77                 putmsg stderr 0 "\t\t  Assertions(a,b) will not run"
  78                 putmsg stderr 1 "\t Res=($res)."
  79                 exit $UNRESOLVED
  80         }
  81         set osid [lindex [lindex $res 1] 2]
  82 }
  83 set oseqid [expr $oseqid + 1]
  84 
  85 
  86 # Now the test assertions
  87 # a: Try to set a WRITE Lock, expect OPENMODE
  88 set expcode "OPENMODE"
  89 set ASSERTION "Try to set a WRITE Lock, expect $expcode"
  90 set tag "$TNAME{a}"
  91 putmsg stdout 0 "$tag: $ASSERTION"
  92 set lseqid 1
  93 set res [compound {Putfh $nfh; 
  94         Lock 2 F 0 125 T $osid $lseqid "$oseqid $cid $open_owner"}]
  95 if {[expr $rflags & $OPEN4_RESULT_LOCKTYPE_POSIX] == \
  96         $OPEN4_RESULT_LOCKTYPE_POSIX} {
  97         ckres "Lock(WR)" $status $expcode $res $PASS
  98 } else {
  99         ckres "Lock(WR)" $status "OK|OPENMODE" $res $PASS
 100 }
 101 
 102 
 103 # b: Try to set a WRITEW Lock, expect OPENMODE
 104 set expcode "OPENMODE"
 105 set ASSERTION "Try to set a WRITEW Lock, expect $expcode"
 106 set tag "$TNAME{b}"
 107 putmsg stdout 0 "$tag: $ASSERTION"
 108 set lseqid 2
 109 incr oseqid
 110 set res [compound {Putfh $nfh; 
 111         Lock 4 F 0 125 T $osid $lseqid "$oseqid $cid $open_owner"}]
 112 if {[expr $rflags & $OPEN4_RESULT_LOCKTYPE_POSIX] == \
 113         $OPEN4_RESULT_LOCKTYPE_POSIX} {
 114         ckres "Lock(WRW)" $status $expcode $res $PASS
 115 } else {
 116         ckres "Lock(WRW)" $status "OK|OPENMODE" $res $PASS
 117 }
 118 
 119 
 120 # Set a READ lock on the file
 121 putmsg stdout 0 "  ** Now set a READ lock for following assertions(m,p):"
 122 
 123 # i: Set a READ lock on the file (for the following assertions), expect OK
 124 set expcode "OK"
 125 set ASSERTION "set a READ Lock on file (for assertions m,p), expect $expcode"
 126 set tag "$TNAME{i}"
 127 putmsg stdout 0 "$tag: $ASSERTION"
 128 set lseqid 3
 129 incr oseqid
 130 set res [compound {Putfh $nfh; 
 131         Lock 1 F 0 125 T $osid $lseqid "$oseqid $cid $open_owner"}]
 132 if {$status != "OK"} {
 133         putmsg stderr 0 "Test UNRESOLVED: READ-lock failed, status=$status"
 134         putmsg stderr 0 "\t\t  Assertions(m,p) will not run"
 135         putmsg stderr 1 "\t Res=($res)."
 136 } else {
 137   logres "PASS"
 138   set lseqid [expr $lseqid + 1]
 139   set lsid [lindex [lindex $res 1] 2]
 140 
 141   # m: Try Lockt of WRITE lock w/lock-range, diff lowner, expect DENIED
 142   set expcode "DENIED"
 143   set ASSERTION "Lockt(WRITE) w/lock-range, diff lowner, expect $expcode"
 144   set tag "$TNAME{m}"
 145   putmsg stdout 0 "$tag: $ASSERTION"
 146   set res [compound {Putfh $nfh; Lockt 2 $cid "lowner.[pid]-s" 1 124}]
 147   ckres "Lockt" $status $expcode $res $PASS
 148 
 149 
 150   # p: Try Locku WRITE lock of the RD-lock expect INVAL
 151   set expcode "INVAL"
 152   set ASSERTION "Try Locku WRITE lock of the RD-lock, expect $expcode"
 153   set tag "$TNAME{p}"
 154   putmsg stdout 0 "$tag: $ASSERTION"
 155   set res [compound {Putfh $nfh; Locku 2 $lseqid $lsid 1 0}]
 156   ckres "Locku" $status $expcode $res $PASS
 157 }
 158 
 159 
 160 # --------------------------------------------------------------
 161 # Now cleanup, and removed created tmp file
 162 set tag "$TNAME-cleanup"
 163 set res [compound {Putfh $bfh; Remove $TFILE}]
 164 if {($status != "OK") && ($status != "NOENT")} {
 165         putmsg stderr 0 "\t WARNING: cleanup to remove created tmp file failed"
 166         putmsg stderr 0 "\t          status=$status; please cleanup manually."
 167         putmsg stderr 1 "\t   res=($res)"
 168         putmsg stderr 1 "  "
 169         exit $WARNING
 170 }
 171 
 172 # --------------------------------------------------------------
 173 # disconnect and exit
 174 Disconnect
 175 exit $PASS