common: kill _supported_os
[xfstests-dev.git] / tests / btrfs / 108
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/108
6 #
7 # Test that a send operation works correctly with reflinked files (cloned
8 # extents which multiple files point to).
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 _require_xfs_io_command "fpunch"
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
44
45 # Create our test file with a single 100K extent.
46 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0K 100K" $SCRATCH_MNT/foo | _filter_xfs_io
47
48 # Clone our file into a new file named bar.
49 cp --reflink=always $SCRATCH_MNT/foo $SCRATCH_MNT/bar
50
51 # Now overwrite parts of our foo file.
52 $XFS_IO_PROG -c "pwrite -S 0xbb 50K 10K" \
53         -c "pwrite -S 0xcc 90K 10K" \
54         -c "fpunch 70K 10k" \
55         $SCRATCH_MNT/foo | _filter_xfs_io
56
57 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/snap
58
59 echo "File digests in the original filesystem:"
60 md5sum $SCRATCH_MNT/snap/foo | _filter_scratch
61 md5sum $SCRATCH_MNT/snap/bar | _filter_scratch
62
63 _run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/snap
64
65 # Now recreate the filesystem by receiving the send stream and verify we get
66 # the same file contents that the original filesystem had.
67 _scratch_unmount
68 _scratch_mkfs >>$seqres.full 2>&1
69 _scratch_mount
70
71 _run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
72
73 # We expect the destination filesystem to have exactly the same file data as
74 # the original filesystem.
75 # The btrfs send implementation had a bug where it sent a clone operation from
76 # file foo into file bar covering the whole [0, 100K[ range after creating
77 # and writing the file foo. This was incorrect because the file bar now included
78 # the updates done to file foo after we cloned foo to bar, breaking the COW
79 # nature of reflink copies (cloned extents).
80 echo "File digests in the new filesystem:"
81 md5sum $SCRATCH_MNT/snap/foo | _filter_scratch
82 md5sum $SCRATCH_MNT/snap/bar | _filter_scratch
83
84 status=0
85 exit