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 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
14 status=1 # failure is the default!
15 trap "_cleanup; exit \$status" 0 1 2 3 15
20 rm -fr $send_files_dir
24 # get standard environment, filters and checks
29 # real QA test starts here
33 _require_xfs_io_command "fiemap"
35 send_files_dir=$TEST_DIR/btrfs-test-$seq
38 rm -fr $send_files_dir
41 _scratch_mkfs >>$seqres.full 2>&1
44 # Create the first test file.
45 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0 4K" $SCRATCH_MNT/foo | _filter_xfs_io
47 # Create a second test file with a 1Mb hole.
49 -c "pwrite -S 0xaa 0 4K" \
50 -c "pwrite -S 0xbb 1028K 4K" \
51 $SCRATCH_MNT/bar | _filter_xfs_io
53 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
54 $SCRATCH_MNT/snap1 >/dev/null
56 # Now add one new extent to our first test file, increasing its size and leaving
57 # a 1Mb hole between the first extent and this new extent.
58 $XFS_IO_PROG -c "pwrite -S 0xbb 1028K 4K" $SCRATCH_MNT/foo | _filter_xfs_io
60 # Now overwrite the last extent of our second test file.
61 $XFS_IO_PROG -c "pwrite -S 0xcc 1028K 4K" $SCRATCH_MNT/bar | _filter_xfs_io
63 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
64 $SCRATCH_MNT/snap2 >/dev/null
67 echo "File digests in the original filesystem:"
68 md5sum $SCRATCH_MNT/snap1/foo | _filter_scratch
69 md5sum $SCRATCH_MNT/snap1/bar | _filter_scratch
70 md5sum $SCRATCH_MNT/snap2/foo | _filter_scratch
71 md5sum $SCRATCH_MNT/snap2/bar | _filter_scratch
74 echo "File snap1/foo fiemap results in the original filesystem:"
75 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap1/foo | _filter_fiemap
77 echo "File snap1/bar fiemap results in the original filesystem:"
78 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap1/bar | _filter_fiemap
80 echo "File snap2/foo fiemap results in the original filesystem:"
81 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap2/foo | _filter_fiemap
83 echo "File snap2/bar fiemap results in the original filesystem:"
84 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap2/bar | _filter_fiemap
87 # Create the send streams to apply later on a new filesystem.
88 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap $SCRATCH_MNT/snap1 2>&1 \
90 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/snap1 -f $send_files_dir/2.snap \
91 $SCRATCH_MNT/snap2 2>&1 | _filter_scratch
93 # Create a new filesystem, receive the send streams and verify that the file
94 # contents are the same as in the original filesystem and that the file holes
95 # exists in both snapshots.
97 _scratch_mkfs >>$seqres.full 2>&1
99 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT >/dev/null
100 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT >/dev/null
103 echo "File digests in the new filesystem:"
104 md5sum $SCRATCH_MNT/snap1/foo | _filter_scratch
105 md5sum $SCRATCH_MNT/snap1/bar | _filter_scratch
106 md5sum $SCRATCH_MNT/snap2/foo | _filter_scratch
107 md5sum $SCRATCH_MNT/snap2/bar | _filter_scratch
110 echo "File snap1/foo fiemap results in the new filesystem:"
111 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap1/foo | _filter_fiemap
113 echo "File snap1/bar fiemap results in the new filesystem:"
114 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap1/bar | _filter_fiemap
116 echo "File snap2/foo fiemap results in the new filesystem:"
117 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap2/foo | _filter_fiemap
119 echo "File snap2/bar fiemap results in the new filesystem:"
120 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap2/bar | _filter_fiemap