Modified devices for cxfsaltix5
[xfstests-dev.git] / 050
1 #! /bin/sh
2 # FS QA Test No. 050
3 #
4 # Exercises basic XFS quota functionality
5 #       uquota, gquota, uqnoenforce, gqnoenforce, pquota, pqnoenforce
6 #
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
9 #-----------------------------------------------------------------------
10 #
11 # creator
12 owner=nathans@sgi.com
13
14 seq=`basename $0`
15 echo "QA output created by $seq"
16
17 here=`pwd`
18 tmp=/tmp/$$
19 status=1        # failure is the default!
20
21 # get standard environment, filters and checks
22 . ./common.rc
23 . ./common.filter
24 . ./common.quota
25
26 _cleanup()
27 {
28         cd /
29         umount $SCRATCH_MNT 2>/dev/null
30         rm -f $tmp.*
31 }
32 trap "_cleanup; exit \$status" 0 1 2 3 15
33
34
35 # real QA test starts here
36 _supported_fs xfs
37 _supported_os Linux IRIX
38
39
40 cp /dev/null $seq.full
41 chmod a+rwx $seq.full   # arbitrary users will write here
42
43 _require_scratch
44 _require_quota
45
46 bsoft=100
47 bhard=500
48 isoft=4
49 ihard=10
50
51
52 _filter_report()
53 {
54         tr -s '[:space:]' | \
55         perl -npe '
56                 s/^\#'$id' /[NAME] /g;
57                 s/^\#0 \d+ /[ROOT] 0 /g;
58                 s/6 days/7 days/g'
59 }
60
61 # The actual point at which limit enforcement takes place for the
62 # hard block limit is variable depending on filesystem blocksize,
63 # and iosize.  What we want to test is that the limit is enforced
64 # (ie. blksize less than limit but not unduly less - ~85% is kind)
65 # nowadays we actually get much closer to the limit before EDQUOT.
66 #
67 _filter_and_check_blks()
68 {
69         perl -npe '
70                 if (/^\#'$id'\s+(\d+)/ && '$enforce') {
71                         $maximum = '$bhard';
72                         $minimum = '$bhard' * 85/100;
73                         if (($1 < $minimum || $1 > $maximum) && '$noextsz') {
74                                 printf(" URK %d: %d is out of range! [%d,%d]\n",
75                                         '$id', $1, $minimum, $maximum);
76                         }
77                         s/^(\#'$id'\s+)(\d+)/\1 =OK=/g;
78                 }
79         ' | _filter_report
80 }
81
82 _exercise()
83 {
84         _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
85         cat $tmp.mkfs >>$seq.full
86
87         # keep the blocksize and data size for dd later
88         . $tmp.mkfs
89
90         _qmount
91
92         # Figure out whether we're doing large allocations
93         # (bail out if they're so large they stuff the test up)
94         _test_inode_flag extsz-inherit $SCRATCH_MNT
95         noextsz=$?
96         extsize=`_test_inode_extsz $SCRATCH_MNT`
97         [ $extsize -ge 512000 ] && \
98                 _notrun "Extent size hint is too large ($extsize bytes)"
99
100         _qsetup
101
102         echo "Using output from '" `ls -l $seq.out` "'" >>$seq.full
103         echo "and using type=$type id=$id" >>$seq.full
104
105         echo
106         echo "*** report no quota settings" | tee -a $seq.full
107         xfs_quota -D $tmp.projects -P $tmp.projid -x -c "repquota -birnN -$type" $SCRATCH_DEV | _filter_report | LC_COLLATE=POSIX sort -r
108
109         echo
110         echo "*** report initial settings" | tee -a $seq.full
111         _file_as_id $SCRATCH_MNT/initme $id $type 1024 0
112         echo "ls -l $SCRATCH_MNT" >>$seq.full
113         ls -l $SCRATCH_MNT >>$seq.full
114         xfs_quota -D $tmp.projects -P $temp.projid -x \
115                 -c "limit -$type bsoft=${bsoft}k bhard=${bhard}k $id" \
116                 -c "limit -$type isoft=$isoft ihard=$ihard $id" \
117                 $SCRATCH_DEV
118         xfs_quota -D $tmp.projects -P $tmp.projid -x -c "repquota -birnN -$type" $SCRATCH_DEV | _filter_report | LC_COLLATE=POSIX sort -r
119
120         echo
121         echo "*** push past the soft inode limit" | tee -a $seq.full
122         _file_as_id $SCRATCH_MNT/softie1 $id $type 1024 0
123         _file_as_id $SCRATCH_MNT/softie2 $id $type 1024 0
124         _qmount
125         xfs_quota -D $tmp.projects -P $tmp.projid -x -c "repquota -birnN -$type" $SCRATCH_DEV | _filter_report | LC_COLLATE=POSIX sort -r
126
127         echo
128         echo "*** push past the soft block limit" | tee -a $seq.full
129         _file_as_id $SCRATCH_MNT/softie $id $type 1024 140
130         _qmount
131         xfs_quota -D $tmp.projects -P $tmp.projid -x -c "repquota -birnN -$type" $SCRATCH_DEV | _filter_report | LC_COLLATE=POSIX sort -r
132
133         echo
134         # Note: for quota accounting (not enforcement), EDQUOT is not expected
135         echo "*** push past the hard inode limit (expect EDQUOT)" | tee -a $seq.full
136         for i in 1 2 3 4 5 6 7 8 9 10 11 12
137         do
138                 _file_as_id $SCRATCH_MNT/hard$i $id $type 1024 0
139         done
140         _qmount
141         xfs_quota -D $tmp.projects -P $tmp.projid -x -c "repquota -birnN -$type" $SCRATCH_DEV | _filter_report | LC_COLLATE=POSIX sort -r
142
143         echo
144         # Note: for quota accounting (not enforcement), EDQUOT is not expected
145         echo "*** push past the hard block limit (expect EDQUOT)" | tee -a $seq.full
146         _file_as_id $SCRATCH_MNT/softie $id $type 1024 540
147         echo "ls -l $SCRATCH_MNT" >>$seq.full
148         ls -l $SCRATCH_MNT >>$seq.full
149         _qmount
150         xfs_quota -D $tmp.projects -P $tmp.projid -x -c "repquota -birnN -$type" $SCRATCH_DEV | _filter_and_check_blks | LC_COLLATE=POSIX sort -r
151
152         echo
153         echo "*** unmount"
154         umount $SCRATCH_MNT
155
156 }
157
158
159 #ensures only one quota mount option is specified
160 _qmount_option()
161 {
162         #replace any user defined quota options
163         export MOUNT_OPTIONS=`echo $MOUNT_OPTIONS \
164         | sed -e 's/uquota/$q_opt/g' \
165                 -e 's/gquota/$q_opt/g' \
166                 -e 's/pquota/$q_opt/g' \
167                 -e 's/quota/$q_opt/g' \
168                 -e 's/uqnoenforce/$q_opt/g' \
169                 -e 's/gqnoenforce/$q_opt/g' \
170                 -e 's/pqnoenforce/$q_opt/g' \
171                 -e 's/qnoenforce/$q_opt/g' \
172         | sed 's/$q_opt/'$1'/g'`
173
174         #check $q_opt is in new mount options
175         echo $MOUNT_OPTIONS | grep "$1" > /dev/null 2>&1
176         [ "$?" -eq 0 ] || export MOUNT_OPTIONS="$MOUNT_OPTIONS -o $1"
177 }
178
179 cat >$tmp.projects <<EOF
180 1:$SCRATCH_MNT
181 EOF
182
183 cat >$tmp.projid <<EOF
184 root:0
185 scrach:1
186 EOF
187
188 projid_file="$tmp.projid"
189
190 echo "*** user"
191 if [ "$HOSTOS" == "IRIX" ]
192 then
193         _qmount_option "quota"
194 else
195         _qmount_option "uquota"
196 fi
197 _exercise
198
199 echo "*** group"
200 _qmount_option "gquota"
201 _exercise
202
203 echo "*** uqnoenforce"
204 if [ "$HOSTOS" == "IRIX" ]
205 then
206         _qmount_option "qnoenforce"
207 else
208         _qmount_option "uqnoenforce"
209 fi
210 _exercise
211
212 echo "*** gqnoenforce"
213 _qmount_option "gqnoenforce"
214 _exercise
215
216 echo "*** pquota"
217 _qmount_option "pquota"
218 _exercise
219
220 echo "*** pqnoenforce"
221 _qmount_option "pqnoenforce"
222 _exercise
223
224 # success, all done
225 status=0
226 exit