fstests: move test group info to test 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 . ./common/preamble
11 _begin_fstest auto quick send dedupe
12
13 # Override the default cleanup function.
14 _cleanup()
15 {
16         cd /
17         rm -fr $send_files_dir
18         rm -f $tmp.*
19 }
20
21 # Import common functions.
22 . ./common/filter
23 . ./common/reflink
24
25 # real QA test starts here
26 _supported_fs btrfs
27 _require_test
28 _require_scratch_dedupe
29 _require_fssum
30
31 send_files_dir=$TEST_DIR/btrfs-test-$seq
32
33 rm -fr $send_files_dir
34 mkdir $send_files_dir
35
36 _scratch_mkfs >>$seqres.full 2>&1
37 _scratch_mount
38
39 # Create our first file. The first half of the file has several 64Kb extents
40 # while the second half as a single 512Kb extent.
41 $XFS_IO_PROG -f -s -c "pwrite -S 0xb8 -b 64K 0 512K" $SCRATCH_MNT/foo \
42         | _filter_xfs_io
43 $XFS_IO_PROG -c "pwrite -S 0xb8 512K 512K" $SCRATCH_MNT/foo | _filter_xfs_io
44
45 # Create the base snapshot and the parent send stream from it.
46 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1 \
47         | _filter_scratch
48
49 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap $SCRATCH_MNT/mysnap1 2>&1 \
50         | _filter_scratch
51
52 # Create our second file, that has exactly the same data as the first file.
53 $XFS_IO_PROG -f -c "pwrite -S 0xb8 0 1M" $SCRATCH_MNT/bar | _filter_xfs_io
54
55 # Create the second snapshot, used for the incremental send, before doing the
56 # file deduplication.
57 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2 \
58         | _filter_scratch
59
60 # Now before creating the incremental send stream:
61 #
62 # 1) Deduplicate into a subrange of file foo in snapshot mysnap1. This will drop
63 #    several extent items and add a new one, also updating the inode's iversion
64 #    (sequence field in inode item) by 1, but not any other field of the inode;
65 #
66 # 2) Deduplicate into a different subrange of file foo in snapshot mysnap2. This
67 #    will replace an extent item with a new one, also updating the inode's
68 #    iversion by 1 but not any other field of the inode.
69 #
70 # After these two deduplication operations, the inode items, for file foo, are
71 # identical in both snapshots, but we have different extent items for this inode
72 # in both snapshots. We want to check this doesn't cause send to fail with an
73 # error or produce an incorrect stream.
74
75 $XFS_IO_PROG -r -c "dedupe $SCRATCH_MNT/bar 0 0 512K" $SCRATCH_MNT/mysnap1/foo \
76         | _filter_xfs_io
77
78 $XFS_IO_PROG -r -c "dedupe $SCRATCH_MNT/bar 512K 512K 512K" \
79         $SCRATCH_MNT/mysnap2/foo | _filter_xfs_io
80
81 # Create the incremental send stream.
82 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
83         $SCRATCH_MNT/mysnap2 2>&1 | _filter_scratch
84
85 # Create the checksums to verify later that the send streams produce correct
86 # results.
87 $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
88 $FSSUM_PROG -A -f -w $send_files_dir/2.fssum \
89         -x $SCRATCH_MNT/mysnap2/mysnap1 $SCRATCH_MNT/mysnap2
90
91 # Now recreate the filesystem by receiving both send streams and verify we get
92 # the same content that the original filesystem had.
93 _scratch_unmount
94 _scratch_mkfs >>$seqres.full 2>&1
95 _scratch_mount
96
97 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT
98 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT
99 $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
100 $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2
101
102 status=0
103 exit