Fix compilation error with recent XFS headers.
[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 blksoft=100
52 blkhard=500
53 inosoft=4
54 inohard=10
55
56 # The actual point at which limit enforcement takes place for the
57 # hard block limit is variable depending on filesystem blocksize,
58 # and iosize.  What we want to test is that the limit is enforced
59 # (ie. blksize less than limit but not unduly less - ~85% is kind)
60 # nowadays we actually get much closer to the limit before EDQUOT.
61
62 _filter_and_check_blocks()
63 {
64         perl -npe '
65                 if (/^'$name'\s+([-|+]){2}\s+(\d+)/ && '$enforce') {
66                         $maximum = '$blkhard';
67                         $minimum = '$blkhard' * 85/100;
68                         if ($2 < $minimum || $2 > $maximum) {
69                                 printf(" URK - %d is out of range! [%d,%d] \n",
70                                         $2, $minimum, $maximum);
71                         }
72                         s/^('$name'\s+[-|+][-|+]\s+)(\d+)/\1 OK/g;
73                 }
74         ' | _filter_repquota
75 }
76
77 _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
78 cat $tmp.mkfs >>$seq.full
79
80 # keep the blocksize and data size for dd later
81 . $tmp.mkfs
82
83 _qmount
84
85 # Irix uses filesystem name and Linux uses device of filesystem
86 if [ $HOSTOS = "Linux" ]; then
87     QUOTA_FS=$SCRATCH_DEV
88 else
89     QUOTA_FS=$SCRATCH_MNT
90 fi
91
92 _qsetup
93
94 echo "Using output from '" `ls -l $seq.out` "'" >>$seq.full
95 echo "and using type=$type id=$id" >>$seq.full
96
97 echo
98 echo "*** report no quota settings" | tee -a $seq.full
99 _repquota -$type $QUOTA_FS | _filter_repquota
100
101 echo
102 echo "*** report initial settings" | tee -a $seq.full
103 _file_as_id $SCRATCH_MNT/initme $id $type 1024 0
104 echo "ls -l $SCRATCH_MNT" >>$seq.full
105 ls -l $SCRATCH_MNT >>$seq.full
106 _setquota -$type $id $blksoft $blkhard $inosoft $inohard $QUOTA_FS
107 _repquota -$type $QUOTA_FS | _filter_repquota
108
109 echo
110 echo "*** push past the soft inode limit" | tee -a $seq.full
111 _file_as_id $SCRATCH_MNT/softie1 $id $type 1024 0
112 _file_as_id $SCRATCH_MNT/softie2 $id $type 1024 0
113 _qmount
114 _repquota -$type $QUOTA_FS | _filter_repquota
115
116 echo
117 echo "*** push past the soft block limit" | tee -a $seq.full
118 _file_as_id $SCRATCH_MNT/softie $id $type 1024 140
119 _qmount
120 _repquota -$type $QUOTA_FS | _filter_repquota
121
122 echo
123 # Note: for quota accounting (not enforcement), EDQUOT is not expected
124 echo "*** push past the hard inode limit (expect EDQUOT)" | tee -a $seq.full
125 for i in 1 2 3 4 5 6 7 8 9 10 11 12
126 do
127         _file_as_id $SCRATCH_MNT/hard$i $id $type 1024 0
128 done
129 _qmount
130 _repquota -$type $QUOTA_FS | _filter_repquota
131
132 echo
133 # Note: for quota accounting (not enforcement), EDQUOT is not expected
134 echo "*** push past the hard block limit (expect EDQUOT)" | tee -a $seq.full
135 _file_as_id $SCRATCH_MNT/softie $id $type 1024 540
136 echo "ls -l $SCRATCH_MNT" >>$seq.full
137 ls -l $SCRATCH_MNT >>$seq.full
138 _qmount
139 _repquota -$type $QUOTA_FS | _filter_and_check_blocks
140
141
142 # success, all done
143 status=0
144 exit