acca654db83c54855faa85acdb9073fd96831cc3
[xfstests-dev.git] / 050
1 #! /bin/bash
2 # FS QA Test No. 050
3 #
4 # Exercises basic XFS quota functionality
5 #       uquota, gquota, uqnoenforce, gqnoenforce, pquota, pqnoenforce
6 #
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation.
13 #
14 # This program is distributed in the hope that it would be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write the Free Software Foundation,
21 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22 #
23 #-----------------------------------------------------------------------
24 #
25 # creator
26 owner=nathans@sgi.com
27
28 seq=`basename $0`
29 echo "QA output created by $seq"
30
31 here=`pwd`
32 tmp=/tmp/$$
33 status=1        # failure is the default!
34
35 # get standard environment, filters and checks
36 . ./common.rc
37 . ./common.filter
38 . ./common.quota
39
40 _cleanup()
41 {
42         cd /
43         umount $SCRATCH_MNT 2>/dev/null
44         rm -f $tmp.*
45 }
46 trap "_cleanup; exit \$status" 0 1 2 3 15
47
48
49 # real QA test starts here
50 _supported_fs xfs
51 _supported_os Linux IRIX
52
53
54 cp /dev/null $seq.full
55 chmod a+rwx $seq.full   # arbitrary users will write here
56
57 _require_scratch
58 _require_xfs_quota
59
60 bsoft=100
61 bhard=500
62 isoft=4
63 ihard=10
64
65
66 _filter_report()
67 {
68         tr -s '[:space:]' | \
69         perl -npe '
70                 s/^\#'$id' /[NAME] /g;
71                 s/^\#0 \d+ /[ROOT] 0 /g;
72                 s/6 days/7 days/g' |
73         perl -npe '
74                 $val = 0;
75                 if ($ENV{'LARGE_SCRATCH_DEV'}) {
76                         $val = $ENV{'NUM_SPACE_FILES'};
77                 }
78                 s/(^\[ROOT\] \S+ \S+ \S+ \S+ \[--------\] )(\S+)/$1@{[$2 - $val]}/g'
79 }
80
81 # The actual point at which limit enforcement takes place for the
82 # hard block limit is variable depending on filesystem blocksize,
83 # and iosize.  What we want to test is that the limit is enforced
84 # (ie. blksize less than limit but not unduly less - ~85% is kind)
85 # nowadays we actually get much closer to the limit before EDQUOT.
86 #
87 _filter_and_check_blks()
88 {
89         perl -npe '
90                 if (/^\#'$id'\s+(\d+)/ && '$enforce') {
91                         $maximum = '$bhard';
92                         $minimum = '$bhard' * 85/100;
93                         if (($1 < $minimum || $1 > $maximum) && '$noextsz') {
94                                 printf(" URK %d: %d is out of range! [%d,%d]\n",
95                                         '$id', $1, $minimum, $maximum);
96                         }
97                         s/^(\#'$id'\s+)(\d+)/\1 =OK=/g;
98                 }
99         ' | _filter_report
100 }
101
102 _exercise()
103 {
104         _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
105         cat $tmp.mkfs >>$seq.full
106
107         # keep the blocksize and data size for dd later
108         . $tmp.mkfs
109
110         _qmount
111
112         # Figure out whether we're doing large allocations
113         # (bail out if they're so large they stuff the test up)
114         _test_inode_flag extsz-inherit $SCRATCH_MNT
115         noextsz=$?
116         extsize=`_test_inode_extsz $SCRATCH_MNT`
117         [ $extsize -ge 512000 ] && \
118                 _notrun "Extent size hint is too large ($extsize bytes)"
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         xfs_quota -D $tmp.projects -P $tmp.projid -x \
128                 -c "repquota -birnN -$type" $SCRATCH_DEV |
129                 _filter_report | LC_COLLATE=POSIX sort -ru
130
131         echo
132         echo "*** report initial settings" | tee -a $seq.full
133         _file_as_id $SCRATCH_MNT/initme $id $type 1024 0
134         echo "ls -l $SCRATCH_MNT" >>$seq.full
135         ls -l $SCRATCH_MNT >>$seq.full
136         xfs_quota -D $tmp.projects -P $temp.projid -x \
137                 -c "limit -$type bsoft=${bsoft}k bhard=${bhard}k $id" \
138                 -c "limit -$type isoft=$isoft ihard=$ihard $id" \
139                 $SCRATCH_DEV
140         xfs_quota -D $tmp.projects -P $tmp.projid -x \
141                 -c "repquota -birnN -$type" $SCRATCH_DEV |
142                 _filter_report | LC_COLLATE=POSIX sort -ru
143
144         echo
145         echo "*** push past the soft inode limit" | tee -a $seq.full
146         _file_as_id $SCRATCH_MNT/softie1 $id $type 1024 0
147         _file_as_id $SCRATCH_MNT/softie2 $id $type 1024 0
148         _qmount
149         xfs_quota -D $tmp.projects -P $tmp.projid -x \
150                 -c "repquota -birnN -$type" $SCRATCH_DEV |
151                 _filter_report | LC_COLLATE=POSIX sort -ru
152
153         echo
154         echo "*** push past the soft block limit" | tee -a $seq.full
155         _file_as_id $SCRATCH_MNT/softie $id $type 1024 140
156         _qmount
157         xfs_quota -D $tmp.projects -P $tmp.projid -x \
158                 -c "repquota -birnN -$type" $SCRATCH_DEV |
159                 _filter_report | LC_COLLATE=POSIX sort -ru
160
161         echo
162         # Note: for quota accounting (not enforcement), EDQUOT is not expected
163         echo "*** push past the hard inode limit (expect EDQUOT)" | tee -a $seq.full
164         for i in 1 2 3 4 5 6 7 8 9 10 11 12
165         do
166                 _file_as_id $SCRATCH_MNT/hard$i $id $type 1024 0
167         done
168         _qmount
169         xfs_quota -D $tmp.projects -P $tmp.projid -x \
170                 -c "repquota -birnN -$type" $SCRATCH_DEV |
171                 _filter_report | LC_COLLATE=POSIX sort -ru
172
173         echo
174         # Note: for quota accounting (not enforcement), EDQUOT is not expected
175         echo "*** push past the hard block limit (expect EDQUOT)" | tee -a $seq.full
176         _file_as_id $SCRATCH_MNT/softie $id $type 1024 540
177         echo "ls -l $SCRATCH_MNT" >>$seq.full
178         ls -l $SCRATCH_MNT >>$seq.full
179         _qmount
180         xfs_quota -D $tmp.projects -P $tmp.projid -x \
181                 -c "repquota -birnN -$type" $SCRATCH_DEV |
182                 _filter_and_check_blks | LC_COLLATE=POSIX sort -ru
183
184         echo
185         echo "*** unmount"
186         umount $SCRATCH_MNT
187
188 }
189
190 cat >$tmp.projects <<EOF
191 1:$SCRATCH_MNT
192 EOF
193
194 cat >$tmp.projid <<EOF
195 root:0
196 scrach:1
197 EOF
198
199 projid_file="$tmp.projid"
200
201 echo "*** user"
202 if [ "$HOSTOS" == "IRIX" ]
203 then
204         _qmount_option "quota"
205 else
206         _qmount_option "uquota"
207 fi
208 _exercise
209
210 echo "*** group"
211 _qmount_option "gquota"
212 _exercise
213
214 echo "*** uqnoenforce"
215 if [ "$HOSTOS" == "IRIX" ]
216 then
217         _qmount_option "qnoenforce"
218 else
219         _qmount_option "uqnoenforce"
220 fi
221 _exercise
222
223 echo "*** gqnoenforce"
224 _qmount_option "gqnoenforce"
225 _exercise
226
227 echo "*** pquota"
228 _qmount_option "pquota"
229 _exercise
230
231 echo "*** pqnoenforce"
232 _qmount_option "pqnoenforce"
233 _exercise
234
235 # success, all done
236 status=0
237 exit