xfstests: remove _need_to_be_root
[xfstests-dev.git] / tests / btrfs / 047
1 #! /bin/bash
2 # FS QA Test No. btrfs/047
3 #
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
12 # send.
13 #
14 # More specifically, this structure preserving guarantee was added by the
15 # following linux kernel commits:
16 #
17 #    Btrfs: send, use fallocate command to punch holes
18 #    Btrfs: send, use fallocate command to allocate extents
19 #
20 #-----------------------------------------------------------------------
21 # Copyright (c) 2014 Filipe Manana.  All Rights Reserved.
22 #
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.
26 #
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.
31 #
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 #-----------------------------------------------------------------------
36 #
37
38 seq=`basename $0`
39 seqres=$RESULT_DIR/$seq
40 echo "QA output created by $seq"
41
42 tmp=/tmp/$$
43 status=1        # failure is the default!
44 trap "_cleanup; exit \$status" 0 1 2 3 15
45
46 _cleanup()
47 {
48     rm -fr $send_files_dir
49     rm -fr $tmp
50 }
51
52 # get standard environment, filters and checks
53 . ./common/rc
54 . ./common/filter
55 . ./common/punch
56
57 # real QA test starts here
58 _supported_fs btrfs
59 _supported_os Linux
60 _require_test
61 _require_scratch
62 _require_fssum
63 _require_xfs_io_command "fiemap"
64 _require_btrfs_send_stream_version
65
66 send_files_dir=$TEST_DIR/btrfs-test-$seq
67
68 rm -f $seqres.full
69 rm -fr $send_files_dir
70 mkdir $send_files_dir
71
72 _scratch_mkfs >/dev/null 2>&1
73 _scratch_mount
74
75 $XFS_IO_PROG -f -c "pwrite -S 0x01 -b 300000 0 300000" $SCRATCH_MNT/foo \
76         | _filter_xfs_io
77
78 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
79
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 \
83         | _filter_xfs_io
84 $XFS_IO_PROG -c "fpunch 250000 20000" $SCRATCH_MNT/foo
85
86 $XFS_IO_PROG -c "falloc -k 300000 1000000" $SCRATCH_MNT/foo
87 $XFS_IO_PROG -c "falloc -k 9000000 2000000" $SCRATCH_MNT/foo
88
89 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
90
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
95
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
100 # the file's size.
101 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/mysnap2/foo | _filter_fiemap
102
103 _scratch_unmount
104 _check_scratch_fs
105
106 _scratch_mkfs >/dev/null 2>&1
107 _scratch_mount
108
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
111
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
116 # the file's size.
117 $XFS_IO_PROG -r -c "fiemap -v" $SCRATCH_MNT/mysnap2/foo | _filter_fiemap
118
119 status=0
120 exit