xfs/029: filter out "extended-header: cycle: 1" from output
[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 _supported_os Linux
35
36 cp /dev/null $seqres.full
37 chmod a+rwx $seqres.full        # arbitrary users will write here
38
39 _require_scratch
40 _require_xfs_quota
41 _require_xfs_mkfs_crc
42 _require_xfs_crc
43
44 _filter_report()
45 {
46         tr -s '[:space:]' | \
47         perl -npe '
48                 s/^\#'$id' /[NAME] /g;
49                 s/^\#0 \d+ /[ROOT] 0 /g;
50                 s/6 days/7 days/g' |
51         perl -npe '
52                 $val = 0;
53                 if ($ENV{'LARGE_SCRATCH_DEV'}) {
54                         $val = $ENV{'NUM_SPACE_FILES'};
55                 }
56                 s/(^\[ROOT\] \S+ \S+ \S+ \S+ \[--------\] )(\S+)/$1@{[$2 - $val]}/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         echo
118         echo "*** report no quota settings" | tee -a $seqres.full
119         xfs_quota -D $tmp.projects -P $tmp.projid -x \
120                 -c "repquota -birnN -$type" $SCRATCH_DEV |
121                 _filter_report | LC_COLLATE=POSIX sort -ru
122
123         echo
124         echo "*** report initial settings" | tee -a $seqres.full
125         _file_as_id $SCRATCH_MNT/initme $id $type 1024 0
126         echo "ls -l $SCRATCH_MNT" >>$seqres.full
127         ls -l $SCRATCH_MNT >>$seqres.full
128         xfs_quota -D $tmp.projects -P $tmp.projid -x \
129                 -c "limit -$type bsoft=${bsoft} bhard=${bhard} $id" \
130                 -c "limit -$type isoft=$isoft ihard=$ihard $id" \
131                 $SCRATCH_DEV
132         xfs_quota -D $tmp.projects -P $tmp.projid -x \
133                 -c "repquota -birnN -$type" $SCRATCH_DEV |
134                 _filter_report | LC_COLLATE=POSIX sort -ru
135
136         echo
137         echo "*** push past the soft inode limit" | tee -a $seqres.full
138         _file_as_id $SCRATCH_MNT/softie1 $id $type 1024 0
139         _file_as_id $SCRATCH_MNT/softie2 $id $type 1024 0
140         _file_as_id $SCRATCH_MNT/softie3 $id $type 1024 0
141         _file_as_id $SCRATCH_MNT/softie4 $id $type 1024 0
142         _qmount
143         xfs_quota -D $tmp.projects -P $tmp.projid -x \
144                 -c "repquota -birnN -$type" $SCRATCH_DEV |
145                 _filter_report | LC_COLLATE=POSIX sort -ru
146
147         echo
148         echo "*** push past the soft block limit" | tee -a $seqres.full
149         _file_as_id $SCRATCH_MNT/softie $id $type $bsize 200
150         _qmount
151         xfs_quota -D $tmp.projects -P $tmp.projid -x \
152                 -c "repquota -birnN -$type" $SCRATCH_DEV |
153                 _filter_report | LC_COLLATE=POSIX sort -ru
154
155         echo
156         # Note: for quota accounting (not enforcement), EDQUOT is not expected
157         echo "*** push past the hard inode limit (expect EDQUOT)" | tee -a $seqres.full
158         for i in 1 2 3 4 5 6 7 8 9 10 11 12
159         do
160                 _file_as_id $SCRATCH_MNT/hard$i $id $type 1024 0
161         done
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         # Note: for quota accounting (not enforcement), EDQUOT is not expected
169         echo "*** push past the hard block limit (expect EDQUOT)" | tee -a $seqres.full
170         _file_as_id $SCRATCH_MNT/softie $id $type $bsize 600
171         echo "ls -l $SCRATCH_MNT" >>$seqres.full
172         ls -l $SCRATCH_MNT >>$seqres.full
173         _qmount
174         xfs_quota -D $tmp.projects -P $tmp.projid -x \
175                 -c "repquota -birnN -$type" $SCRATCH_DEV |
176                 _filter_and_check_blks | LC_COLLATE=POSIX sort -ru
177
178         echo
179
180         # clean up our files so we don't pollute the next run
181         rm -f $SCRATCH_MNT/*
182
183 }
184
185 _scratch_mkfs_xfs -m crc=1 2>/dev/null | _filter_mkfs 2>$tmp.mkfs
186 cat $tmp.mkfs >>$seqres.full
187 # keep the blocksize and data size for dd later
188 . $tmp.mkfs
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, group, and project"
202 _qmount_option "uquota,gquota,pquota"
203 _qmount
204
205 bsize=$(_get_file_block_size $SCRATCH_MNT)
206
207 bsoft=$(( 100 * $bsize ))
208 bhard=$(( 500 * $bsize ))
209 isoft=4
210 ihard=10
211
212 # non-root users need to be able to write to this filesystem
213 chmod 777 $SCRATCH_MNT
214
215 _exercise p
216 _exercise g
217 _exercise u
218
219 echo "*** unmount"
220 _scratch_unmount
221
222
223 _scratch_mkfs_xfs -m crc=1 2>/dev/null | _filter_mkfs 2>$tmp.mkfs
224 cat $tmp.mkfs >>$seqres.full
225 # keep the blocksize and data size for dd later
226 . $tmp.mkfs
227
228 echo "*** uqnoenforce, gqnoenforce, and pqnoenforce"
229 _qmount_option "uqnoenforce,gqnoenforce,pqnoenforce"
230 _qmount
231 _exercise uno
232 _exercise gno
233 _exercise pno
234
235 echo "*** unmount"
236 _scratch_unmount
237
238 # success, all done
239 status=0
240 exit