summaryrefslogtreecommitdiff
path: root/tests/btrfs/112
blob: 2e1238288f666dad04bc472a2680c78056a1e630 (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
#
# FSQA Test No. 112
#
# Test several cases of cloning inline extents that used to lead to file
# corruption or data loss.
#
. ./common/preamble
_begin_fstest auto quick clone prealloc compress

. ./common/filter
. ./common/filter.btrfs

_supported_fs btrfs
_require_scratch
_require_cloner
_require_btrfs_fs_feature "no_holes"
_require_btrfs_mkfs_feature "no-holes"
_require_xfs_io_command "falloc"

test_cloning_inline_extents()
{
	local mkfs_opts=$1
	local mount_opts=$2

	_scratch_mkfs $mkfs_opts >>$seqres.full 2>&1
	_scratch_mount $mount_opts

	# File bar, the source for all the following clone operations, consists
	# of a single inline extent (50 bytes).
	$XFS_IO_PROG -f -c "pwrite -S 0xbb 0 50" $SCRATCH_MNT/bar \
		| _filter_xfs_io

	# Test cloning into a file with an extent (non-inlined) where the
	# destination offset overlaps that extent. It should not be possible to
	# clone the inline extent from file bar into this file.
	$XFS_IO_PROG -f -c "pwrite -S 0xaa 0K 16K" $SCRATCH_MNT/foo \
		| _filter_xfs_io
	$CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo \
		| _filter_btrfs_cloner_error

	# Doing IO against any range in the first 4K of the file should work.
	# Due to a past clone ioctl bug which allowed cloning the inline extent,
	# these operations resulted in EIO errors.
	echo "File foo data after clone operation:"
	# All bytes should have the value 0xaa (clone operation failed and did
	# not modify our file).
	od -t x1 $SCRATCH_MNT/foo
	$XFS_IO_PROG -c "pwrite -S 0xcc 0 100" $SCRATCH_MNT/foo | _filter_xfs_io

	# Test cloning the inline extent against a file which has a hole in its
	# first 4K followed by a non-inlined extent. It should not be possible
	# as well to clone the inline extent from file bar into this file.
	$XFS_IO_PROG -f -c "pwrite -S 0xdd 4K 12K" $SCRATCH_MNT/foo2 \
		| _filter_xfs_io
	$CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo2 \
		| _filter_btrfs_cloner_error

	# Doing IO against any range in the first 4K of the file should work.
	# Due to a past clone ioctl bug which allowed cloning the inline extent,
	# these operations resulted in EIO errors.
	echo "File foo2 data after clone operation:"
	# All bytes should have the value 0x00 (clone operation failed and did
	# not modify our file).
	od -t x1 $SCRATCH_MNT/foo2
	$XFS_IO_PROG -c "pwrite -S 0xee 0 90" $SCRATCH_MNT/foo2 | _filter_xfs_io

	# Test cloning the inline extent against a file which consists of a
	# single inline extent that has a size not greater than the size of
	# bar's inline extent (40 < 50).
	# It should be possible to do the extent cloning from bar to this file.
	$XFS_IO_PROG -f -c "pwrite -S 0x01 0 40" $SCRATCH_MNT/foo4 \
		| _filter_xfs_io
	$CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo4 \
		| _filter_btrfs_cloner_error

	# Doing IO against any range in the first 4K of the file should work.
	echo "File foo4 data after clone operation:"
	# Must match file bar's content.
	od -t x1 $SCRATCH_MNT/foo4
	$XFS_IO_PROG -c "pwrite -S 0x02 0 90" $SCRATCH_MNT/foo4 | _filter_xfs_io

	# Test cloning the inline extent against a file which consists of a
	# single inline extent that has a size greater than the size of bar's
	# inline extent (60 > 50).
	# It should not be possible to clone the inline extent from file bar
	# into this file.
	$XFS_IO_PROG -f -c "pwrite -S 0x03 0 60" $SCRATCH_MNT/foo5 \
		| _filter_xfs_io
	$CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo5 \
		| _filter_btrfs_cloner_error

	# Reading the file should not fail.
	echo "File foo5 data after clone operation:"
	# Must have a size of 60 bytes, with all bytes having a value of 0x03
	# (the clone operation failed and did not modify our file).
	od -t x1 $SCRATCH_MNT/foo5

	# Test cloning the inline extent against a file which has no extents but
	# has a size greater than bar's inline extent (16K > 50).
	# It should not be possible to clone the inline extent from file bar
	# into this file.
	$XFS_IO_PROG -f -c "truncate 16K" $SCRATCH_MNT/foo6 | _filter_xfs_io
	$CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo6 \
		| _filter_btrfs_cloner_error

	# Reading the file should not fail.
	echo "File foo6 data after clone operation:"
	# Must have a size of 16K, with all bytes having a value of 0x00 (the
	# clone operation failed and did not modify our file).
	od -t x1 $SCRATCH_MNT/foo6

	# Test cloning the inline extent against a file which has no extents but
	# has a size not greater than bar's inline extent (30 < 50).
	# It should be possible to clone the inline extent from file bar into
	# this file.
	$XFS_IO_PROG -f -c "truncate 30" $SCRATCH_MNT/foo7 | _filter_xfs_io
	$CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo7 \
		| _filter_btrfs_cloner_error

	# Reading the file should not fail.
	echo "File foo7 data after clone operation:"
	# Must have a size of 50 bytes, with all bytes having a value of 0xbb.
	od -t x1 $SCRATCH_MNT/foo7

	_scratch_unmount
}

echo -e "\nTesting without compression and without the no-holes feature...\n"
test_cloning_inline_extents

echo -e "\nTesting with compression and without the no-holes feature...\n"
test_cloning_inline_extents "" "-o compress"

echo -e "\nTesting without compression and with the no-holes feature...\n"
test_cloning_inline_extents "-O no-holes" ""

echo -e "\nTesting with compression and with the no-holes feature...\n"
test_cloning_inline_extents "-O no-holes" "-o compress"

status=0
exit