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 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
15 status=1 # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
22 rm -fr $send_files_dir
25 # get standard environment, filters and checks
30 # real QA test starts here
33 _require_scratch_reflink
35 send_files_dir=$TEST_DIR/btrfs-test-$seq
38 rm -fr $send_files_dir
41 _scratch_mkfs >>$seqres.full 2>&1
44 # Create our test file with a size of 64K in the parent snapshot.
45 # After the parent snapshot is created, we will increase its size and then clone
46 # one of its extents into a different offset and leave a hole between the shared
47 # extents. The shared extents will be located at offsets greater then size of the
48 # file in the parent snapshot.
49 $XFS_IO_PROG -f -c "pwrite -S 0xf1 0 64K" $SCRATCH_MNT/foobar | _filter_xfs_io
51 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/base 2>&1 \
54 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap $SCRATCH_MNT/base 2>&1 \
57 # Create a 320K extent at file offset 512K, with chunks of 64K having different
58 # content (to check cloning operations from send refer to the correct ranges).
59 # After that clone a range that includes a hole and a part of the extent created
60 # before - the clone range starts at an offset (448K) lower then the extent's
61 # offset (512K). We want to see the existence of the hole doesn't confuse the
62 # kernel's send code to send an invalid clone operation (with a source range
63 # going beyond the file's current size). The hole that confused send to issue
64 # an invalid clone operation spans the file range from offset 384K to 512K.
66 # Use offsets and ranges that are aligned to 64K, so that the test can run on
67 # machines with any page size (and therefore block size).
69 $XFS_IO_PROG -c "pwrite -S 0xab 512K 64K" \
70 -c "pwrite -S 0xcd 576K 64K" \
71 -c "pwrite -S 0xef 640K 64K" \
72 -c "pwrite -S 0x64 704K 64K" \
73 -c "pwrite -S 0x73 768K 64K" \
74 -c "reflink $SCRATCH_MNT/foobar 448K 192K 192K" \
75 $SCRATCH_MNT/foobar | _filter_xfs_io
77 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/incr 2>&1 \
80 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/base -f $send_files_dir/2.snap \
81 $SCRATCH_MNT/incr 2>&1 | _filter_scratch
83 echo "File foobar digest in the original filesystem:"
84 _md5_checksum $SCRATCH_MNT/incr/foobar
86 # Now recreate the filesystem by receiving both send streams and verify we get
87 # the same file contents that the original filesystem had.
89 _scratch_mkfs >>$seqres.full 2>&1
92 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT
93 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT
95 echo "File foobar digest in the new filesystem:"
96 _md5_checksum $SCRATCH_MNT/incr/foobar