1 #! /usr/bin/ksh -p
2 #
3 # CDDL HEADER START
4 #
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
8 #
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
13 #
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 #
20 # CDDL HEADER END
21 #
22
23 #
24 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27 # NFSv4 quota query with quota(1M) and rquotad(1M)
28 # Require root permission to mount the FS w/quota setup.
29 #
30 # Since quota(1M) is to display user quota for UFS filesystem only,
31 # all tests will return UNSUPPORTED if run from an NFSv4/ZFS filesystem,
32 # as ZFS supports different kind of quota.
33
34 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
35
36 NAME=`basename $0`
37 CDIR=`pwd`
38
39 if [ $TestZFS -eq 1 ]; then
40 echo "$NAME{all}: v4 client quota(1M) query test."
41 echo "\t Test UNSUPPORTED: current TESTDIR is ZFS, doesn't\c"
42 echo " support quota(1M)."
43 exit $UNSUPPORTED
44 fi
45
46 id | grep "0(root)" > /dev/null 2>&1
47 if [ $? -ne 0 ]; then
48 echo "$NAME{all}: v4 client quota query test."
49 echo "\t Test UNINITIATED: need root permission to mount FS \c"
50 echo "w/quota setup."
51 exit $UNINITIATED
52 fi
53
54 # proc to check result and print out failure messages
55 # ckres rc message cat_file
56 function ckres
57 {
58 rc=$1
59 msg=${2}
60 cf=${3}
61
62 if [ $rc -ne 0 ]; then
63 echo "\t Test FAIL: $msg"
64 [ -f $cf ] && cat $cf
65 fi
66 return $rc
67 }
68
69 TMPmnt=$ZONE_PATH/$NAME.$$
70 mkdir -m 0777 -p $TMPmnt
71
72
73 # Start test assertions here
74 # ----------------------------------------------------------------------
75 # a: query user's quota on v4 server's FS, expect successful
76 function assertion_a
77 {
78 ASSERTION="query user's quota on v4 server's FS, expect successful"
79 echo "$NAME{a}: $ASSERTION"
80 SRVPATH=$QUOTADIR
81
82 # Do the mount on the $SRVPATH
83 mount -o vers=4,rw $SERVER:$SRVPATH $TMPmnt > $TMPDIR/$NAME.mnt.$$ 2>&1
84 ckres $? "mount did not succeed" $TMPDIR/$NAME.mnt.$$
85 [ $? -ne 0 ] && return $FAIL
86
87 # verify the mount point is access'ble
88 ls $TMPmnt/$DIR0777 > $TMPDIR/$NAME.ck.$$ 2>&1
89 ckres $? "unable to access ($TMPmnt/$DIR0777)" $TMPDIR/$NAME.ck.$$
90 [ $? -ne 0 ] && (umount -f $TMPmnt; return $FAIL)
91
92 # now query quota for user $TUSER2:
93 su $TUSER2 -c "quota -v" > $TMPDIR/$NAME.quota.$$ 2>&1
94 ckres $? "quota query for $TUSER2 failed" $TMPDIR/$NAME.quota.$$
95 [ $? -ne 0 ] && (umount -f $TMPmnt; return $FAIL)
96 awk '{ \
97 if (NF == 1) print $1; \
98 else if ($1 ~ /[0-9][0-9]*/) {printf("%s %s\n"), $3, $NF}; \
99 }' $TMPDIR/$NAME.quota.$$ > $TMPDIR/$NAME.q2.$$
100 echo "$TMPmnt\n5 5" > $TMPDIR/$NAME.q3.$$
101 diff $TMPDIR/$NAME.q2.$$ $TMPDIR/$NAME.q3.$$ > /dev/null 2>&1
102 if [ $? -ne 0 ]; then
103 echo "\t Test FAIL: quota value received not correct"
104 cat $TMPDIR/$NAME.quota.$$
105 umount -f $TMPmnt; return $FAIL
106 fi
107
108 # finally umount it
109 umount $TMPmnt > $TMPDIR/$NAME.umnt.$$ 2>&1
110 ckres $? "umount failed" $TMPDIR/$NAME.umnt.$$
111 [ $? -ne 0 ] && return $FAIL
112
113 echo "\t Test PASS"
114 return $PASS
115 }
116
117
118
119 # Start main program here:
120 # ----------------------------------------------------------------------
121
122 assertion_a
123 rc=$?
124
125 # cleanup here
126 [ $rc -eq $PASS ] && rm -fr $TMPmnt $TMPDIR/$NAME.*.$$
127
128 exit 0