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 # Basic fucntion of LOCK, LOCKT, LOCKU op (different owners)
28
29 # include all test enironment
30 source LOCKsid.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 set TFILE "$TNAME.[pid]"
39 set owner "[pid]-[expr int([expr [expr rand()] * 100000000])]"
40 set cid [getclientid $owner]
41 if {$cid == -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 # Create a test file and get its osid
48 set fsize 8193
49 set nfh [basic_open $bfh $TFILE 1 "$cid $owner" osid oseqid status \
50 1 0 664 $fsize]
51 if {$nfh == -1} {
52 putmsg stderr 0 "$TNAME: setup - basic_open"
53 putmsg stderr 0 "\t Test UNRESOLVED: status=($status)"
54 exit $UNRESOLVED
55 }
56 set oseqid [expr $oseqid + 1]
57 set lowner1 "[pid].lo1"
58 set lowner2 "[pid].lo2"
59 set lseqid1 1
60 set lseqid2 1
61
62
63 # Start testing
64 # --------------------------------------------------------------
65 # a: new LOCK(lowner-1,READW,0,100), expect OK
66 set expcode "OK"
67 set ASSERTION "new LOCK(lowner-1,Rw,0,100), expect $expcode"
68 set tag "$TNAME{a}"
69 putmsg stdout 0 "$tag: $ASSERTION"
70 set res [compound {Putfh $nfh;
71 Lock 3 F 0 100 T $osid $lseqid1 "$oseqid $cid $lowner1"}]
72 if { [ckres "Lock(Rw1)" $status $expcode $res $PASS] == "true" } {
73 set lsid1 [lindex [lindex $res 1] 2]
74 incr lseqid1
75 incr oseqid
76 } else {
77 set lsid1 {11 22}
78 }
79
80 # b: new LOCK(lowner-2,READW,90,10), expect OK
81 set expcode "OK"
82 set ASSERTION "new LOCK(lowner-2,Rw,90,10), expect $expcode"
83 set tag "$TNAME{b}"
84 putmsg stdout 0 "$tag: $ASSERTION"
85 set res [compound {Putfh $nfh;
86 Lock 3 F 10 10 T $osid $lseqid2 "$oseqid $cid $lowner2"}]
87 if { [ckres "Lock(Rw2)" $status $expcode $res $PASS] == "true" } {
88 set lsid2 [lindex [lindex $res 1] 2]
89 incr lseqid2
90 incr oseqid
91 } else {
92 set lsid2 {22 22}
93 }
94
95 # c: LOCK(lowner-2,WRITEW,100,100) also, expect OK
96 set expcode "OK"
97 set ASSERTION "LOCK(lowner-2,Ww,100,100) also, expect $expcode"
98 set tag "$TNAME{c}"
99 putmsg stdout 0 "$tag: $ASSERTION"
100 set res [compound {Putfh $nfh;
101 Lock 4 F 100 100 F $lsid2 $lseqid2 "$oseqid $cid $lowner2"}]
102 if { [ckres "Lock(Ww2)" $status $expcode $res $PASS] == "true" } {
103 set lsid2 [lindex [lindex $res 1] 2]
104 incr lseqid2
105 } else {
106 set lsid2 {32 22}
107 }
108
109 # e: Lockt(lowner1) to check its own & share locks, expect OK
110 set expcode "OK"
111 set ASSERTION "Lockt(lowner1) check its own & share locks, expect $expcode"
112 set tag "$TNAME{e}"
113 putmsg stdout 0 "$tag: $ASSERTION"
114 set res [compound {Putfh $nfh; Lockt 2 $cid $lowner1 0 10;
115 Lockt 1 $cid $lowner1 10 81}]
116 ckres "Lockt" $status $expcode $res $PASS
117
118 # f: Lockt(lowner2) to check its own & share locks, expect OK
119 set expcode "OK"
120 set ASSERTION "Lockt(lowner2) to check its own & share locks, expect $expcode"
121 set tag "$TNAME{f}"
122 putmsg stdout 0 "$tag: $ASSERTION"
123 set res [compound {Putfh $nfh; Lockt 1 $cid $lowner2 88 10;
124 Lockt 2 $cid $lowner2 101 1024}]
125 ckres "Lockt" $status $expcode $res $PASS
126
127 # g: Lockt(anotherlo) for exclusive in other area, expect OK
128 set expcode "OK"
129 set ASSERTION "Lockt(anotherlo) for exclusive in other area, expect $expcode"
130 set tag "$TNAME{g}"
131 putmsg stdout 0 "$tag: $ASSERTION"
132 set res [compound {Putfh $nfh; Lockt 4 $cid "anotherlo" 1024 100}]
133 ckres "Lockt" $status $expcode $res $PASS
134
135 # i: Locku(lowner1) to split its READ lock(10-20), expect OK
136 set expcode "OK"
137 set ASSERTION "Locku(lowner1) to split(10-20), expect $expcode"
138 set tag "$TNAME{i}"
139 putmsg stdout 0 "$tag: $ASSERTION"
140 set res [compound {Putfh $nfh; Locku 1 $lseqid1 $lsid1 10 10}]
141 if { [ckres "Locku" $status $expcode $res $PASS] == "true" } {
142 set lsid1 [lindex [lindex $res 1] 2]
143 incr lseqid1
144 } else {
145 set lsid1 {11 22}
146 }
147
148 # j: Locku(lowner2) over (W-nolock) boundary, expect OK
149 set expcode "OK"
150 set ASSERTION "Locku(lowner2) over (W-nolock) boundary, expect $expcode"
151 set tag "$TNAME{j}"
152 putmsg stdout 0 "$tag: $ASSERTION"
153 set res [compound {Putfh $nfh; Locku 2 $lseqid2 $lsid2 188 80}]
154 if { [ckres "Locku" $status $expcode $res $PASS] == "true" } {
155 set lsid2 [lindex [lindex $res 1] 2]
156 incr lseqid2
157 } else {
158 set lsid2 {22 22}
159 }
160
161 # o: lowner2 to Lock(W) to verify split locks, expect OK
162 set expcode "OK"
163 set ASSERTION "lowner2 to Lock(W) to verify split locks, expect $expcode"
164 set tag "$TNAME{o}"
165 putmsg stdout 0 "$tag: $ASSERTION"
166 set res [compound {Putfh $nfh;
167 Lock 2 F 10 10 F $lsid2 $lseqid2 "$oseqid $cid $lowner2"}]
168 if { [ckres "Lock(W2)" $status $expcode $res $PASS] == "true" } {
169 set lsid2 [lindex [lindex $res 1] 2]
170 incr lseqid2
171 } else {
172 set lsid2 {32 22}
173 }
174
175 # p: Lockt(lowner1) to verify new lock in split region, expect DENIED
176 set expcode "DENIED"
177 set ASSERTION "Lockt(lowner1) to verify new lock, expect $expcode"
178 set tag "$TNAME{p}"
179 putmsg stdout 0 "$tag: $ASSERTION"
180 set res [compound {Putfh $nfh; Lockt 1 $cid $lowner1 5 8}]
181 ckres "Lockt" $status $expcode $res $PASS
182
183 # s: Now Close the file to clear the locks, expect OK|LOCKS_HELD
184 set expcode "OK|LOCKS_HELD"
185 set ASSERTION "Now Close file to clear the locks, expect $expcode"
186 set tag "$TNAME{s}"
187 putmsg stdout 0 "$tag: $ASSERTION"
188 set res [compound {Putfh $nfh; Close $oseqid $osid}]
189 set clst $status
190 if { ($env(SRVOS) == "Solaris") } {
191 ckres "Close" $status "OK" $res $PASS
192 } else {
193 ckres "Close" $status $expcode $res $PASS
194 }
195
196 # t: verify w/Lockt all locks are cleared, expect OK
197 set expcode "OK"
198 set ASSERTION "verify w/Lockt all locks are cleared, expect $expcode"
199 set tag "$TNAME{t}"
200 putmsg stdout 0 "$tag: $ASSERTION"
201 set res [compound {Putfh $nfh; Lockt 2 $cid "anotherlo" 10 10000}]
202 ckres "Lockt" $status $expcode $res $PASS
203 putmsg stdout 1 "\t Close returned $clst"
204
205
206 # --------------------------------------------------------------
207 # Now cleanup, close and removed created tmp file
208 set res [compound {Putfh $bfh; Remove $TFILE}]
209 if {($status != "OK") && ($status != "NOENT")} {
210 putmsg stderr 0 "\t WARNING: cleanup to remove created tmp file failed"
211 putmsg stderr 0 "\t status=$status; please cleanup manually."
212 putmsg stderr 1 "\t res=($res)"
213 putmsg stderr 1 " "
214 exit $WARNING
215 }
216
217 # --------------------------------------------------------------
218 # disconnect and exit
219 Disconnect
220 exit $PASS