2 # FS QA Test No. btrfs/093
4 # Test btrfs file range cloning with the same file as a source and destination.
6 # This tests a specific scenario where the extent layout of the file confused
7 # the clone ioctl implementation making it return -EEXIST to userspace.
8 # This issue was fixed by the following linux kernel patch:
10 # Btrfs: fix range cloning when same inode used as source and destination
12 #-----------------------------------------------------------------------
13 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
14 # Author: Filipe Manana <fdmanana@suse.com>
16 # This program is free software; you can redistribute it and/or
17 # modify it under the terms of the GNU General Public License as
18 # published by the Free Software Foundation.
20 # This program is distributed in the hope that it would be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write the Free Software Foundation,
27 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #-----------------------------------------------------------------------
32 seqres=$RESULT_DIR/$seq
33 echo "QA output created by $seq"
36 status=1 # failure is the default!
37 trap "_cleanup; exit \$status" 0 1 2 3 15
44 # get standard environment, filters and checks
48 # real QA test starts here
57 # Create a file with an extent layout that confused the btrfs clone ioctl
58 # implementation. The first extent item that is cloned by the second call
59 # to the cloner program will have only a trailing part of it referenced by
60 # a new extent item, since the source offset starts in the middle of that
61 # extent. This confused the clone ioctl because after inserting this new
62 # extent item it would immediately after process it again thinking it
63 # corresponded to an extent that existed before - this made it attempt to
64 # insert a duplicated extent item pointing to the same extent again, which
65 # made it return an -EEXIST error to userspace and turn the filesystem to
66 # readonly mode (since the current transaction got aborted).
71 $XFS_IO_PROG -f -c "pwrite -S 0xaa $((2 * $bs)) $((2 * $bs))" \
72 $SCRATCH_MNT/foo | _filter_xfs_io
74 $CLONER_PROG -s $((3 * $bs)) -d $((267 * $bs)) -l 0 $SCRATCH_MNT/foo \
76 $CLONER_PROG -s $((217 * $bs)) -d $((95 * $bs)) -l 0 $SCRATCH_MNT/foo \
79 echo "File digest after clone operations using same file as source and destination"
80 md5sum $SCRATCH_MNT/foo | _filter_scratch
82 # Test cloning using different source and destination files for the
83 # same exact data - it must produce the exact same result as the case
85 $XFS_IO_PROG -f -c "pwrite -S 0xaa $((2 * $bs)) $((2 * $bs))" \
86 $SCRATCH_MNT/a | _filter_xfs_io
87 cp $SCRATCH_MNT/a $SCRATCH_MNT/b
89 $CLONER_PROG -s $((3 * $bs)) -d $((267 * $bs)) -l 0 $SCRATCH_MNT/a \
92 cp $SCRATCH_MNT/b $SCRATCH_MNT/foo2
93 $CLONER_PROG -s $((217 * $bs)) -d $((95 * $bs)) -l 0 $SCRATCH_MNT/b \
96 echo "File digest after clone operations using different files as source and destination"
97 md5sum $SCRATCH_MNT/foo2 | _filter_scratch
101 # Make sure the test passes offsets and lengths to the btrfs clone ioctl that
102 # are multiples of the fs block size. Currently the block size on btrfs must
103 # be a multiple of the page size, so use a 64Kb fs block size in order to be
104 # able to test on every platform supported by linux.
107 echo "Testing without the no-holes feature"
108 _scratch_mkfs "-O ^no-holes -n $bs" >>$seqres.full 2>&1
113 echo -e "\nTesting with the no-holes feature"
115 _scratch_mkfs "-O no-holes -n $bs" >>$seqres.full 2>&1