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 2007 Sun Microsystems, Inc.  All rights reserved.
  24 # Use is subject to license terms.
  25 #
  26 # NFSv4 WRITE operation test - negative tests
  27 #       verify SERVER errors returned with invalid write.
  28 
  29 # include all test enironment
  30 source WRITE.env
  31 
  32 # connect to the test server
  33 Connect
  34 
  35 # setting local variables
  36 set TNAME $argv0
  37 set bfh [get_fh "$BASEDIRS"]
  38 
  39 
  40 # It is assumed the special test filesystem, such public, rofs, nospc
  41 # are setup correct in server for testing.
  42 #
  43 # Start testing
  44 # --------------------------------------------------------------
  45 # a: Try to write on the public-rootfh - expect ISDIR
  46 #
  47 set expcode "ISDIR"
  48 set ASSERTION "Try to write on the public-rootfh, expect $expcode"
  49 set tag "$TNAME{a}"
  50 putmsg stdout 0 "$tag: $ASSERTION"
  51 set tfh [get_fh [path2comp $env(PUBTDIR) $DELM]]
  52 set stateid {0 0}
  53 set res [compound {Putfh $tfh; Write $stateid 0 u a "Write test neg03 \{a\}"}]
  54 ckres "Write" $status $expcode $res $PASS
  55 
  56 
  57 # b: Try to write a file in ROFS - expect ROFS
  58 #
  59 set expcode "ROFS"
  60 set ASSERTION "Try to write a file in ROFS, expect $expcode"
  61 set tag "$TNAME{b}"
  62 putmsg stdout 0 "$tag: $ASSERTION"
  63 set tfh [get_fh [path2comp $env(ROFSDIR) $DELM]]
  64 set stateid {0 0}
  65 set res [compound {Putfh $tfh; Lookup $env(RWFILE);
  66         Write $stateid 0 u a "Write test neg03 \{b\}"}]
  67 ckres "Write" $status $expcode $res $PASS
  68 
  69 
  70 # c: Try to write a file in NOSPC - expect NOSPC
  71 #
  72 set expcode "NOSPC"
  73 set ASSERTION "Try to write a file in NOSPC, expect $expcode"
  74 set tag "$TNAME{c}"
  75 putmsg stdout 0 "$tag: $ASSERTION"
  76 set tfh [get_fh "[path2comp $env(NSPCDIR) $DELM] $env(RWFILE)"]
  77 set res [compound {Putfh $tfh; Getattr size}]
  78 set fsize [lindex [lindex [lindex [lindex $res 1] 2] 0] 1]
  79 set stateid {0 0}
  80 set data [string repeat "Neg3-C........ " 1024]
  81 set res [compound {Putfh $tfh;
  82         Write $stateid $fsize f a $data; Commit 0 0}]
  83 ckres "Write" $status $expcode $res $PASS
  84 
  85 
  86 # d: Try to write a file over QUOTA limit - expect DQUOT
  87 set expcode "DQUOT"
  88 set ASSERTION "Try to write a file over DQUOT, expect $expcode"
  89 set tag "$TNAME{d}"
  90 putmsg stdout 0 "$tag: $ASSERTION"
  91 set qpath [path2comp $env(QUOTADIR) $DELM]
  92 set res [compound {Putrootfh; foreach c $qpath {Lookup $c}; 
  93         Getfh; Lookup "quotas"}]
  94 # add check of quota setup for Solaris:
  95 if {($env(SRVOS) == "Solaris") && ($status == "NOENT")} {
  96         putmsg stdout 0 "\t Test NOTINUSE: QUOTA is not setup in server."
  97 } else {
  98         set qfh [lindex [lindex $res end-1] 2]
  99         set tf "file_$env(TUSER2).2"
 100         set stateid {0 0}
 101         set data [string repeat "D" 1025]
 102         if {[is_cipso $env(SERVER)]} {
 103                 set res [exec zlogin $env(ZONENAME) \
 104                         "su $env(TUSER2) -c \"qfh=$qfh; tf=$tf; \
 105                                 data=$data; export qfh tf data; \
 106                                 /nfsh /$TNAME\""]
 107                 set status [lindex $res 0]
 108         } else {
 109                 set res [compound {Putfh $qfh; Lookup $tf;
 110                         Write $stateid 1 f a $data}]
 111         }
 112         ckres "Write" $status $expcode $res $PASS
 113 }
 114 
 115 # The following tests need clientid to Open the files
 116 putmsg stdout 0 " ** Now try to get the clientid to open the test files;"
 117 putmsg stdout 0 "    If fails, the following assertions {m,n,x} will not run."
 118 set hid "[pid][clock seconds]"
 119 set cid [getclientid $hid]
 120 if {$cid == -1} {
 121         putmsg stdout 0 "$TNAME: test setup - getclientid"
 122         putmsg stderr 0 "\t Test UNRESOLVED: unable to get clientid"
 123         putmsg stderr 0 "\t   program exit."
 124         exit $UNRESOLVED
 125 }
 126 
 127 # m: Try to Write when file is opened READ only - expect OPENMODE
 128 #
 129 set expcode "OPENMODE"
 130 set ASSERTION "Try to Write when file is opened READ only, expect $expcode"
 131 set tag "$TNAME{m}"
 132 putmsg stdout 0 "$tag: $ASSERTION"
 133 set oowner "[pid][expr [clock seconds] / 2]"
 134 set nfh [basic_open $bfh $env(RWFILE) 0 "$cid $oowner" \
 135         osid oseqid status 1 0 666 0 1]
 136 if {$nfh == -1} {
 137         putmsg stderr 0 "\t Test UNRESOLVED: OPEN(rd) failed, status=$status."
 138 } else {
 139         # Now try to write to this file:
 140         set data [string repeat "M" 511]
 141         set res [compound {Putfh $nfh; Write $osid 0 f a $data}]
 142         ckres "Write" $status $expcode $res $PASS
 143         incr oseqid
 144         set res [compound {Putfh $nfh; Close $oseqid $osid}]
 145         putmsg stderr 1 "Close res=$res"
 146 }
 147 
 148 
 149 # n: Try to Write when file is downgraded to READ only - expect OPENMODE
 150 #
 151 set expcode "OPENMODE"
 152 set ASSERTION "Try to Write when file is downgraded READ only, expect $expcode"
 153 set tag "$TNAME{n}"
 154 putmsg stdout 0 "$tag: $ASSERTION"
 155 set oowner "[pid][expr [clock seconds] + 4]"
 156 set nfh [basic_open $bfh $env(RWFILE) 0 "$cid $oowner" \
 157         osid oseqid status 1 0 666 0 3]
 158 if {$nfh == -1} {
 159         putmsg stderr 0 "\t Test UNRESOLVED: OPEN(rw) failed, status=$status."
 160 } else {
 161         # Now try to write to this file:
 162         incr oseqid
 163         set res [compound {Putfh $nfh; Open_downgrade $osid $oseqid 1 0}]
 164         if {$status != "OK"} {
 165             putmsg stderr 0 \
 166                 "\t Test UNRESOLVED: Open_downgrade failed status=$status."
 167             putmsg stderr 1 "\t   Res=$res"
 168         } else {
 169             set osid [lindex [lindex $res 1] 2]
 170             set data [string repeat "M" 511]
 171             set res [compound {Putfh $nfh; Write $osid 0 f a $data}]
 172             ckres "Write" $status $expcode $res $PASS
 173             incr oseqid
 174             set res [compound {Putfh $nfh; Close $oseqid $osid}]
 175             putmsg stderr 1 "Close res=$res"
 176         }
 177 }
 178 
 179 # x: Write a file when lease expired - expect EXPIRED|STALE_STATEID
 180 #
 181 set expcode "EXPIRED|STALE_STATEID"
 182 set ASSERTION "Write a file when lease expired, expect $expcode"
 183 set tag "$TNAME{x}"
 184 putmsg stdout 0 "$tag: $ASSERTION"
 185 set leasetm $LEASE_TIME
 186 
 187 # open a file to get the stateid
 188 set owner "$TNAME.[pid]-a"
 189 set cid_owner "$cid $owner"
 190 set newF "$TNAME.[pid]"
 191 set nfh [basic_open $bfh $newF 1 $cid_owner osid oseqid status]
 192 if {$nfh == -1} {
 193         putmsg stderr 0 "\t Test UNRESOLVED: basic_open failed, status=$status."
 194 } else {
 195         putmsg stdout 1 "  wait for lease time to expire, then write"
 196         after [expr ($leasetm + 18) * 1000]
 197         set data [string repeat "a" 513]
 198         set res [compound {Putfh $nfh; Write $osid 0 f a $data; Getfh}]
 199         ckres "Write" $status $expcode $res $PASS
 200 }
 201 
 202 
 203 # --------------------------------------------------------------
 204 # Cleanup the temp file:
 205 set res [compound {Putfh $bfh; Remove $newF}]
 206 if { "$status" != "OK" } {
 207         putmsg stderr 0 "\t WARNING: cleanup to remove $newF failed"
 208         putmsg stderr 0 "\t          status=$status; please cleanup manually."
 209         putmsg stderr 1 "\t   res=($res)"
 210         putmsg stderr 1 "  "
 211         exit $WARNING
 212 }
 213 
 214 # --------------------------------------------------------------
 215 # disconnect and exit
 216 Disconnect
 217 exit $PASS