summaryrefslogtreecommitdiff
path: root/tests/generic/733
blob: f6ee7f7156f4d8183dda4bd9daa4a413048d5f95 (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
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2023, Oracle and/or its affiliates.  All Rights Reserved.
#
# FS QA Test No. 733
#
# Race file reads with a very slow reflink operation to see if the reads
# actually complete while the reflink is ongoing.  This is a functionality
# test for XFS commit 14a537983b22 "xfs: allow read IO and FICLONE to run
# concurrently" and for BTRFS commit 5d6f0e9890ed "btrfs: stop locking the
# source extent range during reflink".
#
. ./common/preamble
_begin_fstest auto clone punch

# Import common functions.
. ./common/filter
. ./common/attr
. ./common/reflink

# real QA test starts here
_supported_fs generic
_require_scratch_reflink
_require_cp_reflink
_require_xfs_io_command "fpunch"
_require_test_program "punch-alternating"
_require_test_program "t_reflink_read_race"
_require_command "$TIMEOUT_PROG" timeout

case "$FSTYP" in
"btrfs")
	_fixed_by_kernel_commit 5d6f0e9890ed \
		"btrfs: stop locking the source extent range during reflink"
	;;
"xfs")
	_fixed_by_kernel_commit 14a537983b22 \
		"xfs: allow read IO and FICLONE to run concurrently"
	;;
esac

rm -f "$seqres.full"

echo "Format and mount"
_scratch_mkfs > "$seqres.full" 2>&1
_scratch_mount >> "$seqres.full" 2>&1

testdir="$SCRATCH_MNT/test-$seq"
mkdir "$testdir"

calc_space() {
	blocks_needed=$(( 2 ** (fnr + 1) ))
	space_needed=$((blocks_needed * blksz * 5 / 4))
}

# Figure out the number of blocks that we need to get the reflink runtime above
# 1 seconds
echo "Create a many-block file"
for ((fnr = 1; fnr < 40; fnr++)); do
	free_blocks=$(stat -f -c '%a' "$testdir")
	blksz=$(_get_file_block_size "$testdir")
	space_avail=$((free_blocks * blksz))
	calc_space
	test $space_needed -gt $space_avail && \
		_notrun "Insufficient space for stress test; would only create $blocks_needed extents."

	off=$(( (2 ** fnr) * blksz))
	$XFS_IO_PROG -f -c "pwrite -S 0x61 -b 4194304 $off $off" "$testdir/file1" >> "$seqres.full"
	"$here/src/punch-alternating" "$testdir/file1" >> "$seqres.full"

	$TIMEOUT_PROG 1s cp --reflink=always "$testdir/file1" "$testdir/garbage" || break
done
echo "fnr=$fnr" >> $seqres.full

echo "Reflink the big file"
$here/src/t_reflink_read_race "$testdir/file1" "$testdir/file2" \
	"$testdir/outcome" &>> $seqres.full

if [ ! -e "$testdir/outcome" ]; then
	echo "Could not set up program"
elif grep -q "finished read early" "$testdir/outcome"; then
	echo "test completed successfully"
else
	cat "$testdir/outcome"
fi

# success, all done
status=0
exit