b351fe55c2badafe26b80fc9bd06e6525b2fefcf
[xfstests-dev.git] / 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 # creator
27 owner=nathans@sgi.com
28
29 seq=`basename $0`
30 echo "QA output created by $seq"
31
32 here=`pwd`
33 tmp=/tmp/$$
34 status=1        # failure is the default!
35 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
36
37 # get standard environment, filters and checks
38 . ./common.rc
39 . ./common.filter
40 . ./common.quota
41
42 _supported_fs xfs
43 _supported_os Linux #IRIX
44 _require_scratch
45 _require_xfs_quota
46
47 # real QA test starts here
48 _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
49 cat $tmp.mkfs >$seq.full
50 . $tmp.mkfs
51
52 # setup a default run
53 if [ -z "$MOUNT_OPTIONS" ]; then
54         export MOUNT_OPTIONS="-o pquota,sync"
55 else
56         export MOUNT_OPTIONS="$MOUNT_OPTIONS -o sync"
57 fi
58
59 _qmount
60 _require_prjquota $SCRATCH_DEV
61
62 # initial populate
63 target=$SCRATCH_MNT/target
64 $FSSTRESS_PROG -z -s 57069 -m 8 -n 1000 -p 4 \
65 -f allocsp=1 \
66 -f chown=3 \
67 -f creat=4 \
68 -f dwrite=4 \
69 -f fallocate=1 \
70 -f fdatasync=1 \
71 -f fiemap=1 \
72 -f freesp=1 \
73 -f fsync=1 \
74 -f link=1 \
75 -f mkdir=2 \
76 -f mknod=2 \
77 -f punch=1 \
78 -f rename=2 \
79 -f resvsp=1 \
80 -f rmdir=1 \
81 -f setxattr=1 \
82 -f symlink=2 \
83 -f sync=1 \
84 -f truncate=2 \
85 -f unlink=1 \
86 -f unresvsp=1 \
87 -f write=4 \
88 -d $target
89
90 $FSSTRESS_PROG -z -s 57069 -m 8 -n 1000 -p 4 \
91 -f chown=500 \
92 -f setxattr=500 \
93 -d $target
94
95
96 # also use space, to be able to go over/under limits easily
97 uid=255
98 gid=254
99 prid=253
100 rm -f $SCRATCH_MNT/resv
101 $XFS_IO_PROG -fc "resvsp 0 200m" -c "chproj $prid" $SCRATCH_MNT/resv
102 chown $uid $SCRATCH_MNT/resv
103 chgrp $gid $SCRATCH_MNT/resv
104
105 _qmount
106
107 filter_xfs_quota()
108 {
109         perl -ne "
110 s,$SCRATCH_MNT,[SCR_MNT],;
111 s,$SCRATCH_DEV,[SCR_DEV],;
112 s/Inode: \#\d+ \(0 blocks, 0 extents\)/Inode: #[INO] (0 blocks, 0 extents)/;
113 s/Inode: \#\d+ \(\d+ blocks, \d+ extents\)/Inode: #[INO] (X blocks, Y extents)/;
114         print;"
115 }
116
117 test_quot()
118 {
119         echo "checking quot command (type=$type)"  # not deterministic on blks
120         xfs_quota -x -c "quot -n -$type" $SCRATCH_MNT >>$seq.full 2>&1
121 }
122
123 test_report()
124 {
125         echo "checking report command (type=$type)"
126         xfs_quota -x -c "report -h -$type -U 256" $SCRATCH_MNT
127 }
128
129 test_limit1()
130 {
131         echo "checking limit command, pass 1 (type=$type)"
132         xfs_quota -x -c "limit -$type bsoft=100m bhard=100m ihard=2 $id" \
133                 $SCRATCH_MNT
134         xfs_quota -x -c "limit -$type isoft=1 rtbsoft=100m rtbhard=110m $id"\
135                 $SCRATCH_MNT
136         sleep 2         # let the timer day transition happen
137         xfs_quota -x -c "quota -$type -b -hnv $id" $SCRATCH_MNT
138         xfs_quota -x -c "quota -$type -i -hnv $id" $SCRATCH_MNT
139         #xfs_quota -x -c "quota -$type -r -hnv $id" $SCRATCH_MNT
140 }
141
142 test_limit2()
143 {
144         # push limits up high, so that timers are cleared, etc. (for later)
145         echo "checking limit command, pass2 (type=$type)"
146         xfs_quota -x -c "limit -$type bsoft=300m bhard=400m ihard=8800 $id" \
147                 $SCRATCH_MNT
148         xfs_quota -x -c "limit -$type isoft=8000 rtbsoft=310m rtbhard=410m $id"\
149                 $SCRATCH_MNT
150         xfs_quota -x -c "quota -$type -b -hnv $id" $SCRATCH_MNT
151         xfs_quota -x -c "quota -$type -i -hnv $id" $SCRATCH_MNT
152         #xfs_quota -x -c "quota -$type -r -hnv $id" $SCRATCH_MNT
153 }
154
155 test_warn()
156 {
157         echo "checking warn command (type=$type)"
158         xfs_quota -x -c "warn -$type -b 4 $id" $SCRATCH_MNT
159         xfs_quota -x -c "warn -$type -i 3 $id" $SCRATCH_MNT
160         #xfs_quota -x -c "warn -$type -r 2 $id" $SCRATCH_MNT
161         xfs_quota -x -c "quota -$type -b -hnv $id" $SCRATCH_MNT
162         xfs_quota -x -c "quota -$type -i -hnv $id" $SCRATCH_MNT
163         #xfs_quota -x -c "quota -$type -r -hnv $id" $SCRATCH_MNT
164 }
165
166 test_timer()
167 {
168         echo "checking timer command (type=$type)"
169         xfs_quota -x -c "timer -$type -b 3days" $SCRATCH_MNT
170         xfs_quota -x -c "timer -$type -i 2days" $SCRATCH_MNT
171         #xfs_quota -x -c "timer -$type -r 1day" $SCRATCH_MNT
172 }
173
174 test_state()
175 {
176         echo "checking state command (type=$type)"
177         xfs_quota -x -c "state -$type" $SCRATCH_MNT
178         # not yet working properly?
179         #echo "checking disable command (type=$type)"
180         #xfs_quota -x -c "disable -$type -v" $SCRATCH_MNT
181         #echo "checking enable command (type=$type)"
182         #xfs_quota -x -c "enable -$type -v" $SCRATCH_MNT
183         #echo "checking off command (type=$type)"
184         #xfs_quota -x -c "off -$type -v" $SCRATCH_MNT
185         #echo "checking remove command (type=$type)"
186         #xfs_quota -x -c "remove -$type -v" $SCRATCH_MNT
187 }
188
189 test_backup()
190 {
191         echo "checking dump command (type=$type)"
192         rm -f $tmp.backup
193         xfs_quota -x -c "dump -$type -f $tmp.backup -U 256" $SCRATCH_MNT
194         cat $tmp.backup
195
196         echo "changing limits (type=$type)"
197         xfs_quota -x -c "limit -$type isoft=1000 ihard=1100 $id" $SCRATCH_MNT
198         xfs_quota -x -c "quota -$type -i -hnv $id" $SCRATCH_MNT
199
200         echo "checking restore command (type=$type)"
201         xfs_quota -x -c "restore -$type -f $tmp.backup" $SCRATCH_MNT
202         xfs_quota -x -c "quota -$type -i -hnv $id" $SCRATCH_MNT
203         rm -f $tmp.backup
204 }
205
206 test_xfs_quota()
207 {
208         test_quot       ; echo
209         test_report     ; echo
210         test_timer      ; echo
211         test_limit1     ; echo
212         test_warn       ; echo
213         test_limit2     ; echo
214         test_backup     ; echo
215         test_state      ; echo
216         echo            ; echo
217 }
218
219 # real QA test starts here
220 export MOUNT_OPTIONS="-ouquota,sync"
221 _qmount
222 type=u
223 id=$uid
224 test_xfs_quota | filter_xfs_quota
225
226 export MOUNT_OPTIONS="-ogquota,sync"
227 _qmount
228 type=g
229 id=$gid
230 test_xfs_quota | filter_xfs_quota
231
232 export MOUNT_OPTIONS="-opquota,sync"
233 _qmount
234 type=p
235 id=$prid
236 test_xfs_quota | filter_xfs_quota
237
238 umount $SCRATCH_DEV
239 status=0
240 exit