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
34 _require_xfs_io_command "fiemap"
36 send_files_dir=$TEST_DIR/btrfs-test-$seq
39 rm -fr $send_files_dir
42 _scratch_mkfs >>$seqres.full 2>&1
45 # Create the first test file.
46 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0 4K" $SCRATCH_MNT/foo | _filter_xfs_io
48 # Create a second test file with a 1Mb hole.
50 -c "pwrite -S 0xaa 0 4K" \
51 -c "pwrite -S 0xbb 1028K 4K" \
52 $SCRATCH_MNT/bar | _filter_xfs_io
54 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
55 $SCRATCH_MNT/snap1 >/dev/null
57 # Now add one new extent to our first test file, increasing its size and leaving
58 # a 1Mb hole between the first extent and this new extent.
59 $XFS_IO_PROG -c "pwrite -S 0xbb 1028K 4K" $SCRATCH_MNT/foo | _filter_xfs_io
61 # Now overwrite the last extent of our second test file.
62 $XFS_IO_PROG -c "pwrite -S 0xcc 1028K 4K" $SCRATCH_MNT/bar | _filter_xfs_io
64 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
65 $SCRATCH_MNT/snap2 >/dev/null
68 echo "File digests in the original filesystem:"
69 md5sum $SCRATCH_MNT/snap1/foo | _filter_scratch
70 md5sum $SCRATCH_MNT/snap1/bar | _filter_scratch
71 md5sum $SCRATCH_MNT/snap2/foo | _filter_scratch
72 md5sum $SCRATCH_MNT/snap2/bar | _filter_scratch
75 echo "File snap1/foo fiemap results in the original filesystem:"
76 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap1/foo | _filter_fiemap
78 echo "File snap1/bar fiemap results in the original filesystem:"
79 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap1/bar | _filter_fiemap
81 echo "File snap2/foo fiemap results in the original filesystem:"
82 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap2/foo | _filter_fiemap
84 echo "File snap2/bar fiemap results in the original filesystem:"
85 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap2/bar | _filter_fiemap
88 # Create the send streams to apply later on a new filesystem.
89 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap $SCRATCH_MNT/snap1 2>&1 \
91 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/snap1 -f $send_files_dir/2.snap \
92 $SCRATCH_MNT/snap2 2>&1 | _filter_scratch
94 # Create a new filesystem, receive the send streams and verify that the file
95 # contents are the same as in the original filesystem and that the file holes
96 # exists in both snapshots.
98 _scratch_mkfs >>$seqres.full 2>&1
100 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT >/dev/null
101 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT >/dev/null
104 echo "File digests in the new filesystem:"
105 md5sum $SCRATCH_MNT/snap1/foo | _filter_scratch
106 md5sum $SCRATCH_MNT/snap1/bar | _filter_scratch
107 md5sum $SCRATCH_MNT/snap2/foo | _filter_scratch
108 md5sum $SCRATCH_MNT/snap2/bar | _filter_scratch
111 echo "File snap1/foo fiemap results in the new filesystem:"
112 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap1/foo | _filter_fiemap
114 echo "File snap1/bar fiemap results in the new filesystem:"
115 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap1/bar | _filter_fiemap
117 echo "File snap2/foo fiemap results in the new filesystem:"
118 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap2/foo | _filter_fiemap
120 echo "File snap2/bar fiemap results in the new filesystem:"
121 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap2/bar | _filter_fiemap