2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved.
7 # Test that an incremental send with not corrupt data when the source filesystem
8 # has the no-holes feature enabled, a file has prealloc (unwritten) extents that
9 # start after its size and hole is punched (after the first snapshot is made)
10 # that removes all extents from some offset up to the file's size.
13 _begin_fstest auto quick send prealloc punch
15 # Override the default cleanup function.
20 rm -fr $send_files_dir
23 # Import common functions.
26 # real QA test starts here
30 _require_btrfs_fs_feature "no_holes"
31 _require_btrfs_mkfs_feature "no-holes"
32 _require_xfs_io_command "fpunch"
33 _require_xfs_io_command "falloc" "-k"
35 send_files_dir=$TEST_DIR/btrfs-test-$seq
37 rm -fr $send_files_dir
40 _scratch_mkfs "-O no-holes" >>$seqres.full 2>&1
43 # Create our test file with a prealloc extent that starts beyond its size.
44 $XFS_IO_PROG -f -c "pwrite -S 0xab 0 500K" $SCRATCH_MNT/foobar | _filter_xfs_io
45 $XFS_IO_PROG -c "falloc -k 1200K 800K" $SCRATCH_MNT/foobar
47 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/base 2>&1 \
50 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap $SCRATCH_MNT/base 2>&1 \
53 # Now punch a hole that drops all the extents within the file's size.
54 $XFS_IO_PROG -c "fpunch 0 500K" $SCRATCH_MNT/foobar
56 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/incr 2>&1 \
59 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/base -f $send_files_dir/2.snap \
60 $SCRATCH_MNT/incr 2>&1 | _filter_scratch
62 echo "File digest in the original filesystem:"
63 md5sum $SCRATCH_MNT/incr/foobar | _filter_scratch
65 # Now recreate the filesystem by receiving both send streams and verify we get
66 # the same file content that the original filesystem had.
68 _scratch_mkfs >>$seqres.full 2>&1
71 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT
72 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT
74 echo "File digest in the new filesystem:"
75 md5sum $SCRATCH_MNT/incr/foobar | _filter_scratch