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 - positive tests
27 # verify setattr with valid stateid and owner
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 # First create a temp file and get its open_sid and filehandle
40 set TFILE "$TNAME.[pid]"
41 set owner "[pid]-[expr int([expr [expr rand()] * 100000000])]"
42 set cid [getclientid $owner]
43 if {$cid == -1} {
44 putmsg stderr 0 "$TNAME: setup - getclientid"
45 putmsg stderr 0 "\t Test UNRESOLVED: unable to get clientid"
46 exit $UNRESOLVED
47 }
48
49 set fsize 8192
50 set nfh [basic_open $bfh $TFILE 1 "$cid $owner" open_sid oseqid status \
51 1 0 664 $fsize]
52 if {$nfh == -1} {
53 putmsg stderr 0 "$TNAME: setup basic_open"
54 putmsg stderr 0 "\t Test UNRESOLVED: status=($status)"
55 exit $UNRESOLVED
56 }
57
58 # Start testing
59 # --------------------------------------------------------------
60 # a: Setattr size to truncate the file, expect OK
61 set expcode "OK"
62 set ASSERTION "Setattr size to truncate the file, expect $expcode"
63 set tag "$TNAME{a}"
64 putmsg stdout 0 "$tag: $ASSERTION"
65 set nsize 511
66 set res [compound {Putfh $nfh; Getattr time_modify;
67 Setattr $open_sid {{size $nsize}}; Getattr {size time_modify}}]
68 if {[ckres "Setattr" $status $expcode $res $FAIL] == "true"} {
69 set rsize [extract_attr [lindex [lindex $res 3] 2] "size"]
70 if {"$rsize" != "$nsize"} {
71 putmsg stderr 0 "\t Test FAIL: Incorrect filesize after truncation"
72 putmsg stderr 0 "\t expected=($nsize), got=($rsize)"
73 putmsg stderr 1 "\t res=($res)"
74 } else {
75 # verify time_modify attribute is updated after SETATTR
76 set oldtime [extract_attr [lindex [lindex $res 1] 2] "time_modify"]
77 set newtime [extract_attr [lindex [lindex $res 3] 2] "time_modify"]
78 if {"$oldtime" == "$newtime"} {
79 putmsg stderr 0 "\t Test FAIL: same time_modify after truncation"
80 putmsg stderr 0 "\t expected=($newtime), got=($oldtime)"
81 putmsg stderr 1 "\t res=($res)"
82 } else {
83 logres "PASS"
84 }
85 }
86 }
87
88 # e: Setattr owner to original owner of the file, expect OK
89 set expcode "OK"
90 set ASSERTION "Setattr owner to original owner of the file, expect $expcode"
91 set tag "$TNAME{e}"
92 putmsg stdout 0 "$tag: $ASSERTION"
93 set res [compound {Putfh $nfh; Getattr owner}]
94 set fowner [extract_attr [lindex [lindex $res 1] 2] "owner"]
95 set res [compound {Putfh $nfh; Setattr $open_sid {{owner $fowner}};
96 Getattr {owner filehandle}}]
97 if {[ckres "Setattr" $status $expcode $res $FAIL] == "true"} {
98 set rowner [extract_attr [lindex [lindex $res 2] 2] "owner"]
99 set rfh [extract_attr [lindex [lindex $res 2] 2] "filehandle"]
100 if {"$rowner" != "$fowner"} {
101 putmsg stderr 0 "\t Test FAIL: Incorrect new-owner after SETATTR"
102 putmsg stderr 0 "\t expected=($fowner), got=($rowner)"
103 putmsg stderr 1 "\t res=($res)"
104 } else {
105 if {"$nfh" != "$rfh"} {
106 putmsg stderr 0 "\t Test FAIL: Incorrect FH after SETATTR"
107 putmsg stderr 0 "\t expected=($nfh), got=($rfh)"
108 putmsg stderr 1 "\t res=($res)"
109 } else {
110 logres "PASS"
111 }
112 }
113 }
114
115 # f: Setattr group to original owner_group of the file, expect OK
116 set expcode "OK"
117 set ASSERTION "Setattr group to original file owner_group, expect $expcode"
118 set tag "$TNAME{f}"
119 putmsg stdout 0 "$tag: $ASSERTION"
120 set res [compound {Putfh $nfh; Getattr owner_group}]
121 set fgroup [extract_attr [lindex [lindex $res 1] 2] "owner_group"]
122 set res [compound {Putfh $nfh; Setattr $open_sid {{owner_group $fgroup}};
123 Getattr {owner_group filehandle}}]
124 if {[ckres "Setattr" $status $expcode $res $FAIL] == "true"} {
125 set rgroup [extract_attr [lindex [lindex $res 2] 2] "owner_group"]
126 set rfh [extract_attr [lindex [lindex $res 2] 2] "filehandle"]
127 if {"$rgroup" != "$fgroup"} {
128 putmsg stderr 0 "\t Test FAIL: Incorrect new-group after SETATTR"
129 putmsg stderr 0 "\t expected=($fgroup), got=($rgroup)"
130 putmsg stderr 1 "\t res=($res)"
131 } else {
132 if {"$nfh" != "$rfh"} {
133 putmsg stderr 0 "\t Test FAIL: Incorrect FH after SETATTR"
134 putmsg stderr 0 "\t expected=($nfh), got=($rfh)"
135 putmsg stderr 1 "\t res=($res)"
136 } else {
137 logres "PASS"
138 }
139 }
140 }
141
142 # --------------------------------------------------------------
143 # Final cleanup
144 # remove the created tmp file
145 set res [compound {Putfh $bfh; Remove $TFILE}]
146 if { "$status" != "OK" } {
147 putmsg stderr 0 "\t WARNING: cleanup to remove created file failed"
148 putmsg stderr 0 "\t status=$status; please cleanup manually."
149 putmsg stderr 1 "\t res=($res)"
150 putmsg stderr 1 " "
151 exit $WARNING
152 }
153
154 # disconnect and exit
155 Disconnect
156 exit $PASS