d8f55441e5eae57871b1c8291fdcd95211b198ae
[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         _scratch_unmount
159         _qmount_option ""
160         _qmount
161 }
162
163 test_remove()
164 {
165         echo "checking remove command (type=$type)"
166         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
167                         -c "remove -$type -v" \
168                         $SCRATCH_MNT | _filter_scratch
169 }
170
171 test_state()
172 {
173         echo "checking state command (type=$type)"
174         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
175                         -c "state -$type" $SCRATCH_MNT | filter_state
176 }
177
178 test_dump()
179 {
180         echo "checking dump command (type=$type)"
181         rm -f $tmp.backup 2>>/dev/null
182         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
183                         -c "dump -$type -f $tmp.backup" \
184                         $SCRATCH_MNT | _filter_scratch
185 }
186
187 test_restore()
188 {
189         echo "checking restore command (type=$type)"
190         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
191                         -c "restore -$type -f $tmp.backup" \
192                         $SCRATCH_MNT | _filter_scratch
193 }
194
195 test_xfs_quota()
196 {
197         _qmount_option $1
198         _qmount
199
200         if [ $type == "p" ]; then
201                 _require_prjquota $SCRATCH_DEV
202                 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
203                         -c "project -s $id" $SCRATCH_MNT > /dev/null
204         fi
205
206         # init quota
207         echo "init quota limit and timer, and dump it"
208         echo "create_files 1024k 15"; create_files 1024k 15
209         echo "quota remount"; _qmount
210         echo ; test_quot
211         echo ; test_timer
212         echo ; test_limit 512k 2048k 10 20
213         echo ; test_dump
214
215         # report options test
216         echo "report options test"
217         echo ; test_report
218         echo "-N option"; test_report -N
219         echo "-L -U options"; test_report -L $id -U $id
220         echo "-t option"; test_report -t
221         echo "-n option"; test_report -n
222         echo "-h option"; test_report -h
223
224         # quot options test
225         echo "quot options test"
226         echo ; test_quot
227         echo "-f option"; test_quot -f $tmp.quot
228         cat $tmp.quot | filter_quot
229         echo "-n option"; test_quot -n
230
231         # quota options test
232         echo ; test_quota
233         echo "-f option"; test_quota -f $tmp.quota
234         cat $tmp.quota | filter_quota
235         echo "-N option"; test_quota -N
236         echo "-n option"; test_quota -n
237         echo "-h option"; test_quota -h
238
239         # disable/enable test
240         echo "disable quota"
241         echo ; test_disable
242         echo ; test_report -N
243         echo "expect a remove error at here"; test_remove
244         echo ; test_enable
245         echo ; test_report -N
246
247         # off and remove test
248         echo "disable and remove test"
249         echo ; test_limit 100m 100m 100 100
250         echo ; test_quota -N
251         echo ; test_disable
252         echo ; test_state
253         echo ; test_off
254         echo ; test_remove
255         echo ; test_report -N
256         _scratch_unmount
257
258         echo "quota remount";
259         _qmount_option $1
260         _qmount
261         echo ; test_report -N
262
263         # restore test
264         echo "restore quota"
265         echo ; test_restore
266         echo ; test_report -N
267         echo ; test_state
268         echo "cleanup files"; clean_files
269 }
270
271 echo "----------------------- uquota,sync ---------------------------"
272 type=u
273 id=$uqid
274 test_xfs_quota "uquota,sync"
275
276 echo "----------------------- gquota,sync ---------------------------"
277 type=g
278 id=$gqid
279 test_xfs_quota "gquota,sync"
280
281 echo "----------------------- pquota,sync ---------------------------"
282 # Need to clean the group quota before test project quota, because
283 # V4 xfs doesn't support separate project inode. So mkfs at here.
284 _scratch_unmount
285 _scratch_mkfs_xfs >>$seqres.full 2>&1
286 type=p
287 id=$pqid
288 test_xfs_quota "pquota,sync"
289
290 _scratch_unmount
291 # success, all done
292 status=0
293 exit