fstests: move test group info to test files
[xfstests-dev.git] / tests / btrfs / 203
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. 203
6 #
7 # Test that an incremental send operation works correctly when a file has shared
8 # extents with itself in the send snapshot, with a hole between them, and the
9 # file size has increased in the send snapshot.
10 #
11 . ./common/preamble
12 _begin_fstest auto quick send clone
13
14 # Override the default cleanup function.
15 _cleanup()
16 {
17         cd /
18         rm -f $tmp.*
19         rm -fr $send_files_dir
20 }
21
22 # Import common functions.
23 . ./common/filter
24 . ./common/reflink
25
26 # real QA test starts here
27 _supported_fs btrfs
28 _require_test
29 _require_scratch_reflink
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 test file with a size of 64K in the parent snapshot.
40 # After the parent snapshot is created, we will increase its size and then clone
41 # one of its extents into a different offset and leave a hole between the shared
42 # extents. The shared extents will be located at offsets greater then size of the
43 # file in the parent snapshot.
44 $XFS_IO_PROG -f -c "pwrite -S 0xf1 0 64K" $SCRATCH_MNT/foobar | _filter_xfs_io
45
46 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/base 2>&1 \
47         | _filter_scratch
48
49 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap $SCRATCH_MNT/base 2>&1 \
50         | _filter_scratch
51
52 # Create a 320K extent at file offset 512K, with chunks of 64K having different
53 # content (to check cloning operations from send refer to the correct ranges).
54 # After that clone a range that includes a hole and a part of the extent created
55 # before - the clone range starts at an offset (448K) lower then the extent's
56 # offset (512K). We want to see the existence of the hole doesn't confuse the
57 # kernel's send code to send an invalid clone operation (with a source range
58 # going beyond the file's current size). The hole that confused send to issue
59 # an invalid clone operation spans the file range from offset 384K to 512K.
60 #
61 # Use offsets and ranges that are aligned to 64K, so that the test can run on
62 # machines with any page size (and therefore block size).
63 #
64 $XFS_IO_PROG -c "pwrite -S 0xab 512K 64K" \
65              -c "pwrite -S 0xcd 576K 64K" \
66              -c "pwrite -S 0xef 640K 64K" \
67              -c "pwrite -S 0x64 704K 64K" \
68              -c "pwrite -S 0x73 768K 64K" \
69              -c "reflink $SCRATCH_MNT/foobar 448K 192K 192K" \
70              $SCRATCH_MNT/foobar | _filter_xfs_io
71
72 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/incr 2>&1 \
73         | _filter_scratch
74
75 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/base -f $send_files_dir/2.snap \
76                  $SCRATCH_MNT/incr 2>&1 | _filter_scratch
77
78 echo "File foobar digest in the original filesystem:"
79 _md5_checksum $SCRATCH_MNT/incr/foobar
80
81 # Now recreate the filesystem by receiving both send streams and verify we get
82 # the same file contents that the original filesystem had.
83 _scratch_unmount
84 _scratch_mkfs >>$seqres.full 2>&1
85 _scratch_mount
86
87 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT
88 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT
89
90 echo "File foobar digest in the new filesystem:"
91 _md5_checksum $SCRATCH_MNT/incr/foobar
92
93 status=0
94 exit