generic/405: test mkfs against thin provision device
[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
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..." >>$seqres.full
62         # Firstly fit below block soft limit
63         echo "Write 900k..."
64         su $qa_user -c "$XFS_IO_PROG -c 'pwrite 0 900k' -c fsync \
65                 $SCRATCH_MNT/file1" 2>&1 >>$seqres.full | \
66                 _filter_xfs_io_error | 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 | \
72                 _filter_xfs_io_error | tee -a $seqres.full
73         repquota -$type $SCRATCH_MNT  | grep -v "^root" >>$seqres.full 2>&1
74         # Now try to overcome block hardlimit
75         echo "Write 1000k..."
76         su $qa_user -c "$XFS_IO_PROG -c 'pwrite 0 1000k' -c fsync \
77                 $SCRATCH_MNT/file2" 2>&1 >>$seqres.full | \
78                 _filter_xfs_io_error | 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 -c 'truncate 0' -c 'pwrite 0 4096' \
84                 $SCRATCH_MNT/file2" 2>&1 >>$seqres.full | \
85                 _filter_xfs_io_error | tee -a $seqres.full
86         repquota -$type $SCRATCH_MNT  | grep -v "^root" >>$seqres.full 2>&1
87         # And now the softlimit test for inodes
88         # First reset space limits so that we don't have problems with
89         # space reservations on XFS
90         setquota -$type $qa_user 0 0 3 5 $SCRATCH_MNT
91         echo "Touch 3+4"
92         su $qa_user -c "touch $SCRATCH_MNT/file3 $SCRATCH_MNT/file4" \
93                 2>&1 >>$seqres.full | _filter_scratch | tee -a $seqres.full
94         repquota -$type $SCRATCH_MNT  | grep -v "^root" >>$seqres.full 2>&1
95         # Try to exceed inode hardlimit
96         echo "Touch 5+6"
97         su $qa_user -c "touch $SCRATCH_MNT/file5 $SCRATCH_MNT/file6" \
98                 2>&1 >>$seqres.full | _filter_scratch | tee -a $seqres.full
99         repquota -$type $SCRATCH_MNT  | grep -v "^root" >>$seqres.full 2>&1
100         # Wait and check grace time enforcement
101         rm -f $SCRATCH_MNT/file5 >>$seqres.full 2>&1
102         sleep $((grace+1))
103         echo "Touch 5"
104         su $qa_user -c "touch $SCRATCH_MNT/file5" 2>&1 >>$seqres.full |
105                 _filter_scratch | tee -a $seqres.full
106         repquota -$type $SCRATCH_MNT  | grep -v "^root" >>$seqres.full 2>&1
107         echo "--- completed IO ($type)" >>$seqres.full
108 }
109
110 cleanup_files()
111 {
112         rm -f $SCRATCH_MNT/file{1,2,3,4,5,6}
113 }
114
115 # real QA test starts here
116 rm -f $seqres.full
117
118 grace=2
119
120 _scratch_mkfs >> $seqres.full 2>&1
121 _scratch_mount "-o usrquota,grpquota"
122 quotacheck -u -g $SCRATCH_MNT 2>/dev/null
123 quotaon $SCRATCH_MNT 2>/dev/null
124 setquota -u $qa_user 1000 2000 3 5 $SCRATCH_MNT
125 setquota -u -t $grace $grace $SCRATCH_MNT
126 setquota -g $qa_user 1000 2000 3 5 $SCRATCH_MNT
127 setquota -g -t $grace $grace $SCRATCH_MNT
128 _scratch_unmount
129
130 echo; echo "### test user limit enforcement"
131 _scratch_mount "-o usrquota"
132 quotaon $SCRATCH_MNT 2>/dev/null
133 type=u
134 test_files
135 test_enforcement
136 cleanup_files
137 _scratch_unmount 2>/dev/null
138
139 echo; echo "### test group limit enforcement"
140 _scratch_mount "-o grpquota"
141 quotaon $SCRATCH_MNT 2>/dev/null
142 type=g
143 test_files
144 test_enforcement
145 cleanup_files
146 _scratch_unmount 2>/dev/null
147
148 status=0
149 exit