common/rc: add _scratch_{u}mount_idmapped() helpers
[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 _qsetup()
73 {
74         opt=$1
75         enforce=0
76         if [ $opt = "u" -o $opt = "uno" ]; then
77                 type=u
78                 eval `_choose_uid`
79         elif [ $opt = "g" -o $opt = "gno" ]; then
80                 type=g
81                 eval `_choose_gid`
82         elif [ $opt = "p" -o $opt = "pno" ]; then
83                 type=p
84                 eval `_choose_prid`
85         fi
86         [ $opt = "u" -o $opt = "g" -o $opt = "p" ] && enforce=1
87
88         echo "Using type=$type id=$id" >> $seqres.full
89 }
90
91 _exercise()
92 {
93         _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
94         cat $tmp.mkfs >>$seqres.full
95
96         # keep the blocksize and data size for dd later
97         . $tmp.mkfs
98
99         _qmount
100
101         # Figure out whether we're doing large allocations
102         # (bail out if they're so large they stuff the test up)
103         _test_inode_flag extsz-inherit $SCRATCH_MNT
104         noextsz=$?
105         extsize=`_test_inode_extsz $SCRATCH_MNT`
106         [ $extsize -ge 512000 ] && \
107                 _notrun "Extent size hint is too large ($extsize bytes)"
108
109         _qsetup $1
110
111         echo "Using type=$type id=$id" >>$seqres.full
112
113         $XFS_QUOTA_PROG -x -c "warn -$type 65535 -d" $SCRATCH_DEV
114
115         echo
116         echo "*** report no quota settings" | tee -a $seqres.full
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 "*** report initial settings" | tee -a $seqres.full
123         _file_as_id $SCRATCH_MNT/initme $id $type 1024 0
124         echo "ls -l $SCRATCH_MNT" >>$seqres.full
125         ls -l $SCRATCH_MNT >>$seqres.full
126         $XFS_QUOTA_PROG -D $tmp.projects -P $temp.projid -x \
127                 -c "limit -$type bsoft=${bsoft} bhard=${bhard} $id" \
128                 -c "limit -$type isoft=$isoft ihard=$ihard $id" \
129                 $SCRATCH_DEV
130         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
131                 -c "repquota -birnN -$type" $SCRATCH_DEV |
132                 _filter_quota_report | LC_COLLATE=POSIX sort -ru
133
134         echo
135         echo "*** push past the soft inode limit" | tee -a $seqres.full
136         _file_as_id $SCRATCH_MNT/softie1 $id $type 1024 0
137         _file_as_id $SCRATCH_MNT/softie2 $id $type 1024 0
138         _file_as_id $SCRATCH_MNT/softie3 $id $type 1024 0
139         _file_as_id $SCRATCH_MNT/softie4 $id $type 1024 0
140         _qmount
141         $XFS_QUOTA_PROG -x -c "warn -i -$type 0 $id" $SCRATCH_DEV
142         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
143                 -c "repquota -birnN -$type" $SCRATCH_DEV |
144                 _filter_quota_report | LC_COLLATE=POSIX sort -ru
145
146         echo
147         echo "*** push past the soft block limit" | tee -a $seqres.full
148         _file_as_id $SCRATCH_MNT/softie $id $type $bsize 300
149         _qmount
150         $XFS_QUOTA_PROG -x -c "warn -i -$type 0 $id" \
151                 -c "warn -b -$type 0 $id" $SCRATCH_DEV
152         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
153                 -c "repquota -birnN -$type" $SCRATCH_DEV |
154                 _filter_quota_report | LC_COLLATE=POSIX sort -ru
155
156         echo
157         # Note: for quota accounting (not enforcement), EDQUOT is not expected
158         echo "*** push past the hard inode limit (expect EDQUOT)" | tee -a $seqres.full
159         for i in 1 2 3 4 5 6 7 8 9 10 11 12
160         do
161                 _file_as_id $SCRATCH_MNT/hard$i $id $type 1024 0
162         done
163         _qmount
164         $XFS_QUOTA_PROG -x  -c "warn -b -$type 0 $id" \
165                 -c "warn -i -$type 0 $id" $SCRATCH_DEV
166         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
167                 -c "repquota -birnN -$type" $SCRATCH_DEV |
168                 _filter_quota_report | LC_COLLATE=POSIX sort -ru
169
170         echo
171         # Note: for quota accounting (not enforcement), EDQUOT is not expected
172         echo "*** push past the hard block limit (expect EDQUOT)" | tee -a $seqres.full
173         _file_as_id $SCRATCH_MNT/softie $id $type $bsize 1200
174         echo "ls -l $SCRATCH_MNT" >>$seqres.full
175         ls -l $SCRATCH_MNT >>$seqres.full
176         _qmount
177         $XFS_QUOTA_PROG -x -c "warn -b -$type 0 $id" $SCRATCH_DEV
178         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
179                 -c "repquota -birnN -$type" $SCRATCH_DEV |
180                 _filter_and_check_blks | LC_COLLATE=POSIX sort -ru
181
182         echo
183         echo "*** unmount"
184         _scratch_unmount
185
186 }
187
188 cat >$tmp.projects <<EOF
189 1:$SCRATCH_MNT
190 EOF
191
192 cat >$tmp.projid <<EOF
193 root:0
194 scrach:1
195 EOF
196
197 projid_file="$tmp.projid"
198
199 echo "*** user"
200 _qmount_option "uquota"
201 _exercise u
202
203 echo "*** group"
204 _qmount_option "gquota"
205 _exercise g
206
207 echo "*** uqnoenforce"
208 _qmount_option "uqnoenforce"
209 _exercise uno
210
211 echo "*** gqnoenforce"
212 _qmount_option "gqnoenforce"
213 _exercise gno
214
215 echo "*** pquota"
216 _qmount_option "pquota"
217 _exercise p
218
219 echo "*** pqnoenforce"
220 _qmount_option "pqnoenforce"
221 _exercise pno
222
223 # success, all done
224 status=0
225 exit