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
50 _require_btrfs_fs_feature "no_holes"
51 _require_btrfs_mkfs_feature "no-holes"
52 _require_xfs_io_command "falloc"
56 test_cloning_inline_extents()
61 _scratch_mkfs $mkfs_opts >>$seqres.full 2>&1
62 _scratch_mount $mount_opts
64 # File bar, the source for all the following clone operations, consists
65 # of a single inline extent (50 bytes).
66 $XFS_IO_PROG -f -c "pwrite -S 0xbb 0 50" $SCRATCH_MNT/bar \
69 # Test cloning into a file with an extent (non-inlined) where the
70 # destination offset overlaps that extent. It should not be possible to
71 # clone the inline extent from file bar into this file.
72 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0K 16K" $SCRATCH_MNT/foo \
74 $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo
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 foo data after clone operation:"
80 # All bytes should have the value 0xaa (clone operation failed and did
81 # not modify our file).
82 od -t x1 $SCRATCH_MNT/foo
83 $XFS_IO_PROG -c "pwrite -S 0xcc 0 100" $SCRATCH_MNT/foo | _filter_xfs_io
85 # Test cloning the inline extent against a file which has a hole in its
86 # first 4K followed by a non-inlined extent. It should not be possible
87 # as well to clone the inline extent from file bar into this file.
88 $XFS_IO_PROG -f -c "pwrite -S 0xdd 4K 12K" $SCRATCH_MNT/foo2 \
90 $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo2
92 # Doing IO against any range in the first 4K of the file should work.
93 # Due to a past clone ioctl bug which allowed cloning the inline extent,
94 # these operations resulted in EIO errors.
95 echo "File foo2 data after clone operation:"
96 # All bytes should have the value 0x00 (clone operation failed and did
97 # not modify our file).
98 od -t x1 $SCRATCH_MNT/foo2
99 $XFS_IO_PROG -c "pwrite -S 0xee 0 90" $SCRATCH_MNT/foo2 | _filter_xfs_io
101 # Test cloning the inline extent against a file which has a size of zero
102 # but has a prealloc extent. It should not be possible as well to clone
103 # the inline extent from file bar into this file.
104 $XFS_IO_PROG -f -c "falloc -k 0 1M" $SCRATCH_MNT/foo3 | _filter_xfs_io
105 $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo3
107 # Doing IO against any range in the first 4K of the file should work.
108 # Due to a past clone ioctl bug which allowed cloning the inline extent,
109 # these operations resulted in EIO errors.
110 echo "First 50 bytes of foo3 after clone operation:"
111 # Should not be able to read any bytes, file has 0 bytes i_size (the
112 # clone operation failed and did not modify our file).
113 od -t x1 $SCRATCH_MNT/foo3
114 $XFS_IO_PROG -c "pwrite -S 0xff 0 90" $SCRATCH_MNT/foo3 | _filter_xfs_io
116 # Test cloning the inline extent against a file which consists of a
117 # single inline extent that has a size not greater than the size of
118 # bar's inline extent (40 < 50).
119 # It should be possible to do the extent cloning from bar to this file.
120 $XFS_IO_PROG -f -c "pwrite -S 0x01 0 40" $SCRATCH_MNT/foo4 \
122 $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo4
124 # Doing IO against any range in the first 4K of the file should work.
125 echo "File foo4 data after clone operation:"
126 # Must match file bar's content.
127 od -t x1 $SCRATCH_MNT/foo4
128 $XFS_IO_PROG -c "pwrite -S 0x02 0 90" $SCRATCH_MNT/foo4 | _filter_xfs_io
130 # Test cloning the inline extent against a file which consists of a
131 # single inline extent that has a size greater than the size of bar's
132 # inline extent (60 > 50).
133 # It should not be possible to clone the inline extent from file bar
135 $XFS_IO_PROG -f -c "pwrite -S 0x03 0 60" $SCRATCH_MNT/foo5 \
137 $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo5
139 # Reading the file should not fail.
140 echo "File foo5 data after clone operation:"
141 # Must have a size of 60 bytes, with all bytes having a value of 0x03
142 # (the clone operation failed and did not modify our file).
143 od -t x1 $SCRATCH_MNT/foo5
145 # Test cloning the inline extent against a file which has no extents but
146 # has a size greater than bar's inline extent (16K > 50).
147 # It should not be possible to clone the inline extent from file bar
149 $XFS_IO_PROG -f -c "truncate 16K" $SCRATCH_MNT/foo6 | _filter_xfs_io
150 $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo6
152 # Reading the file should not fail.
153 echo "File foo6 data after clone operation:"
154 # Must have a size of 16K, with all bytes having a value of 0x00 (the
155 # clone operation failed and did not modify our file).
156 od -t x1 $SCRATCH_MNT/foo6
158 # Test cloning the inline extent against a file which has no extents but
159 # has a size not greater than bar's inline extent (30 < 50).
160 # It should be possible to clone the inline extent from file bar into
162 $XFS_IO_PROG -f -c "truncate 30" $SCRATCH_MNT/foo7 | _filter_xfs_io
163 $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo7
165 # Reading the file should not fail.
166 echo "File foo7 data after clone operation:"
167 # Must have a size of 50 bytes, with all bytes having a value of 0xbb.
168 od -t x1 $SCRATCH_MNT/foo7
170 # Test cloning the inline extent against a file which has a size not
171 # greater than the size of bar's inline extent (20 < 50) but has
172 # a prealloc extent that goes beyond the file's size. It should not be
173 # possible to clone the inline extent from bar into this file.
174 $XFS_IO_PROG -f -c "falloc -k 0 1M" \
175 -c "pwrite -S 0x88 0 20" \
176 $SCRATCH_MNT/foo8 | _filter_xfs_io
177 $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo8
179 echo "File foo8 data after clone operation:"
180 # Must have a size of 20 bytes, with all bytes having a value of 0x88
181 # (the clone operation did not modify our file).
182 od -t x1 $SCRATCH_MNT/foo8
187 echo -e "\nTesting without compression and without the no-holes feature...\n"
188 test_cloning_inline_extents
190 echo -e "\nTesting with compression and without the no-holes feature...\n"
191 test_cloning_inline_extents "" "-o compress"
193 echo -e "\nTesting without compression and with the no-holes feature...\n"
194 test_cloning_inline_extents "-O no-holes" ""
196 echo -e "\nTesting with compression and with the no-holes feature...\n"
197 test_cloning_inline_extents "-O no-holes" "-o compress"