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 server state recovery test - network partition
  27 
  28 # include all test enironment
  29 source LOCKsid.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 # Get server lease time
  39 set leasetm $LEASE_TIME
  40 
  41 # First, basic setup
  42 putmsg stdout 0 \
  43   "\n  ** Frist basic setup for $TNAME, if fails, program will exit ..."
  44 
  45 # Start testing
  46 # --------------------------------------------------------------
  47 # a: Setclientid/Setclient_confirm, expect OK
  48 set expcode "OK"
  49 set ASSERTION "Setclientid/Setclient_confirm, expect $expcode"
  50 set tag "$TNAME{a}"
  51 putmsg stdout 0 "$tag: $ASSERTION"
  52 set hid "[pid][clock clicks]"
  53 set cid [getclientid $hid]
  54 if {$cid == -1} {
  55         putmsg stderr 0 "Test FAIL: unable to get clientid"
  56         exit $FAIL
  57 } else {
  58         logres PASS
  59 }
  60 
  61 
  62 # b: Open a test file w/good clientid, expect OK
  63 set expcode "OK"
  64 set ASSERTION "Open(& confirm if needed) file w/good clientid, expect $expcode"
  65 set tag "$TNAME{b}"
  66 putmsg stdout 0 "$tag: $ASSERTION"
  67 set seqid 1
  68 set TFILE "$TNAME.[pid]-b"
  69 set fs 8192
  70 set open_owner $TFILE
  71 set nfh [basic_open $bfh $TFILE 1 "$cid $open_owner" osid oseqid status \
  72         $seqid 0 664 $fs]
  73 if {$nfh == -1} {
  74         putmsg stderr 0 "\t Test FAIL: basic_open failed, status=($status)"
  75         exit $FAIL
  76 } else {
  77         putmsg stderr 0 "\t Test PASS"
  78         set oseqid [expr $oseqid + 1]
  79 }
  80 
  81 # c: LOCK(R) the test file w/cid+osid, expect OK
  82 set expcode "OK"
  83 set ASSERTION "LOCK(R) the test file w/cid+osid, expect $expcode"
  84 set tag "$TNAME{c}"
  85 putmsg stdout 0 "$tag: $ASSERTION"
  86 set lseqid 1
  87 set lowner "lowner.[pid]-d"
  88 set res [compound {Putfh $nfh; 
  89         Lock 1 F 0 512 T $osid $lseqid "$oseqid $cid $lowner"}]
  90 if { [ckres "Lock(R)" $status $expcode $res $PASS] == "true" } {
  91         set lsid [lindex [lindex $res 1] 2]
  92         incr oseqid
  93 
  94         # d: Read the LOCKed file w/lsid, expect OK
  95         set expcode "OK"
  96         set ASSERTION "Read the LOCKed file w/lsid, expect $expcode"
  97         putmsg stdout 0 "$TNAME{d}: $ASSERTION"
  98         set tag "$TNAME{d}"
  99         set res [compound {Putfh $nfh; Read $lsid 10 100}]
 100         ckres "Read" $status $expcode $res $PASS
 101 } else {
 102         putmsg stderr 0 "\t Lock(R) failed, assertion d did not run"
 103         putmsg stderr 1 "\t res=($res)"
 104 }
 105 putmsg stdout 0 \
 106   "\n  ** Try to reset clientid w/out confirm, to verify states are valid:"
 107 
 108 # f1: Reset clientid without confirm w/new hid, expect OK
 109 set expcode "OK"
 110 set ASSERTION "Reset clientid w/out confirm w/new hid, expect $expcode"
 111 set tag "$TNAME{f1}"
 112 putmsg stdout 0 "$tag: $ASSERTION"
 113 set verf2 "[pid][expr int([expr [expr rand()] * 100000000])]"
 114 set owner2 "$hid-2"
 115 putmsg stdout 1 "getclientid: verifier=($verf2), owner=($owner2)"
 116 set status [setclient $verf2 $owner2 cid2 cidverf2 res {0 0 0}]
 117 if {$status != "OK"} {
 118         putmsg stderr 0 "\t Test UNRESOLVED: Setclientid failed on reset"
 119         putmsg stderr 0 "\t\t assertions (m's) will not run."
 120         putmsg stdout 1 "\t\t res=($res)"
 121 } else {
 122         logres PASS
 123 
 124 # ... and continue
 125 # f2: Now try a conflict LOCKT w/unconfirmed cid2, new lowner2
 126 set expcode "EXPIRED"
 127 set ASSERTION "Conflict LOCKT w/unconfirmed cid2, lowner2, expect $expcode"
 128 set tag "$TNAME{f2}"
 129 putmsg stdout 0 "$tag: $ASSERTION"
 130 incr lseqid
 131 set lowner2 "$lowner-2"
 132 set res [compound {Putfh $nfh; Lockt 2 $cid2 $lowner2 10 200}]
 133 ckres "LockT" $status $expcode $res $PASS
 134 
 135 # f3: LOCKT with cid1/lowner2, expect DENIED
 136 set expcode "DENIED"
 137 set ASSERTION "LOCKT with cid1/lowner2, expect $expcode"
 138 set tag "$TNAME{f3}"
 139 putmsg stdout 0 "$tag: $ASSERTION"
 140 set res [compound {Putfh $nfh; Lockt 2 $cid $lowner2 10 200}]
 141 ckres "LockT" $status $expcode $res $PASS
 142 
 143 # f4: LOCKT with confirmed cid2/lowner1, expect DENIED
 144 set expcode "DENIED"
 145 set ASSERTION "LOCKT w/confirmed cid2/lowner1, expect $expcode"
 146 set tag "$TNAME{f4}"
 147 putmsg stdout 0 "$tag: $ASSERTION"
 148 # confirm the clientid-2
 149 set status [setclientconf $cid2 $cidverf2 res]
 150 if {$status != "OK"} {
 151         putmsg stderr 0 "\t Test UNRESOLVED: Setclientid_confirm failed on cid2"
 152         putmsg stdout 0 "\t\t res=($res)"
 153 } else {
 154         set res [compound {Putfh $nfh; Lockt 2 $cid2 $lowner 10 200}]
 155         ckres "LockT" $status $expcode $res $PASS
 156 }
 157 
 158 # f5: Check upgrade a section to LOCK(W) w/lsid, expect OK
 159 set expcode "OK"
 160 set ASSERTION "Check upgrade a section to LOCK(W) w/lsid, expect $expcode"
 161 set tag "$TNAME{f5}"
 162 putmsg stdout 0 "$tag: $ASSERTION"
 163 set res [compound {Putfh $nfh; 
 164         Lock 2 F 10 16 F $lsid $lseqid "$oseqid $cid $lowner"}]
 165 if { [ckres "Lock(W)" $status $expcode $res $PASS] == "true" } {
 166         set lsid [lindex [lindex $res 1] 2]
 167 
 168         # f6: Write using still valid lock-stateid, expect OK
 169         set expcode "OK"
 170         set ASSERTION "Write using still valid lock-stateid, expect $expcode"
 171         set tag "$TNAME{f6}"
 172         putmsg stdout 0 "$tag: $ASSERTION"
 173         set res [compound {Putfh $nfh; Write $lsid 5 f a "$tag"}]
 174         ckres "Write" $status $expcode $res $PASS
 175 } else {
 176         putmsg stderr 0 "\t Lock(W) failed, assertion f4 did not run"
 177         putmsg stderr 1 "\t res=($res)"
 178 }
 179 
 180 
 181 }
 182 
 183 
 184 # Wait for lease time to expire
 185 putmsg stdout 0 \
 186   "\n  ** Now wait for lease($leasetm) to expire, then do following (l's):"
 187 exec sleep [expr $leasetm + 10]
 188 
 189 # l1: Now try to LOCK again w/lock_sid, expect EXPIRED|BAD_STATEID
 190 set expcode "EXPIRED|BAD_STATEID"
 191 set ASSERTION "Now try to LOCK w/lock_sid, expect $expcode"
 192 set tag "$TNAME{l1}"
 193 putmsg stdout 0 "$tag: $ASSERTION"
 194 set lseqid 20
 195 set res [compound {Putfh $nfh; 
 196         Lock 2 F 1024 10 F $lsid $lseqid "$oseqid $cid $lowner"}]
 197 ckres "Lock" $status $expcode $res $PASS
 198 
 199 # l2: Now try to LOCKT w/cid & lowner, expect STALE_CLIENTID
 200 set expcode "STALE_CLIENTID"
 201 set ASSERTION "Now try to LOCKT w/cid & lowner, expect $expcode"
 202 set tag "$TNAME{l2}"
 203 putmsg stdout 0 "$tag: $ASSERTION"
 204 #incr lseqid
 205 #set res [compound {Putfh $nfh; Lockt 1 $cid $lowner 10 200}]
 206 #ckres "Lockt" $status $expcode $res $PASS
 207 putmsg stdout 0 "\t Test UNSUPPORTED: invalid in Solaris"
 208 putmsg stdout 1 "\t   This assertion is based on the variability of"
 209 putmsg stdout 1 "\t   interpretation for the server implementation."
 210 
 211 # l3: try to Read the file w/osid, expect EXPIRED|BAD_STATEID
 212 set expcode "EXPIRED|BAD_STATEID"
 213 set ASSERTION "try to Read the file w/osid, expect $expcode"
 214 set tag "$TNAME{l3}"
 215 putmsg stdout 0 "$tag: $ASSERTION"
 216 set res [compound {Putfh $nfh; Read $lsid 10 100}]
 217 ckres "Read" $status $expcode $res $PASS
 218 
 219 # l4: Now try to unLOCK the file w/lsid, expect EXPIRED|BAD_STATEID
 220 set expcode "EXPIRED|BAD_STATEID"
 221 set ASSERTION "Now try to unLOCK the file w/lsid, expect $expcode"
 222 set tag "$TNAME{l4}"
 223 putmsg stdout 0 "$tag: $ASSERTION"
 224 incr lseqid
 225 set res [compound {Putfh $nfh; Locku 1 $lseqid $lsid 10 200}]
 226 ckres "Locku" $status $expcode $res $PASS
 227 
 228 putmsg stdout 0 \
 229   "\n  ** Reset the clientid(w/confirm) w/new hid and do following(m's):"
 230 
 231 # m1: Reset and confirm clientid w/new hid, expect OK
 232 set expcode "OK"
 233 set ASSERTION "Reset and confirm clientid w/new hid, expect $expcode"
 234 set tag "$TNAME{m1}"
 235 putmsg stdout 0 "$tag: $ASSERTION"
 236 set cid2 [getclientid $hid-2]
 237 if {$cid2 == -1} {
 238         putmsg stderr 0 "\t Test UNRESOLVED: getclientid failed on reset"
 239         putmsg stderr 0 "\t\t assertions (m's) will not run."
 240 } else {
 241         logres PASS
 242 
 243 # ... and continue
 244 # m2: Now try a conflict LOCKT w/new cid and new lowner, expect OK
 245 set expcode "OK"
 246 set ASSERTION "Now try a conflict LOCKT w/new cid+lowner, expect $expcode"
 247 set tag "$TNAME{m2}"
 248 putmsg stdout 0 "$tag: $ASSERTION"
 249 incr lseqid
 250 set lowner3 "$lowner-m2"
 251 set res [compound {Putfh $nfh; Lockt 2 $cid2 $lowner3 10 200}]
 252 ckres "LockT" $status $expcode $res $PASS
 253 
 254 
 255 # m3: new LOCK(WRITE) test file w/new cid, but osid,
 256 #       expect STALE_STATEID|STALE_CLIENTID|EXPIRED
 257 set expcode "STALE_STATEID|STALE_CLIENTID|EXPIRED"
 258 set ASSERTION "new LOCK(WRITE) w/new cid, but osid, expect $expcode"
 259 set tag "$TNAME{m3}"
 260 putmsg stdout 0 "$tag: $ASSERTION"
 261 set lseqid 10
 262 set lowner "lowner.[pid]-m"
 263 set res [compound {Putfh $nfh; 
 264         Lock 2 F 512 1024 T $osid $lseqid "$oseqid $cid2 $lowner"}]
 265 ckres "Lock(W)" $status $expcode $res $PASS
 266 
 267 # m4: re-Open test file w/new cid to get new-osid, expect OK
 268 set expcode "OK"
 269 set ASSERTION "Open(& confirm if needed) file w/new cid, expect $expcode"
 270 set tag "$TNAME{m4}"
 271 putmsg stdout 0 "$tag: $ASSERTION"
 272 set seqid 5
 273 set nfh [basic_open $bfh $TFILE 0 "$cid2 $open_owner" osid2 oseqid2 status \
 274         $seqid 0 664 $fs]
 275 if {$nfh == -1} {
 276         putmsg stderr 0 "\t Test FAIL: basic_open2 failed, status=($status)"
 277         exit $FAIL
 278 } else {
 279         putmsg stderr 0 "\t Test PASS"
 280         set oseqid2 [expr $oseqid2 + 1]
 281 }
 282 
 283 # m5: LOCK(WRITE) again w/new cid & new osid, expect OK
 284 set expcode "OK"
 285 set ASSERTION "LOCK(WRITE) again w/new cid & new osid, expect $expcode"
 286 set tag "$TNAME{m5}"
 287 putmsg stdout 0 "$tag: $ASSERTION"
 288 set off 512
 289 set res [compound {Putfh $nfh; 
 290         Lock 2 F $off 1024 T $osid2 $lseqid "$oseqid2 $cid2 $lowner"}]
 291 if { [ckres "Lock(W)" $status $expcode $res $PASS] == "true" } {
 292         set lsid2 [lindex [lindex $res 1] 2]
 293         set lseqid [expr $lseqid + 1]
 294         incr oseqid2
 295 } else {
 296         putmsg stderr 0 "\t ... following assertions may fail unexpectedly."
 297         putmsg stderr 1 "\t res=($res)"
 298 }
 299 
 300 # m6: WRITE some data w/new cid & new osid, expect OK
 301 set expcode "OK"
 302 set ASSERTION "WRITE some data w/new cid & new lsid, expect $expcode"
 303 set tag "$TNAME{m6}"
 304 putmsg stdout 0 "$tag: $ASSERTION"
 305 set data [string repeat "m" 256]
 306 set res [compound {Putfh $nfh; Write $lsid2 $off f a $data}]
 307 ckres "Write" $status $expcode $res $PASS
 308 
 309 # m7: SETATTR to truncate the file w/new lsid2, expect OK
 310 set expcode "OK"
 311 set ASSERTION "SETATTR to truncate the file w/new lsid, expect $expcode"
 312 set tag "$TNAME{m7}"
 313 putmsg stdout 0 "$tag: $ASSERTION"
 314 set nfz [expr $off + 16]
 315 set res [compound {Putfh $nfh; Setattr $lsid2 {{size $nfz} {mode 0600}} }]
 316 ckres "Setattr" $status $expcode $res $PASS
 317 
 318 # m8: try LOCKU portion w/new lsid, expect OK
 319 set expcode "OK"
 320 set ASSERTION "Now LOCKU ($off,10) w/new lsid, expect $expcode"
 321 set tag "$TNAME{m8}"
 322 putmsg stdout 0 "$tag: $ASSERTION"
 323 set res [compound {Putfh $nfh; Locku 2 $lseqid $lsid2 $off 10}]
 324 ckres "Locku" $status $expcode $res $PASS
 325 
 326 # m9: try to Close file w/old osid, expect BAD_STATEID|EXPIRED
 327 set expcode "BAD_STATEID|EXPIRED"
 328 set ASSERTION "try to Close file w/old osid, expect $expcode"
 329 set tag "$TNAME{m9}"
 330 putmsg stdout 0 "$tag: $ASSERTION"
 331 set res [compound {Putfh $nfh; Close $oseqid $osid}]
 332 ckres "Close(old-osid)" $status $expcode $res $PASS
 333 
 334 # m0: Finally Close it with good osid, expect OK
 335 set expcode "OK"
 336 set ASSERTION "Finally Close it w/good osid, expect $expcode"
 337 set tag "$TNAME{m0}"
 338 putmsg stdout 0 "$tag: $ASSERTION"
 339 set res [compound {Putfh $nfh; Close $oseqid2 $osid2}]
 340 ckres "Close(new-osid)" $status $expcode $res $PASS
 341 
 342 
 343 }
 344   
 345 
 346 # --------------------------------------------------------------
 347 # Now cleanup, and removed created tmp file
 348 set res [compound {Putfh $bfh; Remove $TFILE}]
 349 if {($status != "OK") && ($status != "NOENT")} {
 350         putmsg stderr 0 "\t WARNING: cleanup to remove created tmp file failed"
 351         putmsg stderr 0 "\t          status=$status; please cleanup manually."
 352         putmsg stderr 1 "\t   res=($res)"
 353         putmsg stderr 1 "  "
 354         exit $WARNING
 355 }
 356 
 357 # --------------------------------------------------------------
 358 # disconnect and exit
 359 Disconnect
 360 exit $PASS