4 # Test several cases of cloning inline extents that used to lead to file
5 # corruption or data loss.
7 #-----------------------------------------------------------------------
9 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
10 # Author: Filipe Manana <fdmanana@suse.com>
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License as
14 # published by the Free Software Foundation.
16 # This program is distributed in the hope that it would be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write the Free Software Foundation,
23 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #-----------------------------------------------------------------------
28 seqres=$RESULT_DIR/$seq
29 echo "QA output created by $seq"
31 status=1 # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
40 # get standard environment, filters and checks
44 # real QA test starts here
49 _require_btrfs_fs_feature "no_holes"
50 _require_btrfs_mkfs_feature "no-holes"
51 _require_xfs_io_command "falloc"
55 test_cloning_inline_extents()
60 _scratch_mkfs $mkfs_opts >>$seqres.full 2>&1
61 _scratch_mount $mount_opts
63 # File bar, the source for all the following clone operations, consists
64 # of a single inline extent (50 bytes).
65 $XFS_IO_PROG -f -c "pwrite -S 0xbb 0 50" $SCRATCH_MNT/bar \
68 # Test cloning into a file with an extent (non-inlined) where the
69 # destination offset overlaps that extent. It should not be possible to
70 # clone the inline extent from file bar into this file.
71 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0K 16K" $SCRATCH_MNT/foo \
73 $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo
75 # Doing IO against any range in the first 4K of the file should work.
76 # Due to a past clone ioctl bug which allowed cloning the inline extent,
77 # these operations resulted in EIO errors.
78 echo "File foo data after clone operation:"
79 # All bytes should have the value 0xaa (clone operation failed and did
80 # not modify our file).
81 od -t x1 $SCRATCH_MNT/foo
82 $XFS_IO_PROG -c "pwrite -S 0xcc 0 100" $SCRATCH_MNT/foo | _filter_xfs_io
84 # Test cloning the inline extent against a file which has a hole in its
85 # first 4K followed by a non-inlined extent. It should not be possible
86 # as well to clone the inline extent from file bar into this file.
87 $XFS_IO_PROG -f -c "pwrite -S 0xdd 4K 12K" $SCRATCH_MNT/foo2 \
89 $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo2
91 # Doing IO against any range in the first 4K of the file should work.
92 # Due to a past clone ioctl bug which allowed cloning the inline extent,
93 # these operations resulted in EIO errors.
94 echo "File foo2 data after clone operation:"
95 # All bytes should have the value 0x00 (clone operation failed and did
96 # not modify our file).
97 od -t x1 $SCRATCH_MNT/foo2
98 $XFS_IO_PROG -c "pwrite -S 0xee 0 90" $SCRATCH_MNT/foo2 | _filter_xfs_io
100 # Test cloning the inline extent against a file which has a size of zero
101 # but has a prealloc extent. It should not be possible as well to clone
102 # the inline extent from file bar into this file.
103 $XFS_IO_PROG -f -c "falloc -k 0 1M" $SCRATCH_MNT/foo3 | _filter_xfs_io
104 $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo3
106 # Doing IO against any range in the first 4K of the file should work.
107 # Due to a past clone ioctl bug which allowed cloning the inline extent,
108 # these operations resulted in EIO errors.
109 echo "First 50 bytes of foo3 after clone operation:"
110 # Should not be able to read any bytes, file has 0 bytes i_size (the
111 # clone operation failed and did not modify our file).
112 od -t x1 $SCRATCH_MNT/foo3
113 $XFS_IO_PROG -c "pwrite -S 0xff 0 90" $SCRATCH_MNT/foo3 | _filter_xfs_io
115 # Test cloning the inline extent against a file which consists of a
116 # single inline extent that has a size not greater than the size of
117 # bar's inline extent (40 < 50).
118 # It should be possible to do the extent cloning from bar to this file.
119 $XFS_IO_PROG -f -c "pwrite -S 0x01 0 40" $SCRATCH_MNT/foo4 \
121 $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo4
123 # Doing IO against any range in the first 4K of the file should work.
124 echo "File foo4 data after clone operation:"
125 # Must match file bar's content.
126 od -t x1 $SCRATCH_MNT/foo4
127 $XFS_IO_PROG -c "pwrite -S 0x02 0 90" $SCRATCH_MNT/foo4 | _filter_xfs_io
129 # Test cloning the inline extent against a file which consists of a
130 # single inline extent that has a size greater than the size of bar's
131 # inline extent (60 > 50).
132 # It should not be possible to clone the inline extent from file bar
134 $XFS_IO_PROG -f -c "pwrite -S 0x03 0 60" $SCRATCH_MNT/foo5 \
136 $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo5
138 # Reading the file should not fail.
139 echo "File foo5 data after clone operation:"
140 # Must have a size of 60 bytes, with all bytes having a value of 0x03
141 # (the clone operation failed and did not modify our file).
142 od -t x1 $SCRATCH_MNT/foo5
144 # Test cloning the inline extent against a file which has no extents but
145 # has a size greater than bar's inline extent (16K > 50).
146 # It should not be possible to clone the inline extent from file bar
148 $XFS_IO_PROG -f -c "truncate 16K" $SCRATCH_MNT/foo6 | _filter_xfs_io
149 $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo6
151 # Reading the file should not fail.
152 echo "File foo6 data after clone operation:"
153 # Must have a size of 16K, with all bytes having a value of 0x00 (the
154 # clone operation failed and did not modify our file).
155 od -t x1 $SCRATCH_MNT/foo6
157 # Test cloning the inline extent against a file which has no extents but
158 # has a size not greater than bar's inline extent (30 < 50).
159 # It should be possible to clone the inline extent from file bar into
161 $XFS_IO_PROG -f -c "truncate 30" $SCRATCH_MNT/foo7 | _filter_xfs_io
162 $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo7
164 # Reading the file should not fail.
165 echo "File foo7 data after clone operation:"
166 # Must have a size of 50 bytes, with all bytes having a value of 0xbb.
167 od -t x1 $SCRATCH_MNT/foo7
169 # Test cloning the inline extent against a file which has a size not
170 # greater than the size of bar's inline extent (20 < 50) but has
171 # a prealloc extent that goes beyond the file's size. It should not be
172 # possible to clone the inline extent from bar into this file.
173 $XFS_IO_PROG -f -c "falloc -k 0 1M" \
174 -c "pwrite -S 0x88 0 20" \
175 $SCRATCH_MNT/foo8 | _filter_xfs_io
176 $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo8
178 echo "File foo8 data after clone operation:"
179 # Must have a size of 20 bytes, with all bytes having a value of 0x88
180 # (the clone operation did not modify our file).
181 od -t x1 $SCRATCH_MNT/foo8
186 echo -e "\nTesting without compression and without the no-holes feature...\n"
187 test_cloning_inline_extents
189 echo -e "\nTesting with compression and without the no-holes feature...\n"
190 test_cloning_inline_extents "" "-o compress"
192 echo -e "\nTesting without compression and with the no-holes feature...\n"
193 test_cloning_inline_extents "-O no-holes" ""
195 echo -e "\nTesting with compression and with the no-holes feature...\n"
196 test_cloning_inline_extents "-O no-holes" "-o compress"