2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 SUSE Linux Products GmbH. All Rights Reserved.
5 # FS QA Test No. btrfs/149
7 # Test that an incremental send/receive operation will not fail when the
8 # destination filesystem has compression enabled and the source filesystem
9 # has a 4K extent at a file offset 0 that is not compressed and that is
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
17 status=1 # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
23 rm -fr $send_files_dir
27 # get standard environment, filters and checks
32 # real QA test starts here
37 _require_scratch_reflink
40 send_files_dir=$TEST_DIR/btrfs-test-$seq
43 rm -fr $send_files_dir
46 _scratch_mkfs >>$seqres.full 2>&1
47 _scratch_mount "-o compress"
49 # Write to our file using direct IO, so that this way the write ends up not
50 # getting compressed, that is, we get a regular extent which is neither
51 # inlined nor compressed.
52 # Alternatively, we could have mounted the fs without compression enabled,
53 # which would result as well in an uncompressed regular extent.
54 $XFS_IO_PROG -f -d -c "pwrite -S 0xab 0 4K" $SCRATCH_MNT/foobar | _filter_xfs_io
56 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
57 $SCRATCH_MNT/mysnap1 > /dev/null
59 # Clone the regular (not inlined) extent.
60 $XFS_IO_PROG -c "reflink $SCRATCH_MNT/foobar 0 8K 4K" $SCRATCH_MNT/foobar \
63 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
64 $SCRATCH_MNT/mysnap2 > /dev/null
66 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
67 $SCRATCH_MNT/mysnap1 2>&1 >/dev/null | _filter_scratch
69 # Now do an incremental send of the second snapshot. The send stream can have
70 # a clone operation to clone the extent at offset 0 to offset 8K. This operation
71 # would fail on the receiver if it has compression enabled, since the write
72 # operation of the extent at offset 0 was compressed because it was a buffered
73 # write operation, and btrfs' clone implementation does not allow cloning inline
74 # extents to offsets different from 0.
75 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
76 $SCRATCH_MNT/mysnap2 2>&1 >/dev/null | _filter_scratch
78 echo "File digests in the original filesystem:"
79 md5sum $SCRATCH_MNT/mysnap1/foobar | _filter_scratch
80 md5sum $SCRATCH_MNT/mysnap2/foobar | _filter_scratch
82 # Now recreate the filesystem by receiving both send streams and verify we get
83 # the same file content that the original filesystem had.
85 _scratch_mkfs >>$seqres.full 2>&1
86 _scratch_mount "-o compress"
88 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT > /dev/null
89 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT > /dev/null
91 echo "File digests in the new filesystem:"
92 md5sum $SCRATCH_MNT/mysnap1/foobar | _filter_scratch
93 md5sum $SCRATCH_MNT/mysnap2/foobar | _filter_scratch