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