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