common/quota: move _qsetup() helper to common code
[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 # The actual point at which limit enforcement takes place for the
51 # hard block limit is variable depending on filesystem blocksize,
52 # and iosize.  What we want to test is that the limit is enforced
53 # (ie. blksize less than limit but not unduly less - ~85% is kind)
54 # nowadays we actually get much closer to the limit before EDQUOT.
55 #
56 _filter_and_check_blks()
57 {
58         perl -npe '
59                 if (/^\#'$id'\s+(\d+)/ && '$enforce') {
60                         $maximum = '$bhard';
61                         $minimum = '$bhard' * 85/100;
62                         $used = $1 * 1024;
63                         if (($used < $minimum || $used > $maximum) && '$noextsz') {
64                                 printf(" URK %d: %d is out of range! [%d,%d]\n",
65                                         '$id', $used, $minimum, $maximum);
66                         }
67                         s/^(\#'$id'\s+)(\d+)/\1 =OK=/g;
68                 }
69         ' | _filter_quota_report
70 }
71
72 _exercise()
73 {
74         _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
75         cat $tmp.mkfs >>$seqres.full
76
77         # keep the blocksize and data size for dd later
78         . $tmp.mkfs
79
80         _qmount
81
82         # Figure out whether we're doing large allocations
83         # (bail out if they're so large they stuff the test up)
84         _test_inode_flag extsz-inherit $SCRATCH_MNT
85         noextsz=$?
86         extsize=`_test_inode_extsz $SCRATCH_MNT`
87         [ $extsize -ge 512000 ] && \
88                 _notrun "Extent size hint is too large ($extsize bytes)"
89
90         _qsetup $1
91
92         echo "Using type=$type id=$id" >>$seqres.full
93
94         $XFS_QUOTA_PROG -x -c "warn -$type 65535 -d" $SCRATCH_DEV
95
96         echo
97         echo "*** report no quota settings" | tee -a $seqres.full
98         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
99                 -c "repquota -birnN -$type" $SCRATCH_DEV |
100                 _filter_quota_report | LC_COLLATE=POSIX sort -ru
101
102         echo
103         echo "*** report initial settings" | tee -a $seqres.full
104         _file_as_id $SCRATCH_MNT/initme $id $type 1024 0
105         echo "ls -l $SCRATCH_MNT" >>$seqres.full
106         ls -l $SCRATCH_MNT >>$seqres.full
107         $XFS_QUOTA_PROG -D $tmp.projects -P $temp.projid -x \
108                 -c "limit -$type bsoft=${bsoft} bhard=${bhard} $id" \
109                 -c "limit -$type isoft=$isoft ihard=$ihard $id" \
110                 $SCRATCH_DEV
111         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
112                 -c "repquota -birnN -$type" $SCRATCH_DEV |
113                 _filter_quota_report | LC_COLLATE=POSIX sort -ru
114
115         echo
116         echo "*** push past the soft inode limit" | tee -a $seqres.full
117         _file_as_id $SCRATCH_MNT/softie1 $id $type 1024 0
118         _file_as_id $SCRATCH_MNT/softie2 $id $type 1024 0
119         _file_as_id $SCRATCH_MNT/softie3 $id $type 1024 0
120         _file_as_id $SCRATCH_MNT/softie4 $id $type 1024 0
121         _qmount
122         $XFS_QUOTA_PROG -x -c "warn -i -$type 0 $id" $SCRATCH_DEV
123         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
124                 -c "repquota -birnN -$type" $SCRATCH_DEV |
125                 _filter_quota_report | LC_COLLATE=POSIX sort -ru
126
127         echo
128         echo "*** push past the soft block limit" | tee -a $seqres.full
129         _file_as_id $SCRATCH_MNT/softie $id $type $bsize 300
130         _qmount
131         $XFS_QUOTA_PROG -x -c "warn -i -$type 0 $id" \
132                 -c "warn -b -$type 0 $id" $SCRATCH_DEV
133         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
134                 -c "repquota -birnN -$type" $SCRATCH_DEV |
135                 _filter_quota_report | LC_COLLATE=POSIX sort -ru
136
137         echo
138         # Note: for quota accounting (not enforcement), EDQUOT is not expected
139         echo "*** push past the hard inode limit (expect EDQUOT)" | tee -a $seqres.full
140         for i in 1 2 3 4 5 6 7 8 9 10 11 12
141         do
142                 _file_as_id $SCRATCH_MNT/hard$i $id $type 1024 0
143         done
144         _qmount
145         $XFS_QUOTA_PROG -x  -c "warn -b -$type 0 $id" \
146                 -c "warn -i -$type 0 $id" $SCRATCH_DEV
147         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
148                 -c "repquota -birnN -$type" $SCRATCH_DEV |
149                 _filter_quota_report | LC_COLLATE=POSIX sort -ru
150
151         echo
152         # Note: for quota accounting (not enforcement), EDQUOT is not expected
153         echo "*** push past the hard block limit (expect EDQUOT)" | tee -a $seqres.full
154         _file_as_id $SCRATCH_MNT/softie $id $type $bsize 1200
155         echo "ls -l $SCRATCH_MNT" >>$seqres.full
156         ls -l $SCRATCH_MNT >>$seqres.full
157         _qmount
158         $XFS_QUOTA_PROG -x -c "warn -b -$type 0 $id" $SCRATCH_DEV
159         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
160                 -c "repquota -birnN -$type" $SCRATCH_DEV |
161                 _filter_and_check_blks | LC_COLLATE=POSIX sort -ru
162
163         echo
164         echo "*** unmount"
165         _scratch_unmount
166
167 }
168
169 cat >$tmp.projects <<EOF
170 1:$SCRATCH_MNT
171 EOF
172
173 cat >$tmp.projid <<EOF
174 root:0
175 scrach:1
176 EOF
177
178 projid_file="$tmp.projid"
179
180 echo "*** user"
181 _qmount_option "uquota"
182 _exercise u
183
184 echo "*** group"
185 _qmount_option "gquota"
186 _exercise g
187
188 echo "*** uqnoenforce"
189 _qmount_option "uqnoenforce"
190 _exercise uno
191
192 echo "*** gqnoenforce"
193 _qmount_option "gqnoenforce"
194 _exercise gno
195
196 echo "*** pquota"
197 _qmount_option "pquota"
198 _exercise p
199
200 echo "*** pqnoenforce"
201 _qmount_option "pqnoenforce"
202 _exercise pno
203
204 # success, all done
205 status=0
206 exit