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 2006 Sun Microsystems, Inc.  All rights reserved.
  24 # Use is subject to license terms.
  25 #
  26 # NFSv4 SETATTR operation test - negative tests
  27 #       verify SERVER errors returned with invalid Setattr op.
  28 
  29 # include all test enironment
  30 source SETATTR.env
  31 
  32 # connect to the test server
  33 Connect
  34 
  35 # setting local variables
  36 set TNAME $argv0
  37 set tpid [pid]
  38 set bfh [get_fh "$BASEDIRS"]
  39 # create a tmp file and a tmp dir for manipulation
  40 set tmpF "Sattr_tmpF.$tpid"
  41 set ffh [creatv4_file [file join $BASEDIR $tmpF]]
  42 if { $ffh == $NULL } {
  43         putmsg stdout 0 "$TNAME: test setup - creatv4_file"
  44         putmsg stderr 0 "\t Test UNINITIATED: unable to create tmp file."
  45         putmsg stderr 1 "  "
  46         exit $UNINITIATED
  47 }
  48 set tmpD Sattr_tmpD.$tpid
  49 set res [compound {Putfh $bfh; Create $tmpD {{mode 0711}} d; Getfh}]
  50 if { "$status" != "OK" } {
  51         putmsg stdout 0 "$TNAME: test setup - mkdir"
  52         putmsg stderr 0 "\t Test UNINITIATED: unable to create tmp dir."
  53         putmsg stderr 0 "\t   res=($res)"
  54         putmsg stderr 1 "  "
  55         exit $UNINITIATED
  56 } else {
  57         set dfh [lindex [lindex $res 2] 2]
  58 }
  59 
  60 
  61 # Start testing
  62 # --------------------------------------------------------------
  63 # a: Setattr size on a dir, expect ISDIR
  64 set expcode "ISDIR"
  65 set ASSERTION "Setattr size on a dir, expect $expcode"
  66 set tag "$TNAME{a}"
  67 putmsg stdout 0 "$tag: $ASSERTION"
  68 set stateid {0 0}
  69 set res [compound {Putfh $dfh; Setattr $stateid {{size 888}}; Getattr size}]
  70 ckres "Setattr" $status $expcode $res $PASS
  71 
  72 
  73 # b's: Setattr mandatory(RO-attr) on file/dir, expect INVAL
  74 set expcode "INVAL"
  75 # list of the mandatory attributes, except supported_attrs and size
  76 set ma "type fh_expire_type change link_support symlink_support named_attr"
  77 set mandattrs "$ma fsid unique_handles lease_time rdattr_error filehandle"
  78 set i 1
  79 set stateid {0 0}
  80 foreach attr $mandattrs {
  81     set tag "$TNAME{b$i}"
  82     # randomly set cfh to file or dir
  83     set j [expr int([expr [expr rand()] * 100000000])]
  84     if {[expr $j % 2] == 0} {
  85         set nfh $ffh
  86         set obj "file"
  87     } else {
  88         set nfh $dfh
  89         set obj "dir"
  90     }
  91     set ASSERTION "Setattr{$attr, mandatory RO-attr} on a $obj, expect $expcode"
  92     putmsg stdout 0 "$tag: $ASSERTION"
  93     # Use GETATTR to get the attribute value to set
  94     set res [compound {Putfh $ffh; Getattr $attr}]
  95     putmsg stdout 1 "Getattr res=($res)"
  96     if {$status != "OK"} {
  97         putmsg stdout 0 "\t Test UNRESOVED: unable to get ($attr)"
  98         putmsg stdout 0 "\t\t$res"
  99     } else {
 100         set attrval [lindex [lindex $res 1] 2]
 101         putmsg stdout 1 "attr=$attr, av=$attrval"
 102         set res [compound {Putfh $ffh; Setattr $stateid $attrval}]
 103         ckres "Setattr" $status $expcode $res $PASS
 104     }
 105     incr i
 106 }
 107 
 108 # c's: Setattr time related RO-attrs on dir/file, expect INVAL
 109 set expcode "INVAL|ATTRNOTSUPP"
 110 set timeattrs "access backup create delta metadata modify"
 111 set i 1
 112 set stateid {0 0}
 113 set ntime "[clock seconds] 0"
 114 foreach attr $timeattrs {
 115     set nattr "time_$attr"
 116     set tag "$TNAME{c$i}"
 117     # randomly set cfh to file or dir
 118     set j [expr int([expr [expr rand()] * 100000000])]
 119     if {[expr $j % 2] == 0} {
 120         set nfh $dfh
 121         set obj "dir"
 122     } else {
 123         set nfh $ffh
 124         set obj "file"
 125     }
 126     putmsg stdout 0 "$tag: $ASSERTION"
 127     set ASSERTION "Setattr{$nattr, RO-attr} on a $obj, expect $expcode"
 128     putmsg stdout 1 "Putfh $nfh; Setattr $stateid {{$nattr {$ntime}}}"
 129     set res [compound {Putfh $nfh; Setattr $stateid {{$nattr {$ntime}}}}]
 130     ckres "Setattr" $status $expcode $res $PASS
 131     incr i
 132 }
 133 
 134 # d's: Setattr recommended(number, RO-attr) on file/dir, expect INVAL
 135 set expcode "INVAL|ATTRNOTSUPP"
 136 # list of the recommended RO-only number attributes
 137 set ran "aclsupport fileid files_avail files_free files_total"
 138 set ran "$ran maxfilesize maxlink maxname maxread maxwrite numlinks"
 139 set ran "$ran quota_avail_hard quota_avail_soft quota_used"
 140 set ran "$ran space_avail space_free space_total space_used mounted_on_fileid"
 141 set recmnattrs "$ran"
 142 set i 1
 143 set stateid {0 0}
 144 foreach attr $recmnattrs {
 145     set tag "$TNAME{d$i}"
 146     # randomly set cfh to file or dir
 147     set j [expr int([expr [expr rand()] * 100000000])]
 148     if {[expr $j % 2] == 0} {
 149         set nfh $dfh
 150         set obj "dir"
 151     } else {
 152         set nfh $ffh
 153         set obj "file"
 154     }
 155     set ASSERTION \
 156         "Setattr{$attr, recommented RO-attr} on a $obj, expect $expcode"
 157     putmsg stdout 0 "$tag: $ASSERTION"
 158     putmsg stdout 1 "Putfh $nfh; Setattr $stateid {{$attr 100}}"
 159     set res [compound {Putfh $nfh; Setattr $stateid {{$attr 100}}}]
 160     ckres "Setattr" $status $expcode $res $PASS
 161     incr i
 162 }
 163 
 164 # e's: Setattr recommended(bool, RO-attr) on file/dir, expect INVAL
 165 set expcode "INVAL|ATTRNOTSUPP"
 166 # list of the recommended RO-only bool attributes
 167 set rab "cansettime case_insensitive case_preserving chown_restricted"
 168 set recmbattrs "$rab homogeneous no_trunc"
 169 set i 1
 170 set stateid {0 0}
 171 foreach attr $recmbattrs {
 172     set tag "$TNAME{e$i}"
 173     # randomly set cfh to file or dir
 174     set j [expr int([expr [expr rand()] * 100000000])]
 175     if {[expr $j % 2] == 0} {
 176         set nfh $dfh
 177         set obj "dir"
 178     } else {
 179         set nfh $ffh
 180         set obj "file"
 181     }
 182     set ASSERTION \
 183         "Setattr{$attr, recommented RO-attr} on a $obj, expect $expcode"
 184     putmsg stdout 0 "$tag: $ASSERTION"
 185     putmsg stdout 1 "Putfh $nfh; Setattr $stateid {{$attr 100}}"
 186     set res [compound {Putfh $nfh; Setattr $stateid {{$attr true}}}]
 187     ckres "Setattr" $status $expcode $res $PASS
 188     incr i
 189 }
 190 
 191 # f's: Setattr recommended(other, RO-attr) on file/dir, expect INVAL
 192 set expcode "INVAL|ATTRNOTSUPP"
 193 # list of the recommended RO-only other attrs, except fs_locations (not in nfsh)
 194 set recmoattrs "rawdev"
 195 set i 1
 196 set stateid {0 0}
 197 foreach attr $recmoattrs {
 198     set tag "$TNAME{f$i}"
 199     # randomly set cfh to file or dir
 200     set j [expr int([expr [expr rand()] * 100000000])]
 201     if {[expr $j % 2] == 0} {
 202         set nfh $dfh
 203         set obj "dir"
 204     } else {
 205         set nfh $ffh
 206         set obj "file"
 207     }
 208     set ASSERTION \
 209         "Setattr{$attr, recommented RO-attr} on a $obj, expect $expcode"
 210     putmsg stdout 0 "$tag: $ASSERTION"
 211     if { "$attr" == "rawdev" } {
 212         set nattr "{$attr {0 100}}"
 213     }
 214     putmsg stdout 1 "Putfh $nfh; Setattr $stateid $nattr"
 215     set res [compound {Putfh $nfh; Setattr $stateid $nattr}]
 216     ckres "Setattr" $status $expcode $res $PASS
 217     incr i
 218 }
 219 
 220 # h: Setattr size on a symlink file, expect INVAL
 221 set expcode "INVAL"
 222 set ASSERTION "Setattr size symlink file, expect $expcode"
 223 set tag "$TNAME{h}"
 224 putmsg stdout 0 "$tag: $ASSERTION"
 225 set stateid {0 0}
 226 set res [compound {Putfh $bfh; Create newl {{mode 0777}} l $tmpF; 
 227         Setattr $stateid {{size 1000}}}]
 228 ckres "Setattr" $status $expcode $res $PASS
 229 
 230 # i: Setattr w/very big size on a file,
 231 #       expect FBIG for UFS
 232 #       expect OK for ZFS
 233 
 234 # UFS supports filesize range: 0-(2^40-1)
 235 # ZFS supports filesize range: 0-(2^63-1)
 236 # so if 2^40-1 < $nsize < 2^63, UFS should return FBIG,
 237 # but ZFS should return OK
 238 
 239 if $IsZFS {
 240     set expcode "OK"
 241 } else {
 242     set expcode "FBIG"
 243 }
 244 set ASSERTION "Setattr w/very big size on a file, expect $expcode"
 245 set tag "$TNAME{i}"
 246 putmsg stdout 0 "$tag: $ASSERTION"
 247 # Open the tmp file
 248 set clientid [getclientid $tpid]
 249 set oseqid 1
 250 set otype 0
 251 set res [compound {Putfh $bfh; 
 252         Open $oseqid 3 0 {$clientid $tpid} {$otype 0 0} {0 $tmpF}; Getfh}]
 253 if {$status != "OK"} {
 254         putmsg stderr 0 "\t Test UNRESOLVED: Open failed, status=($status)."
 255         putmsg stderr 1 "\t    res=($res)."
 256 } else {
 257     set open_sid [lindex [lindex $res 1] 2]
 258     set rflags [lindex [lindex $res 1] 4] 
 259     set nfh [lindex [lindex $res 2] 2]
 260     incr oseqid
 261     if {[expr $rflags & $OPEN4_RESULT_CONFIRM] == $OPEN4_RESULT_CONFIRM} {
 262         set res [compound {Putfh $nfh; Open_confirm "$open_sid" $oseqid}]
 263         set open_sid [lindex [lindex $res 1] 2]
 264         incr oseqid
 265     }
 266     set nsize [string repeat "8" 19]
 267     set res [compound {Putfh $nfh; Setattr $open_sid {{size $nsize}}}]
 268     ckres "Setattr" $status $expcode $res $PASS
 269     compound {Putfh $nfh; Close $oseqid $open_sid}
 270 }
 271 
 272 
 273 # m: Setattr to a file owned by others, expect PERM
 274 set expcode "PERM"
 275 set ASSERTION "Setattr to a file owned by others, expect $expcode"
 276 set tag "$TNAME{m}"
 277 putmsg stdout 0 "$tag: $ASSERTION"
 278 set stateid {0 0}
 279 set res [compound {Putfh $bfh; Lookup $env(DIR0777);
 280         Setattr $stateid {{mode 0715}}}]
 281 ckres "Setattr" $status $expcode $res $PASS
 282 
 283 
 284 # --------------------------------------------------------------
 285 # Final cleanup
 286 # cleanup remove the created file
 287 set res [compound {Putfh $bfh; Remove $tmpF; Remove $tmpD; Remove newl}]
 288 if { "$status" != "OK" } {
 289         putmsg stderr 0 "\t WARNING: cleanup to remove created dir failed"
 290         putmsg stderr 0 "\t          status=$status; please cleanup manually."
 291         putmsg stderr 1 "\t   res=($res)"
 292         putmsg stderr 1 "  "
 293         exit $WARNING
 294 }
 295 # disconnect and exit
 296 Disconnect
 297 exit $PASS