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 2009 Sun Microsystems, Inc.  All rights reserved.
  24 # Use is subject to license terms.
  25 #
  26 # NFSv4 RELEASE_LOCKOWNER operation test - negative tests
  27 
  28 # include all test enironment
  29 source RELEASE_LOCKOWNER.env
  30 
  31 # connect to the test server
  32 Connect
  33 
  34 # setting local variables
  35 set TNAME $argv0
  36 set leasetm $LEASE_TIME
  37 set bfh [get_fh "$BASEDIRS"]
  38 set hid "[pid][expr int([expr [expr rand()] * 100000000])]"
  39 set cid [getclientid $hid]
  40 if {$cid == -1} {
  41         putmsg stderr 0 "$TNAME: setup - getclientid"
  42         putmsg stderr 0 "\t Test UNRESOLVED: unable to get clientid"
  43         exit $UNRESOLVED
  44 }
  45 # Create a test file and get its osid
  46 set TFILE "$TNAME.[pid]"
  47 set oowner "[pid]-[expr int([expr [expr rand()] * 100000000])]"
  48 set nfh [basic_open $bfh $TFILE 1 "$cid $oowner" osid oseqid status \
  49         1 0 664 1024]
  50 if {$nfh == -1} {
  51         putmsg stderr 0 "$TNAME: setup - basic_open"
  52         putmsg stderr 0 "\t Test UNRESOLVED: status=($status)"
  53         exit $UNRESOLVED
  54 }
  55 set oseqid [expr $oseqid + 1]
  56 set lseqid 1
  57 set lowner "$TNAME-lower.[pid]"
  58 
  59 
  60 # Start testing
  61 # --------------------------------------------------------------
  62 # a: Release_lockowner w/new lock in file, expect LOCKS_HELD
  63 set expcode "LOCKS_HELD"
  64 set ASSERTION "Release_lockowner w/new lock in file, expect $expcode"
  65 set tag "$TNAME{a}"
  66 putmsg stdout 0 "$tag: $ASSERTION"
  67 # First set a lock with the lock owner
  68 set res [compound {Putfh $nfh; 
  69         Lock 1 F 0 100 T $osid $lseqid "$oseqid $cid $lowner"}]
  70 if { [ckres "Lock(R)" $status "OK" $res $FAIL] != "true" } {
  71         set lsid {11 22}
  72 } else {
  73         set lsid [lindex [lindex $res 1] 2]
  74         incr lseqid
  75         incr oseqid
  76         set res [compound {Release_lockowner $cid $lowner}]
  77         ckres "Release_lockowner" $status $expcode $res $PASS 
  78 }
  79 
  80 # b: Release_lockowner w/1 byte locked in file, expect LOCKS_HELD
  81 set expcode "LOCKS_HELD"
  82 set ASSERTION "Release_lockowner w/1-byte still locked, expect $expcode"
  83 set tag "$TNAME{b}"
  84 putmsg stdout 0 "$tag: $ASSERTION"
  85 # Check if lock_stateid is valid
  86 if { [lindex $lsid 1] == "22" } {
  87         putmsg stderr 0 "\t Test UNINITIATED: invalid lsid from previous run"
  88         putmsg stderr 0 "\t lsid=($lsid)"
  89 } else {
  90         set res [compound {Putfh $nfh; Locku 1 $lseqid $lsid 0 99; 
  91                 Release_lockowner $cid $lowner}]
  92         ckres "Release_lockowner/Locku" $status $expcode $res $PASS
  93         # Release all the locks in the file
  94         set lsid [lindex [lindex $res 1] 2]
  95         incr lseqid
  96         compound {Putfh $nfh; Locku 1 $lseqid $lsid 99 1}
  97 }
  98 
  99 # c: Release_lockowner w/invalid clientid, expect STALE_CLIENTID
 100 set expcode "STALE_CLIENTID"
 101 set ASSERTION "Release_lockowner w/invalid clientid, expect $expcode"
 102 set tag "$TNAME{c}"
 103 putmsg stdout 0 "$tag: $ASSERTION"
 104 set icid "xxxxxx"
 105 set res [compound {Release_lockowner $icid $lowner}]
 106 ckres "Release_lockowner" $status $expcode $res $PASS
 107 
 108 # d: Release_lockowner w/expired clientid, expect EXPIRED
 109 set expcode "EXPIRED"
 110 set ASSERTION "Release_lockowner w/expired clientid, expect $expcode"
 111 set tag "$TNAME{d}"
 112 putmsg stdout 0 "$tag: $ASSERTION"
 113 # wait for lease to expire and try the op again
 114 after [expr [expr $leasetm + 1 ] * 1000]
 115 set res [compound {Release_lockowner $cid $lowner}]
 116 if { $status == "OK" } {
 117         putmsg stderr 0 "\t WARNING: The server return OK. Maybe the lockowner had been reaped"
 118         putmsg stderr 0 "\t          before the server received the release_lockowner request"
 119         putmsg stderr 1 "\t   res=($res)"
 120         putmsg stderr 1 "  "
 121         putmsg stdout 0 "\t Test PASS"
 122 } else {
 123         ckres "Release_lockowner" $status $expcode $res $PASS
 124 }
 125 
 126 
 127 # Now cleanup, close and removed created tmp file
 128 set res [compound {Putfh $bfh; Remove $TFILE}]
 129 if {($status != "OK") && ($status != "NOENT")} {
 130         putmsg stderr 0 "\t WARNING: cleanup to remove created tmp file failed"
 131         putmsg stderr 0 "\t          status=$status; please cleanup manually."
 132         putmsg stderr 1 "\t   res=($res)"
 133         putmsg stderr 1 "  "
 134         exit $WARNING
 135 }
 136 
 137 
 138 # --------------------------------------------------------------
 139 # disconnect and exit
 140 Disconnect
 141 exit $PASS