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