xfs: force file creation to the data device for certain layout tests
[xfstests-dev.git] / tests / btrfs / 229
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2021 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/229
6 #
7 # Test that an incremental send operation correctly issues clone operations for
8 # a file that had different parts of one of its extents cloned into itself, at
9 # different offsets, and a large part of that extent was overwritten, so all the
10 # reflinks only point to subranges of the extent.
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 tmp=/tmp/$$
17 status=1        # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
19
20 _cleanup()
21 {
22         cd /
23         rm -fr $send_files_dir
24         rm -f $tmp.*
25 }
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/filter
30 . ./common/reflink
31
32 # real QA test starts here
33 _supported_fs btrfs
34 _require_test
35 _require_scratch_reflink
36
37 send_files_dir=$TEST_DIR/btrfs-test-$seq
38
39 rm -f $seqres.full
40 rm -fr $send_files_dir
41 mkdir $send_files_dir
42
43 _scratch_mkfs >>$seqres.full 2>&1
44 _scratch_mount
45
46 # Create our test file with a single and large extent (1M) and with different
47 # content for different file ranges that will be reflinked later.
48 $XFS_IO_PROG -f \
49              -c "pwrite -S 0xab 0 128K" \
50              -c "pwrite -S 0xcd 128K 128K" \
51              -c "pwrite -S 0xef 256K 256K" \
52              -c "pwrite -S 0x1a 512K 512K" \
53              $SCRATCH_MNT/foobar | _filter_xfs_io
54
55 # Now create the base snapshot, which is going to be the parent snapshot for
56 # a later incremental send.
57 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
58         $SCRATCH_MNT/mysnap1 > /dev/null
59
60 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
61         $SCRATCH_MNT/mysnap1 2>&1 1>/dev/null | _filter_scratch
62
63 # Now do a series of changes to our file such that we end up with different
64 # parts of the extent reflinked into different file offsets and we overwrite
65 # a large part of the extent too, so no file extent items refer to that part
66 # that was overwritten. This used to confuse the algorithm used by the kernel
67 # to figure out which file ranges to clone, making it attempt to clone from
68 # a source range starting at the current eof of the file, resulting in the
69 # receiver to fail since it is an invalid clone operation.
70 #
71 $XFS_IO_PROG -c "reflink $SCRATCH_MNT/foobar 64K 1M 960K" \
72              -c "reflink $SCRATCH_MNT/foobar 0K 512K 256K" \
73              -c "reflink $SCRATCH_MNT/foobar 512K 128K 256K" \
74              -c "pwrite -S 0x73 384K 640K" \
75              $SCRATCH_MNT/foobar | _filter_xfs_io
76
77 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
78                  $SCRATCH_MNT/mysnap2 > /dev/null
79 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
80                  $SCRATCH_MNT/mysnap2 2>&1 1>/dev/null | _filter_scratch
81
82 echo "File digest in the original filesystem:"
83 _md5_checksum $SCRATCH_MNT/mysnap2/foobar
84
85 # Now recreate the filesystem by receiving both send streams and verify we get
86 # the same content that the original filesystem had.
87 _scratch_unmount
88 _scratch_mkfs >>$seqres.full 2>&1
89 _scratch_mount
90
91 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT > /dev/null
92
93 # The receive operation below used to fail with the following error:
94 #
95 #    ERROR: failed to clone extents to foobar: Invalid argument
96 #
97 # This is because the send stream included a clone operation to clone from the
98 # current file eof into eof (we can't clone from eof and neither the source
99 # range can overlap with the destination range), resulting in the receiver to
100 # fail with -EINVAL when attempting the clone operation.
101 #
102 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT > /dev/null
103
104 # Must match what we had in the original filesystem.
105 echo "File digest in the new filesystem:"
106 _md5_checksum $SCRATCH_MNT/mysnap2/foobar
107
108 status=0
109 exit