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 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
16 status=1 # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
23 rm -fr $send_files_dir
26 # get standard environment, filters and checks
30 # real QA test starts here
35 _require_btrfs_fs_feature "no_holes"
36 _require_btrfs_mkfs_feature "no-holes"
37 _require_xfs_io_command "fpunch"
38 _require_xfs_io_command "falloc" "-k"
40 send_files_dir=$TEST_DIR/btrfs-test-$seq
43 rm -fr $send_files_dir
46 _scratch_mkfs "-O no-holes" >>$seqres.full 2>&1
49 # Create our test file with a prealloc extent that starts beyond its size.
50 $XFS_IO_PROG -f -c "pwrite -S 0xab 0 500K" $SCRATCH_MNT/foobar | _filter_xfs_io
51 $XFS_IO_PROG -c "falloc -k 1200K 800K" $SCRATCH_MNT/foobar
53 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/base 2>&1 \
56 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap $SCRATCH_MNT/base 2>&1 \
59 # Now punch a hole that drops all the extents within the file's size.
60 $XFS_IO_PROG -c "fpunch 0 500K" $SCRATCH_MNT/foobar
62 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/incr 2>&1 \
65 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/base -f $send_files_dir/2.snap \
66 $SCRATCH_MNT/incr 2>&1 | _filter_scratch
68 echo "File digest in the original filesystem:"
69 md5sum $SCRATCH_MNT/incr/foobar | _filter_scratch
71 # Now recreate the filesystem by receiving both send streams and verify we get
72 # the same file content that the original filesystem had.
74 _scratch_mkfs >>$seqres.full 2>&1
77 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT
78 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT
80 echo "File digest in the new filesystem:"
81 md5sum $SCRATCH_MNT/incr/foobar | _filter_scratch