Fix fsstress builds when setting the project identifier (fsx interface now).
[xfstests-dev.git] / 050
1 #! /bin/sh
2 # FS QA Test No. 050
3 #
4 # Exercises basic XFS quota functionality
5 #       MOUNT_OPTIONS env var switches the test type (uid/gid/acct/enfd)
6 #       options are:  (-o) uquota, gquota, uqnoenforce, gqnoenforce
7 #
8 #-----------------------------------------------------------------------
9 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
10
11 # This program is free software; you can redistribute it and/or modify it
12 # under the terms of version 2 of the GNU General Public License as
13 # published by the Free Software Foundation.
14
15 # This program is distributed in the hope that it would be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18
19 # Further, this software is distributed without any warranty that it is
20 # free of the rightful claim of any third person regarding infringement
21 # or the like.  Any license provided herein, whether implied or
22 # otherwise, applies only to this software file.  Patent licenses, if
23 # any, provided herein do not apply to combinations of this program with
24 # other software, or any other product whatsoever.
25
26 # You should have received a copy of the GNU General Public License along
27 # with this program; if not, write the Free Software Foundation, Inc., 59
28 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
29
30 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
31 # Mountain View, CA  94043, or:
32
33 # http://www.sgi.com 
34
35 # For further information regarding this notice, see: 
36
37 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
38 #-----------------------------------------------------------------------
39 #
40 # creator
41 owner=nathans@sgi.com
42
43 seq=`basename $0`
44 echo "QA output created by $seq"
45
46 here=`pwd`
47 tmp=/tmp/$$
48 status=1        # failure is the default!
49
50 # get standard environment, filters and checks
51 . ./common.rc
52 . ./common.filter
53 . ./common.quota
54
55 _cleanup()
56 {
57         cd /
58         echo; echo "*** unmount"
59         umount $SCRATCH_MNT 2>/dev/null
60         rm -f $tmp.*
61 }
62 trap "_cleanup; exit \$status" 0 1 2 3 15
63
64
65 # real QA test starts here
66 _supported_fs xfs
67 _supported_os Linux IRIX
68
69 rm -f $seq.out
70 cp /dev/null $seq.full
71 chmod a+rwx $seq.full   # arbitrary users will write here
72
73 _require_scratch
74 _require_quota
75
76 # setup a default run
77 [ -z "$MOUNT_OPTIONS" ] && export MOUNT_OPTIONS="-o uquota"
78
79 blksoft=100
80 blkhard=500
81 inosoft=4
82 inohard=10
83
84 # The actual point at which limit enforcement takes place for the
85 # hard block limit is variable depending on filesystem blocksize,
86 # and iosize.  What we want to test is that the limit is enforced
87 # (ie. blksize less than limit but not unduly less - ~85% is kind)
88 # nowadays we actually get much closer to the limit before EDQUOT.
89
90 _filter_and_check_blocks()
91 {
92         perl -npe '
93                 if (/^'$name'\s+([-|+]){2}\s+(\d+)/ && '$enforce') {
94                         $maximum = '$blkhard';
95                         $minimum = '$blkhard' * 85/100;
96                         if ($2 < $minimum || $2 > $maximum) {
97                                 printf(" URK - %d is out of range! [%d,%d] \n",
98                                         $2, $minimum, $maximum);
99                         }
100                         s/^('$name'\s+[-|+][-|+]\s+)(\d+)/\1 OK/g;
101                 }
102         ' | _filter_repquota
103 }
104
105 _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
106 cat $tmp.mkfs >>$seq.full
107
108 # keep the blocksize and data size for dd later
109 . $tmp.mkfs
110
111 _qmount
112
113 # Irix uses filesystem name and Linux uses device of filesystem
114 if [ $HOSTOS = "Linux" ]; then
115     QUOTA_FS=$SCRATCH_DEV
116 else
117     QUOTA_FS=$SCRATCH_MNT
118 fi
119
120 _qsetup
121
122 echo "Using output from '" `ls -l $seq.out` "'" >>$seq.full
123 echo "and using type=$type id=$id" >>$seq.full
124
125 echo
126 echo "*** report no quota settings" | tee -a $seq.full
127 _repquota -$type $QUOTA_FS | _filter_repquota
128
129 echo
130 echo "*** report initial settings" | tee -a $seq.full
131 _file_as_id $SCRATCH_MNT/initme $id $type 1024 0
132 echo "ls -l $SCRATCH_MNT" >>$seq.full
133 ls -l $SCRATCH_MNT >>$seq.full
134 _setquota -$type $id $blksoft $blkhard $inosoft $inohard $QUOTA_FS
135 _repquota -$type $QUOTA_FS | _filter_repquota
136
137 echo
138 echo "*** push past the soft inode limit" | tee -a $seq.full
139 _file_as_id $SCRATCH_MNT/softie1 $id $type 1024 0
140 _file_as_id $SCRATCH_MNT/softie2 $id $type 1024 0
141 _qmount
142 _repquota -$type $QUOTA_FS | _filter_repquota
143
144 echo
145 echo "*** push past the soft block limit" | tee -a $seq.full
146 _file_as_id $SCRATCH_MNT/softie $id $type 1024 140
147 _qmount
148 _repquota -$type $QUOTA_FS | _filter_repquota
149
150 echo
151 # Note: for quota accounting (not enforcement), EDQUOT is not expected
152 echo "*** push past the hard inode limit (expect EDQUOT)" | tee -a $seq.full
153 for i in 1 2 3 4 5 6 7 8 9 10 11 12
154 do
155         _file_as_id $SCRATCH_MNT/hard$i $id $type 1024 0
156 done
157 _qmount
158 _repquota -$type $QUOTA_FS | _filter_repquota
159
160 echo
161 # Note: for quota accounting (not enforcement), EDQUOT is not expected
162 echo "*** push past the hard block limit (expect EDQUOT)" | tee -a $seq.full
163 _file_as_id $SCRATCH_MNT/softie $id $type 1024 540
164 echo "ls -l $SCRATCH_MNT" >>$seq.full
165 ls -l $SCRATCH_MNT >>$seq.full
166 _qmount
167 _repquota -$type $QUOTA_FS | _filter_and_check_blocks
168
169
170 # success, all done
171 status=0
172 exit