xfstests: remove _need_to_be_root
[xfstests-dev.git] / tests / btrfs / 093
1 #! /bin/bash
2 # FS QA Test No. btrfs/093
3 #
4 # Test btrfs file range cloning with the same file as a source and destination.
5 #
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:
9 #
10 #    Btrfs: fix range cloning when same inode used as source and destination
11 #
12 #-----------------------------------------------------------------------
13 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
14 # Author: Filipe Manana <fdmanana@suse.com>
15 #
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.
19 #
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.
24 #
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 #-----------------------------------------------------------------------
29 #
30
31 seq=`basename $0`
32 seqres=$RESULT_DIR/$seq
33 echo "QA output created by $seq"
34
35 tmp=/tmp/$$
36 status=1        # failure is the default!
37 trap "_cleanup; exit \$status" 0 1 2 3 15
38
39 _cleanup()
40 {
41         rm -f $tmp.*
42 }
43
44 # get standard environment, filters and checks
45 . ./common/rc
46 . ./common/filter
47
48 # real QA test starts here
49 _supported_fs btrfs
50 _supported_os Linux
51 _require_scratch
52 _require_cloner
53
54 rm -f $seqres.full
55
56 # Create a file with an extent layout that confused the btrfs clone ioctl
57 # implementation. The first extent item that is cloned by the second call
58 # to the cloner program will have only a trailing part of it referenced by
59 # a new extent item, since the source offset starts in the middle of that
60 # extent. This confused the clone ioctl because after inserting this new
61 # extent item it would immediately after process it again thinking it
62 # corresponded to an extent that existed before - this made it attempt to
63 # insert a duplicated extent item pointing to the same extent again, which
64 # made it return an -EEXIST error to userspace and turn the filesystem to
65 # readonly mode (since the current transaction got aborted).
66 test_clone()
67 {
68         local bs=$1
69
70         $XFS_IO_PROG -f -c "pwrite -S 0xaa $((2 * $bs)) $((2 * $bs))" \
71                 $SCRATCH_MNT/foo | _filter_xfs_io
72
73         $CLONER_PROG -s $((3 * $bs)) -d $((267 * $bs)) -l 0 $SCRATCH_MNT/foo \
74                 $SCRATCH_MNT/foo
75         $CLONER_PROG -s $((217 * $bs)) -d $((95 * $bs)) -l 0 $SCRATCH_MNT/foo \
76                 $SCRATCH_MNT/foo
77
78         echo "File digest after clone operations using same file as source and destination"
79         md5sum $SCRATCH_MNT/foo | _filter_scratch
80
81         # Test cloning using different source and destination files for the
82         # same exact data - it must produce the exact same result as the case
83         # before.
84         $XFS_IO_PROG -f -c "pwrite -S 0xaa $((2 * $bs)) $((2 * $bs))" \
85                 $SCRATCH_MNT/a | _filter_xfs_io
86         cp $SCRATCH_MNT/a $SCRATCH_MNT/b
87
88         $CLONER_PROG -s $((3 * $bs)) -d $((267 * $bs)) -l 0 $SCRATCH_MNT/a \
89                 $SCRATCH_MNT/b
90
91         cp $SCRATCH_MNT/b $SCRATCH_MNT/foo2
92         $CLONER_PROG -s $((217 * $bs)) -d $((95 * $bs)) -l 0 $SCRATCH_MNT/b \
93                 $SCRATCH_MNT/foo2
94
95         echo "File digest after clone operations using different files as source and destination"
96         md5sum $SCRATCH_MNT/foo2 | _filter_scratch
97
98 }
99
100 # Make sure the test passes offsets and lengths to the btrfs clone ioctl that
101 # are multiples of the fs block size. Currently the block size on btrfs must
102 # be a multiple of the page size, so use a 64Kb fs block size in order to be
103 # able to test on every platform supported by linux.
104 bs=$((64 * 1024))
105
106 echo "Testing without the no-holes feature"
107 _scratch_mkfs "-O ^no-holes -n $bs" >>$seqres.full 2>&1
108 _scratch_mount
109 test_clone $bs
110 _check_scratch_fs
111
112 echo -e "\nTesting with the no-holes feature"
113 _scratch_unmount
114 _scratch_mkfs "-O no-holes -n $bs" >>$seqres.full 2>&1
115 _scratch_mount
116 test_clone $bs
117
118 status=0
119 exit