btrfs: fsync after hole punching with no-holes mode
[xfstests-dev.git] / tests / btrfs / 108
1 #! /bin/bash
2 # FS QA Test No. btrfs/108
3 #
4 # Test that a send operation works correctly with reflinked files (cloned
5 # extents which multiple files point to).
6 #
7 #-----------------------------------------------------------------------
8 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
9 # Author: Filipe Manana <fdmanana@suse.com>
10 #
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License as
13 # published by the Free Software Foundation.
14 #
15 # This program is distributed in the hope that it would be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write the Free Software Foundation,
22 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23 #-----------------------------------------------------------------------
24 #
25
26 seq=`basename $0`
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
29
30 tmp=/tmp/$$
31 status=1        # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
33
34 _cleanup()
35 {
36         cd /
37         rm -fr $send_files_dir
38         rm -f $tmp.*
39 }
40
41 # get standard environment, filters and checks
42 . ./common/rc
43 . ./common/filter
44 . ./common/reflink
45
46 # real QA test starts here
47 _supported_fs btrfs
48 _supported_os Linux
49 _require_scratch
50 _require_cp_reflink
51 _require_xfs_io_command "fpunch"
52
53 send_files_dir=$TEST_DIR/btrfs-test-$seq
54
55 rm -f $seqres.full
56 rm -fr $send_files_dir
57 mkdir $send_files_dir
58
59 _scratch_mkfs >>$seqres.full 2>&1
60 _scratch_mount
61
62 # Create our test file with a single 100K extent.
63 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0K 100K" $SCRATCH_MNT/foo | _filter_xfs_io
64
65 # Clone our file into a new file named bar.
66 cp --reflink=always $SCRATCH_MNT/foo $SCRATCH_MNT/bar
67
68 # Now overwrite parts of our foo file.
69 $XFS_IO_PROG -c "pwrite -S 0xbb 50K 10K" \
70         -c "pwrite -S 0xcc 90K 10K" \
71         -c "fpunch 70K 10k" \
72         $SCRATCH_MNT/foo | _filter_xfs_io
73
74 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/snap
75
76 echo "File digests in the original filesystem:"
77 md5sum $SCRATCH_MNT/snap/foo | _filter_scratch
78 md5sum $SCRATCH_MNT/snap/bar | _filter_scratch
79
80 _run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/snap
81
82 # Now recreate the filesystem by receiving the send stream and verify we get
83 # the same file contents that the original filesystem had.
84 _scratch_unmount
85 _scratch_mkfs >>$seqres.full 2>&1
86 _scratch_mount
87
88 _run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
89
90 # We expect the destination filesystem to have exactly the same file data as
91 # the original filesystem.
92 # The btrfs send implementation had a bug where it sent a clone operation from
93 # file foo into file bar covering the whole [0, 100K[ range after creating
94 # and writing the file foo. This was incorrect because the file bar now included
95 # the updates done to file foo after we cloned foo to bar, breaking the COW
96 # nature of reflink copies (cloned extents).
97 echo "File digests in the new filesystem:"
98 md5sum $SCRATCH_MNT/snap/foo | _filter_scratch
99 md5sum $SCRATCH_MNT/snap/bar | _filter_scratch
100
101 status=0
102 exit