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 numbered attributes:
  27 #
  28 # a: Test get attr FATTR4_FILES_AVAIL which should be small limit, expect OK
  29 # b: Test get attr FATTR4_FILES_FREE which should be small limit, expect OK
  30 # c: Test get attr FATTR4_FILES_TOTAL on the filesystem, expect OK
  31 #
  32 
  33 set TESTROOT $env(TESTROOT)
  34 set delm $env(DELM)
  35 
  36 # include common code and init section
  37 source ${TESTROOT}${delm}tcl.init
  38 source ${TESTROOT}${delm}testproc
  39 
  40 # connect to the test server
  41 Connect
  42 
  43 # setting local variables
  44 set TNAME $argv0
  45 set expcode "OK"
  46 
  47 # Get testfile pathname
  48 set bfh [get_fh "$BASEDIRS"]
  49 
  50 # Start testing
  51 # ---------------------------------------------------------------
  52 # a:Test get attr FATTR4_FILES_AVAIL which should be small limit, expect OK
  53 
  54 set tag "$TNAME{a}"
  55 set ASSERTION "Test get attr FATTR4_FILES_AVAIL from server, expect $expcode"
  56 putmsg stdout 0 "$tag: $ASSERTION"
  57 
  58 # Get files available from server
  59 set avail [ exec df -e ${MNTPTR} | grep -v ifree | awk {{print $2}} ]
  60 set attr {files_avail}
  61 putmsg stderr 1 "avail=<$avail>, attr=<$attr>"
  62 
  63 set PID [pid]
  64 set nflist "newf1.$PID newf2.$PID newf3.$PID newf4.$PID newf5.$PID"
  65 
  66 set sid {0 0}
  67 foreach nf $nflist {
  68         set tfile "[creatv4_file "$BASEDIR${delm}$nf"]"
  69         set res [ compound {Putfh $tfile; Write $sid 0 f a \
  70                 "This is just a test to add some data for $tag"}]
  71         putmsg stderr 1 "WRITE res: $res"
  72         after 10000
  73 }
  74 
  75 # Get the attribute after the new files are created with data
  76 set res [compound {Putfh $tfile; Getattr $attr}]
  77 set cont [ckres "Getattr/$attr" $status $expcode $res $FAIL]
  78 
  79 if { [string equal $cont "true"] == 1 } {
  80         set attrval1 [ extract_attr [lindex [lindex $res 1] 2] $attr ]
  81 
  82         # Verify Getattr files_avail new attr value has decreased after 
  83         # more new files created 
  84         if { $avail <= $attrval1 } {
  85                 putmsg stdout 0  \
  86                   "\t Test FAIL: expected attrval1 files available to decrease"
  87                 putmsg stderr 1 "avail returned $avail"
  88                 putmsg stderr 1 "attrval1 returned $attrval1"
  89                 putmsg stderr 1 "\t\t Res: $res"
  90                 set cont false
  91         }
  92 
  93         # Delete the new files
  94         putmsg stderr 1 "Remove the newly created files ..."
  95         set res [compound {Putfh $bfh; foreach nf $nflist {Remove $nf}}]
  96         if {$status != "OK"} {
  97                 putmsg stdout 0 \
  98                         "WARNING: remove files returned status=$status"
  99                 putmsg stderr 1 "\t\t Res: $res"
 100         }
 101 
 102         if { [string equal $cont "true"] == 1 } {
 103                 after 50000
 104 
 105                 # Get files_avail for file object after new files are deleted
 106                 set res [compound {
 107                         Putfh $bfh;
 108                         Lookup $env(TEXTFILE);
 109                         Getfh;
 110                         Getattr $attr
 111                         }]
 112                 set cont2 [ckres "Getattr/attr2" $status $expcode $res $FAIL]
 113                 set attrval2 [ extract_attr [lindex [lindex $res 3] 2] $attr ]
 114 
 115                 if { [string equal $cont2 "true"] == 1 } {
 116                         # Verify Getattr files_avail attr value increased after
 117                         #       files deleted
 118                         if { $attrval1 >= $attrval2 } {
 119                                 putmsg stderr 1 "attrval1 returned $attrval1"
 120                                 putmsg stderr 1 "attrval2 returned $attrval2"
 121                                 putmsg stderr 1 "\t\t Res: $res"
 122                                 putmsg stdout 0 \
 123                 "\t Test FAIL: expected attrval2 files available to increase"
 124                         } else {
 125                                 prn_attrs [lindex [lindex $res 3] 2]
 126                                 putmsg stdout 0 "\t Test PASS"
 127                         }
 128                 }
 129 
 130         }
 131 
 132 }
 133 
 134 
 135 # ---------------------------------------------------------------
 136 # b:Test get attr FATTR4_FILES_FREE which should be small limit, expect OK
 137 
 138 set tag "$TNAME{b}"
 139 set ASSERTION \
 140     "Test get attr FATTR4_FILES_FREE which should be small limit, expect OK"
 141 putmsg stdout 0 "$tag: $ASSERTION"
 142 
 143 # Get number of files free from the server itself
 144 set expval [ exec df -e ${MNTPTR} | tail +2 | awk {{print $2}} ]
 145 
 146 # Setup testfile for attribute purposes
 147 set attr {files_free}
 148 putmsg stderr 1 "expval=<$expval>, attr=<$attr>"
 149 
 150 #Get the attribute of the test file
 151 set res [compound {
 152         Putfh $bfh;
 153         Lookup $env(TEXTFILE);
 154         Getfh;
 155         Getattr $attr
 156         }]
 157 set cont [ckres "Getattr/$attr" $status $expcode $res $FAIL]
 158 
 159 if { [string equal $cont "true"] == 1 } {
 160         set attrval [ extract_attr [lindex [lindex $res 3] 2] $attr ]
 161 
 162         if { [string equal $expval $attrval ] } { 
 163                 prn_attrs [lindex [lindex $res 3] 2]
 164                 putmsg stdout 0 "\t Test PASS"
 165         } else {
 166                 putmsg stdout 0 \
 167                   "\t Test FAIL: expected value $expval not equal to attr" 
 168                 putmsg stderr 1 "attrval returned $attrval"
 169                 putmsg stderr 1 "\t\t Res: $res"
 170         }
 171 
 172 }
 173 
 174 # ---------------------------------------------------------------
 175 # c:Test get attr FATTR4_FILES_TOTAL on the filesystem, expect OK
 176 
 177 set tag "$TNAME{c}"
 178 set ASSERTION "Test get attr FATTR4_FILES_TOTAL on the filesystem, expect OK"
 179 putmsg stdout 0 "$tag: $ASSERTION"
 180 
 181 # Get total number of file slots on filesystem
 182 set expval [ exec df -t ${MNTPTR} | grep total | awk {{print $4}} ]
 183 
 184 # Setup testfile for attribute purposes
 185 set attr {files_total}
 186 putmsg stderr 1 "expval=<$expval>, attr=<$attr>"
 187 
 188 #Get the attribute of the test file
 189 set res [compound {
 190         Putfh $bfh;
 191         Lookup $env(TEXTFILE);
 192         Getfh;
 193         Getattr $attr
 194         }]
 195 set cont [ckres "Getattr/$attr" $status $expcode $res $FAIL]
 196 
 197 if { [string equal $cont "true"] == 1 } {
 198         set attrval [ extract_attr [lindex [lindex $res 3] 2] $attr ]
 199         if { [string equal $expval $attrval ] } {
 200                 prn_attrs [lindex [lindex $res 3] 2]
 201                 putmsg stdout 0 "\t Test PASS" 
 202         } else {
 203                 putmsg stdout 0 \
 204                   "\t Test FAIL: expected $expval total files on Getattr" 
 205                 putmsg stderr 1 "expected value = $expval" 
 206                 putmsg stderr 1 "getattr returned $attrval"
 207         }
 208 
 209 }
 210 
 211 Disconnect 
 212 exit $PASS
 213