btrfs: test incremental send after removing a directory and all its files
[xfstests-dev.git] / tests / btrfs / 191
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/191
6 #
7 # Test that an incremental send operation works after deduplicating into the
8 # same file in both the parent and send snapshots.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         rm -fr $send_files_dir
22         rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28 . ./common/reflink
29
30 # real QA test starts here
31 _supported_fs btrfs
32 _require_test
33 _require_scratch_dedupe
34 _require_fssum
35
36 send_files_dir=$TEST_DIR/btrfs-test-$seq
37
38 rm -f $seqres.full
39 rm -fr $send_files_dir
40 mkdir $send_files_dir
41
42 _scratch_mkfs >>$seqres.full 2>&1
43 _scratch_mount
44
45 # Create our first file. The first half of the file has several 64Kb extents
46 # while the second half as a single 512Kb extent.
47 $XFS_IO_PROG -f -s -c "pwrite -S 0xb8 -b 64K 0 512K" $SCRATCH_MNT/foo \
48         | _filter_xfs_io
49 $XFS_IO_PROG -c "pwrite -S 0xb8 512K 512K" $SCRATCH_MNT/foo | _filter_xfs_io
50
51 # Create the base snapshot and the parent send stream from it.
52 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1 \
53         | _filter_scratch
54
55 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap $SCRATCH_MNT/mysnap1 2>&1 \
56         | _filter_scratch
57
58 # Create our second file, that has exactly the same data as the first file.
59 $XFS_IO_PROG -f -c "pwrite -S 0xb8 0 1M" $SCRATCH_MNT/bar | _filter_xfs_io
60
61 # Create the second snapshot, used for the incremental send, before doing the
62 # file deduplication.
63 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2 \
64         | _filter_scratch
65
66 # Now before creating the incremental send stream:
67 #
68 # 1) Deduplicate into a subrange of file foo in snapshot mysnap1. This will drop
69 #    several extent items and add a new one, also updating the inode's iversion
70 #    (sequence field in inode item) by 1, but not any other field of the inode;
71 #
72 # 2) Deduplicate into a different subrange of file foo in snapshot mysnap2. This
73 #    will replace an extent item with a new one, also updating the inode's
74 #    iversion by 1 but not any other field of the inode.
75 #
76 # After these two deduplication operations, the inode items, for file foo, are
77 # identical in both snapshots, but we have different extent items for this inode
78 # in both snapshots. We want to check this doesn't cause send to fail with an
79 # error or produce an incorrect stream.
80
81 $XFS_IO_PROG -r -c "dedupe $SCRATCH_MNT/bar 0 0 512K" $SCRATCH_MNT/mysnap1/foo \
82         | _filter_xfs_io
83
84 $XFS_IO_PROG -r -c "dedupe $SCRATCH_MNT/bar 512K 512K 512K" \
85         $SCRATCH_MNT/mysnap2/foo | _filter_xfs_io
86
87 # Create the incremental send stream.
88 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
89         $SCRATCH_MNT/mysnap2 2>&1 | _filter_scratch
90
91 # Create the checksums to verify later that the send streams produce correct
92 # results.
93 $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
94 $FSSUM_PROG -A -f -w $send_files_dir/2.fssum \
95         -x $SCRATCH_MNT/mysnap2/mysnap1 $SCRATCH_MNT/mysnap2
96
97 # Now recreate the filesystem by receiving both send streams and verify we get
98 # the same content that the original filesystem had.
99 _scratch_unmount
100 _scratch_mkfs >>$seqres.full 2>&1
101 _scratch_mount
102
103 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT
104 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT
105 $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
106 $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2
107
108 status=0
109 exit