xfstests: remove _need_to_be_root
[xfstests-dev.git] / tests / btrfs / 097
1 #! /bin/bash
2 # FS QA Test No. btrfs/097
3 #
4 # Test that an incremental send works after a file gets one of its extents
5 # cloned/deduplicated into lower file offsets.
6 #
7 #-----------------------------------------------------------------------
8 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
9 # Author: Filipe Manana <fdmanana@suse.com>
10 #
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License as
13 # published by the Free Software Foundation.
14 #
15 # This program is distributed in the hope that it would be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write the Free Software Foundation,
22 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23 #-----------------------------------------------------------------------
24 #
25
26 seq=`basename $0`
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
29
30 tmp=/tmp/$$
31 status=1        # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
33
34 _cleanup()
35 {
36         rm -fr $send_files_dir
37         rm -f $tmp.*
38 }
39
40 # get standard environment, filters and checks
41 . ./common/rc
42 . ./common/filter
43
44 # real QA test starts here
45 _supported_fs btrfs
46 _supported_os Linux
47 _require_scratch
48 _require_cloner
49
50 send_files_dir=$TEST_DIR/btrfs-test-$seq
51
52 rm -f $seqres.full
53 rm -fr $send_files_dir
54 mkdir $send_files_dir
55
56 _scratch_mkfs >>$seqres.full 2>&1
57 _scratch_mount
58
59 BLOCK_SIZE=$(get_block_size $SCRATCH_MNT)
60
61 # Create our test file with a single extent of 16 blocks starting at a file
62 # offset mapped by 32nd block.
63 $XFS_IO_PROG -f -c "pwrite -S 0xaa $((32 * $BLOCK_SIZE)) $((16 * $BLOCK_SIZE))" \
64              $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
65
66 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
67
68 # Now clone parts of the original extent into lower offsets of the file.
69 #
70 # The first clone operation adds a file extent item to file offset 0 that points
71 # to our initial extent with a data offset of 4 blocks. The corresponding data back
72 # reference in the extent tree has a large value for the 'offset' field, which is
73 # the result of file_offset - data_offset = 0 - (file offset of 4th block).  For
74 # example in case of 4k block size, it will be 0 - 16k = 18446744073709535232.
75
76 # The second clone operation adds a file extent item to file offset mapped by
77 # 4th block that points to our initial extent with a data offset of 12
78 # blocks. The corresponding data back reference in the extent tree has a large
79 # value for the 'offset' field, which is the result of file_offset - data_offset
80 # = (file offset of 4th block) - (file offset of 12th block). For example in
81 # case of 4k block size, it will be 16K - 48K = 18446744073709518848.
82 #
83 # Those large back reference offsets (result of unsigned arithmetic underflow)
84 # confused the back reference walking code (used by an incremental send and
85 # the multiple inspect-internal ioctls) and made it miss the back references,
86 # which for the case of an incremental send it made it fail with -EIO and print
87 # a message like the following to dmesg:
88 #
89 # "BTRFS error (device sdc): did not find backref in send_root. inode=257, \
90 #  offset=0, disk_byte=12845056 found extent=12845056"
91 #
92 $CLONER_PROG -s $(((32 + 4) * $BLOCK_SIZE)) -d 0 -l $((4 * $BLOCK_SIZE)) \
93         $SCRATCH_MNT/foo $SCRATCH_MNT/foo
94 $CLONER_PROG -s $(((32 + 12) * $BLOCK_SIZE)) -d $((4 * $BLOCK_SIZE)) \
95              -l $((4 * $BLOCK_SIZE)) $SCRATCH_MNT/foo $SCRATCH_MNT/foo
96
97 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
98
99 _run_btrfs_util_prog send $SCRATCH_MNT/mysnap1 -f $send_files_dir/1.snap
100 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 $SCRATCH_MNT/mysnap2 \
101         -f $send_files_dir/2.snap
102
103 echo "File contents in the original filesystem:"
104 od -t x1 $SCRATCH_MNT/mysnap2/foo | _filter_od
105
106 # Now recreate the filesystem by receiving both send streams and verify we get
107 # the same file contents that the original filesystem had.
108 _scratch_unmount
109 _scratch_mkfs >>$seqres.full 2>&1
110 _scratch_mount
111
112 _run_btrfs_util_prog receive $SCRATCH_MNT -f $send_files_dir/1.snap
113 _run_btrfs_util_prog receive $SCRATCH_MNT -f $send_files_dir/2.snap
114
115 echo "File contents in the new filesystem:"
116 od -t x1 $SCRATCH_MNT/mysnap2/foo | _filter_od
117
118 status=0
119 exit