2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved.
5 # FS QA Test No. btrfs/191
7 # Test that an incremental send operation works after deduplicating into the
8 # same file in both the parent and send snapshots.
11 _begin_fstest auto quick send dedupe
13 # Override the default cleanup function.
17 rm -fr $send_files_dir
21 # Import common functions.
25 # real QA test starts here
28 _require_scratch_dedupe
31 send_files_dir=$TEST_DIR/btrfs-test-$seq
33 rm -fr $send_files_dir
36 _scratch_mkfs >>$seqres.full 2>&1
39 # Create our first file. The first half of the file has several 64Kb extents
40 # while the second half as a single 512Kb extent.
41 $XFS_IO_PROG -f -s -c "pwrite -S 0xb8 -b 64K 0 512K" $SCRATCH_MNT/foo \
43 $XFS_IO_PROG -c "pwrite -S 0xb8 512K 512K" $SCRATCH_MNT/foo | _filter_xfs_io
45 # Create the base snapshot and the parent send stream from it.
46 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1 \
49 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap $SCRATCH_MNT/mysnap1 2>&1 \
52 # Create our second file, that has exactly the same data as the first file.
53 $XFS_IO_PROG -f -c "pwrite -S 0xb8 0 1M" $SCRATCH_MNT/bar | _filter_xfs_io
55 # Create the second snapshot, used for the incremental send, before doing the
57 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2 \
60 # Now before creating the incremental send stream:
62 # 1) Deduplicate into a subrange of file foo in snapshot mysnap1. This will drop
63 # several extent items and add a new one, also updating the inode's iversion
64 # (sequence field in inode item) by 1, but not any other field of the inode;
66 # 2) Deduplicate into a different subrange of file foo in snapshot mysnap2. This
67 # will replace an extent item with a new one, also updating the inode's
68 # iversion by 1 but not any other field of the inode.
70 # After these two deduplication operations, the inode items, for file foo, are
71 # identical in both snapshots, but we have different extent items for this inode
72 # in both snapshots. We want to check this doesn't cause send to fail with an
73 # error or produce an incorrect stream.
75 $XFS_IO_PROG -r -c "dedupe $SCRATCH_MNT/bar 0 0 512K" $SCRATCH_MNT/mysnap1/foo \
78 $XFS_IO_PROG -r -c "dedupe $SCRATCH_MNT/bar 512K 512K 512K" \
79 $SCRATCH_MNT/mysnap2/foo | _filter_xfs_io
81 # Create the incremental send stream.
82 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
83 $SCRATCH_MNT/mysnap2 2>&1 | _filter_scratch
85 # Create the checksums to verify later that the send streams produce correct
87 $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
88 $FSSUM_PROG -A -f -w $send_files_dir/2.fssum \
89 -x $SCRATCH_MNT/mysnap2/mysnap1 $SCRATCH_MNT/mysnap2
91 # Now recreate the filesystem by receiving both send streams and verify we get
92 # the same content that the original filesystem had.
94 _scratch_mkfs >>$seqres.full 2>&1
97 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT
98 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT
99 $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
100 $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2