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