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