xfs/050: Fix "Push past soft inode limit" case
[xfstests-dev.git] / tests / xfs / 050
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 050
6 #
7 # Exercises basic XFS quota functionality
8 #       uquota, gquota, uqnoenforce, gqnoenforce, pquota, pqnoenforce
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17
18 # get standard environment, filters and checks
19 . ./common/rc
20 . ./common/filter
21 . ./common/quota
22
23 _cleanup()
24 {
25         cd /
26         _scratch_unmount 2>/dev/null
27         rm -f $tmp.*
28 }
29 trap "_cleanup; exit \$status" 0 1 2 3 15
30
31 # real QA test starts here
32 _supported_fs xfs
33 _supported_os Linux
34
35 cp /dev/null $seqres.full
36 chmod a+rwx $seqres.full        # arbitrary users will write here
37
38 _require_scratch
39 _require_xfs_quota
40
41 bsoft=100
42 bhard=500
43 isoft=4
44 ihard=10
45
46 _filter_report()
47 {
48         tr -s '[:space:]' | \
49         perl -npe '
50                 s/^\#'$id' /[NAME] /g;
51                 s/^\#0 \d+ /[ROOT] 0 /g;
52                 s/6 days/7 days/g' |
53         perl -npe '
54                 $val = 0;
55                 if ($ENV{'LARGE_SCRATCH_DEV'}) {
56                         $val = $ENV{'NUM_SPACE_FILES'};
57                 }
58                 s/(^\[ROOT\] \S+ \S+ \S+ \S+ \[--------\] )(\S+)/$1@{[$2 - $val]}/g'
59 }
60
61 # The actual point at which limit enforcement takes place for the
62 # hard block limit is variable depending on filesystem blocksize,
63 # and iosize.  What we want to test is that the limit is enforced
64 # (ie. blksize less than limit but not unduly less - ~85% is kind)
65 # nowadays we actually get much closer to the limit before EDQUOT.
66 #
67 _filter_and_check_blks()
68 {
69         perl -npe '
70                 if (/^\#'$id'\s+(\d+)/ && '$enforce') {
71                         $maximum = '$bhard';
72                         $minimum = '$bhard' * 85/100;
73                         if (($1 < $minimum || $1 > $maximum) && '$noextsz') {
74                                 printf(" URK %d: %d is out of range! [%d,%d]\n",
75                                         '$id', $1, $minimum, $maximum);
76                         }
77                         s/^(\#'$id'\s+)(\d+)/\1 =OK=/g;
78                 }
79         ' | _filter_report
80 }
81
82 _qsetup()
83 {
84         opt=$1
85         enforce=0
86         if [ $opt = "u" -o $opt = "uno" ]; then
87                 type=u
88                 eval `_choose_uid`
89         elif [ $opt = "g" -o $opt = "gno" ]; then
90                 type=g
91                 eval `_choose_gid`
92         elif [ $opt = "p" -o $opt = "pno" ]; then
93                 type=p
94                 eval `_choose_prid`
95         fi
96         [ $opt = "u" -o $opt = "g" -o $opt = "p" ] && enforce=1
97
98         echo "Using type=$type id=$id" >> $seqres.full
99 }
100
101 _exercise()
102 {
103         _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
104         cat $tmp.mkfs >>$seqres.full
105
106         # keep the blocksize and data size for dd later
107         . $tmp.mkfs
108
109         _qmount
110
111         # Figure out whether we're doing large allocations
112         # (bail out if they're so large they stuff the test up)
113         _test_inode_flag extsz-inherit $SCRATCH_MNT
114         noextsz=$?
115         extsize=`_test_inode_extsz $SCRATCH_MNT`
116         [ $extsize -ge 512000 ] && \
117                 _notrun "Extent size hint is too large ($extsize bytes)"
118
119         _qsetup $1
120
121         echo "Using type=$type id=$id" >>$seqres.full
122
123         echo
124         echo "*** report no quota settings" | tee -a $seqres.full
125         xfs_quota -D $tmp.projects -P $tmp.projid -x \
126                 -c "repquota -birnN -$type" $SCRATCH_DEV |
127                 _filter_report | LC_COLLATE=POSIX sort -ru
128
129         echo
130         echo "*** report initial settings" | tee -a $seqres.full
131         _file_as_id $SCRATCH_MNT/initme $id $type 1024 0
132         echo "ls -l $SCRATCH_MNT" >>$seqres.full
133         ls -l $SCRATCH_MNT >>$seqres.full
134         xfs_quota -D $tmp.projects -P $temp.projid -x \
135                 -c "limit -$type bsoft=${bsoft}k bhard=${bhard}k $id" \
136                 -c "limit -$type isoft=$isoft ihard=$ihard $id" \
137                 $SCRATCH_DEV
138         xfs_quota -D $tmp.projects -P $tmp.projid -x \
139                 -c "repquota -birnN -$type" $SCRATCH_DEV |
140                 _filter_report | LC_COLLATE=POSIX sort -ru
141
142         echo
143         echo "*** push past the soft inode limit" | tee -a $seqres.full
144         _file_as_id $SCRATCH_MNT/softie1 $id $type 1024 0
145         _file_as_id $SCRATCH_MNT/softie2 $id $type 1024 0
146         _file_as_id $SCRATCH_MNT/softie3 $id $type 1024 0
147         _file_as_id $SCRATCH_MNT/softie4 $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 $seqres.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 $seqres.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 $seqres.full
176         _file_as_id $SCRATCH_MNT/softie $id $type 1024 540
177         echo "ls -l $SCRATCH_MNT" >>$seqres.full
178         ls -l $SCRATCH_MNT >>$seqres.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         _scratch_unmount
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 _qmount_option "uquota"
203 _exercise u
204
205 echo "*** group"
206 _qmount_option "gquota"
207 _exercise g
208
209 echo "*** uqnoenforce"
210 _qmount_option "uqnoenforce"
211 _exercise uno
212
213 echo "*** gqnoenforce"
214 _qmount_option "gqnoenforce"
215 _exercise gno
216
217 echo "*** pquota"
218 _qmount_option "pquota"
219 _exercise p
220
221 echo "*** pqnoenforce"
222 _qmount_option "pqnoenforce"
223 _exercise pno
224
225 # success, all done
226 status=0
227 exit