Fixed merge issue with TIMESTAMP string printing twice.
[xfstests-dev.git] / 050
1 #! /bin/sh
2 # FS QA Test No. 050
3 #
4 # Exercises basic XFS quota functionality
5 #       MOUNT_OPTIONS env var switches the test type (uid/gid/acct/enfd)
6 #       options are:  (-o) usrquota, grpquota, uqnoenforce, gqnoenforce
7 #
8 #-----------------------------------------------------------------------
9 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
10
11 # This program is free software; you can redistribute it and/or modify it
12 # under the terms of version 2 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, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18
19 # Further, this software is distributed without any warranty that it is
20 # free of the rightful claim of any third person regarding infringement
21 # or the like.  Any license provided herein, whether implied or
22 # otherwise, applies only to this software file.  Patent licenses, if
23 # any, provided herein do not apply to combinations of this program with
24 # other software, or any other product whatsoever.
25
26 # You should have received a copy of the GNU General Public License along
27 # with this program; if not, write the Free Software Foundation, Inc., 59
28 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
29
30 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
31 # Mountain View, CA  94043, or:
32
33 # http://www.sgi.com 
34
35 # For further information regarding this notice, see: 
36
37 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
38 #-----------------------------------------------------------------------
39 #
40 # creator
41 owner=nathans@sgi.com
42
43 seq=`basename $0`
44 echo "QA output created by $seq"
45
46 here=`pwd`
47 tmp=/tmp/$$
48 status=1        # failure is the default!
49
50 export MOUNT_OPTIONS=-ousrquota
51
52 # get standard environment, filters and checks
53 . ./common.rc
54 . ./common.filter
55 . ./common.quota
56
57 _cleanup()
58 {
59         cd /
60         echo; echo "*** unmount"
61         umount $SCRATCH_MNT 2>/dev/null
62         rm -f $tmp.*
63 }
64 trap "_cleanup; exit \$status" 0 1 2 3 15
65
66
67 # real QA test starts here
68 _supported_fs xfs
69 _supported_os Linux
70
71 rm -f $seq.out
72 cp /dev/null $seq.full
73 chmod a+rwx $seq.full   # arbitrary users will write here
74
75 _require_scratch
76 _require_quota
77
78 blksoft=100
79 blkhard=500
80 inosoft=4
81 inohard=10
82
83 # The actual point at which limit enforcement takes place for the
84 # hard block limit is variable depending on filesystem blocksize,
85 # and iosize.  What we want to test is that the limit is enforced
86 # (ie. blksize less than limit but not unduly less - ~85% is kind)
87 # nowadays we actually get much closer to the limit before EDQUOT.
88
89 _filter_and_check_blocks()
90 {
91         perl -npe '
92                 if (/^'$name'\s+([-|+]){2}\s+(\d+)/ && '$enforce') {
93                         $maximum = '$blkhard';
94                         $minimum = '$blkhard' * 85/100;
95                         if ($2 < $minimum || $2 > $maximum) {
96                                 printf(" URK - %d is out of range! [%d,%d] \n",
97                                         $2, $minimum, $maximum);
98                         }
99                         s/^('$name'\s+[-|+][-|+]\s+)(\d+)/\1 OK/g;
100                 }
101         ' | _filter_repquota $1
102 }
103
104 _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
105 cat $tmp.mkfs >>$seq.full
106
107 # keep the blocksize and data size for dd later
108 . $tmp.mkfs
109
110 _qmount
111
112 # setup exactly what it is we'll be testing
113 enforce=1
114 if src/feature -u $SCRATCH_DEV
115 then
116         type=u ; eval `_choose_uid`; ln $seq.usrquota $seq.out
117 elif src/feature -g $SCRATCH_DEV
118 then
119         type=g ; eval `_choose_gid`; ln $seq.grpquota $seq.out
120 elif src/feature -U $SCRATCH_DEV
121 then
122         type=u ; eval `_choose_uid`; ln $seq.uqnoenforce $seq.out
123         enforce=0
124 elif src/feature -G $SCRATCH_DEV
125 then
126         type=g ; eval `_choose_gid`; ln $seq.gqnoenforce $seq.out
127         enforce=0
128 else
129         _notrun "No quota support at mount time"
130 fi
131
132 echo "Using output from '" `ls -l $seq.out` "'" >>$seq.full
133 echo "and using type=$type id=$id" >>$seq.full
134
135 echo
136 echo "*** report no quota settings" | tee -a $seq.full
137 repquota -$type $SCRATCH_DEV | _filter_repquota 6
138
139 echo
140 echo "*** report initial settings" | tee -a $seq.full
141 _file_as_id $SCRATCH_MNT/initme $id $type 1024 0
142 setquota -$type $id $blksoft $blkhard $inosoft $inohard $SCRATCH_DEV
143 repquota -$type $SCRATCH_DEV | _filter_repquota 7
144
145 echo
146 echo "*** push past the soft inode limit" | tee -a $seq.full
147 _file_as_id $SCRATCH_MNT/softie1 $id $type 1024 0
148 _file_as_id $SCRATCH_MNT/softie2 $id $type 1024 0
149 _qmount
150 repquota -$type $SCRATCH_DEV | _filter_repquota 7
151
152 echo
153 echo "*** push past the soft block limit" | tee -a $seq.full
154 _file_as_id $SCRATCH_MNT/softie $id $type 1024 140
155 _qmount
156 repquota -$type $SCRATCH_DEV | _filter_repquota 7
157
158 echo
159 # Note: for quota accounting (not enforcement), EDQUOT is not expected
160 echo "*** push past the hard inode limit (expect EDQUOT)" | tee -a $seq.full
161 for i in 1 2 3 4 5 6 7 8 9 10 11 12
162 do
163         _file_as_id $SCRATCH_MNT/hard$i $id $type 1024 0
164 done
165 _qmount
166 repquota -$type $SCRATCH_DEV | _filter_repquota 7
167
168 echo
169 # Note: for quota accounting (not enforcement), EDQUOT is not expected
170 echo "*** push past the hard block limit (expect EDQUOT)" | tee -a $seq.full
171 _file_as_id $SCRATCH_MNT/softie $id $type 1024 540
172 _qmount
173 repquota -$type $SCRATCH_DEV | _filter_and_check_blocks 7
174
175
176 export -n MOUNT_OPTIONS
177
178 # success, all done
179 status=0
180 exit