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