xfstests: include test subdirectory support
[xfstests-dev.git] / 230
1 #! /bin/bash
2 # FS QA Test No. 230
3 #
4 # Simple quota enforcement test.
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2010 Jan Kara.  All Rights Reserved.
8 #
9 # Based on test 219,
10 # Copyright (c) 2005 Silicon Graphics, Inc.  All Rights Reserved.
11 #
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License as
14 # published by the Free Software Foundation.
15 #
16 # This program is distributed in the hope that it would be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write the Free Software Foundation,
23 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24 #
25 #-----------------------------------------------------------------------
26 #
27
28 seq=`basename $0`
29 echo "QA output created by $seq"
30
31 here=`pwd`
32 tmp=/tmp/$$
33 status=1        # failure is the default!
34 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
35
36 # get standard environment, filters and checks
37 . ./common.rc
38 . ./common.filter
39 . ./common.quota
40
41 # real QA test starts here
42 _supported_fs generic
43 _supported_os Linux #IRIX
44 _require_scratch
45 _require_quota
46 _require_user
47 _need_to_be_root
48
49 test_files()
50 {
51         echo; echo "### create files, setting up ownership (type=$type)"
52         touch $SCRATCH_MNT/file{1,2} 2>/dev/null
53         chown $qa_user $SCRATCH_MNT/file{1,2} 2>/dev/null
54         chgrp $qa_user $SCRATCH_MNT/file{1,2} 2>/dev/null
55         chmod 777 $SCRATCH_MNT 2>/dev/null
56 }
57
58 test_enforcement()
59 {
60         echo "### some buffered IO (type=$type)"
61         echo "--- initiating IO..." >>$seq.full
62         # Firstly fit below block soft limit
63         echo "Write 900k..."
64         su $qa_user -c "$XFS_IO_PROG -F -c 'pwrite 0 900k' -c fsync \
65                 $SCRATCH_MNT/file1" 2>&1 >>$seq.full | tee -a $seq.full
66         repquota -$type $SCRATCH_MNT  | grep -v "^root" >>$seq.full 2>&1
67         # Secondly overcome block soft limit
68         echo "Rewrite 1001k..."
69         su $qa_user -c "$XFS_IO_PROG -F -c 'pwrite 0 1001k' -c fsync \
70                 $SCRATCH_MNT/file1" 2>&1 >>$seq.full | tee -a $seq.full
71         repquota -$type $SCRATCH_MNT  | grep -v "^root" >>$seq.full 2>&1
72         # Now try to overcome block hardlimit
73         echo "Write 1000k..."
74         su $qa_user -c "$XFS_IO_PROG -F -c 'pwrite 0 1000k' -c fsync \
75                 $SCRATCH_MNT/file2" 2>&1 >>$seq.full | tee -a $seq.full
76         repquota -$type $SCRATCH_MNT  | grep -v "^root" >>$seq.full 2>&1
77         # Now sleep for grace time and check that softlimit got enforced
78         sleep $((grace+1))
79         echo "Write 4096..."
80         su $qa_user -c "$XFS_IO_PROG -F -c 'truncate 0' -c 'pwrite 0 4096' \
81                 $SCRATCH_MNT/file2" 2>&1 >>$seq.full | tee -a $seq.full
82         repquota -$type $SCRATCH_MNT  | grep -v "^root" >>$seq.full 2>&1
83         # And now the softlimit test for inodes
84         # First reset space limits so that we don't have problems with
85         # space reservations on XFS
86         setquota -$type $qa_user 0 0 3 5 $SCRATCH_MNT
87         echo "Touch 3+4"
88         su $qa_user -c "touch $SCRATCH_MNT/file3 $SCRATCH_MNT/file4" \
89                 2>&1 >>$seq.full | _filter_scratch | tee -a $seq.full
90         repquota -$type $SCRATCH_MNT  | grep -v "^root" >>$seq.full 2>&1
91         # Try to exceed inode hardlimit
92         echo "Touch 5+6"
93         su $qa_user -c "touch $SCRATCH_MNT/file5 $SCRATCH_MNT/file6" \
94                 2>&1 >>$seq.full | _filter_scratch | tee -a $seq.full
95         repquota -$type $SCRATCH_MNT  | grep -v "^root" >>$seq.full 2>&1
96         # Wait and check grace time enforcement
97         rm -f $SCRATCH_MNT/file5 >>$seq.full 2>&1
98         sleep $((grace+1))
99         echo "Touch 5"
100         su $qa_user -c "touch $SCRATCH_MNT/file5" 2>&1 >>$seq.full |
101                 _filter_scratch | tee -a $seq.full
102         repquota -$type $SCRATCH_MNT  | grep -v "^root" >>$seq.full 2>&1
103         echo "--- completed IO ($type)" >>$seq.full
104 }
105
106 cleanup_files()
107 {
108         rm -f $SCRATCH_MNT/file{1,2,3,4,5,6}
109 }
110
111 # real QA test starts here
112 rm -f $seq.full
113
114 grace=2
115
116 _scratch_mkfs >> $seq.full 2>&1
117 _scratch_mount "-o usrquota,grpquota"
118 quotacheck -u -g $SCRATCH_MNT 2>/dev/null
119 quotaon $SCRATCH_MNT 2>/dev/null
120 setquota -u $qa_user 1000 2000 3 5 $SCRATCH_MNT
121 setquota -u -t $grace $grace $SCRATCH_MNT
122 setquota -g $qa_user 1000 2000 3 5 $SCRATCH_MNT
123 setquota -g -t $grace $grace $SCRATCH_MNT
124 umount $SCRATCH_DEV
125
126 echo; echo "### test user limit enforcement"
127 _scratch_mount "-o usrquota"
128 quotaon $SCRATCH_MNT 2>/dev/null
129 type=u
130 test_files
131 test_enforcement
132 cleanup_files
133 umount $SCRATCH_DEV 2>/dev/null
134
135 echo; echo "### test group limit enforcement"
136 _scratch_mount "-o grpquota"
137 quotaon $SCRATCH_MNT 2>/dev/null
138 type=g
139 test_files
140 test_enforcement
141 cleanup_files
142 umount $SCRATCH_DEV 2>/dev/null
143
144 status=0
145 exit