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 2008 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
25 #
26 # NFSv4 io client recovery tests - negative tests
27 # io tests to test client recovery during grace period after server reboots.
28
29 # include common code and init section
30 source RECOV_proc
31
32 # Connect to the test server
33 Connect
34
35 # setting local variables
36 set TNAME $argv0
37 set tag $TNAME{setup}
38
39 # First check this test is not started before previous tests
40 # grace period ends.
41 ckgrace_period
42
43 # global var
44 global OPEN4_RESULT_CONFIRM
45
46 putmsg stdout 0 \
47 "$tag: Create a test file and its states, then bring down the server."
48 set bfh [get_fh "$BASEDIRS"]
49 set TFILE "$TNAME.[pid]"
50 set owner "[pid]-[expr int([expr [expr rand()] * 100000000])]"
51 set cid [getclientid $owner]
52 if {$cid == -1} {
53 putmsg stdout 0 "$tag: getclientid failed"
54 putmsg stdout 0 "\t Test UNRESOLVED: unable to get clientid"
55 putmsg stdout 1 "\t owner=<$owner>"
56 cleanup $UNRESOLVED
57 }
58
59 # Create a test file and get its osid
60 set fsize 8192
61 set nfh [basic_open $bfh $TFILE 1 "$cid $owner" osid oseqid status \
62 1 0 666 $fsize]
63 if {$nfh == -1} {
64 putmsg stdout 0 "$tag: basic_open"
65 putmsg stdout 0 "\t Test UNRESOLVED: status=($status)"
66 cleanup $UNRESOLVED
67 }
68
69 # Reboot the server
70 putmsg stdout 0 " ** Start to reboot the server ..."
71 reboot_server [file join $env(TMPDIR) $TNAME.tmp.[pid]] $tag
72 putmsg stdout 0 " ** Now wait for server daemon to come up ..."
73 is_nfsd_up $tag
74 putmsg stdout 0 \
75 " ** then run the following assertions within the GRACE period:"
76
77 set cid [getclientid $owner]
78 if {$cid == -1} {
79 putmsg stdout 0 "$tag: getclientid failed"
80 putmsg stdout 0 "\t Test UNRESOLVED: unable to get clientid"
81 putmsg stdout 1 "\t owner=<$owner>"
82 cleanup $UNRESOLVED
83 }
84
85 # Start testing
86 # --------------------------------------------------------------
87 # a: Recovery after Open w/reclaim op during grace period test, expect GRACE
88 set expcode "GRACE"
89 set ASSERTION \
90 "Recovery after Open w/reclaim op during grace period test, expect $expcode"
91 set tag "$TNAME{a}"
92 putmsg stdout 0 "$tag: $ASSERTION"
93
94 # Re-open same test file and get its osid
95 set oseqid 10
96 set res [compound {Putfh $nfh; \
97 Open $oseqid 3 0 "$cid $owner" {0 0 {{mode 0666}}} {1 0}; Getfh}]
98 putmsg stderr 1 "compound {Putfh $nfh;"
99 putmsg stderr 1 \
100 "Open $oseqid 3 0 \"$cid $owner\" {0 0 {{mode 0666}}} {1 0}; Getfh}"
101 putmsg stderr 1 "\tstatus=$status; res=$res"
102 putmsg stderr 1 "\t[clock format [clock seconds]]"
103 set cont [ckres "Open" $status "OK" $res $FAIL]
104
105 if {$cont == "true"} {
106 set osid [lindex [lindex $res 1] 2]
107 set rflags [lindex [lindex $res 1] 4]
108 putmsg stderr 1 "osid=$osid"
109 putmsg stderr 1 "rflags=$rflags"
110
111 if {[expr $rflags & $OPEN4_RESULT_CONFIRM] == $OPEN4_RESULT_CONFIRM} {
112 putmsg stderr 1 \
113 " unexpected request for an Open_confirm, rflags=($rflags)"
114 putmsg stderr 1 "\tRes: $res"
115 putmsg stdout 0 "\t Test FAIL"
116 return -2
117 } else {
118 putmsg stdout 0 "\t Test PASS"
119 }
120 }
121
122 # b: Recovery after Read operation during grace period test, expect GRACE
123 set expcode "GRACE"
124 set ASSERTION \
125 "Recovery after Read operation during grace period test, expect $expcode"
126 set tag "$TNAME{b}"
127 putmsg stdout 0 "$tag: $ASSERTION"
128
129 set res [compound {Putfh $bfh; Lookup $TFILE; Read $osid 0 1024}]
130 putmsg stderr 1 "compound {Putfh $bfh; Lookup $TFILE; Read $osid 0 1024}"
131 putmsg stderr 1 "\tstatus=$status; res=$res"
132 putmsg stderr 1 "\t[clock format [clock seconds]]"
133 ckres "Read" $status $expcode $res $PASS
134
135 # c: Recovery after Write Op during the grace period test, expect GRACE
136 set expcode "GRACE"
137 set ASSERTION \
138 "Recovery after Write Op during the grace period test, expect $expcode"
139 set tag "$TNAME{c}"
140 putmsg stdout 0 "$tag: $ASSERTION"
141
142 set count 1023
143 set data [string repeat "a" $count]
144 set res [compound {Putfh $nfh; Write $osid 0 f a $data; Getfh}]
145 putmsg stderr 1 "compound {Putfh $nfh; Write $osid 0 f a $data; Getfh}"
146 putmsg stderr 1 "\tstatus=$status; res=$res"
147 putmsg stderr 1 "\t[clock format [clock seconds]]"
148 ckres "Write" $status $expcode $res $PASS
149
150 # d: Recovery after Setattr Op during the grace period test, expect GRACE
151 set expcode "GRACE"
152 set ASSERTION \
153 "Recovery after Setattr Op during the grace period test, expect $expcode"
154 set tag "$TNAME{d}"
155 putmsg stdout 0 "$tag: $ASSERTION"
156
157 set nsize [expr $fsize - 16]
158 set res [compound {Putfh $nfh; Setattr $osid {{size $nsize}}; Getfh}]
159 putmsg stderr 1 "compound {Putfh $nfh; Setattr $osid {{size $nsize}}; Getfh}"
160 putmsg stderr 1 "\tstatus=$status; res=$res"
161 putmsg stderr 1 "\t[clock format [clock seconds]]"
162 ckres "Setattr" $status $expcode $res $PASS
163
164 # --------------------------------------------------------------
165 # Now cleanup, and removed created tmp file
166 set tag $TNAME{cleanup}
167 set res [compound {Putfh $bfh; Remove $TFILE}]
168 putmsg stderr 1 "compound {Putfh $bfh; Remove $TFILE"
169 putmsg stderr 1 "\tstatus=$status; res=$res"
170 putmsg stderr 1 "\t[clock format [clock seconds]]"
171 if { "$status" != "OK" } {
172 putmsg stdout 0 "$tag:"
173 putmsg stdout 0 "\t WARNING: cleanup to remove created tmp file failed"
174 putmsg stdout 0 "\t status=$status; please cleanup manually."
175 putmsg stderr 1 "\t res=($res)"
176 putmsg stderr 1 " "
177 cleanup $WARNING
178 }
179
180 # All are good; so exit PASS
181 cleanup $PASS