generic: add _require_odirect to generic/113 and generic/214
[xfstests-dev.git] / tests / generic / 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 seqres=$RESULT_DIR/$seq
30 echo "QA output created by $seq"
31
32 here=`pwd`
33 tmp=/tmp/$$
34 status=1        # failure is the default!
35 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
36
37 # get standard environment, filters and checks
38 . ./common/rc
39 . ./common/filter
40 . ./common/quota
41
42 # real QA test starts here
43 _supported_fs generic
44 _supported_os Linux #IRIX
45 _require_scratch
46 _require_quota
47 _require_user
48 _need_to_be_root
49
50 test_files()
51 {
52         echo; echo "### create files, setting up ownership (type=$type)"
53         touch $SCRATCH_MNT/file{1,2} 2>/dev/null
54         chown $qa_user $SCRATCH_MNT/file{1,2} 2>/dev/null
55         chgrp $qa_user $SCRATCH_MNT/file{1,2} 2>/dev/null
56         chmod 777 $SCRATCH_MNT 2>/dev/null
57 }
58
59 test_enforcement()
60 {
61         echo "### some buffered IO (type=$type)"
62         echo "--- initiating IO..." >>$seqres.full
63         # Firstly fit below block soft limit
64         echo "Write 900k..."
65         su $qa_user -c "$XFS_IO_PROG -c 'pwrite 0 900k' -c fsync \
66                 $SCRATCH_MNT/file1" 2>&1 >>$seqres.full | tee -a $seqres.full
67         repquota -$type $SCRATCH_MNT  | grep -v "^root" >>$seqres.full 2>&1
68         # Secondly overcome block soft limit
69         echo "Rewrite 1001k..."
70         su $qa_user -c "$XFS_IO_PROG -c 'pwrite 0 1001k' -c fsync \
71                 $SCRATCH_MNT/file1" 2>&1 >>$seqres.full | tee -a $seqres.full
72         repquota -$type $SCRATCH_MNT  | grep -v "^root" >>$seqres.full 2>&1
73         # Now try to overcome block hardlimit
74         echo "Write 1000k..."
75         su $qa_user -c "$XFS_IO_PROG -c 'pwrite 0 1000k' -c fsync \
76                 $SCRATCH_MNT/file2" 2>&1 >>$seqres.full | tee -a $seqres.full
77         repquota -$type $SCRATCH_MNT  | grep -v "^root" >>$seqres.full 2>&1
78         # Now sleep for grace time and check that softlimit got enforced
79         sleep $((grace+1))
80         echo "Write 4096..."
81         su $qa_user -c "$XFS_IO_PROG -c 'truncate 0' -c 'pwrite 0 4096' \
82                 $SCRATCH_MNT/file2" 2>&1 >>$seqres.full | tee -a $seqres.full
83         repquota -$type $SCRATCH_MNT  | grep -v "^root" >>$seqres.full 2>&1
84         # And now the softlimit test for inodes
85         # First reset space limits so that we don't have problems with
86         # space reservations on XFS
87         setquota -$type $qa_user 0 0 3 5 $SCRATCH_MNT
88         echo "Touch 3+4"
89         su $qa_user -c "touch $SCRATCH_MNT/file3 $SCRATCH_MNT/file4" \
90                 2>&1 >>$seqres.full | _filter_scratch | tee -a $seqres.full
91         repquota -$type $SCRATCH_MNT  | grep -v "^root" >>$seqres.full 2>&1
92         # Try to exceed inode hardlimit
93         echo "Touch 5+6"
94         su $qa_user -c "touch $SCRATCH_MNT/file5 $SCRATCH_MNT/file6" \
95                 2>&1 >>$seqres.full | _filter_scratch | tee -a $seqres.full
96         repquota -$type $SCRATCH_MNT  | grep -v "^root" >>$seqres.full 2>&1
97         # Wait and check grace time enforcement
98         rm -f $SCRATCH_MNT/file5 >>$seqres.full 2>&1
99         sleep $((grace+1))
100         echo "Touch 5"
101         su $qa_user -c "touch $SCRATCH_MNT/file5" 2>&1 >>$seqres.full |
102                 _filter_scratch | tee -a $seqres.full
103         repquota -$type $SCRATCH_MNT  | grep -v "^root" >>$seqres.full 2>&1
104         echo "--- completed IO ($type)" >>$seqres.full
105 }
106
107 cleanup_files()
108 {
109         rm -f $SCRATCH_MNT/file{1,2,3,4,5,6}
110 }
111
112 # real QA test starts here
113 rm -f $seqres.full
114
115 grace=2
116
117 _scratch_mkfs >> $seqres.full 2>&1
118 _scratch_mount "-o usrquota,grpquota"
119 quotacheck -u -g $SCRATCH_MNT 2>/dev/null
120 quotaon $SCRATCH_MNT 2>/dev/null
121 setquota -u $qa_user 1000 2000 3 5 $SCRATCH_MNT
122 setquota -u -t $grace $grace $SCRATCH_MNT
123 setquota -g $qa_user 1000 2000 3 5 $SCRATCH_MNT
124 setquota -g -t $grace $grace $SCRATCH_MNT
125 _scratch_unmount
126
127 echo; echo "### test user limit enforcement"
128 _scratch_mount "-o usrquota"
129 quotaon $SCRATCH_MNT 2>/dev/null
130 type=u
131 test_files
132 test_enforcement
133 cleanup_files
134 _scratch_unmount 2>/dev/null
135
136 echo; echo "### test group limit enforcement"
137 _scratch_mount "-o grpquota"
138 quotaon $SCRATCH_MNT 2>/dev/null
139 type=g
140 test_files
141 test_enforcement
142 cleanup_files
143 _scratch_unmount 2>/dev/null
144
145 status=0
146 exit