A recent change to XFSQA to resolve mkfs option conflicts means mkfs can be run twice...
[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 # 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 #
12 # creator
13 owner=nathans@sgi.com
14
15 seq=`basename $0`
16 echo "QA output created by $seq"
17
18 here=`pwd`
19 tmp=/tmp/$$
20 status=1        # failure is the default!
21 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
22
23 # get standard environment, filters and checks
24 . ./common.rc
25 . ./common.filter
26 . ./common.quota
27
28 _supported_fs xfs
29 _supported_os Linux #IRIX
30 _require_scratch
31 _require_quota
32 _require_prjquota
33
34 # real QA test starts here
35 _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
36 cat $tmp.mkfs >$seq.full
37 . $tmp.mkfs
38
39 # setup a default run
40 if [ -z "$MOUNT_OPTIONS" ]; then
41         export MOUNT_OPTIONS="-o pquota,sync"
42 else
43         export MOUNT_OPTIONS="$MOUNT_OPTIONS -o sync"
44 fi
45
46 # initial populate
47 _qmount
48 target=$SCRATCH_MNT/target
49 $FSSTRESS_PROG -s 0xdeed -m8 -w -p4 -n1000 $FSSTRESS_AVOID -d $target
50 $FSSTRESS_PROG -s 0xdeed -m8 -z -p4 -n1000 -fsetxattr=500 -fchown=500 -d $target
51
52 # also use space, to be able to go over/under limits easily
53 uid=255
54 gid=254
55 prid=253
56 rm -f $SCRATCH_MNT/resv
57 $XFS_IO_PROG -fc "resvsp 0 200m" -c "chproj $prid" $SCRATCH_MNT/resv
58 chown $uid $SCRATCH_MNT/resv
59 chgrp $gid $SCRATCH_MNT/resv
60
61 _qmount
62
63 filter_xfs_quota()
64 {
65         perl -ne "
66 s,$SCRATCH_MNT,[SCR_MNT],;
67 s,$SCRATCH_DEV,[SCR_DEV],;
68 s/Inode: \#\d+ \(0 blocks, 0 extents\)/Inode: #[INO] (0 blocks, 0 extents)/;
69 s/Inode: \#\d+ \(\d+ blocks, \d+ extents\)/Inode: #[INO] (X blocks, Y extents)/;
70         print;"
71 }
72
73 test_quot()
74 {
75         echo "checking quot command (type=$type)"  # not deterministic on blks
76         xfs_quota -x -c "quot -n -$type" $SCRATCH_MNT >>$seq.full 2>&1
77 }
78
79 test_report()
80 {
81         echo "checking report command (type=$type)"
82         xfs_quota -x -c "report -h -$type -U 256" $SCRATCH_MNT
83 }
84
85 test_limit1()
86 {
87         echo "checking limit command, pass 1 (type=$type)"
88         xfs_quota -x -c "limit -$type bsoft=100m bhard=100m ihard=2 $id" \
89                 $SCRATCH_MNT
90         xfs_quota -x -c "limit -$type isoft=1 rtbsoft=100m rtbhard=110m $id"\
91                 $SCRATCH_MNT
92         sleep 2         # let the timer day transition happen
93         xfs_quota -x -c "quota -$type -b -hnv $id" $SCRATCH_MNT
94         xfs_quota -x -c "quota -$type -i -hnv $id" $SCRATCH_MNT
95         #xfs_quota -x -c "quota -$type -r -hnv $id" $SCRATCH_MNT
96 }
97
98 test_limit2()
99 {
100         # push limits up high, so that timers are cleared, etc. (for later)
101         echo "checking limit command, pass2 (type=$type)"
102         xfs_quota -x -c "limit -$type bsoft=300m bhard=400m ihard=8800 $id" \
103                 $SCRATCH_MNT
104         xfs_quota -x -c "limit -$type isoft=8000 rtbsoft=310m rtbhard=410m $id"\
105                 $SCRATCH_MNT
106         xfs_quota -x -c "quota -$type -b -hnv $id" $SCRATCH_MNT
107         xfs_quota -x -c "quota -$type -i -hnv $id" $SCRATCH_MNT
108         #xfs_quota -x -c "quota -$type -r -hnv $id" $SCRATCH_MNT
109 }
110
111 test_warn()
112 {
113         echo "checking warn command (type=$type)"
114         xfs_quota -x -c "warn -$type -b 4 $id" $SCRATCH_MNT
115         xfs_quota -x -c "warn -$type -i 3 $id" $SCRATCH_MNT
116         #xfs_quota -x -c "warn -$type -r 2 $id" $SCRATCH_MNT
117         xfs_quota -x -c "quota -$type -b -hnv $id" $SCRATCH_MNT
118         xfs_quota -x -c "quota -$type -i -hnv $id" $SCRATCH_MNT
119         #xfs_quota -x -c "quota -$type -r -hnv $id" $SCRATCH_MNT
120 }
121
122 test_timer()
123 {
124         echo "checking timer command (type=$type)"
125         xfs_quota -x -c "timer -$type -b 3days" $SCRATCH_MNT
126         xfs_quota -x -c "timer -$type -i 2days" $SCRATCH_MNT
127         #xfs_quota -x -c "timer -$type -r 1day" $SCRATCH_MNT
128 }
129
130 test_state()
131 {
132         echo "checking state command (type=$type)"
133         xfs_quota -x -c "state -$type" $SCRATCH_MNT
134         # not yet working properly?
135         #echo "checking disable command (type=$type)"
136         #xfs_quota -x -c "disable -$type -v" $SCRATCH_MNT
137         #echo "checking enable command (type=$type)"
138         #xfs_quota -x -c "enable -$type -v" $SCRATCH_MNT
139         #echo "checking off command (type=$type)"
140         #xfs_quota -x -c "off -$type -v" $SCRATCH_MNT
141         #echo "checking remove command (type=$type)"
142         #xfs_quota -x -c "remove -$type -v" $SCRATCH_MNT
143 }
144
145 test_backup()
146 {
147         echo "checking dump command (type=$type)"
148         rm -f $tmp.backup
149         xfs_quota -x -c "dump -$type -f $tmp.backup -U 256" $SCRATCH_MNT
150         cat $tmp.backup
151
152         echo "changing limits (type=$type)"
153         xfs_quota -x -c "limit -$type isoft=1000 ihard=1100 $id" $SCRATCH_MNT
154         xfs_quota -x -c "quota -$type -i -hnv $id" $SCRATCH_MNT
155
156         echo "checking restore command (type=$type)"
157         xfs_quota -x -c "restore -$type -f $tmp.backup" $SCRATCH_MNT
158         xfs_quota -x -c "quota -$type -i -hnv $id" $SCRATCH_MNT
159         rm -f $tmp.backup
160 }
161
162 test_xfs_quota()
163 {
164         test_quot       ; echo
165         test_report     ; echo
166         test_timer      ; echo
167         test_limit1     ; echo
168         test_warn       ; echo
169         test_limit2     ; echo
170         test_backup     ; echo
171         test_state      ; echo
172         echo            ; echo
173 }
174
175 # real QA test starts here
176 export MOUNT_OPTIONS="-ouquota,sync"
177 _qmount
178 type=u
179 id=$uid
180 test_xfs_quota | filter_xfs_quota
181
182 export MOUNT_OPTIONS="-ogquota,sync"
183 _qmount
184 type=g
185 id=$gid
186 test_xfs_quota | filter_xfs_quota
187
188 export MOUNT_OPTIONS="-opquota,sync"
189 _qmount
190 type=p
191 id=$prid
192 test_xfs_quota | filter_xfs_quota
193
194 umount $SCRATCH_DEV
195 status=0
196 exit