summaryrefslogtreecommitdiff
path: root/tests/generic/715
blob: 595953dfcf1598b4e5b46939f6e65536bdf1ff6e (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
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (c) 2022 Oracle.  All Rights Reserved.
#
# FS QA Test No. 715
#
# Test swapext between two files of unlike size.

. ./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 -s 64k -l 64k'
_require_test

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

test_swapext_once() {
	local tag=$1
	local a_len=$2
	local b_len=$3
	local a_off=$4
	local b_off=$5
	local len=$6

	# len is either a block count or -e to swap to EOF
	if [ "$len" != "-e" ]; then
		len="-l $((blksz * len))"
	fi

	rm -f $dir/a $dir/b
	_pwrite_byte 0x58 0 $((blksz * a_len)) $dir/a >> $seqres.full
	_pwrite_byte 0x59 0 $((blksz * b_len)) $dir/b >> $seqres.full
	filesnap "$tag: before swapext" $dir/a $dir/b

	cmd="swapext -v exchrange -s $((blksz * a_off)) -d $((blksz * b_off)) $len $dir/a"
	echo "$cmd" >> $seqres.full
	$XFS_IO_PROG -c "$cmd" $dir/b
	filesnap "$tag: after swapext" $dir/a $dir/b

	_test_cycle_mount
	filesnap "$tag: after cycling mount" $dir/a $dir/b
	echo
}

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

test_swapext_once "last 5 blocks" 27 37 22 32 5

test_swapext_once "whole file to eof" 27 37 0 0 -e

test_swapext_once "blocks 30-40" 27 37 30 30 10

# success, all done
status=0
exit