fstests: move test group info to test files
[xfstests-dev.git] / tests / btrfs / 093
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/093
6 #
7 # Test btrfs file range cloning with the same file as a source and destination.
8 #
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:
12 #
13 #    Btrfs: fix range cloning when same inode used as source and destination
14 #
15 . ./common/preamble
16 _begin_fstest auto quick clone
17
18 # Import common functions.
19 . ./common/filter
20
21 # real QA test starts here
22 _supported_fs btrfs
23 _require_scratch
24 _require_cloner
25
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).
36 test_clone()
37 {
38         local bs=$1
39
40         $XFS_IO_PROG -f -c "pwrite -S 0xaa $((2 * $bs)) $((2 * $bs))" \
41                 $SCRATCH_MNT/foo | _filter_xfs_io
42
43         $CLONER_PROG -s $((3 * $bs)) -d $((267 * $bs)) -l 0 $SCRATCH_MNT/foo \
44                 $SCRATCH_MNT/foo
45         $CLONER_PROG -s $((217 * $bs)) -d $((95 * $bs)) -l 0 $SCRATCH_MNT/foo \
46                 $SCRATCH_MNT/foo
47
48         echo "File digest after clone operations using same file as source and destination"
49         md5sum $SCRATCH_MNT/foo | _filter_scratch
50
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
53         # before.
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
57
58         $CLONER_PROG -s $((3 * $bs)) -d $((267 * $bs)) -l 0 $SCRATCH_MNT/a \
59                 $SCRATCH_MNT/b
60
61         cp $SCRATCH_MNT/b $SCRATCH_MNT/foo2
62         $CLONER_PROG -s $((217 * $bs)) -d $((95 * $bs)) -l 0 $SCRATCH_MNT/b \
63                 $SCRATCH_MNT/foo2
64
65         echo "File digest after clone operations using different files as source and destination"
66         md5sum $SCRATCH_MNT/foo2 | _filter_scratch
67
68 }
69
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.
74 bs=$((64 * 1024))
75
76 echo "Testing without the no-holes feature"
77 _scratch_mkfs "-O ^no-holes -n $bs" >>$seqres.full 2>&1
78 _scratch_mount
79 test_clone $bs
80 _check_scratch_fs
81
82 echo -e "\nTesting with the no-holes feature"
83 _scratch_unmount
84 _scratch_mkfs "-O no-holes -n $bs" >>$seqres.full 2>&1
85 _scratch_mount
86 test_clone $bs
87
88 status=0
89 exit