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: Open a regular file and its states, then bring down the server."
  45 set bfh [get_fh "$BASEDIRS"]
  46 set cid [getclientid $TNAME.[pid]]
  47 if {$cid == -1} {
  48         putmsg stdout 0 "$tag: getclientid failed"
  49         putmsg stdout 0 "\t Test UNRESOLVED: unable to get clientid"
  50         putmsg stdout 1 "\t owner=<$TNAME.[pid]>"
  51         cleanup $UNRESOLVED
  52 }
  53 set seqid 1
  54 set owner "$TNAME-OpenOwner"
  55 
  56 # First Open a regular file to establish some state
  57 set res [compound {Putfh $bfh; Open $seqid 3 0 "$cid $owner" \
  58                     {0 0 {{mode 0777}}} {0 "$env(RWFILE)"}; Getfh}]
  59 putmsg stderr 1 "compound {Putfh $bfh; Open $seqid 3 0 \"$cid $owner\""
  60 putmsg stderr 1 "{0 0 {{mode 0777}}} {0 \"$env(RWFILE)\"}; Getfh}"
  61 putmsg stderr 1 "\tstatus=$status; res=$res"
  62 putmsg stderr 1 "\t[clock format [clock seconds]]"
  63 if {$status != "OK"} {
  64         putmsg stdout 0 "$tag: open regular file"
  65         putmsg stdout 0 "\t Test UNRESOLVED: Open failed, 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 $TNAME.[pid]]
  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=<$TNAME.[pid]>"
  82         cleanup $UNRESOLVED
  83 }
  84 
  85 # Start testing
  86 # --------------------------------------------------------------
  87 # a: Open(reclaim) when <cfh>=dir during GRACE, expect GRACE
  88 set expcode "ISDIR|GRACE"
  89 set ASSERTION "Open(reclaim) when <cfh>=dir during GRACE, expect $expcode"
  90 set tag "$TNAME{a}"
  91 putmsg stdout 0 "$tag: $ASSERTION"
  92 
  93 # Now try to Open <cfh>=dir after reboot
  94 set res [compound {Putfh $bfh; Open $seqid 3 0 "$cid $owner" \
  95                     {0 0 {{mode 0777}}} {1 0}}]
  96 putmsg stderr 1 "compound {Putfh $bfh; Open $seqid 3 0 \"$cid $owner\""
  97 putmsg stderr 1 "{0 0 {{mode 0777}}} {1 0}}"
  98 putmsg stderr 1 "\tstatus=$status; res=$res"
  99 putmsg stderr 1 "\t[clock format [clock seconds]]"
 100 ckres "Open" $status $expcode $res $PASS
 101 
 102 # b: Open(reclaim) w/<cfh> not from open , expect OK
 103 set expcode "OK"
 104 set ASSERTION "Open(reclaim) w/<cfh> not from open, expect $expcode"
 105 set tag "$TNAME{b}"
 106 putmsg stdout 0 "$tag: $ASSERTION"
 107 
 108 set res [compound {
 109         Putfh $bfh;
 110         Lookup $env(ROFILE);
 111         Open $seqid 1 0 "$cid $owner-100" {0 0 {{mode 0666}}} {1 0};
 112         Getfh; Putfh $bfh; Lookup $env(ROFILE); Getfh}]
 113 putmsg stderr 1 "compound {Putfh $bfh; Lookup $env(ROFILE);"
 114 putmsg stderr 1 \
 115         "Open $seqid 1 0 \"$cid $owner-100\" {0 0 {{mode 0666}}} {1 0};"
 116 putmsg stderr 1 "Getfh; Putfh $bfh; Lookup $env(ROFILE); Getfh}"
 117 putmsg stderr 1 "\tstatus=$status; res=$res"
 118 putmsg stderr 1 "\t[clock format [clock seconds]]"
 119 set cont [ckres "Open" $status $expcode $res $FAIL]
 120 
 121 if {$cont == "true"} {
 122    # verify the FH of OPEN is good (to close) and is same as LOOKUP
 123    set stateid [lindex [lindex $res 2] 2]
 124    set rflags [lindex [lindex $res 2] 4]
 125    set fh1 [lindex [lindex $res 3] 2]
 126    set fh2 [lindex [lindex $res 6] 2]
 127    incr seqid
 128    set cont [ckclose $fh1 $rflags $seqid $stateid]
 129    if {$cont == "true"} {
 130       fh_equal $fh1 $fh2 $cont $PASS
 131    }
 132 }
 133 
 134 # --------------------------------------------------------------
 135 # All are good; so exit PASS
 136 cleanup $PASS