2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved.
7 # Test that an incremental send operation works correctly when a file has shared
8 # extents with itself in the send snapshot, with a hole between them, and the
9 # file size has increased in the send snapshot.
12 _begin_fstest auto quick send clone
14 # Override the default cleanup function.
19 rm -fr $send_files_dir
22 # Import common functions.
26 # real QA test starts here
29 _require_scratch_reflink
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 test file with a size of 64K in the parent snapshot.
40 # After the parent snapshot is created, we will increase its size and then clone
41 # one of its extents into a different offset and leave a hole between the shared
42 # extents. The shared extents will be located at offsets greater then size of the
43 # file in the parent snapshot.
44 $XFS_IO_PROG -f -c "pwrite -S 0xf1 0 64K" $SCRATCH_MNT/foobar | _filter_xfs_io
46 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/base 2>&1 \
49 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap $SCRATCH_MNT/base 2>&1 \
52 # Create a 320K extent at file offset 512K, with chunks of 64K having different
53 # content (to check cloning operations from send refer to the correct ranges).
54 # After that clone a range that includes a hole and a part of the extent created
55 # before - the clone range starts at an offset (448K) lower then the extent's
56 # offset (512K). We want to see the existence of the hole doesn't confuse the
57 # kernel's send code to send an invalid clone operation (with a source range
58 # going beyond the file's current size). The hole that confused send to issue
59 # an invalid clone operation spans the file range from offset 384K to 512K.
61 # Use offsets and ranges that are aligned to 64K, so that the test can run on
62 # machines with any page size (and therefore block size).
64 $XFS_IO_PROG -c "pwrite -S 0xab 512K 64K" \
65 -c "pwrite -S 0xcd 576K 64K" \
66 -c "pwrite -S 0xef 640K 64K" \
67 -c "pwrite -S 0x64 704K 64K" \
68 -c "pwrite -S 0x73 768K 64K" \
69 -c "reflink $SCRATCH_MNT/foobar 448K 192K 192K" \
70 $SCRATCH_MNT/foobar | _filter_xfs_io
72 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/incr 2>&1 \
75 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/base -f $send_files_dir/2.snap \
76 $SCRATCH_MNT/incr 2>&1 | _filter_scratch
78 echo "File foobar digest in the original filesystem:"
79 _md5_checksum $SCRATCH_MNT/incr/foobar
81 # Now recreate the filesystem by receiving both send streams and verify we get
82 # the same file contents that the original filesystem had.
84 _scratch_mkfs >>$seqres.full 2>&1
87 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT
88 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT
90 echo "File foobar digest in the new filesystem:"
91 _md5_checksum $SCRATCH_MNT/incr/foobar