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 RENEW operation test - positive tests
27 # verify ops that renew the lease
28
29 # include all test enironment
30 source RENEW.env
31
32 # connect to the test server
33 Connect
34
35 # setting local variables
36 set TNAME $argv0
37 set tag "$TNAME.setup"
38 set bfh [get_fh "$BASEDIRS"]
39
40 # a procedure for cleanup
41 proc do_cleanup {fname exitcode} {
42 global bfh TNAME
43 set tag "$TNAME.cleanup"
44
45 # First remove the test file
46 set res [compound {Putfh $bfh; Remove $fname}]
47 if { ("$status" != "OK") && ($status != "NOENT") } {
48 putmsg stderr 0 "\t WARNING: cleanup to remove ($fname) failed"
49 putmsg stderr 0 \
50 "\t status=$status; please cleanup manually."
51 putmsg stderr 1 "\t res=($res)"
52 putmsg stderr 1 " "
53 exit $WARNING
54 }
55
56 # disconnect and exit
57 Disconnect
58 exit $exitcode
59 }
60
61 # first setup clientid for the tests and get the server lease_time
62 set leasetm $LEASE_TIME
63 putmsg stderr 1 "server lease time is ($leasetm) seconds."
64
65 set hid "[pid][clock seconds]99"
66 set cid [getclientid $hid]
67 if {$cid == -1} {
68 putmsg stdout 0 "$TNAME: test setup - getclientid"
69 putmsg stderr 0 "Test UNINITIATED: getclientid failed"
70 exit $UNINITIATED
71 }
72
73 set halttime [expr ($leasetm / 2) * 1000]
74 set 3qltime [expr 3 * $halttime / 2]
75 set tf "$TNAME.[pid]"
76 putmsg stderr 1 "\nNow wait 1/2 leasetime=($halttime) to prepare for the test"
77 putmsg stderr 1 " start at [clock format [clock seconds]] ..."
78 after $halttime
79
80
81 # Start testing
82 # --------------------------------------------------------------
83 # a: Verify successful OPEN op renew the lease, expect OK
84 set expcode "OK"
85 set ASSERTION "Verify successful OPEN op renew the lease, expect $expcode"
86 set tag "$TNAME{a}"
87 putmsg stdout 0 "$tag: $ASSERTION"
88 set filesize 8193
89 set open_owner "$TNAME-oowner"
90 set nfh [basic_open $bfh $tf 1 "$cid $open_owner" osid oseqid status \
91 1 0 666 $filesize 3]
92 putmsg stderr 1 " end at [clock format [clock seconds]]"
93 if {$nfh == -1} {
94 putmsg stderr 0 \
95 "\t Test UNRESOLVED: basic_open failed, status=($status)"
96 putmsg stderr 0 \
97 "\t Exiting ... rest of the assertions will not be run."
98 do_cleanup $tf $UNRESOLVED
99 }
100
101 # OPEN is OK, the lease should have been renewed
102 putmsg stderr 1 \
103 " wait for 3/4 of leasetime, lease should still be valid after OPEN"
104 putmsg stderr 1 " start at [clock format [clock seconds]] ..."
105 after $3qltime
106 set res [compound {Putfh $nfh; Read $osid 0 10; Getattr size}]
107 putmsg stderr 1 " end at [clock format [clock seconds]]"
108 ckres "OPEN/READ" $status $expcode $res $PASS
109
110
111 # Lease should be renewed by the READ op above.
112 # b: Verify successful READ op renew the lease, expect OK
113 set expcode "OK"
114 set ASSERTION "Verify successful READ op renew the lease, expect $expcode"
115 set tag "$TNAME{b}"
116 putmsg stdout 0 "$tag: $ASSERTION"
117 putmsg stderr 1 \
118 " wait for 3/4 of leasetime, lease should still be valid after READ"
119 putmsg stderr 1 " start at [clock format [clock seconds]] ..."
120 after $3qltime
121 set wdata [string repeat "b" 110]
122 set off [expr $filesize - 10]
123 set res [compound {Putfh $nfh; Write $osid $off f a $wdata}]
124 putmsg stderr 1 " end at [clock format [clock seconds]]"
125 ckres "READ/WRITE" $status $expcode $res $PASS
126
127
128 # Lease should be renewed by the WRITE op above.
129 # c: Verify successful WRITE op renew the lease, expect OK
130 set expcode "OK"
131 set ASSERTION "Verify successful WRITE op renew the lease, expect $expcode"
132 set tag "$TNAME{c}"
133 putmsg stdout 0 "$tag: $ASSERTION"
134 putmsg stderr 1 \
135 " wait for 3/4 of leasetime, lease should still be valid after WRITE"
136 putmsg stderr 1 " start at [clock format [clock seconds]] ..."
137 after $3qltime
138 set newsize [expr $filesize - 100]
139 set res [compound {Putfh $nfh; Setattr $osid {{size $newsize}}}]
140 putmsg stderr 1 " end at [clock format [clock seconds]]"
141 ckres "WRITE/SETATTR" $status $expcode $res $PASS
142
143
144 # Lease should be renewed by the SETATTR op above.
145 # d: Verify successful SETATTR op renew the lease, expect OK
146 set expcode "OK"
147 set ASSERTION "Verify successful SETATTR op renew the lease, expect $expcode"
148 set tag "$TNAME{d}"
149 putmsg stdout 0 "$tag: $ASSERTION"
150 putmsg stderr 1 \
151 " wait for 3/4 of leasetime, lease should still be valid after SETATTR"
152 putmsg stderr 1 " start at [clock format [clock seconds]] ..."
153 after $3qltime
154 incr oseqid
155 set lseqid 10
156 set lowner "[pid]-$newsize"
157 set res [compound {Putfh $nfh;
158 Lock 2 F 10 100 T $osid $lseqid {$oseqid $cid $lowner}}]
159 putmsg stderr 1 " end at [clock format [clock seconds]]"
160 if {[ckres "SETATTR/LOCK" $status $expcode $res $PASS] == "true"} {
161 # save the lock_sid
162 set lsid [lindex [lindex $res 1] 2]
163 } else {
164 set lsid {1234 5678}
165 }
166
167
168 # Lease should be renewed by the LOCK op above.
169 # e: Verify successful LOCK op renew the lease, expect OK
170 set expcode "OK"
171 set ASSERTION "Verify successful LOCK op renew the lease, expect $expcode"
172 set tag "$TNAME{e}"
173 putmsg stdout 0 "$tag: $ASSERTION"
174 putmsg stderr 1 \
175 " wait for 3/4 of leasetime, lease should still be valid after LOCK"
176 putmsg stderr 1 " start at [clock format [clock seconds]] ..."
177 after $3qltime
178 incr lseqid
179 set res [compound {Putfh $nfh; Locku 2 $lseqid $lsid 0 $newsize}]
180 putmsg stderr 1 " end at [clock format [clock seconds]]"
181 ckres "SETATTR/LOCK" $status $expcode $res $PASS
182
183
184 # Lease should be renewed by the LOCKU op above.
185 # f: Verify successful LOCKU op renew the lease, expect OK
186 set expcode "OK"
187 set ASSERTION "Verify successful LOCKU op renew the lease, expect $expcode"
188 set tag "$TNAME{f}"
189 putmsg stdout 0 "$tag: $ASSERTION"
190 putmsg stderr 1 \
191 " wait for 3/4 of leasetime, lease should still be valid after LOCKU"
192 putmsg stderr 1 " start at [clock format [clock seconds]] ..."
193 after $3qltime
194 incr oseqid
195 set res [compound {Putfh $nfh; Open_downgrade $osid $oseqid 2 0}]
196 putmsg stderr 1 " end at [clock format [clock seconds]]"
197 if {[ckres "LOCKU/OPEN_DOWNGRADE" $status $expcode $res $PASS] == "true"} {
198 set osid2 [lindex [lindex $res 1] 2]
199 } else {
200 set osid2 $osid
201 }
202
203
204 # Lease should be renewed by the OPEN_DOWNGRADE op above.
205 # g: Verify successful OPEN_DOWNGRADE op renew the lease, expect OK
206 set newop "OPEN_DOWNGRADE"
207 set expcode "OK"
208 set ASSERTION "Verify successful $newop renew the lease, expect $expcode"
209 set tag "$TNAME{g}"
210 putmsg stdout 0 "$tag: $ASSERTION"
211 putmsg stderr 1 \
212 " wait for 3/4 of leasetime, lease should still be valid after $newop"
213 putmsg stderr 1 " start at [clock format [clock seconds]] ..."
214 after $3qltime
215 incr oseqid
216 set res [compound {Putfh $nfh; Close $oseqid $osid2 }]
217 putmsg stderr 1 " end at [clock format [clock seconds]]"
218 ckres "OPEN_DOWNGRADE/CLOSE" $status $expcode $res $PASS
219
220
221 # Lease should be renewed by the CLOSE op above.
222 # i: Verify successful CLOSE op renew the lease, expect OK
223 set expcode "OK"
224 set ASSERTION "Verify successful CLOSE renew the lease, expect $expcode"
225 set tag "$TNAME{i}"
226 putmsg stdout 0 "$tag: $ASSERTION"
227 putmsg stderr 1 \
228 " wait for 3/4 of leasetime, lease should still be valid after CLOSE"
229 putmsg stderr 1 " start at [clock format [clock seconds]] ..."
230 after $3qltime
231 putmsg stdout 0 " ** Since file is closed, need to reopen the file to get a new"
232 putmsg stdout 0 " valid stateid for the following assertions ..."
233 set open_owner2 "${open_owner}--2"
234 set nfh2 [basic_open $bfh $tf 0 "$cid $open_owner2" osid2 oseqid2 status]
235 putmsg stderr 1 " end at [clock format [clock seconds]]"
236 if {$nfh2 == -1} {
237 putmsg stderr 0 \
238 "\t Test FAIL: open again failed, status=($status)"
239 putmsg stderr 0 \
240 "\t Exiting ... rest of the assertions will not be run."
241 do_cleanup $tf $FAIL
242 }
243 logres "PASS"
244
245
246 # m: Verify successful OPEN op renew the lease, expect OK
247 set expcode "OK"
248 set ASSERTION "Verify successful OPEN renew the lease, expect $expcode"
249 set tag "$TNAME{m}"
250 putmsg stdout 0 "$tag: $ASSERTION"
251 putmsg stderr 1 \
252 " wait for 3/4 of leasetime, lease should still be valid after OPEN"
253 putmsg stderr 1 " start at [clock format [clock seconds]] ..."
254 after $3qltime
255 set res [compound {Putfh $bfh; Lookup $tf; Read {1 1} 0 99}]
256 putmsg stderr 1 " end at [clock format [clock seconds]]"
257 ckres "OPEN/READ{1,1}" $status $expcode $res $PASS
258
259
260 # n: Verify successful READ w/stateid{1 1} does not renew lease, next read
261 # would expect EXPIRED|STALE_STATEID
262 set expcode "EXPIRED|STALE_STATEID"
263 set ASSERTION "Verify successful READ w/special stateid 1 does not renew lease"
264 set ASSERTION "$ASSERTION\n\tnext READ w/good osid will fail, expect $expcode"
265 set tag "$TNAME{n}"
266 putmsg stdout 0 "$tag: $ASSERTION"
267 putmsg stderr 1 \
268 " wait for 3/4 of leasetime, lease should have been expired."
269 putmsg stderr 1 " start at [clock format [clock seconds]] ..."
270 after $3qltime
271 set res [compound {Putfh $nfh2; Read $osid2 1 99}]
272 putmsg stderr 1 " end at [clock format [clock seconds]]"
273 ckres "READ{1,1}/READ(osid)" $status $expcode $res $PASS
274
275
276 putmsg stdout 0 " ** Since the lease has expired, we need to reestablish the"
277 putmsg stdout 0 " clientid for the next assertion ..."
278 # r: Verify successful WRITE w/stateid{0 0} does not renew lease, next OPEN
279 # will fail, expect EXPIRED|STALE_CLIENTID
280 set expcode "EXPIRED|STALE_CLIENTID"
281 set ASSERTION "Verify successful WRITE w/stateid{0 0} does not renew lease,"
282 set ASSERTION "$ASSERTION\n\tnext OPEN w/new cid will fail, expect $expcode"
283 set tag "$TNAME{r}"
284 putmsg stdout 0 "$tag: $ASSERTION"
285 set hid2 "[pid][clock seconds]88"
286 set cid2 [getclientid $hid]
287 if {$cid2 == -1} {
288 putmsg stderr 0 "Test UNRESOLVED: getclientid failed"
289 } else {
290 after $halttime
291 set res [compound {Putfh $nfh; Write {0 0} 1 f a $wdata}]
292 if {[ckres "WRITE{0,0}" $status "OK" $res $FAIL] == "true"} {
293 putmsg stderr 1 \
294 " wait for 3/4 of leasetime, lease should have been expired."
295 after $3qltime
296 # an OPEN call should fail now
297 set res [compound {Putfh $bfh;
298 Open 1 3 0 "$cid2 $tag-00111" {0 0 {{mode 0644}}} {0 $tf}; Getfh}]
299 ckres "OPEN" $status $expcode $res $PASS
300 }
301 }
302
303
304 # --------------------------------------------------------------
305 # Final cleanup
306 do_cleanup $tf $PASS