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 putmsg stdout 0 \
  44         "$tag: Create a test file and its states, then bring down the server."
  45 set bfh [get_fh "$BASEDIRS"]
  46 set TFILE "$TNAME.[pid]"
  47 set owner "[pid]-[expr int([expr [expr rand()] * 100000000])]"
  48 set cid [getclientid $owner]
  49 if {$cid == -1} {
  50         putmsg stdout 0 "$tag: getclientid failed"
  51         putmsg stdout 0 "\t Test UNRESOLVED: unable to get clientid"
  52         putmsg stdout 1 "\t owner=<$owner>"
  53         cleanup $UNRESOLVED
  54 }
  55 
  56 # Create a test file and get its osid
  57 set fsize 8192
  58 set nfh [basic_open $bfh $TFILE 1 "$cid $owner" osid oseqid status \
  59         1 0 664 $fsize]
  60 if {$nfh == -1} {
  61         putmsg stdout 0 "$tag: basic_open"
  62         putmsg stdout 0 "\t Test UNRESOLVED: status=($status)"
  63         cleanup $UNRESOLVED
  64 }
  65 incr oseqid
  66 set lowner "$tag.[pid]"
  67 set lseqid 1
  68 
  69 # Lock the file before server reboot
  70 set res [compound {Putfh $nfh;
  71         Lock 2 F 0 100 T $osid $lseqid "$oseqid $cid $lowner"}]
  72 putmsg stderr 1 "compound {Putfh $nfh;"
  73 putmsg stderr 1 "Lock 2 F 0 100 T $osid $lseqid \"$oseqid $cid $lowner\"}"
  74 putmsg stderr 1 "\tstatus=$status; res=$res"
  75 putmsg stderr 1 "\t[clock format [clock seconds]]"
  76 if {$status != "OK"} {
  77         putmsg stdout 0 "$tag: original lock"
  78         putmsg stdout 0 "\t Test UNRESOLVED: original lock status=($status)"
  79         cleanup $UNRESOLVED
  80 }
  81 incr oseqid
  82 incr lseqid
  83 
  84 # Reboot the server
  85 putmsg stdout 0 "  ** Start to reboot the server ..."
  86 reboot_server [file join $env(TMPDIR) $TNAME.tmp.[pid]] $tag
  87 putmsg stdout 0 "  ** Now wait for server daemon to come up ..."
  88 is_nfsd_up $tag
  89 putmsg stdout 0 \
  90         "  ** then run the following assertions within the GRACE period:"
  91 
  92 # Start testing
  93 # --------------------------------------------------------------
  94 # a: Try open(reclaim) with different open-owner during GRACE, expect NO_GRACE
  95 set expcode "NO_GRACE"
  96 set ASSERTION \
  97     "Open(reclaim) w/different open-owner during GRACE, expect $expcode"
  98 set tag "$TNAME{a}"
  99 putmsg stdout 0 "$tag: $ASSERTION"
 100 
 101 set towner "diff-owner.[pid]"
 102 set cid [getclientid $towner]
 103 if {$cid == -1} {
 104     putmsg stderr 0 "Test UNRESOLVED: failed to getclientid, owner=($towner)"
 105 } else {
 106     set res [compound {Putfh $nfh; \
 107         Open $oseqid 3 0 "$cid $towner" {0 0 {{mode 0664}}} {1 0}; Getfh}]
 108     putmsg stderr 1 "compound {Putfh $nfh;"
 109     putmsg stderr 1 \
 110         "Open $oseqid 3 0 \"$cid $towner\" {0 0 {{mode 0664}}} {1 0}; Getfh}"
 111     putmsg stderr 1 "\tstatus=$status; res=$res"
 112     putmsg stderr 1 "\t[clock format [clock seconds]]"
 113     ckres "Open(reclaim-diff-oo)" $status $expcode $res $PASS
 114     if {$status == $expcode} {
 115         incr oseqid
 116     }
 117 }
 118 
 119 # b: Open(reclaim) with same open-owner during GRACE, expect OK
 120 set expcode "OK"
 121 set ASSERTION "Open(reclaim) w/same open-owner during GRACE, expect $expcode"
 122 set tag "$TNAME{b}"
 123 putmsg stdout 0 "$tag: $ASSERTION"
 124 
 125 set cid [getclientid $owner]
 126 if {$cid == -1} {
 127     putmsg stderr 0 "Test UNRESOLVED: failed to getclientid, owner=($owner)"
 128 } else {
 129     set res [compound {Putfh $nfh; \
 130         Open $oseqid 3 0 "$cid $owner" {0 0 {{mode 0664}}} {1 0}; Getfh}]
 131     putmsg stderr 1 "compound {Putfh $nfh;"
 132     putmsg stderr 1 \
 133         "Open $oseqid 3 0 \"$cid $owner\" {0 0 {{mode 0664}}} {1 0}; Getfh}"
 134     putmsg stderr 1 "\tstatus=$status; res=$res"
 135     putmsg stderr 1 "\t[clock format [clock seconds]]"
 136     ckres "Open(reclaim-same-oo)" $status $expcode $res $PASS
 137     if {$status == $expcode} {
 138         incr oseqid
 139         set newsid [lindex [lindex $res 1] 2]
 140         set open_sid $newsid
 141         set norun 0
 142     } else {
 143         putmsg stdout 0 \
 144                 "\t Open(reclaim) failed, can't run following assertions"
 145         set norun 1
 146     }
 147 }
 148 
 149 # c: Lock(reclaim) during GRACE, expect OK
 150 set expcode "OK"
 151 set ASSERTION "Lock(reclaim) during GRACE, expect $expcode"
 152 set tag "$TNAME{c}"
 153 putmsg stdout 0 "$tag: $ASSERTION"
 154 
 155 if {$norun == 0} {
 156     set res [compound {Putfh $nfh;
 157         Lock 2 T 0 100 T $newsid $lseqid "$oseqid $cid $lowner"}]
 158     putmsg stderr 1 "compound {Putfh $nfh;"
 159     putmsg stderr 1 "Lock 2 T 0 100 T $newsid $lseqid \"$oseqid $cid $lowner\"}"
 160     putmsg stderr 1 "\tstatus=$status; res=$res"
 161     putmsg stderr 1 "\t[clock format [clock seconds]]"
 162     ckres "Lock(W)" $status $expcode $res $PASS
 163     if {[should_seqid_incr $status] == 1} {
 164         incr oseqid
 165         incr lseqid
 166     }
 167     if {$status == "OK"} {
 168         set newsid [lindex [lindex $res 1] 2]
 169     }
 170 } else {
 171     putmsg stderr 0 "Test UNRESOLVED: Open(reclaim) failed, no valid states"
 172 }
 173         
 174 # d: Lock(reclaim) when <cfh>=dir during GRACE, expect ISDIR|GRACE|BAD_STATEID
 175 set expcode "ISDIR|GRACE|BAD_STATEID"
 176 set ASSERTION "Lock(reclaim) when <cfh>=dir during GRACE, expect $expcode"
 177 set tag "$TNAME{d}"
 178 putmsg stdout 0 "$tag: $ASSERTION"
 179 
 180 if {$norun == 0} {
 181     set lowner2 "$tag"
 182     set res [compound {Putfh $bfh;
 183         Lock 2 T 0 200 T $open_sid $lseqid "$oseqid $cid $lowner2"}]
 184     putmsg stderr 1 "compound {Putfh $bfh;"
 185     putmsg stderr 1 \
 186         "Lock 2 T 0 200 T $open_sid $lseqid \"$oseqid $cid $lowner2\"}"
 187     putmsg stderr 1 "\tstatus=$status; res=$res"
 188     putmsg stderr 1 "\t[clock format [clock seconds]]"
 189     ckres "Lock(W)" $status $expcode $res $PASS
 190     if {[should_seqid_incr $status] == 1} {
 191         incr oseqid
 192         incr lseqid
 193     }
 194     if {$status == "OK"} {
 195         set newsid [lindex [lindex $res 1] 2]
 196     }
 197 } else {
 198     putmsg stderr 0 "Test UNRESOLVED: Open(reclaim) failed, no valid states"
 199 }
 200 
 201 # e: Lock(reclaim) w/file has no such lock
 202 set expcode "OK"
 203 set ASSERTION \
 204         "Lock(reclaim) w/file has no such lock during GRACE, expect $expcode"
 205 set tag "$TNAME{e}"
 206 putmsg stdout 0 "$tag: $ASSERTION"
 207 
 208 set owner "$tag-oowner"
 209 set oseqid2 1
 210 set res [compound {Putfh $bfh; Lookup $env(RWFILE); Getfh; \
 211         Open $oseqid2 3 0 "$cid $owner" {0 0 {{mode 0666}}} {1 0}; Getfh}]
 212 putmsg stderr 1 "compound {Putfh $bfh; Lookup $env(RWFILE); Getfh;"
 213 putmsg stderr 1 \
 214         "Open $oseqid2 3 0 \"$cid $owner\" {0 0 {{mode 0666}}} {1 0}; Getfh}"
 215 putmsg stderr 1 "\tstatus=$status; res=$res"
 216 putmsg stderr 1 "\t[clock format [clock seconds]]"
 217 if {[should_seqid_incr $status] == 1} {
 218         incr oseqid2
 219 }
 220 if {$status != "OK" } {
 221         putmsg stdout 0 "\t Test FAIL: Open failed, status=($status)"
 222 } else {
 223         set lseqid2 1
 224         set nsid2 [lindex [lindex $res 3] 2]
 225         set open_sid2 $nsid2
 226         set nfh2 [lindex [lindex $res 4] 2]
 227 
 228         # Now try to Lock(reclaim) on file w/no such lock after reboot
 229         set res [compound {Putfh $nfh2;
 230                 Lock 2 T 0 100 T $nsid2 $lseqid2 "$oseqid2 $cid $lowner"}]
 231         putmsg stderr 1 "compound {Putfh $nfh2;"
 232         putmsg stderr 1 \
 233                 "Lock 2 T 0 100 T $nsid2 $lseqid2 \"$oseqid2 $cid $lowner\"}"
 234         putmsg stderr 1 "\tstatus=$status; res=$res"
 235         putmsg stderr 1 "\t[clock format [clock seconds]]"
 236         ckres "Lock(W)" $status $expcode $res $PASS
 237         if {[should_seqid_incr $status] == 1} {
 238                 incr oseqid2
 239                 incr lseqid2
 240         }
 241         # wait for grace period to end.
 242         ckgrace_period OTHER
 243         if {$status == "OK"} {
 244                 set nsid2 [lindex [lindex $res 1] 2]
 245                 set res [compound {Putfh $nfh2; Locku 2 $lseqid2 $nsid2 0 100}]
 246                 putmsg stderr 1 \
 247                         "compound {Putfh $nfh2; Locku 2 $lseqid2 $nsid2 0 100}"
 248                 putmsg stderr 1 "\tstatus=$status; res=$res"
 249                 putmsg stderr 1 "\t[clock format [clock seconds]]"
 250                 if {[should_seqid_incr $status] == 1} {
 251                         incr oseqid2
 252                         incr lseqid2
 253                 }
 254         }
 255         set res [compound {Putfh $nfh2; Close $oseqid2 $open_sid2}]
 256         putmsg stderr 1 "compound {Putfh $nfh2; Close $oseqid2 $open_sid2}"
 257         putmsg stderr 1 "\tstatus=$status; res=$res"
 258         putmsg stderr 1 "\t[clock format [clock seconds]]"
 259 }
 260 
 261 # --------------------------------------------------------------
 262 # Now cleanup, and removed created tmp file
 263 set tag $TNAME{cleanup}
 264 set res [compound {Putfh $bfh; Remove $TFILE}]
 265 putmsg stderr 1 "compound {Putfh $bfh; Remove $TFILE"
 266 putmsg stderr 1 "\tstatus=$status; res=$res"
 267 putmsg stderr 1 "\t[clock format [clock seconds]]"
 268 if { "$status" != "OK" } {
 269         putmsg stdout 0 "$tag:"
 270         putmsg stdout 0 "\t WARNING: cleanup to remove created tmp file failed"
 271         putmsg stdout 0 "\t   status=$status; please cleanup manually."
 272         putmsg stderr 1 "\t   res=($res)"
 273         putmsg stderr 1 "  "
 274         cleanup $WARNING
 275 }
 276 
 277 # All are good; so exit PASS
 278 cleanup $PASS