xfs/029: filter out "extended-header: cycle: 1" from output
[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 _scratch_mkfs >/dev/null 2>&1
42 _scratch_mount
43 bsize=$(_get_file_block_size $SCRATCH_MNT)
44 _scratch_unmount
45
46 bsoft=$(( 200 * $bsize ))
47 bhard=$(( 1000 * $bsize ))
48 isoft=4
49 ihard=10
50
51 _filter_report()
52 {
53         tr -s '[:space:]' | \
54         perl -npe '
55                 s/^\#'$id' /[NAME] /g;
56                 s/^\#0 \d+ /[ROOT] 0 /g;
57                 s/6 days/7 days/g' |
58         perl -npe '
59                 $val = 0;
60                 if ($ENV{'LARGE_SCRATCH_DEV'}) {
61                         $val = $ENV{'NUM_SPACE_FILES'};
62                 }
63                 s/(^\[ROOT\] \S+ \S+ \S+ \S+ \[--------\] )(\S+)/$1@{[$2 - $val]}/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         echo
132         echo "*** report no quota settings" | tee -a $seqres.full
133         xfs_quota -D $tmp.projects -P $tmp.projid -x \
134                 -c "repquota -birnN -$type" $SCRATCH_DEV |
135                 _filter_report | LC_COLLATE=POSIX sort -ru
136
137         echo
138         echo "*** report initial settings" | tee -a $seqres.full
139         _file_as_id $SCRATCH_MNT/initme $id $type 1024 0
140         echo "ls -l $SCRATCH_MNT" >>$seqres.full
141         ls -l $SCRATCH_MNT >>$seqres.full
142         xfs_quota -D $tmp.projects -P $temp.projid -x \
143                 -c "limit -$type bsoft=${bsoft} bhard=${bhard} $id" \
144                 -c "limit -$type isoft=$isoft ihard=$ihard $id" \
145                 $SCRATCH_DEV
146         xfs_quota -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 inode limit" | tee -a $seqres.full
152         _file_as_id $SCRATCH_MNT/softie1 $id $type 1024 0
153         _file_as_id $SCRATCH_MNT/softie2 $id $type 1024 0
154         _file_as_id $SCRATCH_MNT/softie3 $id $type 1024 0
155         _file_as_id $SCRATCH_MNT/softie4 $id $type 1024 0
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         echo "*** push past the soft block limit" | tee -a $seqres.full
163         _file_as_id $SCRATCH_MNT/softie $id $type $bsize 300
164         _qmount
165         xfs_quota -D $tmp.projects -P $tmp.projid -x \
166                 -c "repquota -birnN -$type" $SCRATCH_DEV |
167                 _filter_report | LC_COLLATE=POSIX sort -ru
168
169         echo
170         # Note: for quota accounting (not enforcement), EDQUOT is not expected
171         echo "*** push past the hard inode limit (expect EDQUOT)" | tee -a $seqres.full
172         for i in 1 2 3 4 5 6 7 8 9 10 11 12
173         do
174                 _file_as_id $SCRATCH_MNT/hard$i $id $type 1024 0
175         done
176         _qmount
177         xfs_quota -D $tmp.projects -P $tmp.projid -x \
178                 -c "repquota -birnN -$type" $SCRATCH_DEV |
179                 _filter_report | LC_COLLATE=POSIX sort -ru
180
181         echo
182         # Note: for quota accounting (not enforcement), EDQUOT is not expected
183         echo "*** push past the hard block limit (expect EDQUOT)" | tee -a $seqres.full
184         _file_as_id $SCRATCH_MNT/softie $id $type $bsize 1200
185         echo "ls -l $SCRATCH_MNT" >>$seqres.full
186         ls -l $SCRATCH_MNT >>$seqres.full
187         _qmount
188         xfs_quota -D $tmp.projects -P $tmp.projid -x \
189                 -c "repquota -birnN -$type" $SCRATCH_DEV |
190                 _filter_and_check_blks | LC_COLLATE=POSIX sort -ru
191
192         echo
193         echo "*** unmount"
194         _scratch_unmount
195
196 }
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"
210 _qmount_option "uquota"
211 _exercise u
212
213 echo "*** group"
214 _qmount_option "gquota"
215 _exercise g
216
217 echo "*** uqnoenforce"
218 _qmount_option "uqnoenforce"
219 _exercise uno
220
221 echo "*** gqnoenforce"
222 _qmount_option "gqnoenforce"
223 _exercise gno
224
225 echo "*** pquota"
226 _qmount_option "pquota"
227 _exercise p
228
229 echo "*** pqnoenforce"
230 _qmount_option "pqnoenforce"
231 _exercise pno
232
233 # success, all done
234 status=0
235 exit