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