common/fuzzy: try to clear blocking flags first in _scratch_fuzz_modify
[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 _supported_os Linux
44 _require_scratch
45 _require_cgroup2 io
46
47 # cgroup v2 writeback is only support on block devices so far
48 _require_block_device $SCRATCH_DEV
49
50 smajor=$((0x`stat -L -c %t $SCRATCH_DEV`))
51 sminor=$((0x`stat -L -c %T $SCRATCH_DEV`))
52 cgdir=$CGROUP2_PATH
53
54 iosize=$((1024 * 1024 * 8))
55
56 # Check cgroup read/write charges against expected values. Allow for some
57 # tolerance as different filesystems seem to account slightly differently.
58 check_cg()
59 {
60         cgroot=$1
61         cgname=$(basename $cgroot)
62         expectedread=$2
63         expectedwrite=$3
64         rbytes=0
65         wbytes=0
66
67         iobytes=`cat $cgroot/io.stat | grep $smajor:$sminor`
68         if [ $? == 0 ]; then
69                 rbytes=`echo $iobytes | awk '{ print $2 }' | \
70                         awk -F = '{ print $2 }'`
71                 wbytes=`echo $iobytes | awk '{ print $3 }' | \
72                         awk -F = '{ print $2 }'`
73         fi
74
75         _within_tolerance "read" $rbytes $expectedread 5% -v
76         _within_tolerance "write" $wbytes $expectedwrite 5% -v
77 }
78
79 # Move current process to another cgroup.
80 switch_cg()
81 {
82         mkdir -p $1
83         echo $$ > $1/cgroup.procs
84 }
85
86 # Reset cgroup state for a new test.
87 reset()
88 {
89         echo $$ > $cgdir/cgroup.procs
90         rmdir $cgdir/$seq-cg* > /dev/null 2>&1
91         $XFS_IO_PROG -fc "pwrite 0 $iosize" $SCRATCH_MNT/file \
92                 >> $seqres.full 2>&1
93         _scratch_cycle_mount || _fail "mount failed"
94         stat $SCRATCH_MNT/file > /dev/null
95 }
96
97 _scratch_mkfs >> $seqres.full 2>&1
98 _scratch_mount
99
100 echo "+io" > $cgdir/cgroup.subtree_control || _fail "subtree control"
101
102 # Read and write from a single group.
103 echo "read/write"
104 reset
105 switch_cg $cgdir/$seq-cg
106 $XFS_IO_PROG -c "pread 0 $iosize" -c "pwrite 0 $iosize" -c fsync \
107         $SCRATCH_MNT/file >> $seqres.full 2>&1
108 switch_cg $cgdir
109 $XFS_IO_PROG -c fsync $SCRATCH_MNT/file
110 check_cg $cgdir/$seq-cg $iosize $iosize
111
112 # Write from one cgroup then read and write from a second. Writes are charged to
113 # the first group and nothing to the second.
114 echo "write -> read/write"
115 reset
116 switch_cg $cgdir/$seq-cg
117 $XFS_IO_PROG -c "pwrite 0 $iosize" $SCRATCH_MNT/file >> $seqres.full 2>&1
118 switch_cg $cgdir/$seq-cg-2
119 $XFS_IO_PROG -c "pread 0 $iosize" -c "pwrite 0 $iosize" $SCRATCH_MNT/file \
120         >> $seqres.full 2>&1
121 switch_cg $cgdir
122 $XFS_IO_PROG -c fsync $SCRATCH_MNT/file
123 check_cg $cgdir/$seq-cg 0 $iosize
124 check_cg $cgdir/$seq-cg-2 0 0
125
126 # Read from one cgroup, read & write from a second. Both reads and writes are
127 # charged to the first group and nothing to the second.
128 echo "read -> read/write"
129 reset
130 switch_cg $cgdir/$seq-cg
131 $XFS_IO_PROG -c "pread 0 $iosize" $SCRATCH_MNT/file >> $seqres.full 2>&1
132 switch_cg $cgdir/$seq-cg-2
133 $XFS_IO_PROG -c "pread 0 $iosize" -c "pwrite 0 $iosize" $SCRATCH_MNT/file \
134         >> $seqres.full 2>&1
135 switch_cg $cgdir
136 $XFS_IO_PROG -c fsync $SCRATCH_MNT/file
137 check_cg $cgdir/$seq-cg $iosize $iosize
138 check_cg $cgdir/$seq-cg-2 0 0
139
140 echo "-io" > $cgdir/cgroup.subtree_control || _fail "subtree control"
141
142 # success, all done
143 status=0
144 exit