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 RENAME operation test - positive tests
27
28 # include all test enironment
29 source RENAME.env
30
31 # connect to the test server
32 Connect
33
34 # setting local variables
35 set TNAME $argv0
36 set bfh [get_fh "$BASEDIRS"]
37
38 # Start testing
39 # --------------------------------------------------------------
40 # a: basic Rename of a file, expect OK
41 set expcode "OK"
42 set ASSERTION "Basic Rename of a file, expect $expcode"
43 putmsg stdout 0 "$TNAME{a}: $ASSERTION"
44 set newf "NewRenF.[pid]"
45 set nffh [creatv4_file [file join $BASEDIR $newf]]
46 if { $nffh != $NULL } {
47 # now the rename test:
48 set res [compound {Putfh $bfh; Savefh;
49 Putfh $bfh; Rename $newf "a.new"; Getfh}]
50 set cont [ckres "Rename" $status $expcode $res $FAIL]
51 set fh1 [lindex [lindex $res 4] 2]
52 } else {
53 putmsg stderr 0 "\t Test UNINITIATED: unable to create temp file."
54 putmsg stderr 1 "\t res=($res)"
55 set cont "false"
56 }
57 # verify original file is removed and new file exist:
58 if {! [string equal $cont "false"]} {
59 set res [compound {Putfh $bfh; Lookup $newf}]
60 if { $status != "NOENT" } {
61 putmsg stderr 0 "\t Test FAIL: orig file exists after Rename."
62 putmsg stderr 1 "\t res=($res)"
63 set cont false
64 } else {
65 set res [compound {Putfh $bfh; Lookup "a.new"}]
66 if { $status != "OK" } {
67 putmsg stderr 0 "\t Test FAIL: new file doesn't exist after Rename."
68 putmsg stderr 1 "\t res=($res)"
69 set cont false
70 }
71 }
72 }
73 # verify FH is not changed after successful Readdir op
74 fh_equal $fh1 $bfh $cont $PASS
75
76
77 # b: basic Rename of a dir entry, expect OK
78 set expcode "OK"
79 set ASSERTION "Basic Rename of a dir entry, expect $expcode"
80 putmsg stdout 0 "$TNAME{b}: $ASSERTION"
81 set newd "NewRenD.[pid]"
82 set res [compound {Putfh $bfh; Savefh; Create $newd {{mode 0777}} d;
83 Putfh $bfh; Rename $newd "b.new"; Getfh}]
84 set cont [ckres "Rename" $status $expcode $res $FAIL]
85 set fh1 [lindex [lindex $res 5] 2]
86 # verify original file is removed and new file exist:
87 if {! [string equal $cont "false"]} {
88 set res [compound {Putfh $bfh; Lookup $newd}]
89 if { $status != "NOENT" } {
90 putmsg stderr 0 "\t Test FAIL: orig file exists after Rename."
91 putmsg stderr 1 "\t res=($res)"
92 set cont false
93 } else {
94 set res [compound {Putfh $bfh; Lookup "b.new"}]
95 if { $status != "OK" } {
96 putmsg stderr 0 "\t Test FAIL: new file doesn't exist after Rename."
97 putmsg stderr 1 "\t res=($res)"
98 set cont false
99 }
100 }
101 }
102 # verify FH is not changed after successful Readdir op
103 fh_equal $fh1 $bfh $cont $PASS
104
105
106 # c: Rename the same file, expect OK
107 set expcode "OK"
108 set ASSERTION "Rename same file (oldname hardlink-to newname), expect $expcode"
109 putmsg stdout 0 "$TNAME{c}: $ASSERTION"
110 set newl "NewRenL.[pid]"
111 set res [compound {Putfh $bfh; Create $newl {{mode 0755}} s; Savefh;
112 Putfh $bfh; Link "c.new"; Savefh; Rename $newl "c.new"; Getfh}]
113 set cont [ckres "Rename" $status $expcode $res $FAIL]
114 set fh1 [lindex [lindex $res 7] 2]
115 # verify both files exist:
116 if {! [string equal $cont "false"]} {
117 set res [compound {Putfh $bfh; Lookup $newl;
118 Putfh $bfh; Lookup "c.new"}]
119 if { $status != "OK" } {
120 putmsg stderr 0 "\t Test FAIL: files don't exist after Rename."
121 putmsg stderr 1 "\t res=($res)"
122 set cont false
123 }
124 }
125 # verify FH is not changed after successful Readdir op
126 fh_equal $fh1 $bfh $cont $PASS
127
128
129 # d: Rename when new name exists (same type), expect OK
130 set expcode "OK"
131 set ASSERTION "Rename when new name exists (same type), expect $expcode"
132 putmsg stdout 0 "$TNAME{d}: $ASSERTION"
133 set newk "NewRenK.[pid]"
134 set res [compound {Putfh $bfh; Savefh; Create $newk {{mode 0777}} d;
135 Putfh $bfh; Create "d.new" {{mode 0775}} d;
136 Putfh $bfh; Lookup "d.new"; Setattr {0 0} {{mode 0751}};
137 Putfh $bfh; Lookup $newk; Getattr mode;
138 Putfh $bfh; Rename $newk "d.new"; Getfh}]
139 set cont [ckres "Rename" $status $expcode $res $FAIL]
140 set fh1 [lindex [lindex $res 13] 2]
141 set expm [lindex [lindex $res 10] 2]
142 # verify original file is removed and new file exist:
143 if {! [string equal $cont "false"]} {
144 set res [compound {Putfh $bfh; Lookup $newk}]
145 if { $status != "NOENT" } {
146 putmsg stderr 0 "\t Test FAIL: orig obj exists after Rename."
147 putmsg stderr 1 "\t res=($res)"
148 set cont false
149 } else {
150 set res [compound {Putfh $bfh; Lookup "d.new"; Getattr mode}]
151 if { $status != "OK" } {
152 putmsg stderr 0 "\t Test FAIL: new obj doesn't exist after Rename."
153 putmsg stderr 1 "\t res=($res)"
154 set cont false
155 } else {
156 set dm [lindex [lindex $res 2] 2]
157 if { $dm == 751 } {
158 putmsg stderr 0 "\t Test FAIL: new obj has incorrect mode."
159 putmsg stderr 0 "\t expected=($dm), got($dm)."
160 putmsg stderr 1 "\t res=($res)"
161 set cont false
162 }
163 }
164 }
165 }
166 # verify FH is not changed after successful Readdir op
167 # verify FH is not changed after successful Readdir op
168 fh_equal $fh1 $bfh $cont $PASS
169
170
171 # --------------------------------------------------------------
172 # Final cleanup:
173 # remove the created temp link files
174 set res [compound {Putfh $bfh; Remove "a.new"; Remove "b.new";
175 Remove $newl; Remove "c.new"; Remove "d.new"}]
176 if { "$status" != "OK" } {
177 putmsg stderr 0 "\t WARNING: cleanup to remove created files failed"
178 putmsg stderr 0 "\t status=$status; please cleanup manually."
179 putmsg stderr 1 "\t res=($res)"
180 putmsg stderr 1 " "
181 exit $WARNING
182 }
183
184 # disconnect and exit
185 Disconnect
186 exit $PASS