3f4ec0962c5ebebac137e9a6372e54a9d0e08684
[xfstests-dev.git] / tests / generic / 219
1 #! /bin/bash
2 # FS QA Test No. 219
3 #
4 # Simple quota accounting test for direct/buffered/mmap IO.
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2009 Eric Sandeen.  All Rights Reserved.
8 #
9 # Based on test 108,
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 echo "QA output created by $seq"
30
31 here=`pwd`
32 tmp=/tmp/$$
33 status=1        # failure is the default!
34 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
35
36 # get standard environment, filters and checks
37 . ./common.rc
38 . ./common.filter
39 . ./common.quota
40
41 # real QA test starts here
42 _supported_fs generic
43 _supported_os Linux #IRIX
44 _require_scratch
45 _require_quota
46 _require_user
47 _require_group
48
49 test_files()
50 {
51         echo; echo "### create files, setting up ownership (type=$type)"
52         rm -f $SCRATCH_MNT/{buffer,direct,mmap}
53         touch $SCRATCH_MNT/{buffer,direct,mmap}
54         chown $qa_user $SCRATCH_MNT/{buffer,direct,mmap}
55         chgrp $qa_group $SCRATCH_MNT/{buffer,direct,mmap}
56         for file in $SCRATCH_MNT/{buffer,direct,mmap}; do
57                 $here/src/lstat64 $file | head -2 | _filter_scratch
58         done
59 }
60
61 check_usage()
62 {
63         wroteblocks=$1
64         wrotefiles=$2
65         read id exceed blocks bsoft bhard inodes isoft ihard
66         if [ "$blocks" -lt "$wroteblocks" ]; then
67                 echo "Too few blocks used (type=$type)"
68         # Save 5% for overhead of metadata or different block size
69         elif [ "$blocks" -gt $((wroteblocks+wroteblocks/20)) ]; then
70                 echo "Too many blocks used (type=$type)"
71         elif [ "$inodes" != "$wrotefiles" ]; then
72                 echo "Bad number of inodes used (type=$type)"
73         else
74                 echo "Usage OK (type=$type)"
75         fi
76 }
77
78 test_accounting()
79 {
80         echo "### some controlled buffered, direct and mmapd IO (type=$type)"
81         echo "--- initiating parallel IO..." >>$seq.full
82         # Small ios here because ext3 will account for indirect blocks too ...
83         # 48k will fit w/o indirect for 4k blocks (default blocksize)
84         $XFS_IO_PROG -F -c 'pwrite 0 48k' -c 'fsync' \
85                                         $SCRATCH_MNT/buffer >>$seq.full 2>&1 &
86         $XFS_IO_PROG -F -c 'pwrite 0 48k' -d \
87                                         $SCRATCH_MNT/direct >>$seq.full 2>&1 &
88         $XFS_IO_PROG -F -c 't 48k' -c 'mm -rw 0 48k' -c 'mw 0 48k' -c 'ms -s' \
89                                         $SCRATCH_MNT/mmap   >>$seq.full 2>&1 &
90         wait
91         echo "--- completed parallel IO ($type)" >>$seq.full
92
93         for file in $SCRATCH_MNT/{buffer,direct,mmap}; do
94                 $here/src/lstat64 $file | head -2 | _filter_scratch
95         done
96
97         if [ $type == 'u' ]; then
98                 id=$qa_user
99         else
100                 id=$qa_group
101         fi
102         repquota -$type $SCRATCH_MNT | grep "^$id" | check_usage 144 3
103 }
104
105 # real QA test starts here
106 rm -f $seq.full
107
108 umount $SCRATCH_DEV 2>/dev/null
109 _scratch_mkfs >> $seq.full 2>&1
110 _scratch_mount "-o usrquota,grpquota"
111 quotacheck -u -g $SCRATCH_MNT 2>/dev/null
112 quotaon $SCRATCH_MNT 2>/dev/null
113 umount $SCRATCH_DEV
114
115 echo; echo "### test user accounting"
116 export MOUNT_OPTIONS="-o usrquota"
117 _qmount
118 quotaon $SCRATCH_MNT 2>/dev/null
119 type=u
120 test_files
121 test_accounting
122 umount $SCRATCH_DEV 2>/dev/null
123
124 echo; echo "### test group accounting"
125 export MOUNT_OPTIONS="-o grpquota"
126 _qmount
127 quotaon $SCRATCH_MNT 2>/dev/null
128 type=g
129 test_files
130 test_accounting
131 umount $SCRATCH_DEV 2>/dev/null
132
133 status=0
134 exit