2b75b89440080ac0a7d8c5870594999fad0b0076
[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 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 _require_group
49
50 test_files()
51 {
52         echo; echo "### create files, setting up ownership (type=$type)"
53         rm -f $SCRATCH_MNT/{buffer,direct,mmap}
54         touch $SCRATCH_MNT/{buffer,direct,mmap}
55         chown $qa_user $SCRATCH_MNT/{buffer,direct,mmap}
56         chgrp $qa_group $SCRATCH_MNT/{buffer,direct,mmap}
57         for file in $SCRATCH_MNT/{buffer,direct,mmap}; do
58                 $here/src/lstat64 $file | head -2 | _filter_scratch
59         done
60 }
61
62 check_usage()
63 {
64         wroteblocks=$1
65         wrotefiles=$2
66         read id exceed blocks bsoft bhard inodes isoft ihard
67         if [ "$blocks" -lt "$wroteblocks" ]; then
68                 echo "Too few blocks used (type=$type)"
69         # Save 5% for overhead of metadata or different block size
70         elif [ "$blocks" -gt $((wroteblocks+wroteblocks/20)) ]; then
71                 echo "Too many blocks used (type=$type)"
72         elif [ "$inodes" != "$wrotefiles" ]; then
73                 echo "Bad number of inodes used (type=$type)"
74         else
75                 echo "Usage OK (type=$type)"
76         fi
77 }
78
79 test_accounting()
80 {
81         echo "### some controlled buffered, direct and mmapd IO (type=$type)"
82         echo "--- initiating parallel IO..." >>$seqres.full
83         # Small ios here because ext3 will account for indirect blocks too ...
84         # 48k will fit w/o indirect for 4k blocks (default blocksize)
85         $XFS_IO_PROG -c 'pwrite 0 48k' -c 'fsync' \
86                                         $SCRATCH_MNT/buffer >>$seqres.full 2>&1 &
87         $XFS_IO_PROG -c 'pwrite 0 48k' -d \
88                                         $SCRATCH_MNT/direct >>$seqres.full 2>&1 &
89         $XFS_IO_PROG -c 't 48k' -c 'mm -rw 0 48k' -c 'mw 0 48k' -c 'ms -s' \
90                                         $SCRATCH_MNT/mmap   >>$seqres.full 2>&1 &
91         wait
92         echo "--- completed parallel IO ($type)" >>$seqres.full
93
94         for file in $SCRATCH_MNT/{buffer,direct,mmap}; do
95                 $here/src/lstat64 $file | head -2 | _filter_scratch
96         done
97
98         if [ $type == 'u' ]; then
99                 id=$qa_user
100         else
101                 id=$qa_group
102         fi
103         repquota -$type $SCRATCH_MNT | grep "^$id" | check_usage 144 3
104 }
105
106 # real QA test starts here
107 rm -f $seqres.full
108
109 umount $SCRATCH_DEV 2>/dev/null
110 _scratch_mkfs >> $seqres.full 2>&1
111 _scratch_mount "-o usrquota,grpquota"
112 quotacheck -u -g $SCRATCH_MNT 2>/dev/null
113 quotaon $SCRATCH_MNT 2>/dev/null
114 umount $SCRATCH_DEV
115
116 echo; echo "### test user accounting"
117 export MOUNT_OPTIONS="-o usrquota"
118 _qmount
119 quotaon $SCRATCH_MNT 2>/dev/null
120 type=u
121 test_files
122 test_accounting
123 umount $SCRATCH_DEV 2>/dev/null
124
125 echo; echo "### test group accounting"
126 export MOUNT_OPTIONS="-o grpquota"
127 _qmount
128 quotaon $SCRATCH_MNT 2>/dev/null
129 type=g
130 test_files
131 test_accounting
132 umount $SCRATCH_DEV 2>/dev/null
133
134 status=0
135 exit