7fa200af38aea5ee5821d8bde881c626b2efea99
[xfstests-dev.git] / 108
1 #! /bin/bash
2 # FS QA Test No. 108
3 #
4 # Simple quota accounting test for direct/buffered/mmap IO.
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2005 Silicon Graphics, Inc.  All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #
22 #-----------------------------------------------------------------------
23 #
24 # creator
25 owner=nathans@sgi.com
26
27 seq=`basename $0`
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=1        # failure is the default!
33 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
34
35 # get standard environment, filters and checks
36 . ./common.rc
37 . ./common.filter
38 . ./common.quota
39
40 filter_scratch()
41 {
42         perl -ne "
43 s,$SCRATCH_MNT,[SCR_MNT],;
44 s,$SCRATCH_DEV,[SCR_DEV],;
45         print;"
46 }
47
48 # real QA test starts here
49 _supported_fs xfs
50 _supported_os Linux #IRIX
51 _require_scratch
52 _require_xfs_quota
53
54 test_files()
55 {
56         echo; echo "### create files, setting up ownership (type=$type)"
57         rm -f $SCRATCH_MNT/{buffer,direct,mmap}
58         $XFS_IO_PROG -fc "chproj $prid" $SCRATCH_MNT/{buffer,direct,mmap}
59         chown $uid $SCRATCH_MNT/{buffer,direct,mmap}
60         chgrp $gid $SCRATCH_MNT/{buffer,direct,mmap}
61         for file in $SCRATCH_MNT/{buffer,direct,mmap}; do
62                 $here/src/lstat64 $file | head -3 | filter_scratch
63                 $XFS_IO_PROG -c lsproj $file
64         done
65 }
66
67 test_accounting()
68 {
69         echo "### some controlled buffered, direct and mmapd IO (type=$type)"
70         echo "--- initiating parallel IO..." >>$seq.full
71         $XFS_IO_PROG -c 'pwrite -b 1m 0 16m' -c 'fsync' \
72                                         $SCRATCH_MNT/buffer >>$seq.full 2>&1 &
73         $XFS_IO_PROG -c 'pwrite -b 1m 0 16m' -d \
74                                         $SCRATCH_MNT/direct >>$seq.full 2>&1 &
75         $XFS_IO_PROG -c 't 16m' -c 'mm -rw 0 16m' -c 'mw 0 16m' -c 'ms -s' \
76                                         $SCRATCH_MNT/mmap   >>$seq.full 2>&1 &
77         wait
78         echo "--- completed parallel IO ($type)" >>$seq.full
79
80         for file in $SCRATCH_MNT/{buffer,direct,mmap}; do
81                 $here/src/lstat64 $file | head -3 | filter_scratch
82         done
83         xfs_quota -c "quota -hnb -$type $id" $QARGS | filter_scratch
84         xfs_quota -c "quota -hni -$type $id" $QARGS | filter_scratch
85         xfs_quota -c "quota -hnr -$type $id" $QARGS | filter_scratch
86 }
87
88 export MOUNT_OPTIONS="-opquota"
89 _qmount
90 _require_prjquota $SCRATCH_DEV
91
92 # real QA test starts here
93 rm -f $tmp.projects $seq.full
94 umount $SCRATCH_DEV 2>/dev/null
95 _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
96 cat $tmp.mkfs >>$seq.full
97 _scratch_mount
98
99 uid=1
100 gid=2
101 prid=3
102 export QARGS="-x -D /dev/null -P /dev/null $SCRATCH_MNT"
103 umount $SCRATCH_DEV
104
105 echo; echo "### test user accounting"
106 export MOUNT_OPTIONS="-ouquota"
107 _qmount
108 type=u
109 id=$uid
110 test_files
111 test_accounting
112 umount $SCRATCH_DEV 2>/dev/null
113
114 echo; echo "### test group accounting"
115 export MOUNT_OPTIONS="-ogquota"
116 _qmount
117 type=g
118 id=$gid
119 test_files
120 test_accounting
121 umount $SCRATCH_DEV 2>/dev/null
122
123 #echo; echo "### test project accounting"
124 export MOUNT_OPTIONS="-opquota"
125 _qmount
126 type=p
127 id=$prid
128 test_files
129 test_accounting
130 umount $SCRATCH_DEV 2>/dev/null
131
132 status=0
133 exit