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 RENAME operation test - negative tests
  27 
  28 # include all test enironment
  29 source RENAME.env
  30 
  31 # connect to the test server
  32 Connect
  33 
  34 # setting local variables
  35 set TNAME $argv0
  36 set bfh [get_fh "$BASEDIRS"]
  37 
  38 # create a tmp file to be rename
  39 set tmpf Renm2file.[pid]
  40 creatv4_file [file join $BASEDIR $tmpf]
  41 
  42 
  43 # Start testing
  44 # --------------------------------------------------------------
  45 # a: Rename with oldname not exist, expect ENOENT
  46 set expcode "NOENT"
  47 set ASSERTION "Rename with oldname not exist, expect $expcode"
  48 putmsg stdout 0 "$TNAME{a}: $ASSERTION"
  49 set res [compound {Putfh $bfh; Savefh; Rename "ENOENT" "Ren2a.[pid]"}]
  50 set cont [ckres "Rename" $status $expcode $res $FAIL]
  51 # check newname does not exist
  52   if {! [string equal $cont "false"]} {
  53       set res [compound {Putfh $bfh; Lookup "Ren2a.[pid]"}]
  54       if { $status != "NOENT" } {
  55           putmsg stderr 0 "\t Test FAIL: newname exists after Rename failed"
  56           putmsg stderr 1 "\t   res=($res)"
  57       } else {
  58         logres PASS
  59       }
  60   }
  61 
  62 
  63 # b: try to Rename while target dir is removed, expect STALE
  64 set expcode "STALE"
  65 set ASSERTION "Rename while target dir is removed, expect $expcode"
  66 putmsg stdout 0 "$TNAME{b}: $ASSERTION"
  67 set tmpd "tmp.[pid]"
  68 set res [compound {Putfh $bfh; Create $tmpd {{mode 0777}} d; 
  69         Getfh; Create xx {{mode 0775}} d;}]
  70 set tfh [lindex [lindex $res 2] 2]
  71 check_op "Putfh $tfh; Remove xx; Lookupp; Remove $tmpd" "OK" "UNINITIATED"
  72 set res [compound {Putfh $bfh; Savefh; Putfh $tfh; Rename xx "Ren2b.[pid]"}]
  73 set cont [ckres "Rename" $status $expcode $res $FAIL]
  74 # check newname does not exist
  75   if {! [string equal $cont "false"]} {
  76       set res [compound {Putfh $bfh; Lookup "Ren2b.[pid]"}]
  77       if { $status != "NOENT" } {
  78           putmsg stderr 0 "\t Test FAIL: newname exists after Rename failed"
  79           putmsg stderr 1 "\t   res=($res)"
  80       } else {
  81         logres PASS
  82       }
  83   }
  84 
  85 
  86 # c: Rename with newname has zero length, expect INVAL
  87 set expcode "INVAL"
  88 set ASSERTION "Rename with newname has zero length, expect $expcode"
  89 putmsg stdout 0 "$TNAME{c}: $ASSERTION"
  90 set res [compound {Putfh $bfh; Savefh; Rename $tmpf ""}]
  91 set cont [ckres "Rename" $status $expcode $res $FAIL]
  92 # check oldname still exist
  93   if {! [string equal $cont "false"]} {
  94       set res [compound {Putfh $bfh; Lookup "$tmpf"}]
  95       if { $status != "OK" } {
  96           if { $status == "NOENT" } {
  97                 putmsg stderr 0 \
  98                         "\t Test FAIL: oldname is gone after Rename failed"
  99                 putmsg stderr 1 "\t   res=($res)"
 100           } else {
 101                 putmsg stderr 0 \
 102                         "\t Test FAIL: 2nd compound got=($status), expected OK"
 103           }
 104       } else {
 105         logres PASS
 106       }
 107   }
 108 
 109 
 110 # d: Rename with newname is not UTF-8, expect INVAL
 111 set expcode "INVAL"
 112 set ASSERTION "Rename with newname is not UTF-8, expect $expcode"
 113 #putmsg stdout 0 "$TNAME{d}: $ASSERTION"
 114 #puts "\t Test UNTESTED: XXX how to create non-UTF-8 compliance name??\n"
 115 
 116 
 117 # e: Rename with newname set to ".", expect INVAL|OK
 118 set expcode "INVAL|OK"
 119 set ASSERTION "Rename with newname set to '.', expect $expcode"
 120 putmsg stdout 0 "$TNAME{e}: $ASSERTION"
 121 set res [compound {Putfh $bfh; Savefh; Rename $tmpf "."}]
 122 set cont [ckres "Rename" $status $expcode $res $FAIL]
 123 # check oldname still exist
 124   if {! [string equal $cont "false"]} {
 125       set res [compound {Putfh $bfh; Lookup "$tmpf"}]
 126       if { $status != "OK" } {
 127           if { $status == "NOENT" } {
 128                 putmsg stderr 0 \
 129                         "\t Test FAIL: oldname is gone after Rename failed"
 130                 putmsg stderr 1 "\t   res=($res)"
 131           } else {
 132                 putmsg stderr 0 \
 133                         "\t Test FAIL: 2nd compound got=($status), expected OK"
 134           }
 135       } else {
 136         logres PASS
 137       }
 138   }
 139 
 140 
 141 # f: Rename with newname set to "..", expect INVAL|OK
 142 set expcode "INVAL|OK"
 143 set ASSERTION "Rename with newname set to '..', expect $expcode"
 144 putmsg stdout 0 "$TNAME{f}: $ASSERTION"
 145 set res [compound {Putfh $bfh; Savefh; Rename $tmpf ".."}]
 146 set cont [ckres "Rename" $status $expcode $res $FAIL]
 147 # check oldname still exist
 148   if {! [string equal $cont "false"]} {
 149       set res [compound {Putfh $bfh; Lookup "$tmpf"}]
 150       if { $status != "OK" } {
 151           if { $status == "NOENT" } {
 152                 putmsg stderr 0 \
 153                         "\t Test FAIL: oldname is gone after Rename failed"
 154                 putmsg stderr 1 "\t   res=($res)"
 155           } else {
 156                 putmsg stderr 0 \
 157                         "\t Test FAIL: 2nd compound got=($status), expected OK"
 158           }
 159       } else {
 160         logres PASS
 161       }
 162   }
 163 
 164 
 165 # g: Rename w/newname include path delimiter, expect INVAL
 166 set expcode "INVAL"
 167 set ASSERTION "Rename w/newname include path delimiter, expect $expcode"
 168 putmsg stdout 0 "$TNAME{g}: $ASSERTION"
 169 set res [compound {Putfh $bfh; Savefh; Rename $tmpf "XX${DELM}xx"}]
 170 set cont [ckres "Rename" $status $expcode $res $FAIL]
 171 # check oldname still exist
 172   if {! [string equal $cont "false"]} {
 173       set res [compound {Putfh $bfh; Lookup "$tmpf"}]
 174       if { $status != "OK" } {
 175           if { $status == "NOENT" } {
 176                 putmsg stderr 0 \
 177                         "\t Test FAIL: oldname is gone after Rename failed"
 178                 putmsg stderr 1 "\t   res=($res)"
 179           } else {
 180                 putmsg stderr 0 \
 181                         "\t Test FAIL: 2nd compound got=($status), expected OK"
 182           }
 183       } else {
 184         logres PASS
 185       }
 186   }
 187 
 188 
 189 # h: Rename with oldname has zero length, expect INVAL
 190 set expcode "INVAL"
 191 set ASSERTION "Rename with oldname has zero length, expect $expcode"
 192 putmsg stdout 0 "$TNAME{h}: $ASSERTION"
 193 set res [compound {Putfh $bfh; Savefh; Rename "" XXX}]
 194 set cont [ckres "Rename" $status $expcode $res $FAIL]
 195 # check newname should not exist
 196   if {! [string equal $cont "false"]} {
 197       set res [compound {Putfh $bfh; Lookup "XXX"}]
 198       if { $status == "OK" } {
 199           putmsg stderr 0 "\t Test FAIL: newname exists after Rename failed"
 200           putmsg stderr 1 "\t   res=($res)"
 201       } else {
 202         logres PASS
 203       }
 204   }
 205 
 206 
 207 # i: Rename with oldname is not UTF-8, expect INVAL
 208 set expcode "INVAL"
 209 set ASSERTION "Rename with oldname is not UTF-8, expect $expcode"
 210 #putmsg stdout 0 "$TNAME{i}: $ASSERTION"
 211 #puts "\t Test UNTESTED: XXX how to create non-UTF-8 compliance name??\n"
 212 
 213 
 214 # j: Rename with oldname set to ".", expect INVAL|NOENT
 215 set expcode "INVAL|NOENT"
 216 set ASSERTION "Rename with oldname set to '.', expect $expcode"
 217 putmsg stdout 0 "$TNAME{j}: $ASSERTION"
 218 set res [compound {Putfh $bfh; Savefh; Rename "." XXX}]
 219 set cont [ckres "Rename" $status $expcode $res $FAIL]
 220 # check newname should not exist
 221   if {! [string equal $cont "false"]} {
 222       set res [compound {Putfh $bfh; Lookup "XXX"}]
 223       if { $status == "OK" } {
 224           putmsg stderr 0 "\t Test FAIL: newname exists after Rename failed"
 225           putmsg stderr 1 "\t   res=($res)"
 226       } else {
 227         logres PASS
 228       }
 229   }
 230 
 231 
 232 # k: Rename with oldname set to "..", expect INVAL|NOENT
 233 set expcode "INVAL|NOENT"
 234 set ASSERTION "Rename with oldname set to '..', expect $expcode"
 235 putmsg stdout 0 "$TNAME{k}: $ASSERTION"
 236 set res [compound {Putfh $bfh; Savefh; Rename ".." XXX}]
 237 set cont [ckres "Rename" $status $expcode $res $FAIL]
 238 # check newname should not exist
 239   if {! [string equal $cont "false"]} {
 240       set res [compound {Putfh $bfh; Lookup "XXX"}]
 241       if { $status == "OK" } {
 242           putmsg stderr 0 "\t Test FAIL: newname exists after Rename failed"
 243           putmsg stderr 1 "\t   res=($res)"
 244       } else {
 245         logres PASS
 246       }
 247   }
 248 
 249 
 250 # l: Rename with oldname include path delimiter, expect INVAL|NOENT
 251 set expcode "INVAL|NOENT"
 252 set ASSERTION "Rename w/oldname include path delimiter, expect $expcode"
 253 putmsg stdout 0 "$TNAME{l}: $ASSERTION"
 254 set res [compound {Putfh $bfh; Savefh; Rename "XX${DELM}xx" XXX}]
 255 set cont [ckres "Rename" $status $expcode $res $FAIL]
 256 # check newname should not exist
 257   if {! [string equal $cont "false"]} {
 258       set res [compound {Putfh $bfh; Lookup "XXX"}]
 259       if { $status == "OK" } {
 260           putmsg stderr 0 "\t Test FAIL: newname exists after Rename failed"
 261           putmsg stderr 1 "\t   res=($res)"
 262       } else {
 263         logres PASS
 264       }
 265   }
 266 
 267 
 268 # m: Rename with newname longer than maxname, expect NAMETOOLONG
 269 set expcode "NAMETOOLONG"
 270 set ASSERTION "Rename with newname longer than maxname, expect $expcode"
 271 putmsg stdout 0 "$TNAME{m}: $ASSERTION"
 272 set nli [set_maxname $bfh]
 273 set res [compound {Putfh $bfh; Savefh; Rename $tmpf $nli}]
 274 set cont [ckres "Rename" $status $expcode $res $FAIL]
 275 # check oldname still exist
 276   if {! [string equal $cont "false"]} {
 277       set res [compound {Putfh $bfh; Lookup "$tmpf"}]
 278       if { $status != "OK" } {
 279           if { $status == "NOENT" } {
 280                 putmsg stderr 0 \
 281                         "\t Test FAIL: oldname is gone after Rename failed"
 282                 putmsg stderr 1 "\t   res=($res)"
 283                 putmsg stderr 1 "\t   length of newname=([string length $nli])"
 284           } else {
 285                 putmsg stderr 0 \
 286                         "\t Test FAIL: 2nd compound got=($status), expected OK"
 287           }
 288       } else {
 289         logres PASS
 290       }
 291   }
 292 
 293 
 294 # n: Rename across filesystems, expect XDEV
 295 set expcode "XDEV"
 296 set ASSERTION "Rename to a file across filesystem, expect $expcode"
 297 putmsg stdout 0 "$TNAME{n}: $ASSERTION"
 298 set ofh [get_fh [path2comp $env(SSPCDIR) $DELM]]
 299 set res [compound {Putfh $bfh; Getattr numlinks; Savefh;
 300         Putfh $ofh; Rename $env(RWFILE) "RendirN" }]
 301 set cont [ckres "Rename" $status $expcode $res $FAIL]
 302 # check oldname still exist
 303   if {! [string equal $cont "false"]} {
 304       set res [compound {Putfh $ofh; Lookup "$env(RWFILE)"}]
 305       if { $status != "OK" } {
 306           if { $status == "NOENT" } {
 307                 putmsg stderr 0 \
 308                         "\t Test FAIL: oldname is gone after Rename failed"
 309                 putmsg stderr 1 "\t   res=($res)"
 310           } else {
 311                 putmsg stderr 0 \
 312                         "\t Test FAIL: 2nd compound got=($status), expected OK"
 313           }
 314       } else {
 315         logres PASS
 316       }
 317   }
 318 
 319 # o: Rename of named_attr across filesystems, expect XDEV
 320 set expcode "XDEV"
 321 set ASSERTION "Rename of named_attr across filesystem, expect $expcode"
 322 putmsg stdout 0 "$TNAME{o}: $ASSERTION"
 323 set ofh [get_fh [path2comp $env(SSPCDIR) $DELM]]
 324 set res [compound {Putfh $ofh; Savefh; 
 325         Putfh $bfh; Lookup $env(ATTRDIR); Openattr f;
 326         Rename $env(RWFILE) "RendirO" }]
 327 set cont [ckres "Rename" $status $expcode $res $FAIL]
 328 # check oldname still exist
 329   if {! [string equal $cont "false"]} {
 330       set res [compound {Putfh $ofh; Lookup "$env(RWFILE)"}]
 331       if { $status != "OK" } {
 332           if { $status == "NOENT" } {
 333                 putmsg stderr 0 \
 334                         "\t Test FAIL: oldname is gone after Rename failed"
 335                 putmsg stderr 1 "\t   res=($res)"
 336           } else {
 337                 putmsg stderr 0 \
 338                         "\t Test FAIL: 2nd compound got=($status), expected OK"
 339           }
 340       } else {
 341         logres PASS
 342       }
 343   }
 344 
 345 # p: Rename a file into named_attrd across filesystems, expect XDEV
 346 set expcode "XDEV"
 347 set ASSERTION "Rename a file into named_attrd across FSs, expect $expcode"
 348 putmsg stdout 0 "$TNAME{p}: $ASSERTION"
 349 set ofh [get_fh [path2comp $env(SSPCDIR) $DELM]]
 350 set res [compound {Putfh $bfh; Lookup $env(ATTRDIR); Openattr f; Savefh;
 351         Getfh; Putfh $ofh; Rename $env(ATTRDIR_AT1) "RendirP" }]
 352 set cont [ckres "Rename" $status $expcode $res $FAIL]
 353 # check oldname still exist
 354   if {! [string equal $cont "false"]} {
 355       set nfh [lindex [lindex $res 4] 2]
 356       set res [compound {Putfh $nfh; Lookup "$env(ATTRDIR_AT1)"}]
 357       if { $status != "OK" } {
 358           if { $status == "NOENT" } {
 359                 putmsg stderr 0 \
 360                         "\t Test FAIL: oldname is gone after Rename failed"
 361                 putmsg stderr 1 "\t   res=($res)"
 362           } else {
 363                 putmsg stderr 0 \
 364                         "\t Test FAIL: 2nd compound got=($status), expected OK"
 365           }
 366       } else {
 367         logres PASS
 368       }
 369   }
 370 
 371 
 372 # --------------------------------------------------------------
 373 # Final cleanup:
 374 #   remove the created temp files
 375 set res [compound {Putfh $bfh; Remove $tmpf}]
 376 if { "$status" != "OK" } {
 377         putmsg stderr 0 "\t WARNING: cleanup to remove created files failed"
 378         putmsg stderr 0 "\t          status=$status; please cleanup manually."
 379         putmsg stderr 1 "\t   res=($res)"
 380         putmsg stderr 1 "  "
 381         exit $WARNING
 382 }
 383 
 384 # disconnect and exit
 385 Disconnect
 386 exit $PASS