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