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 operations test - positive tests
  27 #   File opened with deny bits, test LOCKT
  28 
  29 # include test environment
  30 source LOCKsid.env
  31 source [file join ${TESTROOT} lcltools]
  32 
  33 # connect to the test server
  34 Connect
  35 
  36 # setting local variables
  37 set TNAME $argv0
  38 set dfh [get_fh "$BASEDIRS"]
  39 
  40 set clientid [getclientid $TNAME]
  41 if {$clientid == -1} {
  42         putmsg stderr 0 "$TNAME: setup - getclientid"
  43         putmsg stderr 0 "\t Test UNRESOLVED: unable to get clientid"
  44         exit $UNRESOLVED
  45 }
  46 
  47 
  48 # Create a test file and get its osid
  49 proc openfile {dfh filename clientid deny Afh Aostateid Aoseqid Alowner} {
  50         global PASS FAIL UNRESOLVED
  51         upvar 1 $Afh fh
  52         upvar 1 $Aostateid ostateid
  53         upvar 1 $Aoseqid oseqid
  54         upvar 1 $Alowner lowner
  55         # pass status if exists as global
  56         if {[info vars ::status] != ""} {
  57                 upvar 1 status status
  58         }
  59         putmsg stderr 1 "openlock $dfh $filename"
  60         putmsg stderr 1 "\t$clientid $deny"
  61         putmsg stderr 1 "\t$Afh $Aostateid $Aoseqid $Alowner"
  62         set tag "$filename.setup"
  63 
  64         set fsize 8193
  65         set fh [basic_open $dfh $filename 1 "$clientid $filename.[pid]" \
  66                 ostateid oseqid status 1 0 664 $fsize 3 $deny]
  67         if {$fh == -1} {
  68                 putmsg stderr 0 "ERROR openlock: setup->basic_open ($filename)"
  69                 putmsg stderr 0 "\tTest UNRESOLVED: status=($status)"
  70                 putmsg stderr 0 "\tnext 4 assertions will not execute."
  71                 return $UNRESOLVED
  72         }
  73         set oseqid [expr $oseqid + 1]
  74         set lowner "${filename}.lck[clock clicks]"
  75         set lseqid 1
  76         #lock first 1K
  77 
  78         return $PASS
  79 }
  80 
  81 
  82 proc tlock {type} {
  83         global tag ASSERTION fh clientid lowner status expcode res PASS FAIL
  84 
  85         putmsg stdout 0 "$tag: $ASSERTION"
  86         set res [compound {Putfh $fh; Lockt $type $clientid $lowner 1000 8193;
  87                 Lockt $type $clientid $lowner 1025 2048}]
  88         putmsg stderr 1 \
  89                 "compound {Putfh $fh; Lockt $type $clientid $lowner 1000 8193;"
  90         putmsg stderr 1 "\tLockt $type $clientid $lowner 1025 2048}"
  91         ckres "Lockt" $status $expcode $res $PASS
  92 }
  93 
  94 
  95 # Start testing
  96 # --------------------------------------------------------------
  97 
  98 # open a file with deny read
  99 set filename "Oread"
 100 set TESTFILE [file join $BASEDIR $filename]
 101 set st [openfile $dfh $filename $clientid 1 fh stateid seqid lowner]
 102 if {$st == $PASS} {
 103         # a: Open deny read, try Lockt read, expect OK
 104         set expcode "OK"
 105         set ASSERTION "Open deny read, try Lockt read, expect $expcode"
 106         set tag "$TNAME{a}"
 107         tlock 1
 108 
 109         # b: Open deny read, try Lockt write, expect OK
 110         set expcode "OK"
 111         set ASSERTION \
 112                 "Open deny read, try Lockt write, expect $expcode"
 113         set tag "$TNAME{b}"
 114         tlock 2
 115 
 116         # c: Open deny read, try Lockt readwait, expect OK
 117         set expcode "OK"
 118         set ASSERTION \
 119                 "Open deny read, try Lockt readwait, expect $expcode"
 120         set tag "$TNAME{c}"
 121         tlock 3
 122 
 123         # d: Open deny read, try Lockt writewait, expect OK
 124         set expcode "OK"
 125         set ASSERTION \
 126                 "Open deny read, try Lockt writewait, expect $expcode"
 127         set tag "$TNAME{d}"
 128         tlock 4
 129 }
 130 closev4 $TESTFILE $fh $stateid $seqid
 131 
 132 
 133 # open a file with deny write
 134 set filename "Owrite"
 135 set TESTFILE [file join $BASEDIR $filename]
 136 set st [openfile $dfh $filename $clientid 2 fh stateid seqid lowner]
 137 if {$st == $PASS} {
 138         # e: Open deny write, try Lockt read, expect OK
 139         set expcode "OK"
 140         set ASSERTION \
 141                 "Open deny write, try Lockt read, expect $expcode"
 142         set tag "$TNAME{e}"
 143         tlock 1
 144 
 145         # f: Open deny write, try Lockt write, expect OK
 146         set expcode "OK"
 147         set ASSERTION \
 148                 "Open deny write, try Lockt write, expect $expcode"
 149         set tag "$TNAME{f}"
 150         tlock 2
 151 
 152         # g: Open deny write, try Lockt readwait, expect OK
 153         set expcode "OK"
 154         set ASSERTION \
 155                 "Open deny write, try Lockt readwait, expect $expcode"
 156         set tag "$TNAME{g}"
 157         tlock 3
 158 
 159         # h: Open deny write, try Lockt writewait, expect OK
 160         set expcode "OK"
 161         set ASSERTION \
 162                 "Open deny write, try Lockt writewait, expect $expcode"
 163         set tag "$TNAME{h}"
 164         tlock 4
 165 }
 166 closev4 $TESTFILE $fh $stateid $seqid
 167 
 168 
 169 # open a file with deny both
 170 set filename "Oboth"
 171 set TESTFILE [file join $BASEDIR $filename]
 172 set st [openfile $dfh $filename $clientid 3 fh stateid seqid lowner]
 173 if {$st == $PASS} {
 174         # i: Open deny both, try Lockt read, expect OK
 175         set expcode "OK"
 176         set ASSERTION "Open deny both, try Lockt read, expect $expcode"
 177         set tag "$TNAME{i}"
 178         tlock 1
 179 
 180         # j: Open deny both, try Lockt write, expect OK
 181         set expcode "OK"
 182         set ASSERTION \
 183                 "Open deny both, try Lockt write, expect $expcode"
 184         set tag "$TNAME{j}"
 185         tlock 2
 186 
 187         # k: Open deny both, try Lockt readwait, expect OK
 188         set expcode "OK"
 189         set ASSERTION \
 190                 "Open deny both, try Lockt readwait, expect $expcode"
 191         set tag "$TNAME{k}"
 192         tlock 3
 193 
 194         # l: Open deny both, try Lockt writewait, expect OK
 195         set expcode "OK"
 196         set ASSERTION \
 197                 "Open deny both, try Lockt writewait, expect $expcode"
 198         set tag "$TNAME{l}"
 199         tlock 4
 200 }
 201 closev4 $TESTFILE $fh $stateid $seqid
 202 
 203 
 204 # --------------------------------------------------------------
 205 # disconnect and exit
 206 Disconnect
 207 exit $PASS