Add three additional quota tests - 106/107/108.
[xfstests-dev.git] / 106
1 #! /bin/sh
2 # FS QA Test No. 106
3 #
4 # Exercise basic xfs_quota functionality (user/group/project quota)
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2005 Silicon Graphics, Inc.  All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or modify it
10 # under the terms of version 2 of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 #
17 # Further, this software is distributed without any warranty that it is
18 # free of the rightful claim of any third person regarding infringement
19 # or the like.  Any license provided herein, whether implied or
20 # otherwise, applies only to this software file.  Patent licenses, if
21 # any, provided herein do not apply to combinations of this program with
22 # other software, or any other product whatsoever.
23 #
24 # You should have received a copy of the GNU General Public License along
25 # with this program; if not, write the Free Software Foundation, Inc., 59
26 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
27 #
28 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
29 # Mountain View, CA  94043, or:
30 #
31 # http://www.sgi.com
32 #
33 # For further information regarding this notice, see:
34 #
35 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
36 #-----------------------------------------------------------------------
37 #
38 # creator
39 owner=nathans@sgi.com
40
41 seq=`basename $0`
42 echo "QA output created by $seq"
43
44 here=`pwd`
45 tmp=/tmp/$$
46 status=1        # failure is the default!
47 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
48
49 # get standard environment, filters and checks
50 . ./common.rc
51 . ./common.filter
52 . ./common.quota
53
54 _supported_fs xfs
55 _supported_os Linux #IRIX
56 _require_scratch
57 _require_quota
58
59 # real QA test starts here
60 _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
61 cat $tmp.mkfs >>$seq.full
62 . $tmp.mkfs
63
64 # setup a default run
65 [ -z "$MOUNT_OPTIONS" ] && export MOUNT_OPTIONS="-o uquota"
66
67 # initial populate
68 _qmount
69 target=$SCRATCH_MNT/target
70 ltp/fsstress -s 0xdeed -m8 -w -p4 -n1000 $FSSTRESS_AVOID -d $target
71 ltp/fsstress -s 0xdeed -m8 -z -p4 -n1000 -fchproj=500 -fchown=500 -d $target
72
73 # also use space, to be able to go over/under limits easily
74 uid=255
75 gid=254
76 prid=253
77 rm -f $SCRATCH_MNT/resv
78 xfs_io -fc "resvsp 0 200m" -c "chproj $prid" $SCRATCH_MNT/resv
79 chown $uid $SCRATCH_MNT/resv
80 chgrp $gid $SCRATCH_MNT/resv
81
82 _qmount
83
84 filter_xfs_quota()
85 {
86         perl -ne "
87 s,$SCRATCH_MNT,[SCR_MNT],;
88 s,$SCRATCH_DEV,[SCR_DEV],;
89 s/Inode: \#\d+ \(0 blocks, 0 extents\)/Inode: #[INO] (0 blocks, 0 extents)/;
90 s/Inode: \#\d+ \(\d+ blocks, \d+ extents\)/Inode: #[INO] (X blocks, Y extents)/;
91         print;"
92 }
93
94 test_quot()
95 {
96         echo "checking quot command (type=$type)"  # not deterministic on blks
97         xfs_quota -x -c "quot -n -$type" $SCRATCH_MNT >>$seq.full 2>&1
98 }
99
100 test_report()
101 {
102         echo "checking report command (type=$type)"
103         xfs_quota -x -c "report -h -$type -U 256" $SCRATCH_MNT
104 }
105
106 test_limit1()
107 {
108         echo "checking limit command, pass 1 (type=$type)"
109         xfs_quota -x -c "limit -$type bsoft=100m bhard=100m ihard=2 $id" \
110                 $SCRATCH_MNT
111         xfs_quota -x -c "limit -$type isoft=1 rtbsoft=100m rtbhard=110m $id"\
112                 $SCRATCH_MNT
113         sleep 2         # let the timer day transition happen
114         xfs_quota -x -c "quota -$type -b -hnv $id" $SCRATCH_MNT
115         xfs_quota -x -c "quota -$type -i -hnv $id" $SCRATCH_MNT
116         #xfs_quota -x -c "quota -$type -r -hnv $id" $SCRATCH_MNT
117 }
118
119 test_limit2()
120 {
121         # push limits up high, so that timers are cleared, etc. (for later)
122         echo "checking limit command, pass2 (type=$type)"
123         xfs_quota -x -c "limit -$type bsoft=300m bhard=400m ihard=8800 $id" \
124                 $SCRATCH_MNT
125         xfs_quota -x -c "limit -$type isoft=8000 rtbsoft=310m rtbhard=410m $id"\
126                 $SCRATCH_MNT
127         xfs_quota -x -c "quota -$type -b -hnv $id" $SCRATCH_MNT
128         xfs_quota -x -c "quota -$type -i -hnv $id" $SCRATCH_MNT
129         #xfs_quota -x -c "quota -$type -r -hnv $id" $SCRATCH_MNT
130 }
131
132 test_warn()
133 {
134         echo "checking warn command (type=$type)"
135         xfs_quota -x -c "warn -$type -b 4 $id" $SCRATCH_MNT
136         xfs_quota -x -c "warn -$type -i 3 $id" $SCRATCH_MNT
137         #xfs_quota -x -c "warn -$type -r 2 $id" $SCRATCH_MNT
138         xfs_quota -x -c "quota -$type -b -hnv $id" $SCRATCH_MNT
139         xfs_quota -x -c "quota -$type -i -hnv $id" $SCRATCH_MNT
140         #xfs_quota -x -c "quota -$type -r -hnv $id" $SCRATCH_MNT
141 }
142
143 test_timer()
144 {
145         echo "checking timer command (type=$type)"
146         xfs_quota -x -c "timer -$type -b 3days" $SCRATCH_MNT
147         xfs_quota -x -c "timer -$type -i 2days" $SCRATCH_MNT
148         #xfs_quota -x -c "timer -$type -r 1day" $SCRATCH_MNT
149 }
150
151 test_state()
152 {
153         echo "checking state command (type=$type)"
154         xfs_quota -x -c "state -$type" $SCRATCH_MNT
155         # not yet working properly?
156         #echo "checking disable command (type=$type)"
157         #xfs_quota -x -c "disable -$type -v" $SCRATCH_MNT
158         #echo "checking enable command (type=$type)"
159         #xfs_quota -x -c "enable -$type -v" $SCRATCH_MNT
160         #echo "checking off command (type=$type)"
161         #xfs_quota -x -c "off -$type -v" $SCRATCH_MNT
162         #echo "checking remove command (type=$type)"
163         #xfs_quota -x -c "remove -$type -v" $SCRATCH_MNT
164 }
165
166 test_backup()
167 {
168         echo "checking dump command (type=$type)"
169         rm -f $tmp.backup
170         xfs_quota -x -c "dump -$type -f $tmp.backup -U 256" $SCRATCH_MNT
171         cat $tmp.backup
172
173         echo "changing limits (type=$type)"
174         xfs_quota -x -c "limit -$type isoft=1000 ihard=1100 $id" $SCRATCH_MNT
175         xfs_quota -x -c "quota -$type -i -hnv $id" $SCRATCH_MNT
176
177         echo "checking restore command (type=$type)"
178         xfs_quota -x -c "restore -$type -f $tmp.backup" $SCRATCH_MNT
179         xfs_quota -x -c "quota -$type -i -hnv $id" $SCRATCH_MNT
180         rm -f $tmp.backup
181 }
182
183 test_xfs_quota()
184 {
185         test_quot       ; echo
186         test_report     ; echo
187         test_timer      ; echo
188         test_limit1     ; echo
189         test_warn       ; echo
190         test_limit2     ; echo
191         test_backup     ; echo
192         test_state      ; echo
193         echo            ; echo
194 }
195
196 # real QA test starts here
197 export MOUNT_OPTIONS="-ouquota"
198 _qmount
199 type=u
200 id=$uid
201 test_xfs_quota | filter_xfs_quota
202
203 export MOUNT_OPTIONS="-ogquota"
204 _qmount
205 type=g
206 id=$gid
207 test_xfs_quota | filter_xfs_quota
208
209 export MOUNT_OPTIONS="-opquota"
210 _qmount
211 type=p
212 id=$prid
213 test_xfs_quota | filter_xfs_quota
214
215 umount $SCRATCH_DEV
216 status=0
217 exit