Update 062, because permissions now enforced in VFS and symlink/dev attrs are disallowed.
[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) uquota, gquota, uqnoenforce, gqnoenforce
7 #
8 #-----------------------------------------------------------------------
9 # Copyright (c) 2000-2002 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
22 # get standard environment, filters and checks
23 . ./common.rc
24 . ./common.filter
25 . ./common.quota
26
27 _cleanup()
28 {
29         cd /
30         echo; echo "*** unmount"
31         umount $SCRATCH_MNT 2>/dev/null
32         rm -f $tmp.*
33 }
34 trap "_cleanup; exit \$status" 0 1 2 3 15
35
36
37 # real QA test starts here
38 _supported_fs xfs
39 _supported_os Linux IRIX
40
41 rm -f $seq.out
42 cp /dev/null $seq.full
43 chmod a+rwx $seq.full   # arbitrary users will write here
44
45 _require_scratch
46 _require_quota
47
48 # setup a default run
49 [ -z "$MOUNT_OPTIONS" ] && export MOUNT_OPTIONS="-o uquota"
50
51 bsoft=100
52 bhard=500
53 isoft=4
54 ihard=10
55
56 _filter_report()
57 {
58         tr -s '[:space:]' | sed -e "s/^\#$id /[NAME] /g" -e "s/^#0 /[ROOT] /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 _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
83 cat $tmp.mkfs >>$seq.full
84
85 # keep the blocksize and data size for dd later
86 . $tmp.mkfs
87
88 _qmount
89
90 # Figure out whether we're doing large allocations
91 # (bail out if they're so large they stuff the test up)
92 _test_inode_flag extsz-inherit $SCRATCH_MNT
93 noextsz=$?
94 extsize=`_test_inode_extsz $SCRATCH_MNT`
95 [ $extsize -ge 512000 ] && \
96         _notrun "Extent size hint is too large ($extsize bytes)"
97
98 _qsetup
99
100 echo "Using output from '" `ls -l $seq.out` "'" >>$seq.full
101 echo "and using type=$type id=$id" >>$seq.full
102
103 echo
104 echo "*** report no quota settings" | tee -a $seq.full
105 xfs_quota -x -c "repquota -birnN -$type" $SCRATCH_DEV | _filter_report
106
107 echo
108 echo "*** report initial settings" | tee -a $seq.full
109 _file_as_id $SCRATCH_MNT/initme $id $type 1024 0
110 echo "ls -l $SCRATCH_MNT" >>$seq.full
111 ls -l $SCRATCH_MNT >>$seq.full
112 xfs_quota -x \
113         -c "limit -$type bsoft=${bsoft}k bhard=${bhard}k $id" \
114         -c "limit -$type isoft=$isoft ihard=$ihard $id" \
115         $SCRATCH_DEV
116 xfs_quota -x -c "repquota -birnN -$type" $SCRATCH_DEV | _filter_report
117
118 echo
119 echo "*** push past the soft inode limit" | tee -a $seq.full
120 _file_as_id $SCRATCH_MNT/softie1 $id $type 1024 0
121 _file_as_id $SCRATCH_MNT/softie2 $id $type 1024 0
122 _qmount
123 xfs_quota -x -c "repquota -birnN -$type" $SCRATCH_DEV | _filter_report
124
125 echo
126 echo "*** push past the soft block limit" | tee -a $seq.full
127 _file_as_id $SCRATCH_MNT/softie $id $type 1024 140
128 _qmount
129 xfs_quota -x -c "repquota -birnN -$type" $SCRATCH_DEV | _filter_report
130
131 echo
132 # Note: for quota accounting (not enforcement), EDQUOT is not expected
133 echo "*** push past the hard inode limit (expect EDQUOT)" | tee -a $seq.full
134 for i in 1 2 3 4 5 6 7 8 9 10 11 12
135 do
136         _file_as_id $SCRATCH_MNT/hard$i $id $type 1024 0
137 done
138 _qmount
139 xfs_quota -x -c "repquota -birnN -$type" $SCRATCH_DEV | _filter_report
140
141 echo
142 # Note: for quota accounting (not enforcement), EDQUOT is not expected
143 echo "*** push past the hard block limit (expect EDQUOT)" | tee -a $seq.full
144 _file_as_id $SCRATCH_MNT/softie $id $type 1024 540
145 echo "ls -l $SCRATCH_MNT" >>$seq.full
146 ls -l $SCRATCH_MNT >>$seq.full
147 _qmount
148 xfs_quota -x -c "repquota -birnN -$type" $SCRATCH_DEV | _filter_and_check_blks
149
150 # success, all done
151 status=0
152 exit