2 # FS QA Test No. btrfs/149
4 # Test that an incremental send/receive operation will not fail when the
5 # destination filesystem has compression enabled and the source filesystem
6 # has a 4K extent at a file offset 0 that is not compressed and that is
9 #-----------------------------------------------------------------------
11 # Copyright (C) 2017 SUSE Linux Products GmbH. All Rights Reserved.
12 # Author: Filipe Manana <fdmanana@suse.com>
14 # This program is free software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License as
16 # published by the Free Software Foundation.
18 # This program is distributed in the hope that it would be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write the Free Software Foundation,
25 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #-----------------------------------------------------------------------
30 seqres=$RESULT_DIR/$seq
31 echo "QA output created by $seq"
34 status=1 # failure is the default!
35 trap "_cleanup; exit \$status" 0 1 2 3 15
40 rm -fr $send_files_dir
44 # get standard environment, filters and checks
49 # real QA test starts here
54 _require_scratch_reflink
57 send_files_dir=$TEST_DIR/btrfs-test-$seq
60 rm -fr $send_files_dir
63 _scratch_mkfs >>$seqres.full 2>&1
64 _scratch_mount "-o compress"
66 # Write to our file using direct IO, so that this way the write ends up not
67 # getting compressed, that is, we get a regular extent which is neither
68 # inlined nor compressed.
69 # Alternatively, we could have mounted the fs without compression enabled,
70 # which would result as well in an uncompressed regular extent.
71 $XFS_IO_PROG -f -d -c "pwrite -S 0xab 0 4K" $SCRATCH_MNT/foobar | _filter_xfs_io
73 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
74 $SCRATCH_MNT/mysnap1 > /dev/null
76 # Clone the regular (not inlined) extent.
77 $XFS_IO_PROG -c "reflink $SCRATCH_MNT/foobar 0 8K 4K" $SCRATCH_MNT/foobar \
80 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
81 $SCRATCH_MNT/mysnap2 > /dev/null
83 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
84 $SCRATCH_MNT/mysnap1 2>&1 >/dev/null | _filter_scratch
86 # Now do an incremental send of the second snapshot. The send stream can have
87 # a clone operation to clone the extent at offset 0 to offset 8K. This operation
88 # would fail on the receiver if it has compression enabled, since the write
89 # operation of the extent at offset 0 was compressed because it was a buffered
90 # write operation, and btrfs' clone implementation does not allow cloning inline
91 # extents to offsets different from 0.
92 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
93 $SCRATCH_MNT/mysnap2 2>&1 >/dev/null | _filter_scratch
95 echo "File digests in the original filesystem:"
96 md5sum $SCRATCH_MNT/mysnap1/foobar | _filter_scratch
97 md5sum $SCRATCH_MNT/mysnap2/foobar | _filter_scratch
99 # Now recreate the filesystem by receiving both send streams and verify we get
100 # the same file content that the original filesystem had.
102 _scratch_mkfs >>$seqres.full 2>&1
103 _scratch_mount "-o compress"
105 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT > /dev/null
106 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT > /dev/null
108 echo "File digests in the new filesystem:"
109 md5sum $SCRATCH_MNT/mysnap1/foobar | _filter_scratch
110 md5sum $SCRATCH_MNT/mysnap2/foobar | _filter_scratch