fstests: move test group info to test files
[xfstests-dev.git] / tests / generic / 219
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2009 Eric Sandeen.  All Rights Reserved.
4 # Copyright (c) 2005 Silicon Graphics, Inc.  All Rights Reserved.
5 #
6 # FS QA Test No. 219
7 #
8 # Simple quota accounting test for direct/buffered/mmap IO.
9 #
10 . ./common/preamble
11 _begin_fstest auto quota quick
12
13 # Import common functions.
14 . ./common/filter
15 . ./common/quota
16
17 # real QA test starts here
18 _supported_fs generic
19 _require_scratch
20 _require_quota
21 _require_user
22 _require_group
23
24 test_files()
25 {
26         echo; echo "### create files, setting up ownership (type=$type)"
27         rm -f $SCRATCH_MNT/{buffer,direct,mmap}
28         touch $SCRATCH_MNT/{buffer,direct,mmap}
29         chown $qa_user $SCRATCH_MNT/{buffer,direct,mmap}
30         chgrp $qa_group $SCRATCH_MNT/{buffer,direct,mmap}
31         for file in $SCRATCH_MNT/{buffer,direct,mmap}; do
32                 $here/src/lstat64 $file | head -2 | _filter_scratch
33         done
34 }
35
36 check_usage()
37 {
38         wroteblocks=$1
39         wrotefiles=$2
40         read id exceed blocks bsoft bhard inodes isoft ihard
41         if [ "$blocks" -lt "$wroteblocks" ]; then
42                 echo "Too few blocks used (type=$type)"
43         # Save 5% for overhead of metadata or different block size
44         elif [ "$blocks" -gt $((wroteblocks+wroteblocks/20)) ]; then
45                 echo "Too many blocks used (type=$type)"
46         elif [ "$inodes" != "$wrotefiles" ]; then
47                 echo "Bad number of inodes used (type=$type)"
48         else
49                 echo "Usage OK (type=$type)"
50         fi
51 }
52
53 test_accounting()
54 {
55         echo "### some controlled buffered, direct and mmapd IO (type=$type)"
56         echo "--- initiating parallel IO..." >>$seqres.full
57         # Small ios here because ext3 will account for indirect blocks too ...
58         # 48k will fit w/o indirect for 4k blocks (default blocksize)
59         $XFS_IO_PROG -c 'pwrite 0 48k' -c 'fsync' \
60                                         $SCRATCH_MNT/buffer >>$seqres.full 2>&1 &
61         $XFS_IO_PROG -c 'pwrite 0 48k' -d \
62                                         $SCRATCH_MNT/direct >>$seqres.full 2>&1 &
63         $XFS_IO_PROG -c 't 48k' -c 'mm -rw 0 48k' -c 'mw 0 48k' -c 'ms -s' \
64                                         $SCRATCH_MNT/mmap   >>$seqres.full 2>&1 &
65         wait
66         echo "--- completed parallel IO ($type)" >>$seqres.full
67
68         for file in $SCRATCH_MNT/{buffer,direct,mmap}; do
69                 $here/src/lstat64 $file | head -2 | _filter_scratch
70         done
71
72         if [ $type == 'u' ]; then
73                 id=$qa_user
74         else
75                 id=$qa_group
76         fi
77         repquota -$type $SCRATCH_MNT | grep "^$id" | check_usage 144 3
78 }
79
80 # real QA test starts here
81
82 _scratch_unmount 2>/dev/null
83 _scratch_mkfs >> $seqres.full 2>&1
84 _scratch_mount "-o usrquota,grpquota"
85 quotacheck -u -g $SCRATCH_MNT 2>/dev/null
86 quotaon $SCRATCH_MNT 2>/dev/null
87 _scratch_unmount
88
89 echo; echo "### test user accounting"
90 export MOUNT_OPTIONS="-o usrquota"
91 _qmount
92 quotaon $SCRATCH_MNT 2>/dev/null
93 type=u
94 test_files
95 test_accounting
96 _scratch_unmount 2>/dev/null
97
98 echo; echo "### test group accounting"
99 export MOUNT_OPTIONS="-o grpquota"
100 _qmount
101 quotaon $SCRATCH_MNT 2>/dev/null
102 type=g
103 test_files
104 test_accounting
105 _scratch_unmount 2>/dev/null
106
107 status=0
108 exit