summaryrefslogtreecommitdiff
path: root/tests/generic/415
blob: c435e62633af99131bba0fb27f654607944c3c4f (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
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2017 Plexistor Ltd. All Rights Reserved.
#
# FS QA Test No. 415
#
# test for races between write or fpunch operations on reflinked files
# to read operations on the target file
#
. ./common/preamble
_begin_fstest auto clone punch

status=0    # success is the default!

# Import common functions.
. ./common/reflink

# real QA test starts here
_supported_fs generic
_require_scratch_reflink
_require_cp_reflink
_require_xfs_io_command "fpunch"

_scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
_scratch_mount || _fail "mount failed"
_require_fs_space $SCRATCH_MNT $((250 * 1024))

echo "Silence is golden"

workfile=${SCRATCH_MNT}/workfile
light_clone=${SCRATCH_MNT}/light_clone

file_size=$((10 * 1024 * 1024))
bs=`_get_block_size $SCRATCH_MNT`
block_num=$((file_size / bs))
reflinks_num=20

$XFS_IO_PROG -f -c "pwrite 0 $file_size" $workfile >> $seqres.full

for ((i=1; i<=reflinks_num; i++)); do
	_cp_reflink $workfile ${light_clone}_$i
done

# for each block simultaneously pwrite (or fpunch) all reflinks
# while performing pread from the targted file
for ((block_index=0; block_index<block_num; block_index++)); do
	for ((i=1; i<=reflinks_num; i++)); do
		$XFS_IO_PROG -c "pread $((block_index * bs)) $bs" \
					$workfile >> $seqres.full &
		if [ $((block_index % 2)) -eq 0 ]; then
			$XFS_IO_PROG -c "pwrite $((block_index * bs)) $bs" \
					${light_clone}_$i  >> $seqres.full &
		else
			$XFS_IO_PROG -c "fpunch $((block_index * bs)) $bs" \
					${light_clone}_$i >> $seqres.full &
		fi
	done
	# wait for all threads to join before moving to next block
	wait
done

# success, all done
status=0
exit