xfs/{263,106}: erase max warnings printout
[xfstests-dev.git] / tests / btrfs / 109
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/109
6 #
7 # Test that a send operation works correctly with reflinked files (cloned
8 # extents which multiple files point to) that have compressed extents.
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 _supported_os Linux
33 _require_scratch
34 _require_cp_reflink
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 "-o compress"
44
45 # Create our file with an extent of 100K starting at file offset 0K.
46 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0K 100K"       \
47                 -c "fsync"                        \
48                 $SCRATCH_MNT/foo | _filter_xfs_io
49
50 # Rewrite part of the previous extent (its first 40K) and write a new 100K
51 # extent starting at file offset 100K.
52 $XFS_IO_PROG -c "pwrite -S 0xbb 0K 40K"    \
53                 -c "pwrite -S 0xcc 100K 100K"      \
54                 $SCRATCH_MNT/foo | _filter_xfs_io
55
56 # Our file foo now has 3 file extent items in its metadata:
57 #
58 # 1) One covering the file range 0 to 40K;
59 # 2) One covering the file range 40K to 100K, which points to the first extent
60 #    we wrote to the file and has a data offset field with value 40K (our file
61 #    no longer uses the first 40K of data from that extent);
62 # 3) One covering the file range 100K to 200K.
63
64 # Now clone our file foo into file bar.
65 cp --reflink=always $SCRATCH_MNT/foo $SCRATCH_MNT/bar
66
67 # Create our snapshot for the send operation.
68 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/snap
69
70 echo "File digests in the original filesystem:"
71 md5sum $SCRATCH_MNT/snap/foo | _filter_scratch
72 md5sum $SCRATCH_MNT/snap/bar | _filter_scratch
73
74 _run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/snap
75
76 # Now recreate the filesystem by receiving the send stream and verify we get
77 # the same file contents that the original filesystem had.
78 # Btrfs send used to issue a clone operation from foo's range [80K, 140K[ to
79 # bar's range [40K, 100K[ when cloning the extent pointed to by foo's second
80 # file extent item, this was incorrect because of bad accounting of the file
81 # extent item's data offset field. The correct range to clone from should have
82 # been [40K, 100K[.
83 _scratch_unmount
84 _scratch_mkfs >>$seqres.full 2>&1
85 _scratch_mount "-o compress"
86
87 _run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
88
89 echo "File digests in the new filesystem:"
90 # Must match the digests we got in the original filesystem.
91 md5sum $SCRATCH_MNT/snap/foo | _filter_scratch
92 md5sum $SCRATCH_MNT/snap/bar | _filter_scratch
93
94 status=0
95 exit