2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved.
7 # Check that send operations (full and incremental) are able to issue clone
8 # operations for extents that are shared between the same file.
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
14 status=1 # failure is the default!
15 trap "_cleanup; exit \$status" 0 1 2 3 15
21 rm -fr $send_files_dir
24 # get standard environment, filters and checks
30 # real QA test starts here
34 _require_scratch_reflink
35 _require_xfs_io_command "fiemap"
37 send_files_dir=$TEST_DIR/btrfs-test-$seq
40 rm -fr $send_files_dir
43 _scratch_mkfs >>$seqres.full 2>&1
46 # Create our first test file, which has an extent that is shared only with
47 # itself and no other files. We want to verify a full send operation will
49 $XFS_IO_PROG -f -c "pwrite -S 0xb1 -b 64K 0 64K" $SCRATCH_MNT/foo \
51 $XFS_IO_PROG -c "reflink $SCRATCH_MNT/foo 0 64K 64K" $SCRATCH_MNT/foo \
54 # Create out second test file which initially, for the first send operation,
55 # only has a single extent that is not shared.
56 $XFS_IO_PROG -f -c "pwrite -S 0xc7 -b 64K 0 64K" $SCRATCH_MNT/bar \
59 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/base 2>&1 \
62 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap $SCRATCH_MNT/base 2>&1 \
65 # Now clone the existing extent in file bar to itself at a different offset.
66 # We want to verify the incremental send operation below will issue a clone
67 # operation instead of a write operation.
68 $XFS_IO_PROG -c "reflink $SCRATCH_MNT/bar 0 64K 64K" $SCRATCH_MNT/bar \
71 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/incr 2>&1 \
74 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/base -f $send_files_dir/2.snap \
75 $SCRATCH_MNT/incr 2>&1 | _filter_scratch
77 # Compute digests of the snapshot trees so that later we can compare against
78 # digests of the trees in the new filesystem, to see if they match (no data or
79 # metadata corruption happened).
80 $FSSUM_PROG -A -f -w $send_files_dir/base.fssum $SCRATCH_MNT/base
81 $FSSUM_PROG -A -f -w $send_files_dir/incr.fssum \
82 -x $SCRATCH_MNT/incr/base $SCRATCH_MNT/incr
84 # Now recreate the filesystem by receiving both send streams and verify we get
85 # the same file contents that the original filesystem had and that files foo
86 # and bar have shared extents.
88 _scratch_mkfs >>$seqres.full 2>&1
91 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT
92 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT
94 # Compute digests of the snapshot trees in the new filesystem and compare them
95 # to the ones in the original filesystem, they must match.
96 $FSSUM_PROG -r $send_files_dir/base.fssum $SCRATCH_MNT/base
97 $FSSUM_PROG -r $send_files_dir/incr.fssum $SCRATCH_MNT/incr
99 num_extents=$(_count_extents $SCRATCH_MNT/base/foo)
100 num_exclusive_extents=$(_count_exclusive_extents $SCRATCH_MNT/base/foo)
101 if [ $num_extents -ne 2 ] || [ $num_exclusive_extents -ne 1 ]; then
102 echo "File foo does not have 2 shared extents in the base snapshot"
103 $XFS_IO_PROG -r -c "fiemap" $SCRATCH_MNT/base/foo
106 num_extents=$(_count_extents $SCRATCH_MNT/incr/foo)
107 num_exclusive_extents=$(_count_exclusive_extents $SCRATCH_MNT/incr/foo)
108 if [ $num_extents -ne 2 ] || [ $num_exclusive_extents -ne 1 ]; then
109 echo "File foo does not have 2 shared extents in the incr snapshot"
110 $XFS_IO_PROG -r -c "fiemap" $SCRATCH_MNT/incr/foo
113 num_extents=$(_count_extents $SCRATCH_MNT/incr/bar)
114 num_exclusive_extents=$(_count_exclusive_extents $SCRATCH_MNT/incr/bar)
115 if [ $num_extents -ne 2 ] || [ $num_exclusive_extents -ne 1 ]; then
116 echo "File bar does not have 2 shared extents in the incr snapshot"
117 $XFS_IO_PROG -r -c "fiemap" $SCRATCH_MNT/incr/bar