aboutsummaryrefslogtreecommitdiffstats
path: root/tests/generic/615
blob: 4979306d56e3b92f9d585011dd84ba7e9c957c71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved.
#
# FS QA Test No. 615
#
# Test that if we keep overwriting an entire file, either with buffered writes
# or direct IO writes, the number of used blocks reported by stat(2) is never
# zero while writeback is in progress.
#
. ./common/preamble
_begin_fstest auto rw

# Import common functions.
. ./common/filter

# real QA test starts here
_supported_fs generic
_require_scratch
_require_odirect

stat_loop()
{
	trap "wait; exit" SIGTERM
	local filepath=$1
	local blocks

	while :; do
		blocks=$(stat -c %b $filepath)
		if [ $blocks -eq 0 ]; then
		    echo "error: stat(2) reported zero blocks"
		    break
		fi
	done
}

_scratch_mkfs >>$seqres.full 2>&1
_scratch_mount

$XFS_IO_PROG -f -s -c "pwrite -b 64K 0 64K" $SCRATCH_MNT/foo > /dev/null

stat_loop $SCRATCH_MNT/foo &
loop_pid=$!

echo "Testing buffered writes"

# Now keep overwriting the entire file, triggering writeback after each write,
# while another process is calling stat(2) on the file. We expect the number of
# used blocks reported by stat(2) to be always greater than 0.
for ((i = 0; i < 2000; i++)); do
	if ! kill -s 0 $loop_pid &> /dev/null; then
	    break
	fi
	$XFS_IO_PROG -s -c "pwrite -b 64K 0 64K" $SCRATCH_MNT/foo > /dev/null
done

echo "Testing direct IO writes"

# Now similar to what we did before but for direct IO writes.
for ((i = 0; i < 2000; i++)); do
	if ! kill -s 0 $loop_pid &> /dev/null; then
	    break
	fi
	$XFS_IO_PROG -d -c "pwrite -b 64K 0 64K" $SCRATCH_MNT/foo > /dev/null
done

kill $loop_pid &> /dev/null
wait

status=0
exit