fstests: convert remaining tests to SPDX license tags
[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         _qmount
147         xfs_quota -D $tmp.projects -P $tmp.projid -x \
148                 -c "repquota -birnN -$type" $SCRATCH_DEV |
149                 _filter_report | LC_COLLATE=POSIX sort -ru
150
151         echo
152         echo "*** push past the soft block limit" | tee -a $seqres.full
153         _file_as_id $SCRATCH_MNT/softie $id $type 1024 140
154         _qmount
155         xfs_quota -D $tmp.projects -P $tmp.projid -x \
156                 -c "repquota -birnN -$type" $SCRATCH_DEV |
157                 _filter_report | LC_COLLATE=POSIX sort -ru
158
159         echo
160         # Note: for quota accounting (not enforcement), EDQUOT is not expected
161         echo "*** push past the hard inode limit (expect EDQUOT)" | tee -a $seqres.full
162         for i in 1 2 3 4 5 6 7 8 9 10 11 12
163         do
164                 _file_as_id $SCRATCH_MNT/hard$i $id $type 1024 0
165         done
166         _qmount
167         xfs_quota -D $tmp.projects -P $tmp.projid -x \
168                 -c "repquota -birnN -$type" $SCRATCH_DEV |
169                 _filter_report | LC_COLLATE=POSIX sort -ru
170
171         echo
172         # Note: for quota accounting (not enforcement), EDQUOT is not expected
173         echo "*** push past the hard block limit (expect EDQUOT)" | tee -a $seqres.full
174         _file_as_id $SCRATCH_MNT/softie $id $type 1024 540
175         echo "ls -l $SCRATCH_MNT" >>$seqres.full
176         ls -l $SCRATCH_MNT >>$seqres.full
177         _qmount
178         xfs_quota -D $tmp.projects -P $tmp.projid -x \
179                 -c "repquota -birnN -$type" $SCRATCH_DEV |
180                 _filter_and_check_blks | LC_COLLATE=POSIX sort -ru
181
182         echo
183         echo "*** unmount"
184         _scratch_unmount
185
186 }
187
188 cat >$tmp.projects <<EOF
189 1:$SCRATCH_MNT
190 EOF
191
192 cat >$tmp.projid <<EOF
193 root:0
194 scrach:1
195 EOF
196
197 projid_file="$tmp.projid"
198
199 echo "*** user"
200 _qmount_option "uquota"
201 _exercise u
202
203 echo "*** group"
204 _qmount_option "gquota"
205 _exercise g
206
207 echo "*** uqnoenforce"
208 _qmount_option "uqnoenforce"
209 _exercise uno
210
211 echo "*** gqnoenforce"
212 _qmount_option "gqnoenforce"
213 _exercise gno
214
215 echo "*** pquota"
216 _qmount_option "pquota"
217 _exercise p
218
219 echo "*** pqnoenforce"
220 _qmount_option "pqnoenforce"
221 _exercise pno
222
223 # success, all done
224 status=0
225 exit