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 (same owner)
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 8192
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 lowner "$TNAME-lower.[pid]"
58 set lseqid 1
59
60
61 # Start testing
62 # --------------------------------------------------------------
63 # a: new LOCK(READ,0,100), expect OK
64 set expcode "OK"
65 set ASSERTION "new LOCK(READ,0,100), expect $expcode"
66 set tag "$TNAME{a}"
67 putmsg stdout 0 "$tag: $ASSERTION"
68 set res [compound {Putfh $nfh;
69 Lock 1 F 0 100 T $osid $lseqid "$oseqid $cid $lowner"}]
70 if { [ckres "Lock(R)" $status $expcode $res $PASS] == "true" } {
71 set lsid [lindex [lindex $res 1] 2]
72 incr lseqid
73 incr oseqid
74 } else {
75 set lsid {11 22}
76 }
77
78 # b: another cross boundary LOCK(WRITE,88,100), expect OK
79 set expcode "OK"
80 set ASSERTION "another cross boundary LOCK(WRITE,88,100), expect $expcode"
81 set tag "$TNAME{b}"
82 putmsg stdout 0 "$tag: $ASSERTION"
83 set res [compound {Putfh $nfh;
84 Lock 2 F 88 100 F $lsid $lseqid "$oseqid $cid $lowner"}]
85 if { [ckres "Lock(W)" $status $expcode $res $PASS] == "true" } {
86 set lsid [lindex [lindex $res 1] 2]
87 incr lseqid
88 } else {
89 set lsid {11 22}
90 }
91
92 # e: Lockt(same lowner) to check the R/W locks, expect OK
93 set expcode "OK"
94 set ASSERTION "Lockt(same lowner) to check the READ locks, expect $expcode"
95 set tag "$TNAME{e}"
96 putmsg stdout 0 "$tag: $ASSERTION"
97 set res [compound {Putfh $nfh; Lockt 1 $cid $lowner 10 77;
98 Lockt 2 $cid $lowner 88 10}]
99 ckres "Lockt" $status $expcode $res $PASS
100
101 # f: Lockt(same lowner) on bondary locks, expect OK
102 set expcode "OK"
103 set ASSERTION "Lockt(same lowner) on bondary locks, expect $expcode"
104 set tag "$TNAME{f}"
105 putmsg stdout 0 "$tag: $ASSERTION"
106 set res [compound {Putfh $nfh; Lockt 1 $cid $lowner 80 22}]
107 ckres "Lockt" $status $expcode $res $PASS
108
109 # i: Locku(same lowner) on bondary locks, expect OK
110 set expcode "OK"
111 set ASSERTION "Locku(same lowner) on bondary locks, expect $expcode"
112 set tag "$TNAME{i}"
113 putmsg stdout 0 "$tag: $ASSERTION"
114 set res [compound {Putfh $nfh; Locku 1 $lseqid $lsid 80 22}]
115 if { [ckres "Locku" $status $expcode $res $PASS] == "true" } {
116 set lsid [lindex [lindex $res 1] 2]
117 incr lseqid
118 } else {
119 set lsid {11 22}
120 }
121
122 # j: Locku(same lowner) whole file w/holes in it, expect OK
123 set expcode "OK"
124 set ASSERTION "Locku(same lowner) whole file w/holes, expect $expcode"
125 set tag "$TNAME{j}"
126 putmsg stdout 0 "$tag: $ASSERTION"
127 set res [compound {Putfh $nfh; Locku 2 $lseqid $lsid 0 $fsize}]
128 if { [ckres "Locku" $status $expcode $res $PASS] == "true" } {
129 set lsid [lindex [lindex $res 1] 2]
130 }
131
132 # o: new-lowner to Lock(W) to verify no conflict locks, expect OK
133 set expcode "OK"
134 set ASSERTION "new-lowner to Lock(W) whole file, expect $expcode"
135 set tag "$TNAME{o}"
136 putmsg stdout 0 "$tag: $ASSERTION"
137 set lseqid 100
138 set lowner2 "$lowner-2"
139 set res [compound {Putfh $nfh;
140 Lock 1 F 0 $fsize T $osid $lseqid "$oseqid $cid $lowner2"}]
141 if { [ckres "Lock(W)" $status $expcode $res $PASS] == "true" } {
142 set lsid [lindex [lindex $res 1] 2]
143 incr lseqid
144 incr oseqid
145 } else {
146 set lsid {11 22}
147 }
148
149 # p: Now Close the file to clear the locks, expect OK|LOCKS_HELD
150 # some server not support CLOSE that file still has record locks held
151 set expcode "OK|LOCKS_HELD"
152 set ASSERTION "Now Close file to clear the locks, expect $expcode"
153 set tag "$TNAME{p}"
154 putmsg stdout 0 "$tag: $ASSERTION"
155 set res [compound {Putfh $nfh; Close $oseqid $osid}]
156 set clst $status
157 if { ($env(SRVOS) == "Solaris") } {
158 ckres "Close" $status "OK" $res $PASS
159 } else {
160 ckres "Close" $status $expcode $res $PASS
161 }
162
163
164 # q: verify w/Lockt locks clear for orig-lowner, expect OK
165 set expcode "OK"
166 set ASSERTION "verify w/Lockt locks clear for orig-lowner, expect $expcode"
167 set tag "$TNAME{q}"
168 putmsg stdout 0 "$tag: $ASSERTION"
169 set res [compound {Putfh $nfh; Lockt 2 $cid $lowner 10 10000}]
170 ckres "Lockt" $status $expcode $res $PASS
171 putmsg stdout 1 "\t Close returned $clst"
172
173
174 # --------------------------------------------------------------
175 # Now cleanup, close and removed created tmp file
176 set res [compound {Putfh $bfh; Remove $TFILE}]
177 if {($status != "OK") && ($status != "NOENT")} {
178 putmsg stderr 0 "\t WARNING: cleanup to remove created tmp file failed"
179 putmsg stderr 0 "\t status=$status; please cleanup manually."
180 putmsg stderr 1 "\t res=($res)"
181 putmsg stderr 1 " "
182 exit $WARNING
183 }
184
185 # --------------------------------------------------------------
186 # disconnect and exit
187 Disconnect
188 exit $PASS