btrfs: test sending snapshots received from other filesystems
[xfstests-dev.git] / tests / btrfs / 111
1 #! /bin/bash
2 # FS QA Test No. btrfs/111
3 #
4 # Test that resending snapshots from a different filesystem is possible for
5 # both full and incremental send operations.
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
45 # real QA test starts here
46 _supported_fs btrfs
47 _supported_os Linux
48 _require_scratch
49 _need_to_be_root
50
51 send_files_dir=$TEST_DIR/btrfs-test-$seq
52
53 rm -f $seqres.full
54 rm -fr $send_files_dir
55 mkdir $send_files_dir
56
57 _scratch_mkfs >>$seqres.full 2>&1
58 _scratch_mount
59
60 # Create a test file
61 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0K 32K" $SCRATCH_MNT/foo | _filter_xfs_io
62
63 # Create the first snapshot.
64 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/snap1
65
66 # Modify our file and create the second snapshot, used later for an incremental
67 # send operation.
68 $XFS_IO_PROG -c "pwrite -S 0xbb 4K 4K" $SCRATCH_MNT/foo | _filter_xfs_io
69
70 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/snap2
71
72 echo "File digests in the first filesystem:"
73 md5sum $SCRATCH_MNT/snap1/foo | _filter_scratch
74 md5sum $SCRATCH_MNT/snap2/foo | _filter_scratch
75
76 # Save send streams for the snapshots. For the first one we use a full send
77 # operation and the for the second snapshot we use an incremental send.
78 _run_btrfs_util_prog send $SCRATCH_MNT/snap1 -f $send_files_dir/1.snap
79 _run_btrfs_util_prog send -p $SCRATCH_MNT/snap1 $SCRATCH_MNT/snap2 \
80         -f $send_files_dir/2.snap
81
82 # Create a new filesystem and receive the snapshots.
83 _scratch_unmount
84 _scratch_mkfs >>$seqres.full 2>&1
85 _scratch_mount
86
87 _run_btrfs_util_prog receive $SCRATCH_MNT -vv -f $send_files_dir/1.snap
88 _run_btrfs_util_prog receive $SCRATCH_MNT -vv -f $send_files_dir/2.snap
89
90 echo "File digests in the second filesystem:"
91 # Must match the digests we got in the first filesystem.
92 md5sum $SCRATCH_MNT/snap1/foo | _filter_scratch
93 md5sum $SCRATCH_MNT/snap2/foo | _filter_scratch
94
95 # Call sync to flush all delalloc data that the receiver processes created.
96 # Although 'btrfs receive' at the end calls a btrfs specific ioctl to change
97 # the snapshot from RW mode to RO mode, which commits the current btrfs
98 # transaction, the dealalloc data is not flushed, as the transaction commit
99 # intentionally does not do it unless the fs is mounted with '-o flushoncommit'.
100 # This is a detail that should probably be addressed either in the btrfs ioctls
101 # called by 'btrfs receive' or in the tools - our test has a different purpose,
102 # so we get around this by calling 'sync' to make sure all delalloc data is
103 # durably persisted and the respective file extent items are added to the
104 # snapshot's btree.
105 sync
106
107 # Now create send streams for the snapshots from this new filesystem. For the
108 # first snapshot we do a full send while for the second snapshot we do an
109 # incremental send.
110 _run_btrfs_util_prog send $SCRATCH_MNT/snap1 -f $send_files_dir/1_2.snap
111 _run_btrfs_util_prog send -p $SCRATCH_MNT/snap1 $SCRATCH_MNT/snap2 \
112         -f $send_files_dir/2_2.snap
113
114 # Create a new filesystem and receive the send streams we just created from the
115 # second filesystem. This worked until the linux kernel 4.2, where a regression
116 # was introduced. The problem was that the send stream included an incorrect
117 # value for the uuid field, which matched a snapshot's uuid (which is different
118 # on each filesystem) instead of the snapshot's received_uuid value (which is
119 # preserved across different filesystems).
120 _scratch_unmount
121 _scratch_mkfs >>$seqres.full 2>&1
122 _scratch_mount
123
124 _run_btrfs_util_prog receive $SCRATCH_MNT -vv -f $send_files_dir/1_2.snap
125 _run_btrfs_util_prog receive $SCRATCH_MNT -vv -f $send_files_dir/2_2.snap
126
127 echo "File digests in the third filesystem:"
128 # Must match the digests we got in the first and second filesystems.
129 md5sum $SCRATCH_MNT/snap1/foo | _filter_scratch
130 md5sum $SCRATCH_MNT/snap2/foo | _filter_scratch
131
132 status=0
133 exit