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