blob: cd3e3b83ac53ed062f4cdd69149046f033fd73f2 (
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
|
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved.
#
# FS QA Test No. 200
#
# Check that send operations (full and incremental) are able to issue clone
# operations for extents that are shared between the same file.
#
. ./common/preamble
_begin_fstest auto quick send clone fiemap
# Override the default cleanup function.
_cleanup()
{
cd /
rm -f $tmp.*
rm -fr $send_files_dir
}
. ./common/filter
. ./common/reflink
. ./common/punch
_supported_fs btrfs
_require_fssum
_require_test
_require_scratch_reflink
_require_xfs_io_command "fiemap"
send_files_dir=$TEST_DIR/btrfs-test-$seq
rm -fr $send_files_dir
mkdir $send_files_dir
_scratch_mkfs >>$seqres.full 2>&1
_scratch_mount
# Create our first test file, which has an extent that is shared only with
# itself and no other files. We want to verify a full send operation will
# clone the extent.
$XFS_IO_PROG -f -c "pwrite -S 0xb1 -b 64K 0 64K" $SCRATCH_MNT/foo \
| _filter_xfs_io
$XFS_IO_PROG -c "reflink $SCRATCH_MNT/foo 0 64K 64K" $SCRATCH_MNT/foo \
| _filter_xfs_io
# Create out second test file which initially, for the first send operation,
# only has a single extent that is not shared.
$XFS_IO_PROG -f -c "pwrite -S 0xc7 -b 64K 0 64K" $SCRATCH_MNT/bar \
| _filter_xfs_io
_btrfs subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/base
$BTRFS_UTIL_PROG send -f $send_files_dir/1.snap $SCRATCH_MNT/base 2>&1 \
| _filter_scratch
# Now clone the existing extent in file bar to itself at a different offset.
# We want to verify the incremental send operation below will issue a clone
# operation instead of a write operation.
$XFS_IO_PROG -c "reflink $SCRATCH_MNT/bar 0 64K 64K" $SCRATCH_MNT/bar \
| _filter_xfs_io
_btrfs subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/incr
$BTRFS_UTIL_PROG send -p $SCRATCH_MNT/base -f $send_files_dir/2.snap \
$SCRATCH_MNT/incr 2>&1 | _filter_scratch
# Compute digests of the snapshot trees so that later we can compare against
# digests of the trees in the new filesystem, to see if they match (no data or
# metadata corruption happened).
$FSSUM_PROG -A -f -w $send_files_dir/base.fssum $SCRATCH_MNT/base
$FSSUM_PROG -A -f -w $send_files_dir/incr.fssum \
-x $SCRATCH_MNT/incr/base $SCRATCH_MNT/incr
# Now recreate the filesystem by receiving both send streams and verify we get
# the same file contents that the original filesystem had and that files foo
# and bar have shared extents.
_scratch_unmount
_scratch_mkfs >>$seqres.full 2>&1
_scratch_mount
$BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT
$BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT
# Compute digests of the snapshot trees in the new filesystem and compare them
# to the ones in the original filesystem, they must match.
$FSSUM_PROG -r $send_files_dir/base.fssum $SCRATCH_MNT/base
$FSSUM_PROG -r $send_files_dir/incr.fssum $SCRATCH_MNT/incr
num_extents=$(_count_extents $SCRATCH_MNT/base/foo)
num_exclusive_extents=$(_count_exclusive_extents $SCRATCH_MNT/base/foo)
if [ $num_extents -ne 2 ] || [ $num_exclusive_extents -ne 1 ]; then
echo "File foo does not have 2 shared extents in the base snapshot"
$XFS_IO_PROG -r -c "fiemap" $SCRATCH_MNT/base/foo
fi
num_extents=$(_count_extents $SCRATCH_MNT/incr/foo)
num_exclusive_extents=$(_count_exclusive_extents $SCRATCH_MNT/incr/foo)
if [ $num_extents -ne 2 ] || [ $num_exclusive_extents -ne 1 ]; then
echo "File foo does not have 2 shared extents in the incr snapshot"
$XFS_IO_PROG -r -c "fiemap" $SCRATCH_MNT/incr/foo
fi
num_extents=$(_count_extents $SCRATCH_MNT/incr/bar)
num_exclusive_extents=$(_count_exclusive_extents $SCRATCH_MNT/incr/bar)
if [ $num_extents -ne 2 ] || [ $num_exclusive_extents -ne 1 ]; then
echo "File bar does not have 2 shared extents in the incr snapshot"
$XFS_IO_PROG -r -c "fiemap" $SCRATCH_MNT/incr/bar
fi
status=0
exit
|