fstests: move test group info to test files
[xfstests-dev.git] / tests / xfs / 153
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0+
3 #
4 # Copyright (c) 2021 Christian Brauner <christian.brauner@ubuntu.com>
5 # All Rights Reserved.
6 #
7 # FS QA Test No. 153
8 #
9 # Exercises basic XFS quota functionality
10 #       uquota, gquota, uqnoenforce, gqnoenforce
11 #
12 . ./common/preamble
13 _begin_fstest auto quick quota idmapped
14
15 # Import common functions.
16 . ./common/filter
17 . ./common/quota
18
19 # Override the default cleanup function.
20 _cleanup()
21 {
22         cd /
23         _scratch_unmount 2>/dev/null
24         rm -f $tmp.*
25 }
26
27 # real QA test starts here
28 _supported_fs xfs
29
30 cp /dev/null $seqres.full
31 chmod a+rwx $seqres.full        # arbitrary users will write here
32
33 _require_scratch
34 _require_xfs_quota
35 _require_user fsgqa
36 _require_idmapped_mounts
37 _require_test_program "idmapped-mounts/mount-idmapped"
38
39 _scratch_mkfs >/dev/null 2>&1
40 _scratch_mount
41 bsize=$(_get_file_block_size $SCRATCH_MNT)
42 _scratch_unmount
43
44 bsoft=$(( 200 * $bsize ))
45 bhard=$(( 1000 * $bsize ))
46 isoft=4
47 ihard=10
48
49 # The actual point at which limit enforcement takes place for the
50 # hard block limit is variable depending on filesystem blocksize,
51 # and iosize.  What we want to test is that the limit is enforced
52 # (ie. blksize less than limit but not unduly less - ~85% is kind)
53 # nowadays we actually get much closer to the limit before EDQUOT.
54 #
55 _filter_and_check_blks()
56 {
57         perl -npe '
58                 if (/^\#'$id'\s+(\d+)/ && '$enforce') {
59                         $maximum = '$bhard';
60                         $minimum = '$bhard' * 85/100;
61                         $used = $1 * 1024;
62                         if (($used < $minimum || $used > $maximum) && '$noextsz') {
63                                 printf(" URK %d: %d is out of range! [%d,%d]\n",
64                                         '$id', $used, $minimum, $maximum);
65                         }
66                         s/^(\#'$id'\s+)(\d+)/\1 =OK=/g;
67                 }
68         ' | _filter_quota_report
69 }
70
71 run_tests()
72 {
73         _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
74         cat $tmp.mkfs >>$seqres.full
75
76         # keep the blocksize and data size for dd later
77         . $tmp.mkfs
78
79         _qmount
80
81         # Figure out whether we're doing large allocations
82         # (bail out if they're so large they stuff the test up)
83         _test_inode_flag extsz-inherit $SCRATCH_MNT
84         noextsz=$?
85         extsize=`_test_inode_extsz $SCRATCH_MNT`
86         [ $extsize -ge 512000 ] && \
87                 _notrun "Extent size hint is too large ($extsize bytes)"
88
89         _qsetup $1
90
91         echo "Using type=$type id=$id" >>$seqres.full
92
93         $XFS_QUOTA_PROG -x -c "warn -$type 65535 -d" $SCRATCH_DEV
94
95         echo
96         echo "*** report no quota settings" | tee -a $seqres.full
97         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
98                 -c "repquota -birnN -$type" $SCRATCH_DEV |
99                 _filter_quota_report | LC_COLLATE=POSIX sort -ru
100
101         echo
102         echo "*** report initial settings" | tee -a $seqres.full
103         _scratch_mount_idmapped $type $id
104         _file_as_id $SCRATCH_MNT/initme 0 $type 1024 0
105         _scratch_umount_idmapped
106         echo "ls -l $SCRATCH_MNT" >>$seqres.full
107         ls -l $SCRATCH_MNT >>$seqres.full
108         $XFS_QUOTA_PROG -D $tmp.projects -P $temp.projid -x \
109                 -c "limit -$type bsoft=${bsoft} bhard=${bhard} $id" \
110                 -c "limit -$type isoft=$isoft ihard=$ihard $id" \
111                 $SCRATCH_DEV
112         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
113                 -c "repquota -birnN -$type" $SCRATCH_DEV |
114                 _filter_quota_report | LC_COLLATE=POSIX sort -ru
115
116         echo
117         echo "*** push past the soft inode limit" | tee -a $seqres.full
118         _scratch_mount_idmapped $type $id
119         _file_as_id $SCRATCH_MNT/softie1 0 $type 1024 0
120         _file_as_id $SCRATCH_MNT/softie2 0 $type 1024 0
121         _file_as_id $SCRATCH_MNT/softie3 0 $type 1024 0
122         _file_as_id $SCRATCH_MNT/softie4 0 $type 1024 0
123         _scratch_umount_idmapped
124         _qmount
125         $XFS_QUOTA_PROG -x -c "warn -i -$type 0 $id" $SCRATCH_DEV
126         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
127                 -c "repquota -birnN -$type" $SCRATCH_DEV |
128                 _filter_quota_report | LC_COLLATE=POSIX sort -ru
129
130         echo
131         echo "*** push past the soft block limit" | tee -a $seqres.full
132         _scratch_mount_idmapped $type $id
133         _file_as_id $SCRATCH_MNT/softie 0 $type $bsize 300
134         _scratch_umount_idmapped
135         _qmount
136         $XFS_QUOTA_PROG -x -c "warn -i -$type 0 $id" \
137                 -c "warn -b -$type 0 $id" $SCRATCH_DEV
138         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
139                 -c "repquota -birnN -$type" $SCRATCH_DEV |
140                 _filter_quota_report | LC_COLLATE=POSIX sort -ru
141
142         echo
143         # Note: for quota accounting (not enforcement), EDQUOT is not expected
144         echo "*** push past the hard inode limit (expect EDQUOT)" | tee -a $seqres.full
145         for i in 1 2 3 4 5 6 7 8 9 10 11 12
146         do
147                 _scratch_mount_idmapped $type $id
148                 _file_as_id $SCRATCH_MNT/hard$i 0 $type 1024 0
149                 _scratch_umount_idmapped
150         done
151         _qmount
152         $XFS_QUOTA_PROG -x  -c "warn -b -$type 0 $id" \
153                 -c "warn -i -$type 0 $id" $SCRATCH_DEV
154         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
155                 -c "repquota -birnN -$type" $SCRATCH_DEV |
156                 _filter_quota_report | LC_COLLATE=POSIX sort -ru
157
158         echo
159         # Note: for quota accounting (not enforcement), EDQUOT is not expected
160         echo "*** push past the hard block limit (expect EDQUOT)" | tee -a $seqres.full
161         _scratch_mount_idmapped $type $id
162         _file_as_id $SCRATCH_MNT/softie 0 $type $bsize 1200
163         _scratch_umount_idmapped
164         echo "ls -l $SCRATCH_MNT" >>$seqres.full
165         ls -l $SCRATCH_MNT >>$seqres.full
166         _qmount
167         $XFS_QUOTA_PROG -x -c "warn -b -$type 0 $id" $SCRATCH_DEV
168         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
169                 -c "repquota -birnN -$type" $SCRATCH_DEV |
170                 _filter_and_check_blks | LC_COLLATE=POSIX sort -ru
171
172         echo
173         echo "*** unmount"
174         _scratch_unmount
175
176 }
177
178 cat >$tmp.projects <<EOF
179 1:$SCRATCH_MNT
180 EOF
181
182 cat >$tmp.projid <<EOF
183 root:0
184 scrach:1
185 EOF
186
187 projid_file="$tmp.projid"
188
189 echo "*** user"
190 _qmount_option "uquota"
191 run_tests u
192
193 echo "*** group"
194 _qmount_option "gquota"
195 run_tests g
196
197 echo "*** uqnoenforce"
198 _qmount_option "uqnoenforce"
199 run_tests uno
200
201 echo "*** gqnoenforce"
202 _qmount_option "gqnoenforce"
203 run_tests gno
204
205 # success, all done
206 status=0
207 exit