2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
5 # FS QA Test No. btrfs/093
7 # Test btrfs file range cloning with the same file as a source and destination.
9 # This tests a specific scenario where the extent layout of the file confused
10 # the clone ioctl implementation making it return -EEXIST to userspace.
11 # This issue was fixed by the following linux kernel patch:
13 # Btrfs: fix range cloning when same inode used as source and destination
16 _begin_fstest auto quick clone
18 # Import common functions.
21 # real QA test starts here
26 # Create a file with an extent layout that confused the btrfs clone ioctl
27 # implementation. The first extent item that is cloned by the second call
28 # to the cloner program will have only a trailing part of it referenced by
29 # a new extent item, since the source offset starts in the middle of that
30 # extent. This confused the clone ioctl because after inserting this new
31 # extent item it would immediately after process it again thinking it
32 # corresponded to an extent that existed before - this made it attempt to
33 # insert a duplicated extent item pointing to the same extent again, which
34 # made it return an -EEXIST error to userspace and turn the filesystem to
35 # readonly mode (since the current transaction got aborted).
40 $XFS_IO_PROG -f -c "pwrite -S 0xaa $((2 * $bs)) $((2 * $bs))" \
41 $SCRATCH_MNT/foo | _filter_xfs_io
43 $CLONER_PROG -s $((3 * $bs)) -d $((267 * $bs)) -l 0 $SCRATCH_MNT/foo \
45 $CLONER_PROG -s $((217 * $bs)) -d $((95 * $bs)) -l 0 $SCRATCH_MNT/foo \
48 echo "File digest after clone operations using same file as source and destination"
49 md5sum $SCRATCH_MNT/foo | _filter_scratch
51 # Test cloning using different source and destination files for the
52 # same exact data - it must produce the exact same result as the case
54 $XFS_IO_PROG -f -c "pwrite -S 0xaa $((2 * $bs)) $((2 * $bs))" \
55 $SCRATCH_MNT/a | _filter_xfs_io
56 cp $SCRATCH_MNT/a $SCRATCH_MNT/b
58 $CLONER_PROG -s $((3 * $bs)) -d $((267 * $bs)) -l 0 $SCRATCH_MNT/a \
61 cp $SCRATCH_MNT/b $SCRATCH_MNT/foo2
62 $CLONER_PROG -s $((217 * $bs)) -d $((95 * $bs)) -l 0 $SCRATCH_MNT/b \
65 echo "File digest after clone operations using different files as source and destination"
66 md5sum $SCRATCH_MNT/foo2 | _filter_scratch
70 # Make sure the test passes offsets and lengths to the btrfs clone ioctl that
71 # are multiples of the fs block size. Currently the block size on btrfs must
72 # be a multiple of the page size, so use a 64Kb fs block size in order to be
73 # able to test on every platform supported by linux.
76 echo "Testing without the no-holes feature"
77 _scratch_mkfs "-O ^no-holes -n $bs" >>$seqres.full 2>&1
82 echo -e "\nTesting with the no-holes feature"
84 _scratch_mkfs "-O no-holes -n $bs" >>$seqres.full 2>&1