summaryrefslogtreecommitdiff
path: root/tests/generic/714
blob: b48a4b7d315ad9a130bc0ab7785a6e60652c8cf6 (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (c) 2022 Oracle.  All Rights Reserved.
#
# FS QA Test No. 714
#
# Test swapext between ranges of two different files, when one of the files
# is shared.

. ./common/preamble
_begin_fstest auto quick fiexchange swapext

# Override the default cleanup function.
_cleanup()
{
	cd /
	rm -r -f $tmp.* $dir
}

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

# real QA test starts here
_require_xfs_io_command swapext '-v exchrange'
_require_xfs_io_command "falloc"
_require_test_reflink

filesnap() {
	echo "$1"
	if [ "$2" != "$3" ]; then
		md5sum $2 $3 | _filter_test_dir
	else
		md5sum $2 | _filter_test_dir
	fi
}

test_swapext_once() {
	filesnap "$1: before swapext" $dir/$3 $dir/$4
	$XFS_IO_PROG -c "swapext -v exchrange $2 $dir/$3" $dir/$4
	filesnap "$1: after swapext" $dir/$3 $dir/$4
	_test_cycle_mount
	filesnap "$1: after cycling mount" $dir/$3 $dir/$4
	echo
}

test_swapext_two() {
	# swapext the same range of two files
	test_swapext_once "$*: samerange" \
		"-s $((blksz * 3)) -d $((blksz * 3)) -l $((blksz * 5))" b a

	# swapext different ranges of two files
	test_swapext_once "$*: diffrange" \
		"-s $((blksz * 37)) -d $((blksz * 47)) -l $((blksz * 7))" b a

	# swapext overlapping ranges of two files
	test_swapext_once "$*: overlap" \
		"-s $((blksz * 17)) -d $((blksz * 23)) -l $((blksz * 7))" b a

	# Now let's overwrite a entirely to make sure COW works
	echo "overwrite A and B entirely"
	md5sum $dir/sharea | _filter_test_dir
	$XFS_IO_PROG -c "pwrite -S 0x60 0 $((blksz * nrblks))" $dir/a >> $seqres.full
	$XFS_IO_PROG -c "pwrite -S 0x60 0 $((blksz * nrblks))" $dir/b >> $seqres.full
	md5sum $dir/sharea | _filter_test_dir
	_test_cycle_mount
	md5sum $dir/sharea | _filter_test_dir
	echo
}

dir=$TEST_DIR/test-$seq
mkdir -p $dir
blksz=65536
_require_congruent_file_oplen $TEST_DIR $blksz
nrblks=57

# Set up some simple files for a first test.
rm -f $dir/a $dir/b $dir/sharea
_pwrite_byte 0x58 0 $((blksz * nrblks)) $dir/a >> $seqres.full
_pwrite_byte 0x59 0 $((blksz * nrblks)) $dir/b >> $seqres.full
_cp_reflink $dir/a $dir/sharea
test_swapext_two "simple"

# Set up some crazy rainbow files
rm -f $dir/a $dir/b $dir/sharea
_weave_file_rainbow $blksz $nrblks $dir/a >> $seqres.full
_weave_file_rainbow $blksz $nrblks $dir/b >> $seqres.full
_cp_reflink $dir/a $dir/sharea
test_swapext_two "rainbow"

# Now set up a simple file for testing within the same file
rm -f $dir/c $dir/sharec
$XFS_IO_PROG -f -c "pwrite -S 0x58 0 $((blksz * nrblks))" \
	-c "pwrite -S 0x59 $((blksz * nrblks)) $((blksz * nrblks))" \
	$dir/c >> $seqres.full
_cp_reflink $dir/c $dir/sharec

# swapext the same offset into the 'X' and 'Y' regions of the file
test_swapext_once "single: sameXandY" \
	"-s $((blksz * 3)) -d $((blksz * (nrblks + 3))) -l $((blksz * 5))" c c

# swapext the same offset into the 'X' and 'Y' regions of the file
test_swapext_once "single: overlap" \
	"-s $((blksz * 13)) -d $((blksz * 17)) -l $((blksz * 5))" c c

# Now let's overwrite a entirely to make sure COW works
echo "overwrite C entirely"
md5sum $dir/sharec | _filter_test_dir
$XFS_IO_PROG -c "pwrite -S 0x60 0 $((blksz * nrblks))" $dir/c >> $seqres.full
md5sum $dir/sharec | _filter_test_dir
_test_cycle_mount
md5sum $dir/sharec | _filter_test_dir

# success, all done
status=0
exit