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 - XXX recovery
  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 set TFILE "$TNAME.[pid]"
  38 
  39 # Get server lease time
  40 set leasetm $LEASE_TIME
  41 
  42 # --------------------------------------------------------------
  43 # clean proc to removed created tmp file
  44 proc cleanup { exitcode } {
  45     global bfh TFILE WARNING
  46 
  47     # remove tmp file
  48     set res [compound {Putfh $bfh; Remove $TFILE}]
  49     if {($status != "OK") && ($status != "NOENT")} {
  50         putmsg stderr 0 "\t WARNING: cleanup to remove created tmp file failed"
  51         putmsg stderr 0 "\t          status=$status; please cleanup manually."
  52         putmsg stderr 1 "\t   res=($res)"
  53         putmsg stderr 1 "  "
  54         set exitcode $WARNING
  55     }
  56 
  57     # disconnect and exit
  58     Disconnect
  59     exit $exitcode
  60 }
  61 
  62 putmsg stdout 0 \
  63   "\n  ** Frist basic setup for $TNAME, if fails, program will exit ..."
  64 
  65 # Start testing
  66 # --------------------------------------------------------------
  67 # a: Setclientid/Setclient_confirm, expect OK
  68 set expcode "OK"
  69 set ASSERTION "Setclientid/Setclient_confirm, expect $expcode"
  70 set tag "$TNAME{a}"
  71 putmsg stdout 0 "$tag: $ASSERTION"
  72 set hid "[pid][expr int([expr [expr rand()] * 100000000])]"
  73 set cid [getclientid $hid]
  74 if {$cid == -1} {
  75         putmsg stderr 0 "Test FAIL: unable to get clientid"
  76         exit $FAIL
  77 } else {
  78         logres PASS
  79 }
  80 
  81 
  82 # b: Open a test file w/good clientid, expect OK
  83 set expcode "OK"
  84 set ASSERTION "Open(& confirm if needed) file w/good clientid, expect $expcode"
  85 set tag "$TNAME{b}"
  86 putmsg stdout 0 "$tag: $ASSERTION"
  87 set seqid 1
  88 set fs 8192
  89 set open_owner $TFILE
  90 set nfh [basic_open $bfh $TFILE 1 "$cid $open_owner" osid oseqid status \
  91         $seqid 0 664 $fs]
  92 if {$nfh == -1} {
  93         putmsg stderr 0 "\t Test FAIL: basic_open failed, status=($status)"
  94         cleanup $FAIL
  95 } else {
  96         putmsg stderr 0 "\t Test PASS"
  97         set oseqid [expr $oseqid + 1]
  98 }
  99 
 100 # c: LOCK(lower-1) the test file w/cid+osid, expect OK
 101 set expcode "OK"
 102 set ASSERTION "LOCK(lower-1) the test file w/cid+osid, expect $expcode"
 103 set tag "$TNAME{c}"
 104 putmsg stdout 0 "$tag: $ASSERTION"
 105 set lseqid 1
 106 set lowner1 "lowner.[pid]-1"
 107 set res [compound {Putfh $nfh; 
 108         Lock 1 F 0 512 T $osid $lseqid "$oseqid $cid $lowner1"}]
 109 if { [ckres "Lock(lo1)" $status $expcode $res $PASS] != "true" } {
 110         cleanup $FAIL
 111 }
 112 set lsid1 [lindex [lindex $res 1] 2]
 113 incr oseqid
 114 
 115 # d: conflict LOCK(lower-2) file w/cid+osid, expect DENIED
 116 set expcode "DENIED"
 117 set ASSERTION "conflict LOCK(lower-2) file w/cid+osid, expect $expcode"
 118 set tag "$TNAME{d}"
 119 putmsg stdout 0 "$tag: $ASSERTION"
 120 set lseqid2 20
 121 set lowner2 "lowner.[pid]-2"
 122 set res [compound {Putfh $nfh; 
 123         Lock 2 F 0 10 T $osid $lseqid2 "$oseqid $cid $lowner2"}]
 124 if { [ckres "Lock(lo2)" $status $expcode $res $PASS] != "true" } {
 125         cleanup $FAIL
 126 }
 127 
 128 
 129 putmsg stdout 0 \
 130   "\n  ** Reset the clientid w/new hid and do following assertions."
 131 
 132 # h: Reset cid Setclientid w/new hid, expect OK
 133 set expcode "OK"
 134 set ASSERTION "Reset clientid Setclientid w/new hid, expect $expcode"
 135 set tag "$TNAME{h}"
 136 putmsg stdout 0 "$tag: $ASSERTION"
 137 set newverf "3388[pid]"
 138 set cid2 ""
 139 set cidverf2 ""
 140 set status [setclient $newverf $hid cid2 cidverf2 res]
 141 if { [ckres "Setclientid(2)" $status $expcode $res $PASS] != "true" } {
 142         cleanup $FAIL
 143 }
 144 set cid2 [lindex [lindex $res 0] 2]
 145 
 146 
 147 # Verify states in server are not clear until Setclient_confirm.
 148 # i: try conflict LOCK(lower-2) again w/out confirm, expect DENIED
 149 set expcode "DENIED"
 150 set ASSERTION "conflict LOCK(lower-2) again w/out confirm, expect $expcode"
 151 set tag "$TNAME{i}"
 152 putmsg stdout 0 "$tag: $ASSERTION"
 153 incr lseqid2
 154 incr oseqid
 155 set res [compound {Putfh $nfh; 
 156         Lock 2 F 0 10 T $osid $lseqid2 "$oseqid $cid2 $lowner2"}]
 157 if { [ckres "Lock(lo3)" $status $expcode $res $PASS] != "true" } {
 158         cleanup $FAIL
 159 }
 160 
 161 # j: Now confirm the new clientid, expect OK
 162 set expcode "OK"
 163 set ASSERTION "Now confirm the new clientid, expect $expcode"
 164 putmsg stdout 0 "$TNAME{j}: $ASSERTION"
 165 set status [setclientconf $cid2 $cidverf2 res]
 166 if { [ckres "Setclientid_confirm(2)" $status $expcode $res $PASS] != "true" } {
 167         cleanup $FAIL
 168 }
 169 
 170 # k: then try conflict LOCK again w/old-osid,
 171 #       expect STALE_STATEID|STALE_CLIENTID|EXPIRED
 172 set expcode "STALE_STATEID|STALE_CLIENTID|EXPIRED"
 173 set ASSERTION "then try conflict LOCK again w/old-osid, expect $expcode"
 174 putmsg stdout 0 "$TNAME{k}: $ASSERTION"
 175 incr lseqid2
 176 set res [compound {Putfh $nfh; 
 177         Lock 2 F 0 10 T $osid $lseqid2 "$oseqid $cid2 $lowner2"}]
 178 ckres "Lock(lo4)" $status $expcode $res $PASS
 179 
 180 # l: Open the file again w/new confirmed cid, expect OK
 181 set expcode "OK"
 182 set ASSERTION "Open(& confirm if needed) file w/new cid, expect $expcode"
 183 putmsg stdout 0 "$TNAME{l}: $ASSERTION"
 184 set seqid 100
 185 set nfh2 [basic_open $bfh $TFILE 0 "$cid2 $open_owner" osid2 oseqid2 status]
 186 if {$nfh == -1} {
 187         putmsg stderr 0 "\t Test FAIL: basic_open again failed"
 188         putmsg stderr 0 "\t   status=($status)"
 189         cleanup $FAIL
 190 } else {
 191         putmsg stderr 0 "\t Test PASS"
 192         set oseqid2 [expr $oseqid2 + 1]
 193 }
 194 
 195 # m: try conflict LOCK one more time w/new-osid, expect OK
 196 set expcode "OK"
 197 set ASSERTION "try conflict LOCK one more time w/new-osid, expect $expcode"
 198 putmsg stdout 0 "$TNAME{m}: $ASSERTION"
 199 incr lseqid2
 200 set res [compound {Putfh $nfh2; 
 201         Lock 2 F 0 10 T $osid2 $lseqid2 "$oseqid2 $cid2 $lowner2"}]
 202 ckres "Lock(lo5)" $status $expcode $res $PASS
 203 incr oseqid2
 204 
 205 # n: try to Close the file with old osid, expect OLD_STATEID
 206 set expcode "OLD_STATEID"
 207 set ASSERTION "try to Close file w/old osid, expect $expcode"
 208 putmsg stdout 0 "$TNAME{n}: $ASSERTION"
 209 set res [compound {Putfh $nfh; Close $oseqid2 $osid}]
 210 ckres "Close(old-osid)" $status $expcode $res $PASS
 211 
 212 # o: Finally Close it with good osid, expect OK
 213 set expcode "OK"
 214 set ASSERTION "Finally Close it w/good osid, expect $expcode"
 215 putmsg stdout 0 "$TNAME{o}: $ASSERTION"
 216 set res [compound {Putfh $nfh; Close $oseqid2 $osid2}]
 217 ckres "Close(new-osid)" $status $expcode $res $PASS
 218 
 219 cleanup $PASS