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