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