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 server name space test - positive tests
  27 #
  28 
  29 # include all test enironment
  30 source SNSPC.env
  31 
  32 set TNAME $argv0
  33 
  34 # proc to recursively list the directory hierachy
  35 proc dolist { fh } {
  36     set cookie 0
  37     set eof false
  38     while { $eof != "true" } {
  39         set res [compound { Putfh $fh; Readdir $cookie 0 1024 1024 {type} }]
  40         if {$status != "OK"} {
  41             return "$status $res"
  42         }
  43         set readdirres [ lindex $res 1 ]
  44         set eof [ lindex $readdirres 4 ]
  45         set dirlist [ lindex $readdirres 3 ]
  46 
  47         # Examine each entry in the directory
  48         foreach entry $dirlist {
  49             set cookie [ lindex $entry 0 ]
  50             set name   [ lindex $entry 1 ]
  51             set attrs  [ lindex $entry 2 ]
  52             set type   [ extract_attr $attrs "type" ]
  53 
  54             # If the entry is a directory, invoke the
  55             # procedure recursively.
  56             if {$type == "dir"} {
  57                 set res [compound { Putfh $fh; Lookup $name; Getfh }]
  58                 if {$status != "OK"} {
  59                     return "$status $res"
  60                 }
  61                 set fh2 [ lindex [lindex $res 2] 2]
  62                 dolist $fh2
  63             }
  64         }
  65     }
  66     return "OK"
  67 }
  68 
  69 # Start the assertion proc's here
  70 # --------------------------------------------------------------
  71 # a: Walk down path thru pseudo & exported nodes, expect OK
  72 #    the 'ssnpd' would have crossing mount & export points.
  73 proc assertion_a {path} {
  74     global TNAME
  75     set expcode "OK"
  76     set ASSERTION \
  77         "Walk down the path thru pseudo & exported nodes, expect $expcode"
  78     putmsg stdout 0 "$TNAME{a}: $ASSERTION"
  79     set tag "$TNAME{a}"
  80 
  81     set res [dolist [get_fh $path]]
  82     if {"[lindex $res 0]" != "$expcode"} {
  83         putmsg stderr 0 "\t Test FAIL: unable to dolist."
  84         putmsg stderr 1 "\t   res=($res)"
  85         return (-1)
  86     }
  87 
  88     logres PASS
  89     return (0)
  90 }
  91 
  92 
  93 # b: Verify mount point crossing, expect OK
  94 #    the 'ssnpd' would have crossing mount & export points.
  95 proc assertion_b {ssnpd} {
  96     global TNAME
  97     global BASEDIRS
  98     set expcode "OK"
  99     set ASSERTION "Verify mount point crossing, expect $expcode"
 100     putmsg stdout 0 "$TNAME{b}: $ASSERTION"
 101     set tag "$TNAME{b}"
 102 
 103     # Do the compound to LOOKUP thru the path with crossing mount points
 104     # starts to traverse from the BASEDIR.
 105     set save_spc ""
 106     set fh [get_fh $BASEDIRS]
 107     foreach d "[lrange $ssnpd [llength $BASEDIRS] end]" {
 108         set res [compound {Putfh $fh; Readdir 0 0 1024 8192 {type filehandle};
 109                 Lookup $d; Getattr {space_avail}; Getfh}]
 110         if {$status != "$expcode"} {
 111             putmsg stderr 0 \
 112                 "\t Test UNRESOLVED: compound of <$d> got status=($status)"
 113             putmsg stderr 0 "\t                  expected=($expcode)"
 114             putmsg stderr 1 "\t   res=($res)"
 115             return (-1)
 116         }
 117 
 118         # check FH in crossing mount points
 119         set rdres [lindex [lindex $res 1] 3]
 120         set spc [extract_attr [lindex [lindex $res 3] 2] "space_avail"]
 121         foreach entry $rdres {
 122             set attr [lindex $entry 2]
 123             set type [extract_attr $attr "type"]
 124 
 125             # The crossing mount point should be a 'dir'
 126             # and the space_avail value will be different from its parent.
 127             if {($spc != "") && ($spc != $save_spc) && ($type == "dir")} {
 128                 set name [lindex $entry 1]
 129                 if {$name == $d} {
 130                     set dfh [extract_attr $attr "filehandle"]
 131                     # Filehandles are different from crossing mnt & its parent
 132                     if {$dfh == $fh} {
 133                         putmsg stderr 0 \
 134                 "\t Test FAIL: <$d> crossing mnt-point, but FHs are the same"
 135                         putmsg stderr 1 "\t   fh=($fh)"
 136                         putmsg stderr 1 "\t   dfh=($dfh)"
 137                         return (-1)
 138                     }
 139                 }
 140             }
 141         }
 142         set save_spc $spc
 143         set fh [lindex [lindex $res 4] 2]
 144     }
 145 
 146     logres PASS
 147     return (0)
 148 }
 149 
 150 
 151 # c: Check fsid for crossing filesystems, expect OK
 152 proc assertion_c {bdir rofs} {
 153     global TNAME
 154     set expcode "OK"
 155     set ASSERTION "Check fsid for crossing filesystems, expect $expcode"
 156     putmsg stdout 0 "$TNAME{c}: $ASSERTION"
 157     set tag "$TNAME{c}"
 158 
 159     # First Get fsid pseudo node and BASEDIR
 160     set pnode [lrange $bdir 0 [expr [llength $bdir] - 2]]
 161     set pfh [get_fh $pnode]
 162     set rfh [get_fh $rofs]
 163     if {"$rfh" == ""} {
 164         # no such filesystem setup in server, exit the test
 165         putmsg stderr 0 \
 166                 "\t Test NOTINUSE: ROFS is not setup in server."
 167         return (2)
 168     }
 169     set res [compound {Putfh $pfh; Getattr fsid;
 170                 Putfh $rfh; Getattr fsid}]
 171     if {$status != "$expcode"} {
 172         putmsg stderr 0 \
 173                 "\t Test UNRESOLVED: Getattr got status=($status)"
 174         putmsg stderr 0 \
 175                 "\t                  expected=($expcode)"
 176         putmsg stderr 1 "\t   res=($res)"
 177         return (-1)
 178     }
 179     set pfsid [lindex [lindex [lindex [lindex $res 1] 2] 0] 1]
 180     set rfsid [lindex [lindex [lindex [lindex $res 3] 2] 0] 1]
 181 
 182     # Check the fsid's, should be different
 183     if {$pfsid == $rfsid} {
 184         putmsg stderr 0 \
 185             "\t Test FAIL: fsid on 2 diff_FSs are the same."
 186         putmsg stderr 1 "\t   res=($res)"
 187         return (-1)
 188     }
 189 
 190     logres PASS
 191     return (0)
 192 }
 193 
 194 
 195 # Start the main program here
 196 # --------------------------------------------------------------
 197 # connect to the test server
 198 if {[catch {connect -p ${PORT} -t ${TRANSPORT} ${SERVER}} msg]} {
 199         putmsg stderr 0 "Test UNINITIATED: unable to connect to $SERVER"
 200         putmsg stderr 1 $msg
 201         exit $UNINITIATED
 202 }
 203 
 204 assertion_a "[path2comp $env(SSPCDIR) $env(DELM)]"
 205 assertion_b "[path2comp $env(SSPCDIR3) $env(DELM)]"
 206 assertion_c $BASEDIRS [path2comp $env(ROFSDIR) $env(DELM)]
 207 
 208 
 209 # --------------------------------------------------------------
 210 # disconnect and exit
 211 set tag ""
 212 disconnect
 213 exit $PASS