btrfs: fsync after hole punching with no-holes mode
[xfstests-dev.git] / tests / btrfs / 137
1 #! /bin/bash
2 # FS QA Test No. btrfs/137
3 #
4 # Test that both incremental and full send operations preserve file holes.
5 #
6 #-----------------------------------------------------------------------
7 #
8 # Copyright (C) 2017 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/punch
45
46 # real QA test starts here
47 _supported_fs btrfs
48 _supported_os Linux
49 _require_test
50 _require_scratch
51 _require_xfs_io_command "fiemap"
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 the first test file.
63 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0 4K" $SCRATCH_MNT/foo | _filter_xfs_io
64
65 # Create a second test file with a 1Mb hole.
66 $XFS_IO_PROG -f \
67      -c "pwrite -S 0xaa 0 4K" \
68      -c "pwrite -S 0xbb 1028K 4K" \
69      $SCRATCH_MNT/bar | _filter_xfs_io
70
71 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
72         $SCRATCH_MNT/snap1 >/dev/null
73
74 # Now add one new extent to our first test file, increasing its size and leaving
75 # a 1Mb hole between the first extent and this new extent.
76 $XFS_IO_PROG -c "pwrite -S 0xbb 1028K 4K" $SCRATCH_MNT/foo | _filter_xfs_io
77
78 # Now overwrite the last extent of our second test file.
79 $XFS_IO_PROG -c "pwrite -S 0xcc 1028K 4K" $SCRATCH_MNT/bar | _filter_xfs_io
80
81 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
82                  $SCRATCH_MNT/snap2 >/dev/null
83
84 echo
85 echo "File digests in the original filesystem:"
86 md5sum $SCRATCH_MNT/snap1/foo | _filter_scratch
87 md5sum $SCRATCH_MNT/snap1/bar | _filter_scratch
88 md5sum $SCRATCH_MNT/snap2/foo | _filter_scratch
89 md5sum $SCRATCH_MNT/snap2/bar | _filter_scratch
90
91 echo
92 echo "File snap1/foo fiemap results in the original filesystem:"
93 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap1/foo | _filter_fiemap
94 echo
95 echo "File snap1/bar fiemap results in the original filesystem:"
96 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap1/bar | _filter_fiemap
97 echo
98 echo "File snap2/foo fiemap results in the original filesystem:"
99 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap2/foo | _filter_fiemap
100 echo
101 echo "File snap2/bar fiemap results in the original filesystem:"
102 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap2/bar | _filter_fiemap
103 echo
104
105 # Create the send streams to apply later on a new filesystem.
106 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap $SCRATCH_MNT/snap1 2>&1 \
107         | _filter_scratch
108 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/snap1 -f $send_files_dir/2.snap \
109         $SCRATCH_MNT/snap2 2>&1 | _filter_scratch
110
111 # Create a new filesystem, receive the send streams and verify that the file
112 # contents are the same as in the original filesystem and that the file holes
113 # exists in both snapshots.
114 _scratch_unmount
115 _scratch_mkfs >>$seqres.full 2>&1
116 _scratch_mount
117 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT >/dev/null
118 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT >/dev/null
119
120 echo
121 echo "File digests in the new filesystem:"
122 md5sum $SCRATCH_MNT/snap1/foo | _filter_scratch
123 md5sum $SCRATCH_MNT/snap1/bar | _filter_scratch
124 md5sum $SCRATCH_MNT/snap2/foo | _filter_scratch
125 md5sum $SCRATCH_MNT/snap2/bar | _filter_scratch
126
127 echo
128 echo "File snap1/foo fiemap results in the new filesystem:"
129 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap1/foo | _filter_fiemap
130 echo
131 echo "File snap1/bar fiemap results in the new filesystem:"
132 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap1/bar | _filter_fiemap
133 echo
134 echo "File snap2/foo fiemap results in the new filesystem:"
135 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap2/foo | _filter_fiemap
136 echo
137 echo "File snap2/bar fiemap results in the new filesystem:"
138 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/snap2/bar | _filter_fiemap
139
140 status=0
141 exit