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 SETATTR operation test - negative tests
27 # verify SERVER errors returned with invalid Setattr op.
28
29 # include all test enironment
30 source SETATTR.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
39 set cid [getclientid $TNAME.[pid]]
40 if {$cid == -1} {
41 putmsg stdout 0 "$TNAME: test setup - getclientid"
42 putmsg stderr 0 "\t Test UNRESOLVED: unable to get clientid"
43 exit $UNRESOLVED
44 }
45
46 # create a tmp file for manipulation
47 set tmpF "Sattr_tmpF.[pid]"
48 set owner "$TNAME-OpenOwner"
49 set tfh [basic_open $bfh $tmpF 1 "$cid $owner" osid oseqid status \
50 1 0 664 88]
51 if {$tfh == -1} {
52 putmsg stderr 0 "$TNAME: test setup - basic_open"
53 putmsg stderr 0 "\t Test UNRESOLVED: status=($status)"
54 exit $UNRESOLVED
55 }
56 incr oseqid
57
58
59 # Start testing
60 # --------------------------------------------------------------
61 # a: Setattr with an invalid stateid for size changing,
62 # expect BAD_STATEID|STALE_STATEID
63 set expcode "BAD_STATEID|STALE_STATEID"
64 set ASSERTION "Setattr w/invalid sid for changing size, expect $expcode"
65 set tag "$TNAME{a}"
66 putmsg stdout 0 "$tag: $ASSERTION"
67 set stateid {22 812322}
68 set res [compound {Putfh $tfh; Setattr $stateid {{size 888}}; Getattr size}]
69 ckres "Setattr" $status $expcode $res $PASS
70
71
72 # b: Setattr(size) w/invalid stateid (seqid+1), expect BAD_STATEID
73 set expcode "BAD_STATEID"
74 set ASSERTION "Setattr(size) w/invalid stateid (seqid+1), expect $expcode"
75 set tag "$TNAME{b}"
76 putmsg stdout 0 "$tag: $ASSERTION"
77 set bseqid [expr [lindex $osid 0] + 1]
78 set bosid "$bseqid [lindex $osid 1]"
79 putmsg stderr 1 " new open_sid with trashed seqid: bosid=($bosid)"
80 set res [compound {Putfh $tfh; Setattr $bosid {{mode 0664} {size 1025}};
81 Getattr size}]
82 ckres "Setattr" $status $expcode $res $PASS
83
84
85 # c: Setattr(size) w/invalid stateid (trashed other), expect BAD_STATEID
86 set expcode "BAD_STATEID|STALE_STATEID"
87 set ASSERTION "Setattr(size) w/invalid stateid (trashed other), expect $expcode"
88 set tag "$TNAME{c}"
89 putmsg stdout 0 "$tag: $ASSERTION"
90 set newS ""
91 set oldS [lindex $osid 1]
92 set l [string length $oldS]
93 for {set i 0} {$i < $l} {incr i} {
94 append newS [string index $oldS end-$i]
95 }
96 set cosid "[lindex $osid 0] $newS"
97 putmsg stderr 1 " new open_sid with trashed other: cosid=($cosid)"
98 set res [compound {Putfh $tfh; Setattr $cosid {{size 1}}}]
99 ckres "Setattr" $status $expcode $res $PASS
100
101
102 # g: Setattr(size) with stateid on a closed file, expect BAD_STATEID|OLD_STATEID
103 set expcode "BAD_STATEID|OLD_STATEID"
104 set ASSERTION "Setattr(size) w/stateid on a closed file, expect $expcode"
105 set tag "$TNAME{g}"
106 putmsg stdout 0 "$tag: $ASSERTION"
107 # first close the file
108 set res [compound {Putfh $tfh; Close $oseqid $osid}]
109 if {$status != "OK"} {
110 putmsg stderr 0 "\t Test UNRESOLVED: CLOSE failed, status=($status)"
111 } else {
112 set res [compound {Putfh $tfh; Setattr $osid {{size 333}}}]
113 ckres "Setattr" $status $expcode $res $PASS
114 }
115
116
117 # i: try OPEN,LOCK-1,LOCK-2,SETATTR(LOCK-1-sid), expect OLD_STATEID
118 set expcode "OLD_STATEID"
119 set ASSERTION "try OPEN,LOCK-1,LOCK-2,SETATTR(LOCK-1-sid), expect $expcode"
120 set tag "$TNAME{i}"
121 putmsg stdout 0 "$tag: $ASSERTION"
122 # OPEN and LOCK(2 locks) the file:
123 set tmpFi "Sattr_tmpFi.[pid]"
124 set nfh [basic_open $bfh $tmpFi 1 "$cid $tmpFi" osid oseqid status]
125 if {$nfh == -1} {
126 putmsg stderr 0 "\t Test UNRESOLVED: basic_open failed, status=($status)"
127 } else {
128 incr oseqid
129 set lowner1 "$owner-l1"
130 set lseqid 1
131 set res [compound {Putfh $nfh;
132 Lock 1 F 0 10 T $osid $lseqid {$oseqid $cid $lowner1}}]
133 if {[ckres "Lock-1" $status "OK" $res $FAIL] == "true" } {
134 # Get 2nd Lock
135 set lsid1 [lindex [lindex $res 1] 2]
136 set oseqid [expr $oseqid + 1]
137 set lseqid [expr $lseqid + 1]
138 set res [compound {Putfh $nfh;
139 Lock 2 F 16 10 F $lsid1 $lseqid {$oseqid $cid $lowner1}}]
140 if {[ckres "Lock-2" $status "OK" $res $FAIL] == "true" } {
141 # now Setattr/size using $osid instead of $lock_sid
142 set res [compound {Putfh $nfh; Setattr $lsid1 {{size 222}}}]
143 ckres "Setattr" $status $expcode $res $PASS
144 compound {Putfh $nfh; Close $oseqid $osid}
145 }
146 }
147 }
148
149
150 # m: Setattr(size) w/file open READ only, expect OPENMODE
151 set expcode "OPENMODE"
152 set ASSERTION "Setattr(size) w/file open READ only, expect $expcode"
153 set tag "$TNAME{m}"
154 putmsg stdout 0 "$tag: $ASSERTION"
155 # OPEN a file with access=READ
156 set oowner "[pid][expr [clock seconds] / 2]"
157 set nfh [basic_open $bfh $env(ROFILE) 0 "$cid $oowner" \
158 osid oseqid status 1 0 666 0 1]
159 if {$nfh == -1} {
160 putmsg stderr 0 "\t Test UNRESOLVED: open failed, status=($status)"
161 } else {
162 # Now try to setattr size of this file:
163 set res [compound {Putfh $nfh; Setattr $osid {{size 1023}}}]
164 ckres "Setattr" $status $expcode $res $PASS
165 incr oseqid
166 set res [compound {Putfh $nfh; Close $oseqid $osid}]
167 putmsg stderr 1 " Close res=$res"
168 }
169
170
171 # --------------------------------------------------------------
172 # Final cleanup
173 # cleanup remove the created file
174 set res [compound {Putfh $bfh; Remove $tmpF; Remove $tmpFi}]
175 if { "$status" != "OK" } {
176 putmsg stderr 0 "\t WARNING: cleanup to remove created dir failed"
177 putmsg stderr 0 "\t status=$status; please cleanup manually."
178 putmsg stderr 1 "\t res=($res)"
179 putmsg stderr 1 " "
180 exit $WARNING
181 }
182 # disconnect and exit
183 Disconnect
184 exit $PASS