2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
7 # Test several cases of cloning inline extents that used to lead to file
8 # corruption or data loss.
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
14 status=1 # failure is the default!
15 trap "_cleanup; exit \$status" 0 1 2 3 15
23 # get standard environment, filters and checks
26 . ./common/filter.btrfs
28 # real QA test starts here
32 _require_btrfs_fs_feature "no_holes"
33 _require_btrfs_mkfs_feature "no-holes"
34 _require_xfs_io_command "falloc"
38 test_cloning_inline_extents()
43 _scratch_mkfs $mkfs_opts >>$seqres.full 2>&1
44 _scratch_mount $mount_opts
46 # File bar, the source for all the following clone operations, consists
47 # of a single inline extent (50 bytes).
48 $XFS_IO_PROG -f -c "pwrite -S 0xbb 0 50" $SCRATCH_MNT/bar \
51 # Test cloning into a file with an extent (non-inlined) where the
52 # destination offset overlaps that extent. It should not be possible to
53 # clone the inline extent from file bar into this file.
54 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0K 16K" $SCRATCH_MNT/foo \
56 $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo \
57 | _filter_btrfs_cloner_error
59 # Doing IO against any range in the first 4K of the file should work.
60 # Due to a past clone ioctl bug which allowed cloning the inline extent,
61 # these operations resulted in EIO errors.
62 echo "File foo data after clone operation:"
63 # All bytes should have the value 0xaa (clone operation failed and did
64 # not modify our file).
65 od -t x1 $SCRATCH_MNT/foo
66 $XFS_IO_PROG -c "pwrite -S 0xcc 0 100" $SCRATCH_MNT/foo | _filter_xfs_io
68 # Test cloning the inline extent against a file which has a hole in its
69 # first 4K followed by a non-inlined extent. It should not be possible
70 # as well to clone the inline extent from file bar into this file.
71 $XFS_IO_PROG -f -c "pwrite -S 0xdd 4K 12K" $SCRATCH_MNT/foo2 \
73 $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo2 \
74 | _filter_btrfs_cloner_error
76 # Doing IO against any range in the first 4K of the file should work.
77 # Due to a past clone ioctl bug which allowed cloning the inline extent,
78 # these operations resulted in EIO errors.
79 echo "File foo2 data after clone operation:"
80 # All bytes should have the value 0x00 (clone operation failed and did
81 # not modify our file).
82 od -t x1 $SCRATCH_MNT/foo2
83 $XFS_IO_PROG -c "pwrite -S 0xee 0 90" $SCRATCH_MNT/foo2 | _filter_xfs_io
85 # Test cloning the inline extent against a file which consists of a
86 # single inline extent that has a size not greater than the size of
87 # bar's inline extent (40 < 50).
88 # It should be possible to do the extent cloning from bar to this file.
89 $XFS_IO_PROG -f -c "pwrite -S 0x01 0 40" $SCRATCH_MNT/foo4 \
91 $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo4 \
92 | _filter_btrfs_cloner_error
94 # Doing IO against any range in the first 4K of the file should work.
95 echo "File foo4 data after clone operation:"
96 # Must match file bar's content.
97 od -t x1 $SCRATCH_MNT/foo4
98 $XFS_IO_PROG -c "pwrite -S 0x02 0 90" $SCRATCH_MNT/foo4 | _filter_xfs_io
100 # Test cloning the inline extent against a file which consists of a
101 # single inline extent that has a size greater than the size of bar's
102 # inline extent (60 > 50).
103 # It should not be possible to clone the inline extent from file bar
105 $XFS_IO_PROG -f -c "pwrite -S 0x03 0 60" $SCRATCH_MNT/foo5 \
107 $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo5 \
108 | _filter_btrfs_cloner_error
110 # Reading the file should not fail.
111 echo "File foo5 data after clone operation:"
112 # Must have a size of 60 bytes, with all bytes having a value of 0x03
113 # (the clone operation failed and did not modify our file).
114 od -t x1 $SCRATCH_MNT/foo5
116 # Test cloning the inline extent against a file which has no extents but
117 # has a size greater than bar's inline extent (16K > 50).
118 # It should not be possible to clone the inline extent from file bar
120 $XFS_IO_PROG -f -c "truncate 16K" $SCRATCH_MNT/foo6 | _filter_xfs_io
121 $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo6 \
122 | _filter_btrfs_cloner_error
124 # Reading the file should not fail.
125 echo "File foo6 data after clone operation:"
126 # Must have a size of 16K, with all bytes having a value of 0x00 (the
127 # clone operation failed and did not modify our file).
128 od -t x1 $SCRATCH_MNT/foo6
130 # Test cloning the inline extent against a file which has no extents but
131 # has a size not greater than bar's inline extent (30 < 50).
132 # It should be possible to clone the inline extent from file bar into
134 $XFS_IO_PROG -f -c "truncate 30" $SCRATCH_MNT/foo7 | _filter_xfs_io
135 $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo7 \
136 | _filter_btrfs_cloner_error
138 # Reading the file should not fail.
139 echo "File foo7 data after clone operation:"
140 # Must have a size of 50 bytes, with all bytes having a value of 0xbb.
141 od -t x1 $SCRATCH_MNT/foo7
146 echo -e "\nTesting without compression and without the no-holes feature...\n"
147 test_cloning_inline_extents
149 echo -e "\nTesting with compression and without the no-holes feature...\n"
150 test_cloning_inline_extents "" "-o compress"
152 echo -e "\nTesting without compression and with the no-holes feature...\n"
153 test_cloning_inline_extents "-O no-holes" ""
155 echo -e "\nTesting with compression and with the no-holes feature...\n"
156 test_cloning_inline_extents "-O no-holes" "-o compress"