btrfs: fsync after hole punching with no-holes mode
[xfstests-dev.git] / tests / btrfs / 149
1 #! /bin/bash
2 # FS QA Test No. btrfs/149
3 #
4 # Test that an incremental send/receive operation will not fail when the
5 # destination filesystem has compression enabled and the source filesystem
6 # has a 4K extent at a file offset 0 that is not compressed and that is
7 # shared.
8 #
9 #-----------------------------------------------------------------------
10 #
11 # Copyright (C) 2017 SUSE Linux Products GmbH. All Rights Reserved.
12 # Author: Filipe Manana <fdmanana@suse.com>
13 #
14 # This program is free software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License as
16 # published by the Free Software Foundation.
17 #
18 # This program is distributed in the hope that it would be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 # GNU General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write the Free Software Foundation,
25 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
26 #-----------------------------------------------------------------------
27 #
28
29 seq=`basename $0`
30 seqres=$RESULT_DIR/$seq
31 echo "QA output created by $seq"
32
33 tmp=/tmp/$$
34 status=1        # failure is the default!
35 trap "_cleanup; exit \$status" 0 1 2 3 15
36
37 _cleanup()
38 {
39         cd /
40         rm -fr $send_files_dir
41         rm -f $tmp.*
42 }
43
44 # get standard environment, filters and checks
45 . ./common/rc
46 . ./common/filter
47 . ./common/reflink
48
49 # real QA test starts here
50 _supported_fs btrfs
51 _supported_os Linux
52 _require_test
53 _require_scratch
54 _require_scratch_reflink
55 _require_odirect
56
57 send_files_dir=$TEST_DIR/btrfs-test-$seq
58
59 rm -f $seqres.full
60 rm -fr $send_files_dir
61 mkdir $send_files_dir
62
63 _scratch_mkfs >>$seqres.full 2>&1
64 _scratch_mount "-o compress"
65
66 # Write to our file using direct IO, so that this way the write ends up not
67 # getting compressed, that is, we get a regular extent which is neither
68 # inlined nor compressed.
69 # Alternatively, we could have mounted the fs without compression enabled,
70 # which would result as well in an uncompressed regular extent.
71 $XFS_IO_PROG -f -d -c "pwrite -S 0xab 0 4K" $SCRATCH_MNT/foobar | _filter_xfs_io
72
73 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
74         $SCRATCH_MNT/mysnap1 > /dev/null
75
76 # Clone the regular (not inlined) extent.
77 $XFS_IO_PROG -c "reflink $SCRATCH_MNT/foobar 0 8K 4K" $SCRATCH_MNT/foobar \
78         | _filter_xfs_io
79
80 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
81         $SCRATCH_MNT/mysnap2 > /dev/null
82
83 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
84                  $SCRATCH_MNT/mysnap1 2>&1 >/dev/null | _filter_scratch
85
86 # Now do an incremental send of the second snapshot. The send stream can have
87 # a clone operation to clone the extent at offset 0 to offset 8K. This operation
88 # would fail on the receiver if it has compression enabled, since the write
89 # operation of the extent at offset 0 was compressed because it was a buffered
90 # write operation, and btrfs' clone implementation does not allow cloning inline
91 # extents to offsets different from 0.
92 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
93                  $SCRATCH_MNT/mysnap2 2>&1 >/dev/null | _filter_scratch
94
95 echo "File digests in the original filesystem:"
96 md5sum $SCRATCH_MNT/mysnap1/foobar | _filter_scratch
97 md5sum $SCRATCH_MNT/mysnap2/foobar | _filter_scratch
98
99 # Now recreate the filesystem by receiving both send streams and verify we get
100 # the same file content that the original filesystem had.
101 _scratch_unmount
102 _scratch_mkfs >>$seqres.full 2>&1
103 _scratch_mount "-o compress"
104
105 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT > /dev/null
106 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT > /dev/null
107
108 echo "File digests in the new filesystem:"
109 md5sum $SCRATCH_MNT/mysnap1/foobar | _filter_scratch
110 md5sum $SCRATCH_MNT/mysnap2/foobar | _filter_scratch
111
112 status=0
113 exit