xfs/{263,106}: erase max warnings printout
[xfstests-dev.git] / tests / xfs / 106
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2005 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 106
6 #
7 # Exercise basic xfs_quota functionality (user/group/project quota)
8 # Use of "sync" mount option here is an attempt to get deterministic
9 # allocator behaviour.
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
15 here=`pwd`
16 tmp=/tmp/$$
17 status=1        # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
19
20 _cleanup()
21 {
22         cd /
23         rm -f $tmp.*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29 . ./common/quota
30
31 # remove previous $seqres.full before test
32 rm -f $seqres.full
33
34 # real QA test starts here
35 _supported_fs xfs
36 _supported_os Linux
37 _require_scratch
38 _require_xfs_quota
39 _require_user
40 _require_group
41
42 _scratch_mkfs_xfs >>$seqres.full 2>&1
43
44 uqid=`id -u fsgqa`
45 gqid=`id -g fsgqa`
46 pqid=10
47 cat >$tmp.projects <<EOF
48 $pqid:$SCRATCH_MNT
49 EOF
50
51 cat >$tmp.projid <<EOF
52 root:0
53 fsgqa:$pqid
54 EOF
55
56 create_files()
57 {
58         local bs=$1
59         local inum=$2
60
61         echo "Using type=$type id=$id" >> $seqres.full
62
63         for ((i=0; i<$((inum-1)); i++)); do
64                 _file_as_id $SCRATCH_MNT/inode$i $id $type 1024 0
65         done
66
67         _file_as_id $SCRATCH_MNT/block $id $type $bs 1
68 }
69
70 clean_files()
71 {
72         rm -rf $SCRATCH_MNT/* 2>/dev/null
73         rm -rf $tmp.quot 2>/dev/null
74         rm -rf $tmp.quota 2>/dev/null
75 }
76
77 filter_quot()
78 {
79         _filter_quota | grep -v "root \|\#0 " \
80                 | sed -e '/#[0-9]*/s/#[0-9]*/#ID/g'
81 }
82
83 filter_report()
84 {
85         _filter_quota | grep -v "^root \|^\#0 " \
86                 | sed -e '/^#[0-9]*/s/^#[0-9]*/#ID/g'
87 }
88
89 filter_quota()
90 {
91         _filter_quota | sed -e "/Disk quotas for/s/([0-9]*)/(ID)/g" \
92                             -e "/Disk quotas for/s/#[0-9]*/#ID/g"
93 }
94
95 filter_state()
96 {
97         _filter_quota | sed -e "s/Inode: #[0-9]* (0 blocks, 0 extents)/Inode: #[INO] (0 blocks, 0 extents)/g" \
98                             -e "s/Inode: #[0-9]* ([0-9]* blocks, [0-9]* extents)/Inode: #[INO] (X blocks, Y extents)/g" \
99                             -e "/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/s/ [0-9][0-9]:[0-9][0-9]:[0-9][0-9]//g" \
100                             -e '/max warnings:/d'
101 }
102
103 test_quot()
104 {
105         local opt="$*"
106
107         echo "checking quot command (type=$type)"
108         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
109                         -c "quot -$type $opt -bi" $SCRATCH_MNT | filter_quot
110 }
111
112 test_report()
113 {
114         local opt="$*"
115
116         echo "checking report command (type=$type)"
117         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
118                         -c "report -$type $opt -bi" \
119                         $SCRATCH_MNT | filter_report
120 }
121
122 test_quota()
123 {
124         local opt="$*"
125
126         echo "checking quota command (type=$type)"
127         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
128                         -c "quota -$type $opt -bi $id" \
129                         $SCRATCH_MNT | filter_quota
130 }
131
132 test_limit()
133 {
134         local bs=$1
135         local bh=$2
136         local is=$3
137         local ih=$4
138
139         echo "checking limit command (type=$type, bsoft=$bs, bhard=$bh, isoft=$is, ihard=$ih)"
140         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
141                         -c "limit -$type bsoft=$bs bhard=$bh fsgqa" \
142                         -c "limit -$type isoft=$is ihard=$ih fsgqa" \
143                         $SCRATCH_MNT
144
145         # let the timer day transition happen
146         sleep 2
147 }
148
149 test_timer()
150 {
151         echo "checking timer command (type=$type)"
152         # set 3days+1h for time won't become 2days soon
153         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
154                         -c "timer -$type -bi 73h" \
155                         $SCRATCH_MNT | _filter_scratch
156 }
157
158 test_disable()
159 {
160         echo "checking disable command (type=$type)"
161         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
162                         -c "disable -$type -v" \
163                         $SCRATCH_MNT | filter_state
164 }
165
166 test_enable()
167 {
168         echo "checking enable command (type=$type)"
169         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
170                         -c "enable -$type -v" $SCRATCH_MNT | filter_state
171 }
172
173 test_off()
174 {
175         echo "checking off command (type=$type)"
176         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
177                         -c "off -$type -v" $SCRATCH_MNT | _filter_scratch
178 }
179
180 test_remove()
181 {
182         echo "checking remove command (type=$type)"
183         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
184                         -c "remove -$type -v" \
185                         $SCRATCH_MNT | _filter_scratch
186 }
187
188 test_state()
189 {
190         echo "checking state command (type=$type)"
191         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
192                         -c "state -$type" $SCRATCH_MNT | filter_state
193 }
194
195 test_dump()
196 {
197         echo "checking dump command (type=$type)"
198         rm -f $tmp.backup 2>>/dev/null
199         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
200                         -c "dump -$type -f $tmp.backup" \
201                         $SCRATCH_MNT | _filter_scratch
202 }
203
204 test_restore()
205 {
206         echo "checking restore command (type=$type)"
207         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
208                         -c "restore -$type -f $tmp.backup" \
209                         $SCRATCH_MNT | _filter_scratch
210 }
211
212 test_xfs_quota()
213 {
214         # init quota
215         echo "init quota limit and timer, and dump it"
216         echo "create_files 1024k 15"; create_files 1024k 15
217         echo "quota remount"; _qmount
218         echo ; test_quot
219         echo ; test_timer
220         echo ; test_limit 512k 2048k 10 20
221         echo ; test_dump
222
223         # report options test
224         echo "report options test"
225         echo ; test_report
226         echo "-N option"; test_report -N
227         echo "-L -U options"; test_report -L $id -U $id
228         echo "-t option"; test_report -t
229         echo "-n option"; test_report -n
230         echo "-h option"; test_report -h
231
232         # quot options test
233         echo "quot options test"
234         echo ; test_quot
235         echo "-f option"; test_quot -f $tmp.quot
236         cat $tmp.quot | filter_quot
237         echo "-n option"; test_quot -n
238
239         # quota options test
240         echo ; test_quota
241         echo "-f option"; test_quota -f $tmp.quota
242         cat $tmp.quota | filter_quota
243         echo "-N option"; test_quota -N
244         echo "-n option"; test_quota -n
245         echo "-h option"; test_quota -h
246
247         # disable/enable test
248         echo "disable quota"
249         echo ; test_disable
250         echo ; test_report -N
251         echo "expect a remove error at here"; test_remove
252         echo ; test_enable
253         echo ; test_report -N
254
255         # off and remove test
256         echo "off and remove test"
257         echo ; test_limit 100m 100m 100 100
258         echo ; test_quota -N
259         echo ; test_off
260         echo ; test_state
261         echo ; test_remove
262         echo ; test_report -N
263         echo "quota remount"; _qmount
264         echo ; test_report -N
265
266         # restore test
267         echo "restore quota"
268         echo ; test_restore
269         echo ; test_report -N
270         echo ; test_state
271         echo "cleanup files"; clean_files
272 }
273
274 echo "----------------------- uquota,sync ---------------------------"
275 _qmount_option "uquota,sync"
276 _qmount
277 type=u
278 id=$uqid
279 test_xfs_quota
280
281 echo "----------------------- gquota,sync ---------------------------"
282 _qmount_option "gquota,sync"
283 _qmount
284 type=g
285 id=$gqid
286 test_xfs_quota
287
288 echo "----------------------- pquota,sync ---------------------------"
289 # Need to clean the group quota before test project quota, because
290 # V4 xfs doesn't support separate project inode. So mkfs at here.
291 _scratch_unmount
292 _scratch_mkfs_xfs >>$seqres.full 2>&1
293 _qmount_option "pquota,sync"
294 _qmount
295 type=p
296 id=$pqid
297 _require_prjquota $SCRATCH_DEV
298 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
299                 -c "project -s $id" \
300                 $SCRATCH_MNT > /dev/null
301 test_xfs_quota
302
303 _scratch_unmount
304 # success, all done
305 status=0
306 exit