summaryrefslogtreecommitdiff
path: root/tests/generic/464
blob: cf9caac23ae78c4836f839b3cca7857c6016f079 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2017 Red Hat Inc. All Rights Reserved.
#
# FS QA Test 464
#
# Run delalloc writes & append writes & non-data-integrity syncs concurrently
# to test the race between block map change vs writeback.
#
. ./common/preamble
_begin_fstest auto rw

# Import common functions.
. ./common/filter

MAXFILES=200
BLOCK_SZ=65536

LOOP_CNT=10
LOOP_TIME=5
PROC_CNT=16

stop=$tmp.stop

# get a random file to work on
getfile()
{
	echo $SCRATCH_MNT/$((RANDOM % MAXFILES))
}

# delalloc write a relative big file to get enough dirty pages to be written
# back, and XFS needs big enough file to trigger speculative preallocations, so
# freeing these eofblocks could change the extent record
do_write()
{
	local blockcount=$((RANDOM % 100))
	local filesize=$((blockcount * BLOCK_SZ))
	$XFS_IO_PROG -ftc "pwrite -b $BLOCK_SZ 0 $filesize" `getfile` \
		>/dev/null 2>&1
}

# append another dirty page to the file, the writeback might pick it up too if
# the file is already under writeback
do_append()
{
	echo "test string" >> `getfile`
}

# issue WB_SYNC_NONE writeback with the '-w' option of sync_range xfs_io
# command, so that the last dirty page from append write can be picked up in
# this writeback cycle. This is not mandatory but could help reproduce XFS
# corruption more easily.
do_writeback()
{
	$XFS_IO_PROG -c "sync_range -w 0 0" `getfile` >/dev/null 2>&1
}

# real QA test starts here
_supported_fs generic
# do fsck after each iteration in test
_require_scratch_nocheck
_require_xfs_io_command "sync_range"

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

# loop for $LOOP_CNT iterations, and each iteration starts $PROC_CNT processes
# for each operation and runs for $LOOP_TIME seconds, and check filesystem
# consistency after each iteration
for i in `seq 1 $LOOP_CNT`; do
	rm -f $stop
	for j in `seq 1 $PROC_CNT`; do
		while [ ! -e $stop ]; do
			do_write
		done &

		while [ ! -e $stop ]; do
			do_append
		done &

		while [ ! -e $stop ]; do
			do_writeback
		done &
	done
	sleep $LOOP_TIME
	touch $stop
	wait

	_scratch_unmount
	# test exits here if fs is inconsistent
	_check_scratch_fs
	_scratch_mount
done

echo "Silence is golden"

# success, all done
status=0
exit