generic/563: use a loop device to avoid partition incompatibility
[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 _require_scratch
33 _require_cp_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 "-o compress"
43
44 # Create our file with an extent of 100K starting at file offset 0K.
45 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0K 100K"       \
46                 -c "fsync"                        \
47                 $SCRATCH_MNT/foo | _filter_xfs_io
48
49 # Rewrite part of the previous extent (its first 40K) and write a new 100K
50 # extent starting at file offset 100K.
51 $XFS_IO_PROG -c "pwrite -S 0xbb 0K 40K"    \
52                 -c "pwrite -S 0xcc 100K 100K"      \
53                 $SCRATCH_MNT/foo | _filter_xfs_io
54
55 # Our file foo now has 3 file extent items in its metadata:
56 #
57 # 1) One covering the file range 0 to 40K;
58 # 2) One covering the file range 40K to 100K, which points to the first extent
59 #    we wrote to the file and has a data offset field with value 40K (our file
60 #    no longer uses the first 40K of data from that extent);
61 # 3) One covering the file range 100K to 200K.
62
63 # Now clone our file foo into file bar.
64 cp --reflink=always $SCRATCH_MNT/foo $SCRATCH_MNT/bar
65
66 # Create our snapshot for the send operation.
67 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/snap
68
69 echo "File digests in the original filesystem:"
70 md5sum $SCRATCH_MNT/snap/foo | _filter_scratch
71 md5sum $SCRATCH_MNT/snap/bar | _filter_scratch
72
73 _run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/snap
74
75 # Now recreate the filesystem by receiving the send stream and verify we get
76 # the same file contents that the original filesystem had.
77 # Btrfs send used to issue a clone operation from foo's range [80K, 140K[ to
78 # bar's range [40K, 100K[ when cloning the extent pointed to by foo's second
79 # file extent item, this was incorrect because of bad accounting of the file
80 # extent item's data offset field. The correct range to clone from should have
81 # been [40K, 100K[.
82 _scratch_unmount
83 _scratch_mkfs >>$seqres.full 2>&1
84 _scratch_mount "-o compress"
85
86 _run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
87
88 echo "File digests in the new filesystem:"
89 # Must match the digests we got in the original filesystem.
90 md5sum $SCRATCH_MNT/snap/foo | _filter_scratch
91 md5sum $SCRATCH_MNT/snap/bar | _filter_scratch
92
93 status=0
94 exit