btrfs/112: add missing _require_xfs_io_command for falloc
[xfstests-dev.git] / tests / btrfs / 112
1 #! /bin/bash
2 # FSQA Test No. 112
3 #
4 # Test several cases of cloning inline extents that used to lead to file
5 # corruption or data loss.
6 #
7 #-----------------------------------------------------------------------
8 #
9 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
10 # Author: Filipe Manana <fdmanana@suse.com>
11 #
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.
15 #
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.
20 #
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 #-----------------------------------------------------------------------
25 #
26
27 seq=`basename $0`
28 seqres=$RESULT_DIR/$seq
29 echo "QA output created by $seq"
30 tmp=/tmp/$$
31 status=1        # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
33
34 _cleanup()
35 {
36         cd /
37         rm -f $tmp.*
38 }
39
40 # get standard environment, filters and checks
41 . ./common/rc
42 . ./common/filter
43
44 # real QA test starts here
45 _need_to_be_root
46 _supported_fs btrfs
47 _supported_os Linux
48 _require_scratch
49 _require_cloner
50 _require_btrfs_fs_feature "no_holes"
51 _require_btrfs_mkfs_feature "no-holes"
52 _require_xfs_io_command "falloc"
53
54 rm -f $seqres.full
55
56 test_cloning_inline_extents()
57 {
58         local mkfs_opts=$1
59         local mount_opts=$2
60
61         _scratch_mkfs $mkfs_opts >>$seqres.full 2>&1
62         _scratch_mount $mount_opts
63
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 \
67                 | _filter_xfs_io
68
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 \
73                 | _filter_xfs_io
74         $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo
75
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
84
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 \
89                 | _filter_xfs_io
90         $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo2
91
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
100
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
106
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
115
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 \
121                 | _filter_xfs_io
122         $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo4
123
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
129
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
134         # into this file.
135         $XFS_IO_PROG -f -c "pwrite -S 0x03 0 60" $SCRATCH_MNT/foo5 \
136                 | _filter_xfs_io
137         $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo5
138
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
144
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
148         # into this file.
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
151
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
157
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
161         # this file.
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
164
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
169
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
178
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
183
184         _scratch_unmount
185 }
186
187 echo -e "\nTesting without compression and without the no-holes feature...\n"
188 test_cloning_inline_extents
189
190 echo -e "\nTesting with compression and without the no-holes feature...\n"
191 test_cloning_inline_extents "" "-o compress"
192
193 echo -e "\nTesting without compression and with the no-holes feature...\n"
194 test_cloning_inline_extents "-O no-holes" ""
195
196 echo -e "\nTesting with compression and with the no-holes feature...\n"
197 test_cloning_inline_extents "-O no-holes" "-o compress"
198
199 status=0
200 exit