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