generic/611: Use _getfattr instead of GETFATTR_PROG
[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 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
18
19 # get standard environment, filters and checks
20 . ./common/rc
21 . ./common/filter
22 . ./common/quota
23
24 # real QA test starts here
25 _supported_fs generic
26 _require_scratch
27 _require_quota
28 _require_user
29 _require_group
30
31 test_files()
32 {
33         echo; echo "### create files, setting up ownership (type=$type)"
34         rm -f $SCRATCH_MNT/{buffer,direct,mmap}
35         touch $SCRATCH_MNT/{buffer,direct,mmap}
36         chown $qa_user $SCRATCH_MNT/{buffer,direct,mmap}
37         chgrp $qa_group $SCRATCH_MNT/{buffer,direct,mmap}
38         for file in $SCRATCH_MNT/{buffer,direct,mmap}; do
39                 $here/src/lstat64 $file | head -2 | _filter_scratch
40         done
41 }
42
43 check_usage()
44 {
45         wroteblocks=$1
46         wrotefiles=$2
47         read id exceed blocks bsoft bhard inodes isoft ihard
48         if [ "$blocks" -lt "$wroteblocks" ]; then
49                 echo "Too few blocks used (type=$type)"
50         # Save 5% for overhead of metadata or different block size
51         elif [ "$blocks" -gt $((wroteblocks+wroteblocks/20)) ]; then
52                 echo "Too many blocks used (type=$type)"
53         elif [ "$inodes" != "$wrotefiles" ]; then
54                 echo "Bad number of inodes used (type=$type)"
55         else
56                 echo "Usage OK (type=$type)"
57         fi
58 }
59
60 test_accounting()
61 {
62         echo "### some controlled buffered, direct and mmapd IO (type=$type)"
63         echo "--- initiating parallel IO..." >>$seqres.full
64         # Small ios here because ext3 will account for indirect blocks too ...
65         # 48k will fit w/o indirect for 4k blocks (default blocksize)
66         $XFS_IO_PROG -c 'pwrite 0 48k' -c 'fsync' \
67                                         $SCRATCH_MNT/buffer >>$seqres.full 2>&1 &
68         $XFS_IO_PROG -c 'pwrite 0 48k' -d \
69                                         $SCRATCH_MNT/direct >>$seqres.full 2>&1 &
70         $XFS_IO_PROG -c 't 48k' -c 'mm -rw 0 48k' -c 'mw 0 48k' -c 'ms -s' \
71                                         $SCRATCH_MNT/mmap   >>$seqres.full 2>&1 &
72         wait
73         echo "--- completed parallel IO ($type)" >>$seqres.full
74
75         for file in $SCRATCH_MNT/{buffer,direct,mmap}; do
76                 $here/src/lstat64 $file | head -2 | _filter_scratch
77         done
78
79         if [ $type == 'u' ]; then
80                 id=$qa_user
81         else
82                 id=$qa_group
83         fi
84         repquota -$type $SCRATCH_MNT | grep "^$id" | check_usage 144 3
85 }
86
87 # real QA test starts here
88 rm -f $seqres.full
89
90 _scratch_unmount 2>/dev/null
91 _scratch_mkfs >> $seqres.full 2>&1
92 _scratch_mount "-o usrquota,grpquota"
93 quotacheck -u -g $SCRATCH_MNT 2>/dev/null
94 quotaon $SCRATCH_MNT 2>/dev/null
95 _scratch_unmount
96
97 echo; echo "### test user accounting"
98 export MOUNT_OPTIONS="-o usrquota"
99 _qmount
100 quotaon $SCRATCH_MNT 2>/dev/null
101 type=u
102 test_files
103 test_accounting
104 _scratch_unmount 2>/dev/null
105
106 echo; echo "### test group accounting"
107 export MOUNT_OPTIONS="-o grpquota"
108 _qmount
109 quotaon $SCRATCH_MNT 2>/dev/null
110 type=g
111 test_files
112 test_accounting
113 _scratch_unmount 2>/dev/null
114
115 status=0
116 exit