generic/611: Use _getfattr instead of GETFATTR_PROG
[xfstests-dev.git] / tests / generic / 563
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2019 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 011
6 #
7 # This test verifies that cgroup aware writeback properly accounts I/Os in
8 # various scenarios. We perform reads/writes from different combinations of
9 # cgroups and verify that pages are accounted against the group that brought
10 # them into cache.
11 #
12
13 seq=`basename $0`
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
16
17 here=`pwd`
18 tmp=/tmp/$$
19 status=1        # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 _cleanup()
23 {
24         cd /
25         rm -f $tmp.*
26
27         echo $$ > $cgdir/cgroup.procs
28         rmdir $cgdir/$seq-cg* > /dev/null 2>&1
29 }
30
31 # get standard environment, filters and checks
32 . ./common/rc
33 . ./common/filter
34 . ./common/cgroup2
35
36 # remove previous $seqres.full before test
37 rm -f $seqres.full
38
39 # real QA test starts here
40
41 # Modify as appropriate.
42 _supported_fs generic
43 _require_scratch
44 _require_cgroup2 io
45
46 # cgroup v2 writeback is only support on block devices so far
47 _require_block_device $SCRATCH_DEV
48
49 smajor=$((0x`stat -L -c %t $SCRATCH_DEV`))
50 sminor=$((0x`stat -L -c %T $SCRATCH_DEV`))
51 cgdir=$CGROUP2_PATH
52
53 iosize=$((1024 * 1024 * 8))
54
55 # Check cgroup read/write charges against expected values. Allow for some
56 # tolerance as different filesystems seem to account slightly differently.
57 check_cg()
58 {
59         cgroot=$1
60         cgname=$(basename $cgroot)
61         expectedread=$2
62         expectedwrite=$3
63         rbytes=0
64         wbytes=0
65
66         iobytes=`cat $cgroot/io.stat | grep $smajor:$sminor`
67         if [ $? == 0 ]; then
68                 rbytes=`echo $iobytes | awk '{ print $2 }' | \
69                         awk -F = '{ print $2 }'`
70                 wbytes=`echo $iobytes | awk '{ print $3 }' | \
71                         awk -F = '{ print $2 }'`
72         fi
73
74         _within_tolerance "read" $rbytes $expectedread 5% -v
75         _within_tolerance "write" $wbytes $expectedwrite 5% -v
76 }
77
78 # Move current process to another cgroup.
79 switch_cg()
80 {
81         mkdir -p $1
82         echo $$ > $1/cgroup.procs
83 }
84
85 # Reset cgroup state for a new test.
86 reset()
87 {
88         echo $$ > $cgdir/cgroup.procs
89         rmdir $cgdir/$seq-cg* > /dev/null 2>&1
90         $XFS_IO_PROG -fc "pwrite 0 $iosize" $SCRATCH_MNT/file \
91                 >> $seqres.full 2>&1
92         _scratch_cycle_mount || _fail "mount failed"
93         stat $SCRATCH_MNT/file > /dev/null
94 }
95
96 _scratch_mkfs >> $seqres.full 2>&1
97 _scratch_mount
98
99 echo "+io" > $cgdir/cgroup.subtree_control || _fail "subtree control"
100
101 # Read and write from a single group.
102 echo "read/write"
103 reset
104 switch_cg $cgdir/$seq-cg
105 $XFS_IO_PROG -c "pread 0 $iosize" -c "pwrite 0 $iosize" -c fsync \
106         $SCRATCH_MNT/file >> $seqres.full 2>&1
107 switch_cg $cgdir
108 $XFS_IO_PROG -c fsync $SCRATCH_MNT/file
109 check_cg $cgdir/$seq-cg $iosize $iosize
110
111 # Write from one cgroup then read and write from a second. Writes are charged to
112 # the first group and nothing to the second.
113 echo "write -> read/write"
114 reset
115 switch_cg $cgdir/$seq-cg
116 $XFS_IO_PROG -c "pwrite 0 $iosize" $SCRATCH_MNT/file >> $seqres.full 2>&1
117 switch_cg $cgdir/$seq-cg-2
118 $XFS_IO_PROG -c "pread 0 $iosize" -c "pwrite 0 $iosize" $SCRATCH_MNT/file \
119         >> $seqres.full 2>&1
120 switch_cg $cgdir
121 $XFS_IO_PROG -c fsync $SCRATCH_MNT/file
122 check_cg $cgdir/$seq-cg 0 $iosize
123 check_cg $cgdir/$seq-cg-2 0 0
124
125 # Read from one cgroup, read & write from a second. Both reads and writes are
126 # charged to the first group and nothing to the second.
127 echo "read -> read/write"
128 reset
129 switch_cg $cgdir/$seq-cg
130 $XFS_IO_PROG -c "pread 0 $iosize" $SCRATCH_MNT/file >> $seqres.full 2>&1
131 switch_cg $cgdir/$seq-cg-2
132 $XFS_IO_PROG -c "pread 0 $iosize" -c "pwrite 0 $iosize" $SCRATCH_MNT/file \
133         >> $seqres.full 2>&1
134 switch_cg $cgdir
135 $XFS_IO_PROG -c fsync $SCRATCH_MNT/file
136 check_cg $cgdir/$seq-cg $iosize $iosize
137 check_cg $cgdir/$seq-cg-2 0 0
138
139 echo "-io" > $cgdir/cgroup.subtree_control || _fail "subtree control"
140
141 # success, all done
142 status=0
143 exit