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 
  27 # TESTROOT directory; must be set in the environment already
  28 set TESTROOT $env(TESTROOT)
  29 
  30 # include common code and init environment
  31 source [file join ${TESTROOT} tcl.init]
  32 source [file join ${TESTROOT} testproc]
  33 
  34 # TCL procedure for OPEN operation testing
  35 # NFSv4 constant:
  36 set OPEN4_RESULT_CONFIRM        2
  37 
  38 set SRVPROG srv_ckshare
  39 
  40 #---------------------------------------------------------
  41 # Test procedure to close the file; but also Open_confirm (if needed).
  42 #  Usage: ckclose nfh rflags seqid sid
  43 #         nfh:         the filehandle to be closed
  44 #        rflags:  the rflags for OPEN_CONFIRM
  45 #        seqid:   the sequence id
  46 #        sid:     the state id 
  47 #
  48 #  Return: 
  49 #        true:          Close succeed
  50 #        false:         things failed during the process
  51 #
  52 proc ckclose {nfh rflags seqid sid} {
  53     global DEBUG OPEN4_RESULT_CONFIRM
  54 
  55     set cont true
  56     if {[expr $rflags & $OPEN4_RESULT_CONFIRM] == $OPEN4_RESULT_CONFIRM} {
  57         putmsg stderr 1 "  Open_confirm $sid $seqid"
  58         set res [compound {Putfh $nfh; Open_confirm $sid $seqid}]
  59         if {$status != "OK"} {
  60             putmsg stderr 0 \
  61                 "\t Test FAIL: Open_confirm failed, status=($status)."
  62             putmsg stderr 1 "\t   res=($res)"
  63             set cont false
  64         }
  65         set sid [lindex [lindex $res 1] 2]
  66         incr seqid
  67     }
  68     # verify the filehandle of OPEN is good to close and same as LOOKUP
  69     if {$cont == "true"} {
  70         # Close the file
  71         putmsg stderr 1 "  Close $seqid $sid"
  72         set res [compound {Putfh $nfh; Close $seqid $sid}]
  73         if {$status != "OK"} {
  74             putmsg stderr 0 \
  75                 "\t Test FAIL: Close failed, status=($status)."
  76             putmsg stderr 1 "\t   res=($res)"
  77             set cont false
  78         }
  79     }
  80     return $cont
  81 }
  82 
  83 #-----------------------------------------------------------------------
  84 # Test procedure to check if the grace period is end or not
  85 #  Usage: ckgrace_period [type]
  86 #       type    exit status type if the checking fail, default UNRESOLVED
  87 #
  88 #  Return: 
  89 #       nothing
  90 #
  91 proc ckgrace_period {{type UNRESOLVED}} {
  92     global MNTPTR DELM
  93 
  94     if {[catch {exec echo "xxx" > $MNTPTR${DELM}wait_for_grace} msg]} {
  95         putmsg stdout 0 "Failed to check the grace period"
  96         putmsg stdout 0 "\t msg=($msg)"
  97         file delete $MNTPTR${DELM}wait_for_grace
  98         cleanup $type
  99     }
 100     file delete $MNTPTR${DELM}wait_for_grace
 101 }
 102 
 103 #-----------------------------------------------------------------------
 104 # Test procedure to disconnect and exit with specific status
 105 #  Usage: cleanup exit_status
 106 #
 107 #  Return: 
 108 #       nothing
 109 #
 110 proc cleanup {exit_status} {
 111     Disconnect
 112     exit $exit_status
 113 }
 114 
 115 #-----------------------------------------------------------------------
 116 # Test procedure to reboot the server
 117 #  Usage: reboot_server TmpFile tag
 118 #       TmpFile the temp file for logging the output of the command
 119 #       tag     the test case name which calls this procedure
 120 #
 121 #  Return: 
 122 #       nothing
 123 #
 124 proc reboot_server {TmpFile tag} {
 125     global SERVER UNRESOLVED
 126 
 127     if {[catch {exec isserverup reboot 2> $TmpFile} msg]} {
 128         putmsg stdout 0 "$tag: Reboot the server $SERVER"
 129         putmsg stdout 0 "\t Test UNRESOLVED: failed to reboot server $SERVER"
 130         putmsg stdout 0 "\t msg=($msg)"
 131         putmsg stderr 0 "\t err=([exec cat $TmpFile])"
 132         file delete $TmpFile
 133         if { [file exists $TmpFile] != 0 } {
 134             putmsg stdout 0 "\t WARNING: TmpFile=($TmpFile) was not removed"
 135             putmsg stdout 0 "\t   please cleanup manually."
 136         }
 137         cleanup $UNRESOLVED
 138     }
 139     file delete $TmpFile
 140     if { [file exists $TmpFile] != 0 } {
 141         putmsg stdout 0 "\t WARNING: TmpFile=($TmpFile) was not removed"
 142         putmsg stdout 0 "\t   please cleanup manually."
 143     }
 144 }
 145 
 146 #-----------------------------------------------------------------------
 147 # Test procedure to check if the nfsd is up or not
 148 #  Usage: is_nfsd_up tag
 149 #       tag     the test case name which calls this procedure
 150 #
 151 #  Return: 
 152 #       nothing
 153 #
 154 proc is_nfsd_up {tag} {
 155     global BASEDIRS NOTICEDIR UNRESOLVED
 156 
 157     set i 0
 158     set path "$BASEDIRS $NOTICEDIR DONE_reboot"
 159     set res [compound {Putrootfh; foreach c $path {Lookup $c}; Getfh}]
 160     while { $status != "OK" } {
 161         if { $i < 300 } {
 162             incr i
 163             after 1000
 164             set res [compound {Putrootfh; foreach c $path {Lookup $c}; Getfh}]
 165         } else {
 166             putmsg stdout 0 "$tag: Reboot: nfsd failed"
 167             putmsg stdout 0 "\t Test UNRESOLVED: server reboot failed"
 168             putmsg stdout 0 "\t status=$status"
 169             putmsg stdout 0 "\t res=$res"
 170             cleanup $UNRESOLVED
 171         }
 172     }
 173 }