summaryrefslogtreecommitdiff
path: root/tests/generic/717
blob: 2c45e715f47c6faee37078a3b3bba89c02ecaf15 (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
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (c) 2022 Oracle.  All Rights Reserved.
#
# FS QA Test No. 717
#
# Try invalid parameters to see if they fail.

. ./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 startupdate
_require_test
_require_scratch
_require_chattr i

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

_scratch_mkfs >> $seqres.full
_scratch_mount

_pwrite_byte 0x58 0 $((blksz * nrblks)) $dir/a >> $seqres.full
_pwrite_byte 0x58 0 $((blksz * nrblks)) $dir/b >> $seqres.full

echo Immutable files
$XFS_IO_PROG -c 'chattr +i' -c "swapext $dir/b" $dir/a
$CHATTR_PROG -i $dir/a

echo Readonly files
$XFS_IO_PROG -r -c "swapext $dir/b" $dir/a

echo Directories
$XFS_IO_PROG -c "swapext $dir/b" $dir

echo Unaligned ranges
$XFS_IO_PROG -c "swapext -s 37 -d 61 -l 17 $dir/b" $dir/a

echo file1 range entirely beyond EOF
$XFS_IO_PROG -c "swapext -s $(( blksz * (nrblks + 500) )) -d 0 -l $blksz $dir/b" $dir/a

echo file2 range entirely beyond EOF
$XFS_IO_PROG -c "swapext -d $(( blksz * (nrblks + 500) )) -s 0 -l $blksz $dir/b" $dir/a

echo Both ranges entirely beyond EOF
$XFS_IO_PROG -c "swapext -d $(( blksz * (nrblks + 500) )) -s $(( blksz * (nrblks + 500) )) -l $blksz $dir/b" $dir/a

echo file1 range crossing EOF
$XFS_IO_PROG -c "swapext -s $(( blksz * (nrblks - 1) )) -d 0 -l $((2 * blksz)) $dir/b" $dir/a

echo file2 range crossing EOF
$XFS_IO_PROG -c "swapext -d $(( blksz * (nrblks  - 1) )) -s 0 -l $((2 * blksz)) $dir/b" $dir/a

echo Both ranges crossing EOF
$XFS_IO_PROG -c "swapext -d $(( blksz * (nrblks - 1) )) -s $(( blksz * (nrblks - 1) )) -l $((blksz * 2)) $dir/b" $dir/a

echo file1 unaligned EOF to file2 nowhere near EOF
_pwrite_byte 0x58 $((blksz * nrblks)) 37 $dir/a >> $seqres.full
_pwrite_byte 0x59 $((blksz * nrblks)) 37 $dir/b >> $seqres.full
$XFS_IO_PROG -c "swapext -d 0 -s $(( blksz * nrblks )) -l 37 $dir/b" $dir/a

echo file2 unaligned EOF to file1 nowhere near EOF
$XFS_IO_PROG -c "swapext -s 0 -d $(( blksz * nrblks )) -l 37 $dir/b" $dir/a

echo Files of unequal length
_pwrite_byte 0x58 $((blksz * nrblks)) $((blksz * 2)) $dir/a >> $seqres.full
_pwrite_byte 0x59 $((blksz * nrblks)) $blksz $dir/b >> $seqres.full
$XFS_IO_PROG -c "swapext $dir/b" $dir/a

echo Files on different filesystems
_pwrite_byte 0x58 0 $((blksz * nrblks)) $SCRATCH_MNT/c >> $seqres.full
$XFS_IO_PROG -c "swapext $SCRATCH_MNT/c" $dir/a

echo Files on different mounts
mkdir -p $SCRATCH_MNT/xyz
mount --bind $dir $SCRATCH_MNT/xyz --bind
_pwrite_byte 0x60 0 $((blksz * (nrblks + 2))) $dir/c >> $seqres.full
$XFS_IO_PROG -c "swapext $SCRATCH_MNT/xyz/c" $dir/a
umount $SCRATCH_MNT/xyz

echo Swapping a file with itself
$XFS_IO_PROG -c "swapext $dir/a" $dir/a

# success, all done
status=0
exit