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