xfstests: cleanup duplicates in all tests
[xfstests-dev.git] / tests / xfs / 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
26 seq=`basename $0`
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=1        # failure is the default!
33
34 # get standard environment, filters and checks
35 . ./common/rc
36 . ./common/filter
37 . ./common/quota
38
39 _cleanup()
40 {
41         cd /
42         umount $SCRATCH_MNT 2>/dev/null
43         rm -f $tmp.*
44 }
45 trap "_cleanup; exit \$status" 0 1 2 3 15
46
47 # real QA test starts here
48 _supported_fs xfs
49 _supported_os Linux IRIX
50
51 cp /dev/null $seqres.full
52 chmod a+rwx $seqres.full        # arbitrary users will write here
53
54 _require_scratch
55 _require_xfs_quota
56
57 bsoft=100
58 bhard=500
59 isoft=4
60 ihard=10
61
62 _filter_report()
63 {
64         tr -s '[:space:]' | \
65         perl -npe '
66                 s/^\#'$id' /[NAME] /g;
67                 s/^\#0 \d+ /[ROOT] 0 /g;
68                 s/6 days/7 days/g' |
69         perl -npe '
70                 $val = 0;
71                 if ($ENV{'LARGE_SCRATCH_DEV'}) {
72                         $val = $ENV{'NUM_SPACE_FILES'};
73                 }
74                 s/(^\[ROOT\] \S+ \S+ \S+ \S+ \[--------\] )(\S+)/$1@{[$2 - $val]}/g'
75 }
76
77 # The actual point at which limit enforcement takes place for the
78 # hard block limit is variable depending on filesystem blocksize,
79 # and iosize.  What we want to test is that the limit is enforced
80 # (ie. blksize less than limit but not unduly less - ~85% is kind)
81 # nowadays we actually get much closer to the limit before EDQUOT.
82 #
83 _filter_and_check_blks()
84 {
85         perl -npe '
86                 if (/^\#'$id'\s+(\d+)/ && '$enforce') {
87                         $maximum = '$bhard';
88                         $minimum = '$bhard' * 85/100;
89                         if (($1 < $minimum || $1 > $maximum) && '$noextsz') {
90                                 printf(" URK %d: %d is out of range! [%d,%d]\n",
91                                         '$id', $1, $minimum, $maximum);
92                         }
93                         s/^(\#'$id'\s+)(\d+)/\1 =OK=/g;
94                 }
95         ' | _filter_report
96 }
97
98 _qsetup()
99 {
100         opt=$1
101         enforce=0
102         if [ $opt = "u" -o $opt = "uno" ]; then
103                 type=u
104                 eval `_choose_uid`
105         elif [ $opt = "g" -o $opt = "gno" ]; then
106                 type=g
107                 eval `_choose_gid`
108         elif [ $opt = "p" -o $opt = "pno" ]; then
109                 type=p
110                 eval `_choose_prid`
111         fi
112         [ $opt = "u" -o $opt = "g" -o $opt = "p" ] && enforce=1
113
114         echo "Using type=$type id=$id" >> $seqres.full
115 }
116
117 _exercise()
118 {
119         _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
120         cat $tmp.mkfs >>$seqres.full
121
122         # keep the blocksize and data size for dd later
123         . $tmp.mkfs
124
125         _qmount
126
127         # Figure out whether we're doing large allocations
128         # (bail out if they're so large they stuff the test up)
129         _test_inode_flag extsz-inherit $SCRATCH_MNT
130         noextsz=$?
131         extsize=`_test_inode_extsz $SCRATCH_MNT`
132         [ $extsize -ge 512000 ] && \
133                 _notrun "Extent size hint is too large ($extsize bytes)"
134
135         _qsetup $1
136
137         echo "Using type=$type id=$id" >>$seqres.full
138
139         echo
140         echo "*** report no quota settings" | tee -a $seqres.full
141         xfs_quota -D $tmp.projects -P $tmp.projid -x \
142                 -c "repquota -birnN -$type" $SCRATCH_DEV |
143                 _filter_report | LC_COLLATE=POSIX sort -ru
144
145         echo
146         echo "*** report initial settings" | tee -a $seqres.full
147         _file_as_id $SCRATCH_MNT/initme $id $type 1024 0
148         echo "ls -l $SCRATCH_MNT" >>$seqres.full
149         ls -l $SCRATCH_MNT >>$seqres.full
150         xfs_quota -D $tmp.projects -P $temp.projid -x \
151                 -c "limit -$type bsoft=${bsoft}k bhard=${bhard}k $id" \
152                 -c "limit -$type isoft=$isoft ihard=$ihard $id" \
153                 $SCRATCH_DEV
154         xfs_quota -D $tmp.projects -P $tmp.projid -x \
155                 -c "repquota -birnN -$type" $SCRATCH_DEV |
156                 _filter_report | LC_COLLATE=POSIX sort -ru
157
158         echo
159         echo "*** push past the soft inode limit" | tee -a $seqres.full
160         _file_as_id $SCRATCH_MNT/softie1 $id $type 1024 0
161         _file_as_id $SCRATCH_MNT/softie2 $id $type 1024 0
162         _qmount
163         xfs_quota -D $tmp.projects -P $tmp.projid -x \
164                 -c "repquota -birnN -$type" $SCRATCH_DEV |
165                 _filter_report | LC_COLLATE=POSIX sort -ru
166
167         echo
168         echo "*** push past the soft block limit" | tee -a $seqres.full
169         _file_as_id $SCRATCH_MNT/softie $id $type 1024 140
170         _qmount
171         xfs_quota -D $tmp.projects -P $tmp.projid -x \
172                 -c "repquota -birnN -$type" $SCRATCH_DEV |
173                 _filter_report | LC_COLLATE=POSIX sort -ru
174
175         echo
176         # Note: for quota accounting (not enforcement), EDQUOT is not expected
177         echo "*** push past the hard inode limit (expect EDQUOT)" | tee -a $seqres.full
178         for i in 1 2 3 4 5 6 7 8 9 10 11 12
179         do
180                 _file_as_id $SCRATCH_MNT/hard$i $id $type 1024 0
181         done
182         _qmount
183         xfs_quota -D $tmp.projects -P $tmp.projid -x \
184                 -c "repquota -birnN -$type" $SCRATCH_DEV |
185                 _filter_report | LC_COLLATE=POSIX sort -ru
186
187         echo
188         # Note: for quota accounting (not enforcement), EDQUOT is not expected
189         echo "*** push past the hard block limit (expect EDQUOT)" | tee -a $seqres.full
190         _file_as_id $SCRATCH_MNT/softie $id $type 1024 540
191         echo "ls -l $SCRATCH_MNT" >>$seqres.full
192         ls -l $SCRATCH_MNT >>$seqres.full
193         _qmount
194         xfs_quota -D $tmp.projects -P $tmp.projid -x \
195                 -c "repquota -birnN -$type" $SCRATCH_DEV |
196                 _filter_and_check_blks | LC_COLLATE=POSIX sort -ru
197
198         echo
199         echo "*** unmount"
200         umount $SCRATCH_MNT
201
202 }
203
204 cat >$tmp.projects <<EOF
205 1:$SCRATCH_MNT
206 EOF
207
208 cat >$tmp.projid <<EOF
209 root:0
210 scrach:1
211 EOF
212
213 projid_file="$tmp.projid"
214
215 echo "*** user"
216 if [ "$HOSTOS" == "IRIX" ]
217 then
218         _qmount_option "quota"
219 else
220         _qmount_option "uquota"
221 fi
222 _exercise u
223
224 echo "*** group"
225 _qmount_option "gquota"
226 _exercise g
227
228 echo "*** uqnoenforce"
229 if [ "$HOSTOS" == "IRIX" ]
230 then
231         _qmount_option "qnoenforce"
232 else
233         _qmount_option "uqnoenforce"
234 fi
235 _exercise uno
236
237 echo "*** gqnoenforce"
238 _qmount_option "gqnoenforce"
239 _exercise gno
240
241 echo "*** pquota"
242 _qmount_option "pquota"
243 _exercise p
244
245 echo "*** pqnoenforce"
246 _qmount_option "pqnoenforce"
247 _exercise pno
248
249 # success, all done
250 status=0
251 exit