2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 SUSE Linux Products GmbH. All Rights Reserved.
5 # FS QA Test No. btrfs/137
7 # Test that both incremental and full send operations preserve file holes.
10 _begin_fstest auto quick send
12 # Override the default cleanup function.
16 rm -fr $send_files_dir
20 # Import common functions.
24 # real QA test starts here
28 _require_xfs_io_command "fiemap"
30 send_files_dir=$TEST_DIR/btrfs-test-$seq
32 rm -fr $send_files_dir
35 _scratch_mkfs >>$seqres.full 2>&1
38 # Create the first test file.
39 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0 4K" $SCRATCH_MNT/foo | _filter_xfs_io
41 # Create a second test file with a 1Mb hole.
43 -c "pwrite -S 0xaa 0 4K" \
44 -c "pwrite -S 0xbb 1028K 4K" \
45 $SCRATCH_MNT/bar | _filter_xfs_io
47 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
48 $SCRATCH_MNT/snap1 >/dev/null
50 # Now add one new extent to our first test file, increasing its size and leaving
51 # a 1Mb hole between the first extent and this new extent.
52 $XFS_IO_PROG -c "pwrite -S 0xbb 1028K 4K" $SCRATCH_MNT/foo | _filter_xfs_io
54 # Now overwrite the last extent of our second test file.
55 $XFS_IO_PROG -c "pwrite -S 0xcc 1028K 4K" $SCRATCH_MNT/bar | _filter_xfs_io
57 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
58 $SCRATCH_MNT/snap2 >/dev/null
61 echo "File digests in the original filesystem:"
62 md5sum $SCRATCH_MNT/snap1/foo | _filter_scratch
63 md5sum $SCRATCH_MNT/snap1/bar | _filter_scratch
64 md5sum $SCRATCH_MNT/snap2/foo | _filter_scratch
65 md5sum $SCRATCH_MNT/snap2/bar | _filter_scratch
68 echo "File snap1/foo fiemap results in the original filesystem:"
69 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap1/foo | _filter_fiemap
71 echo "File snap1/bar fiemap results in the original filesystem:"
72 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap1/bar | _filter_fiemap
74 echo "File snap2/foo fiemap results in the original filesystem:"
75 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap2/foo | _filter_fiemap
77 echo "File snap2/bar fiemap results in the original filesystem:"
78 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap2/bar | _filter_fiemap
81 # Create the send streams to apply later on a new filesystem.
82 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap $SCRATCH_MNT/snap1 2>&1 \
84 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/snap1 -f $send_files_dir/2.snap \
85 $SCRATCH_MNT/snap2 2>&1 | _filter_scratch
87 # Create a new filesystem, receive the send streams and verify that the file
88 # contents are the same as in the original filesystem and that the file holes
89 # exists in both snapshots.
91 _scratch_mkfs >>$seqres.full 2>&1
93 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT >/dev/null
94 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT >/dev/null
97 echo "File digests in the new filesystem:"
98 md5sum $SCRATCH_MNT/snap1/foo | _filter_scratch
99 md5sum $SCRATCH_MNT/snap1/bar | _filter_scratch
100 md5sum $SCRATCH_MNT/snap2/foo | _filter_scratch
101 md5sum $SCRATCH_MNT/snap2/bar | _filter_scratch
104 echo "File snap1/foo fiemap results in the new filesystem:"
105 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap1/foo | _filter_fiemap
107 echo "File snap1/bar fiemap results in the new filesystem:"
108 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap1/bar | _filter_fiemap
110 echo "File snap2/foo fiemap results in the new filesystem:"
111 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap2/foo | _filter_fiemap
113 echo "File snap2/bar fiemap results in the new filesystem:"
114 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap2/bar | _filter_fiemap