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 seqres=$RESULT_DIR/$seq
17 echo "QA output created by $seq"
20 status=1 # failure is the default!
21 trap "_cleanup; exit \$status" 0 1 2 3 15
28 # get standard environment, filters and checks
32 # real QA test starts here
40 # Create a file with an extent layout that confused the btrfs clone ioctl
41 # implementation. The first extent item that is cloned by the second call
42 # to the cloner program will have only a trailing part of it referenced by
43 # a new extent item, since the source offset starts in the middle of that
44 # extent. This confused the clone ioctl because after inserting this new
45 # extent item it would immediately after process it again thinking it
46 # corresponded to an extent that existed before - this made it attempt to
47 # insert a duplicated extent item pointing to the same extent again, which
48 # made it return an -EEXIST error to userspace and turn the filesystem to
49 # readonly mode (since the current transaction got aborted).
54 $XFS_IO_PROG -f -c "pwrite -S 0xaa $((2 * $bs)) $((2 * $bs))" \
55 $SCRATCH_MNT/foo | _filter_xfs_io
57 $CLONER_PROG -s $((3 * $bs)) -d $((267 * $bs)) -l 0 $SCRATCH_MNT/foo \
59 $CLONER_PROG -s $((217 * $bs)) -d $((95 * $bs)) -l 0 $SCRATCH_MNT/foo \
62 echo "File digest after clone operations using same file as source and destination"
63 md5sum $SCRATCH_MNT/foo | _filter_scratch
65 # Test cloning using different source and destination files for the
66 # same exact data - it must produce the exact same result as the case
68 $XFS_IO_PROG -f -c "pwrite -S 0xaa $((2 * $bs)) $((2 * $bs))" \
69 $SCRATCH_MNT/a | _filter_xfs_io
70 cp $SCRATCH_MNT/a $SCRATCH_MNT/b
72 $CLONER_PROG -s $((3 * $bs)) -d $((267 * $bs)) -l 0 $SCRATCH_MNT/a \
75 cp $SCRATCH_MNT/b $SCRATCH_MNT/foo2
76 $CLONER_PROG -s $((217 * $bs)) -d $((95 * $bs)) -l 0 $SCRATCH_MNT/b \
79 echo "File digest after clone operations using different files as source and destination"
80 md5sum $SCRATCH_MNT/foo2 | _filter_scratch
84 # Make sure the test passes offsets and lengths to the btrfs clone ioctl that
85 # are multiples of the fs block size. Currently the block size on btrfs must
86 # be a multiple of the page size, so use a 64Kb fs block size in order to be
87 # able to test on every platform supported by linux.
90 echo "Testing without the no-holes feature"
91 _scratch_mkfs "-O ^no-holes -n $bs" >>$seqres.full 2>&1
96 echo -e "\nTesting with the no-holes feature"
98 _scratch_mkfs "-O no-holes -n $bs" >>$seqres.full 2>&1