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
27 # 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
58 # Doing IO against any range in the first 4K of the file should work.
59 # Due to a past clone ioctl bug which allowed cloning the inline extent,
60 # these operations resulted in EIO errors.
61 echo "File foo data after clone operation:"
62 # All bytes should have the value 0xaa (clone operation failed and did
63 # not modify our file).
64 od -t x1 $SCRATCH_MNT/foo
65 $XFS_IO_PROG -c "pwrite -S 0xcc 0 100" $SCRATCH_MNT/foo | _filter_xfs_io
67 # Test cloning the inline extent against a file which has a hole in its
68 # first 4K followed by a non-inlined extent. It should not be possible
69 # as well to clone the inline extent from file bar into this file.
70 $XFS_IO_PROG -f -c "pwrite -S 0xdd 4K 12K" $SCRATCH_MNT/foo2 \
72 $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo2
74 # Doing IO against any range in the first 4K of the file should work.
75 # Due to a past clone ioctl bug which allowed cloning the inline extent,
76 # these operations resulted in EIO errors.
77 echo "File foo2 data after clone operation:"
78 # All bytes should have the value 0x00 (clone operation failed and did
79 # not modify our file).
80 od -t x1 $SCRATCH_MNT/foo2
81 $XFS_IO_PROG -c "pwrite -S 0xee 0 90" $SCRATCH_MNT/foo2 | _filter_xfs_io
83 # Test cloning the inline extent against a file which has a size of zero
84 # but has a prealloc extent. It should not be possible as well to clone
85 # the inline extent from file bar into this file.
86 $XFS_IO_PROG -f -c "falloc -k 0 1M" $SCRATCH_MNT/foo3 | _filter_xfs_io
87 $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo3
89 # Doing IO against any range in the first 4K of the file should work.
90 # Due to a past clone ioctl bug which allowed cloning the inline extent,
91 # these operations resulted in EIO errors.
92 echo "First 50 bytes of foo3 after clone operation:"
93 # Should not be able to read any bytes, file has 0 bytes i_size (the
94 # clone operation failed and did not modify our file).
95 od -t x1 $SCRATCH_MNT/foo3
96 $XFS_IO_PROG -c "pwrite -S 0xff 0 90" $SCRATCH_MNT/foo3 | _filter_xfs_io
98 # Test cloning the inline extent against a file which consists of a
99 # single inline extent that has a size not greater than the size of
100 # bar's inline extent (40 < 50).
101 # It should be possible to do the extent cloning from bar to this file.
102 $XFS_IO_PROG -f -c "pwrite -S 0x01 0 40" $SCRATCH_MNT/foo4 \
104 $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo4
106 # Doing IO against any range in the first 4K of the file should work.
107 echo "File foo4 data after clone operation:"
108 # Must match file bar's content.
109 od -t x1 $SCRATCH_MNT/foo4
110 $XFS_IO_PROG -c "pwrite -S 0x02 0 90" $SCRATCH_MNT/foo4 | _filter_xfs_io
112 # Test cloning the inline extent against a file which consists of a
113 # single inline extent that has a size greater than the size of bar's
114 # inline extent (60 > 50).
115 # It should not be possible to clone the inline extent from file bar
117 $XFS_IO_PROG -f -c "pwrite -S 0x03 0 60" $SCRATCH_MNT/foo5 \
119 $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo5
121 # Reading the file should not fail.
122 echo "File foo5 data after clone operation:"
123 # Must have a size of 60 bytes, with all bytes having a value of 0x03
124 # (the clone operation failed and did not modify our file).
125 od -t x1 $SCRATCH_MNT/foo5
127 # Test cloning the inline extent against a file which has no extents but
128 # has a size greater than bar's inline extent (16K > 50).
129 # It should not be possible to clone the inline extent from file bar
131 $XFS_IO_PROG -f -c "truncate 16K" $SCRATCH_MNT/foo6 | _filter_xfs_io
132 $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo6
134 # Reading the file should not fail.
135 echo "File foo6 data after clone operation:"
136 # Must have a size of 16K, with all bytes having a value of 0x00 (the
137 # clone operation failed and did not modify our file).
138 od -t x1 $SCRATCH_MNT/foo6
140 # Test cloning the inline extent against a file which has no extents but
141 # has a size not greater than bar's inline extent (30 < 50).
142 # It should be possible to clone the inline extent from file bar into
144 $XFS_IO_PROG -f -c "truncate 30" $SCRATCH_MNT/foo7 | _filter_xfs_io
145 $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo7
147 # Reading the file should not fail.
148 echo "File foo7 data after clone operation:"
149 # Must have a size of 50 bytes, with all bytes having a value of 0xbb.
150 od -t x1 $SCRATCH_MNT/foo7
152 # Test cloning the inline extent against a file which has a size not
153 # greater than the size of bar's inline extent (20 < 50) but has
154 # a prealloc extent that goes beyond the file's size. It should not be
155 # possible to clone the inline extent from bar into this file.
156 $XFS_IO_PROG -f -c "falloc -k 0 1M" \
157 -c "pwrite -S 0x88 0 20" \
158 $SCRATCH_MNT/foo8 | _filter_xfs_io
159 $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo8
161 echo "File foo8 data after clone operation:"
162 # Must have a size of 20 bytes, with all bytes having a value of 0x88
163 # (the clone operation did not modify our file).
164 od -t x1 $SCRATCH_MNT/foo8
169 echo -e "\nTesting without compression and without the no-holes feature...\n"
170 test_cloning_inline_extents
172 echo -e "\nTesting with compression and without the no-holes feature...\n"
173 test_cloning_inline_extents "" "-o compress"
175 echo -e "\nTesting without compression and with the no-holes feature...\n"
176 test_cloning_inline_extents "-O no-holes" ""
178 echo -e "\nTesting with compression and with the no-holes feature...\n"
179 test_cloning_inline_extents "-O no-holes" "-o compress"