2 # FS QA Test No. btrfs/047
4 # Verify that after an incremental btrfs send the replicated file has
5 # the same exact hole and data structure as in the origin filesystem.
6 # This didn't use to be the case before the send stream version 2 -
7 # holes were sent as write operations of 0 valued bytes instead of punching
8 # holes with the fallocate system call, and pre-allocated extents were sent
9 # as well as write operations of 0 valued bytes instead of intructions for
10 # the receiver to use the fallocate system call. Also check that prealloc
11 # extents that lie beyond the file's size are replicated by an incremental
14 # More specifically, this structure preserving guarantee was added by the
15 # following linux kernel commits:
17 # Btrfs: send, use fallocate command to punch holes
18 # Btrfs: send, use fallocate command to allocate extents
20 #-----------------------------------------------------------------------
21 # Copyright (c) 2014 Filipe Manana. All Rights Reserved.
23 # This program is free software; you can redistribute it and/or
24 # modify it under the terms of the GNU General Public License as
25 # published by the Free Software Foundation.
27 # This program is distributed in the hope that it would be useful,
28 # but WITHOUT ANY WARRANTY; without even the implied warranty of
29 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 # GNU General Public License for more details.
32 # You should have received a copy of the GNU General Public License
33 # along with this program; if not, write the Free Software Foundation,
34 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
35 #-----------------------------------------------------------------------
39 seqres=$RESULT_DIR/$seq
40 echo "QA output created by $seq"
43 status=1 # failure is the default!
44 trap "_cleanup; exit \$status" 0 1 2 3 15
48 rm -fr $send_files_dir
52 # get standard environment, filters and checks
57 # real QA test starts here
63 _require_xfs_io_command "fiemap"
64 _require_btrfs_send_stream_version
66 send_files_dir=$TEST_DIR/btrfs-test-$seq
69 rm -fr $send_files_dir
72 _scratch_mkfs >/dev/null 2>&1
75 $XFS_IO_PROG -f -c "pwrite -S 0x01 -b 300000 0 300000" $SCRATCH_MNT/foo \
78 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
80 $XFS_IO_PROG -c "fpunch 100000 50000" $SCRATCH_MNT/foo
81 $XFS_IO_PROG -c "falloc 100000 50000" $SCRATCH_MNT/foo
82 $XFS_IO_PROG -c "pwrite -S 0xff -b 1000 120000 1000" $SCRATCH_MNT/foo \
84 $XFS_IO_PROG -c "fpunch 250000 20000" $SCRATCH_MNT/foo
86 $XFS_IO_PROG -c "falloc -k 300000 1000000" $SCRATCH_MNT/foo
87 $XFS_IO_PROG -c "falloc -k 9000000 2000000" $SCRATCH_MNT/foo
89 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
91 _run_btrfs_util_prog send --stream-version 2 $SCRATCH_MNT/mysnap1 \
92 -f $send_files_dir/1.snap
93 _run_btrfs_util_prog send --stream-version 2 -p $SCRATCH_MNT/mysnap1 \
94 $SCRATCH_MNT/mysnap2 -f $send_files_dir/2.snap
96 md5sum $SCRATCH_MNT/mysnap2/foo | _filter_scratch
97 # List all hole and data segments.
98 $XFS_IO_PROG -r -c "seek -r -a 0" $SCRATCH_MNT/mysnap2/foo
99 # List all extents, we're interested here in prealloc extents that lie beyond
101 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/mysnap2/foo | _filter_fiemap
106 _scratch_mkfs >/dev/null 2>&1
109 _run_btrfs_util_prog receive $SCRATCH_MNT -f $send_files_dir/1.snap
110 _run_btrfs_util_prog receive $SCRATCH_MNT -f $send_files_dir/2.snap
112 md5sum $SCRATCH_MNT/mysnap2/foo | _filter_scratch
113 # List all hole and data segments.
114 $XFS_IO_PROG -r -c "seek -r -a 0" $SCRATCH_MNT/mysnap2/foo
115 # List all extents, we're interested here in prealloc extents that lie beyond
117 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/mysnap2/foo | _filter_fiemap