blob: 13d3446fc1cc0aa5fb3d1c1a3ea2aa5f41783d39 (
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
|
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
#
# FS QA Test No. btrfs/109
#
# Test that a send operation works correctly with reflinked files (cloned
# extents which multiple files point to) that have compressed extents.
#
. ./common/preamble
_begin_fstest auto quick send clone compress
# Override the default cleanup function.
_cleanup()
{
cd /
rm -fr $send_files_dir
rm -f $tmp.*
}
. ./common/filter
. ./common/reflink
_supported_fs btrfs
_require_scratch
_require_cp_reflink
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 "-o compress"
# Create our file with an extent of 100K starting at file offset 0K.
$XFS_IO_PROG -f -c "pwrite -S 0xaa 0K 100K" \
-c "fsync" \
$SCRATCH_MNT/foo | _filter_xfs_io
# Rewrite part of the previous extent (its first 40K) and write a new 100K
# extent starting at file offset 100K.
$XFS_IO_PROG -c "pwrite -S 0xbb 0K 40K" \
-c "pwrite -S 0xcc 100K 100K" \
$SCRATCH_MNT/foo | _filter_xfs_io
# Our file foo now has 3 file extent items in its metadata:
#
# 1) One covering the file range 0 to 40K;
# 2) One covering the file range 40K to 100K, which points to the first extent
# we wrote to the file and has a data offset field with value 40K (our file
# no longer uses the first 40K of data from that extent);
# 3) One covering the file range 100K to 200K.
# Now clone our file foo into file bar.
cp --reflink=always $SCRATCH_MNT/foo $SCRATCH_MNT/bar
# Create our snapshot for the send operation.
_btrfs subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/snap
echo "File digests in the original filesystem:"
md5sum $SCRATCH_MNT/snap/foo | _filter_scratch
md5sum $SCRATCH_MNT/snap/bar | _filter_scratch
_btrfs send -f $send_files_dir/1.snap $SCRATCH_MNT/snap
# Now recreate the filesystem by receiving the send stream and verify we get
# the same file contents that the original filesystem had.
# Btrfs send used to issue a clone operation from foo's range [80K, 140K[ to
# bar's range [40K, 100K[ when cloning the extent pointed to by foo's second
# file extent item, this was incorrect because of bad accounting of the file
# extent item's data offset field. The correct range to clone from should have
# been [40K, 100K[.
_scratch_unmount
_scratch_mkfs >>$seqres.full 2>&1
_scratch_mount "-o compress"
_btrfs receive -f $send_files_dir/1.snap $SCRATCH_MNT
echo "File digests in the new filesystem:"
# Must match the digests we got in the original filesystem.
md5sum $SCRATCH_MNT/snap/foo | _filter_scratch
md5sum $SCRATCH_MNT/snap/bar | _filter_scratch
status=0
exit
|