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