15e0edf6671202a592f63428d374ac5c17f018e8
[xfstests-dev.git] / tests / xfs / 299
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. 299
6 #
7 # Exercises basic XFS quota functionality, with all 3 quotas together
8 #       uquota, gquota, pquota
9 #       uqnoenforce, gqnoenforce, pqnoenforce
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
15 here=`pwd`
16 tmp=/tmp/$$
17 status=1        # failure is the default!
18
19 # get standard environment, filters and checks
20 . ./common/rc
21 . ./common/filter
22 . ./common/quota
23
24 _cleanup()
25 {
26         cd /
27         _scratch_unmount 2>/dev/null
28         rm -f $tmp.*
29 }
30 trap "_cleanup; exit \$status" 0 1 2 3 15
31
32 # real QA test starts here
33 _supported_fs xfs
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 _require_xfs_mkfs_crc
41 _require_xfs_crc
42
43 _filter_report()
44 {
45         tr -s '[:space:]' | \
46         perl -npe '
47                 s/^\#'$id' /[NAME] /g;
48                 s/^\#0 \d+ /[ROOT] 0 /g;
49                 s/6 days/7 days/g' |
50         perl -npe '
51                 $val = 0;
52                 if ($ENV{'LARGE_SCRATCH_DEV'}) {
53                         $val = $ENV{'NUM_SPACE_FILES'};
54                 }
55                 s/(^\[ROOT\] \S+ \S+ \S+ \S+ \[--------\] )(\S+)/$1@{[$2 - $val]}/g' |
56         sed -e 's/ 65535 \[--------\]/ 00 \[--------\]/g' |
57         perl -npe '
58                 s|^(.*?) (\d+) (\d+) (\d+)|$1 @{[$2 * 1024 /'$bsize']} @{[$3 * 1024 /'$bsize']} @{[$4 * 1024 /'$bsize']}|'
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                         $used = $1 * 1024;
74                         if (($used < $minimum || $used > $maximum) && '$noextsz') {
75                                 printf(" URK %d: %d is out of range! [%d,%d]\n",
76                                         '$id', $used, $minimum, $maximum);
77                         }
78                         s/^(\#'$id'\s+)(\d+)/\1 =OK=/g;
79                 }
80         ' | _filter_report
81 }
82
83 _qsetup()
84 {
85         opt=$1
86         enforce=0
87         if [ $opt = "u" -o $opt = "uno" ]; then
88                 type=u
89                 eval `_choose_uid`
90         elif [ $opt = "g" -o $opt = "gno" ]; then
91                 type=g
92                 eval `_choose_gid`
93         elif [ $opt = "p" -o $opt = "pno" ]; then
94                 type=p
95                 eval `_choose_prid`
96         fi
97         [ $opt = "u" -o $opt = "g" -o $opt = "p" ] && enforce=1
98
99         echo "Using type=$type id=$id" >> $seqres.full
100 }
101
102 _exercise()
103 {
104
105         # Figure out whether we're doing large allocations
106         # (bail out if they're so large they stuff the test up)
107         _test_inode_flag extsz-inherit $SCRATCH_MNT
108         noextsz=$?
109         extsize=`_test_inode_extsz $SCRATCH_MNT`
110         [ $extsize -ge 512000 ] && \
111                 _notrun "Extent size hint is too large ($extsize bytes)"
112
113         _qsetup $1
114
115         echo "Using type=$type id=$id" >>$seqres.full
116
117         $XFS_QUOTA_PROG -x -c "warn -$type 65535 -d" $SCRATCH_DEV
118
119         echo
120         echo "*** report no quota settings" | tee -a $seqres.full
121         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
122                 -c "repquota -birnN -$type" $SCRATCH_DEV |
123                 _filter_report | LC_COLLATE=POSIX sort -ru
124
125         echo
126         echo "*** report initial settings" | tee -a $seqres.full
127         _file_as_id $SCRATCH_MNT/initme $id $type 1024 0
128         echo "ls -l $SCRATCH_MNT" >>$seqres.full
129         ls -l $SCRATCH_MNT >>$seqres.full
130         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
131                 -c "limit -$type bsoft=${bsoft} bhard=${bhard} $id" \
132                 -c "limit -$type isoft=$isoft ihard=$ihard $id" \
133                 $SCRATCH_DEV
134         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
135                 -c "repquota -birnN -$type" $SCRATCH_DEV |
136                 _filter_report | LC_COLLATE=POSIX sort -ru
137
138         echo
139         echo "*** push past the soft inode limit" | tee -a $seqres.full
140         _file_as_id $SCRATCH_MNT/softie1 $id $type 1024 0
141         _file_as_id $SCRATCH_MNT/softie2 $id $type 1024 0
142         _file_as_id $SCRATCH_MNT/softie3 $id $type 1024 0
143         _file_as_id $SCRATCH_MNT/softie4 $id $type 1024 0
144         _qmount
145         $XFS_QUOTA_PROG -x -c "warn -i -$type 0 $id" $SCRATCH_DEV
146         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
147                 -c "repquota -birnN -$type" $SCRATCH_DEV |
148                 _filter_report | LC_COLLATE=POSIX sort -ru
149
150         echo
151         echo "*** push past the soft block limit" | tee -a $seqres.full
152         _file_as_id $SCRATCH_MNT/softie $id $type $bsize 200
153         _qmount
154         $XFS_QUOTA_PROG -x -c "warn -i -$type 0 $id" \
155                 -c "warn -b -$type 0 $id" $SCRATCH_DEV
156         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
157                 -c "repquota -birnN -$type" $SCRATCH_DEV |
158                 _filter_report | LC_COLLATE=POSIX sort -ru
159
160         echo
161         # Note: for quota accounting (not enforcement), EDQUOT is not expected
162         echo "*** push past the hard inode limit (expect EDQUOT)" | tee -a $seqres.full
163         for i in 1 2 3 4 5 6 7 8 9 10 11 12
164         do
165                 _file_as_id $SCRATCH_MNT/hard$i $id $type 1024 0
166         done
167         _qmount
168         $XFS_QUOTA_PROG -x  -c "warn -b -$type 0 $id" \
169                 -c "warn -i -$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 block limit (expect EDQUOT)" | tee -a $seqres.full
177         _file_as_id $SCRATCH_MNT/softie $id $type $bsize 600
178         echo "ls -l $SCRATCH_MNT" >>$seqres.full
179         ls -l $SCRATCH_MNT >>$seqres.full
180         _qmount
181         $XFS_QUOTA_PROG -x -c "warn -b -$type 0 $id" $SCRATCH_DEV
182         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
183                 -c "repquota -birnN -$type" $SCRATCH_DEV |
184                 _filter_and_check_blks | LC_COLLATE=POSIX sort -ru
185
186         echo
187
188         # clean up our files so we don't pollute the next run
189         rm -f $SCRATCH_MNT/*
190
191 }
192
193 _scratch_mkfs_xfs -m crc=1 2>/dev/null | _filter_mkfs 2>$tmp.mkfs
194 cat $tmp.mkfs >>$seqres.full
195 # keep the blocksize and data size for dd later
196 . $tmp.mkfs
197
198 cat >$tmp.projects <<EOF
199 1:$SCRATCH_MNT
200 EOF
201
202 cat >$tmp.projid <<EOF
203 root:0
204 scrach:1
205 EOF
206
207 projid_file="$tmp.projid"
208
209 echo "*** user, group, and project"
210 _qmount_option "uquota,gquota,pquota"
211 _qmount
212
213 bsize=$(_get_file_block_size $SCRATCH_MNT)
214
215 bsoft=$(( 100 * $bsize ))
216 bhard=$(( 500 * $bsize ))
217 isoft=4
218 ihard=10
219
220 # non-root users need to be able to write to this filesystem
221 chmod 777 $SCRATCH_MNT
222
223 _exercise p
224 _exercise g
225 _exercise u
226
227 echo "*** unmount"
228 _scratch_unmount
229
230
231 _scratch_mkfs_xfs -m crc=1 2>/dev/null | _filter_mkfs 2>$tmp.mkfs
232 cat $tmp.mkfs >>$seqres.full
233 # keep the blocksize and data size for dd later
234 . $tmp.mkfs
235
236 echo "*** uqnoenforce, gqnoenforce, and pqnoenforce"
237 _qmount_option "uqnoenforce,gqnoenforce,pqnoenforce"
238 _qmount
239 _exercise uno
240 _exercise gno
241 _exercise pno
242
243 echo "*** unmount"
244 _scratch_unmount
245
246 # success, all done
247 status=0
248 exit