xfstests: eliminate warnings under dmapi/src/suite1/cmd (3)
[xfstests-dev.git] / 050
1 #! /bin/bash
2 # FS QA Test No. 050
3 #
4 # Exercises basic XFS quota functionality
5 #       uquota, gquota, uqnoenforce, gqnoenforce, pquota, pqnoenforce
6 #
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation.
13 #
14 # This program is distributed in the hope that it would be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write the Free Software Foundation,
21 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22 #
23 #-----------------------------------------------------------------------
24 #
25 # creator
26 owner=nathans@sgi.com
27
28 seq=`basename $0`
29 echo "QA output created by $seq"
30
31 here=`pwd`
32 tmp=/tmp/$$
33 status=1        # failure is the default!
34
35 # get standard environment, filters and checks
36 . ./common.rc
37 . ./common.filter
38 . ./common.quota
39
40 _cleanup()
41 {
42         cd /
43         umount $SCRATCH_MNT 2>/dev/null
44         rm -f $tmp.*
45 }
46 trap "_cleanup; exit \$status" 0 1 2 3 15
47
48
49 # real QA test starts here
50 _supported_fs xfs
51 _supported_os Linux IRIX
52
53
54 cp /dev/null $seq.full
55 chmod a+rwx $seq.full   # arbitrary users will write here
56
57 _require_scratch
58 _require_xfs_quota
59
60 bsoft=100
61 bhard=500
62 isoft=4
63 ihard=10
64
65
66 _filter_report()
67 {
68         tr -s '[:space:]' | \
69         perl -npe '
70                 s/^\#'$id' /[NAME] /g;
71                 s/^\#0 \d+ /[ROOT] 0 /g;
72                 s/6 days/7 days/g'
73 }
74
75 # The actual point at which limit enforcement takes place for the
76 # hard block limit is variable depending on filesystem blocksize,
77 # and iosize.  What we want to test is that the limit is enforced
78 # (ie. blksize less than limit but not unduly less - ~85% is kind)
79 # nowadays we actually get much closer to the limit before EDQUOT.
80 #
81 _filter_and_check_blks()
82 {
83         perl -npe '
84                 if (/^\#'$id'\s+(\d+)/ && '$enforce') {
85                         $maximum = '$bhard';
86                         $minimum = '$bhard' * 85/100;
87                         if (($1 < $minimum || $1 > $maximum) && '$noextsz') {
88                                 printf(" URK %d: %d is out of range! [%d,%d]\n",
89                                         '$id', $1, $minimum, $maximum);
90                         }
91                         s/^(\#'$id'\s+)(\d+)/\1 =OK=/g;
92                 }
93         ' | _filter_report
94 }
95
96 _exercise()
97 {
98         _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
99         cat $tmp.mkfs >>$seq.full
100
101         # keep the blocksize and data size for dd later
102         . $tmp.mkfs
103
104         _qmount
105
106         # Figure out whether we're doing large allocations
107         # (bail out if they're so large they stuff the test up)
108         _test_inode_flag extsz-inherit $SCRATCH_MNT
109         noextsz=$?
110         extsize=`_test_inode_extsz $SCRATCH_MNT`
111         [ $extsize -ge 512000 ] && \
112                 _notrun "Extent size hint is too large ($extsize bytes)"
113
114         _qsetup
115
116         echo "Using output from '" `ls -l $seq.out` "'" >>$seq.full
117         echo "and using type=$type id=$id" >>$seq.full
118
119         echo
120         echo "*** report no quota settings" | tee -a $seq.full
121         xfs_quota -D $tmp.projects -P $tmp.projid -x \
122                 -c "repquota -birnN -$type" $SCRATCH_DEV |
123                 _filter_report | LC_COLLATE=POSIX sort -ru
124
125         echo
126         echo "*** report initial settings" | tee -a $seq.full
127         _file_as_id $SCRATCH_MNT/initme $id $type 1024 0
128         echo "ls -l $SCRATCH_MNT" >>$seq.full
129         ls -l $SCRATCH_MNT >>$seq.full
130         xfs_quota -D $tmp.projects -P $temp.projid -x \
131                 -c "limit -$type bsoft=${bsoft}k bhard=${bhard}k $id" \
132                 -c "limit -$type isoft=$isoft ihard=$ihard $id" \
133                 $SCRATCH_DEV
134         xfs_quota -D $tmp.projects -P $tmp.projid -x \
135                 -c "repquota -birnN -$type" $SCRATCH_DEV |
136                 _filter_report | LC_COLLATE=POSIX sort -ru
137
138         echo
139         echo "*** push past the soft inode limit" | tee -a $seq.full
140         _file_as_id $SCRATCH_MNT/softie1 $id $type 1024 0
141         _file_as_id $SCRATCH_MNT/softie2 $id $type 1024 0
142         _qmount
143         xfs_quota -D $tmp.projects -P $tmp.projid -x \
144                 -c "repquota -birnN -$type" $SCRATCH_DEV |
145                 _filter_report | LC_COLLATE=POSIX sort -ru
146
147         echo
148         echo "*** push past the soft block limit" | tee -a $seq.full
149         _file_as_id $SCRATCH_MNT/softie $id $type 1024 140
150         _qmount
151         xfs_quota -D $tmp.projects -P $tmp.projid -x \
152                 -c "repquota -birnN -$type" $SCRATCH_DEV |
153                 _filter_report | LC_COLLATE=POSIX sort -ru
154
155         echo
156         # Note: for quota accounting (not enforcement), EDQUOT is not expected
157         echo "*** push past the hard inode limit (expect EDQUOT)" | tee -a $seq.full
158         for i in 1 2 3 4 5 6 7 8 9 10 11 12
159         do
160                 _file_as_id $SCRATCH_MNT/hard$i $id $type 1024 0
161         done
162         _qmount
163         xfs_quota -D $tmp.projects -P $tmp.projid -x \
164                 -c "repquota -birnN -$type" $SCRATCH_DEV |
165                 _filter_report | LC_COLLATE=POSIX sort -ru
166
167         echo
168         # Note: for quota accounting (not enforcement), EDQUOT is not expected
169         echo "*** push past the hard block limit (expect EDQUOT)" | tee -a $seq.full
170         _file_as_id $SCRATCH_MNT/softie $id $type 1024 540
171         echo "ls -l $SCRATCH_MNT" >>$seq.full
172         ls -l $SCRATCH_MNT >>$seq.full
173         _qmount
174         xfs_quota -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         umount $SCRATCH_MNT
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 if [ "$HOSTOS" == "IRIX" ]
197 then
198         _qmount_option "quota"
199 else
200         _qmount_option "uquota"
201 fi
202 _exercise
203
204 echo "*** group"
205 _qmount_option "gquota"
206 _exercise
207
208 echo "*** uqnoenforce"
209 if [ "$HOSTOS" == "IRIX" ]
210 then
211         _qmount_option "qnoenforce"
212 else
213         _qmount_option "uqnoenforce"
214 fi
215 _exercise
216
217 echo "*** gqnoenforce"
218 _qmount_option "gqnoenforce"
219 _exercise
220
221 echo "*** pquota"
222 _qmount_option "pquota"
223 _exercise
224
225 echo "*** pqnoenforce"
226 _qmount_option "pqnoenforce"
227 _exercise
228
229 # success, all done
230 status=0
231 exit