generic: test for non-zero used blocks while writing into a file
[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 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
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 -f $tmp.*
22         rm -fr $send_files_dir
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_reflink
34
35 send_files_dir=$TEST_DIR/btrfs-test-$seq
36
37 rm -f $seqres.full
38 rm -fr $send_files_dir
39 mkdir $send_files_dir
40
41 _scratch_mkfs >>$seqres.full 2>&1
42 _scratch_mount
43
44 # Create our test file with a size of 64K in the parent snapshot.
45 # After the parent snapshot is created, we will increase its size and then clone
46 # one of its extents into a different offset and leave a hole between the shared
47 # extents. The shared extents will be located at offsets greater then size of the
48 # file in the parent snapshot.
49 $XFS_IO_PROG -f -c "pwrite -S 0xf1 0 64K" $SCRATCH_MNT/foobar | _filter_xfs_io
50
51 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/base 2>&1 \
52         | _filter_scratch
53
54 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap $SCRATCH_MNT/base 2>&1 \
55         | _filter_scratch
56
57 # Create a 320K extent at file offset 512K, with chunks of 64K having different
58 # content (to check cloning operations from send refer to the correct ranges).
59 # After that clone a range that includes a hole and a part of the extent created
60 # before - the clone range starts at an offset (448K) lower then the extent's
61 # offset (512K). We want to see the existence of the hole doesn't confuse the
62 # kernel's send code to send an invalid clone operation (with a source range
63 # going beyond the file's current size). The hole that confused send to issue
64 # an invalid clone operation spans the file range from offset 384K to 512K.
65 #
66 # Use offsets and ranges that are aligned to 64K, so that the test can run on
67 # machines with any page size (and therefore block size).
68 #
69 $XFS_IO_PROG -c "pwrite -S 0xab 512K 64K" \
70              -c "pwrite -S 0xcd 576K 64K" \
71              -c "pwrite -S 0xef 640K 64K" \
72              -c "pwrite -S 0x64 704K 64K" \
73              -c "pwrite -S 0x73 768K 64K" \
74              -c "reflink $SCRATCH_MNT/foobar 448K 192K 192K" \
75              $SCRATCH_MNT/foobar | _filter_xfs_io
76
77 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/incr 2>&1 \
78         | _filter_scratch
79
80 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/base -f $send_files_dir/2.snap \
81                  $SCRATCH_MNT/incr 2>&1 | _filter_scratch
82
83 echo "File foobar digest in the original filesystem:"
84 _md5_checksum $SCRATCH_MNT/incr/foobar
85
86 # Now recreate the filesystem by receiving both send streams and verify we get
87 # the same file contents that the original filesystem had.
88 _scratch_unmount
89 _scratch_mkfs >>$seqres.full 2>&1
90 _scratch_mount
91
92 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT
93 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT
94
95 echo "File foobar digest in the new filesystem:"
96 _md5_checksum $SCRATCH_MNT/incr/foobar
97
98 status=0
99 exit