Btrfs: use right clone root offset for compressed extents
PATCH 1/1 Btrfs: use right clone root offset for compressed extents
For non compressed extents, iterate_extent_inodes() gives us offsets that take into account the data offset from the file extent items, while for compressed extents it doesn't. Therefore we have to adjust them before placing them in a send clone instruction. Not doing this adjustment leads to the receiving end requesting for a wrong a file range to the clone ioctl, which results in different file content from the one in the original send root.
Issue reproducible with the following xfstest:
_scratch_mkfs >/dev/null 2>&1
_scratch_mount "-o compress-force=lzo"
run_check $XFS_IO_PROG -f -c "truncate 118811" $SCRATCH_MNT/foo
$XFS_IO_PROG -c "fpunch 582007 864596" $SCRATCH_MNT/foo
run_check $XFS_IO_PROG -c "pwrite -S 0x0d -b 39987 92267 39987" \
$SCRATCH_MNT/foo
run_check $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
$SCRATCH_MNT/mysnap1
run_check $XFS_IO_PROG -c "pwrite -S 0xe1 -b 38804 1119395 38804" \
$SCRATCH_MNT/foo
run_check $XFS_IO_PROG -c "pwrite -S 0x0e -b 41125 80802 41125" \
$SCRATCH_MNT/foo
run_check $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
$SCRATCH_MNT/mysnap2
run_check $FSSUM_PROG -A -f -w $tmp/1.fssum $SCRATCH_MNT/mysnap1
run_check $FSSUM_PROG -A -f -w $tmp/2.fssum -x $SCRATCH_MNT/mysnap2/mysnap1 \
$SCRATCH_MNT/mysnap2
run_check $BTRFS_UTIL_PROG send $SCRATCH_MNT/mysnap1 -f $tmp/1.snap
run_check $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/mysnap1 $SCRATCH_MNT/mysnap2 \
-f $tmp/2.snap _scratch_unmount
_scratch_mkfs >/dev/null 2>&1
_scratch_mount
run_check $BTRFS_UTIL_PROG receive $SCRATCH_MNT -f $tmp/1.snap run_check $FSSUM_PROG -r $tmp/1.fssum $SCRATCH_MNT/mysnap1 2>> $seqres.full
run_check $BTRFS_UTIL_PROG receive $SCRATCH_MNT -f $tmp/2.snap run_check $FSSUM_PROG -r $tmp/2.fssum $SCRATCH_MNT/mysnap2 2>> $seqres.full
--- fs/btrfs/send.c | 7 +++++++ 1 file changed, 7 insertions(+)
fs/btrfs/send.c +7 -0
@@ -1295,6 +1295,13 @@ verbose_printk(KERN_DEBUG "btrfs: find_extent_clone: data_offset=%llu, " }if (cur_clone_root) { +if (compressed !=BTRFS_COMPRESS_NONE ) { +/* +* Compensate the offsets set by: +* backref.c:check_extent_in_eb() +*/ + cur_clone_root->offset += logical - found_key.objectid; + } *found = cur_clone_root; ret =0 ; }else {
Signature · 1 line
1.7.9.5
PATCH v2 1/1 Btrfs: use right clone root offset for compressed extents
For non compressed extents, iterate_extent_inodes() gives us offsets that take into account the data offset from the file extent items, while for compressed extents it doesn't. Therefore we have to adjust them before placing them in a send clone instruction. Not doing this adjustment leads to the receiving end requesting for a wrong a file range to the clone ioctl, which results in different file content from the one in the original send root.
Issue reproducible with the following excerpt from the test I made for xfstests:
_scratch_mkfs
_scratch_mount "-o compress-force=lzo"
$XFS_IO_PROG -f -c "truncate 118811" $SCRATCH_MNT/foo $XFS_IO_PROG -c "pwrite -S 0x0d -b 39987 92267 39987" $SCRATCH_MNT/foo
$BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
$XFS_IO_PROG -c "pwrite -S 0x3e -b 80000 200000 80000" $SCRATCH_MNT/foo $BTRFS_UTIL_PROG filesystem sync $SCRATCH_MNT
$XFS_IO_PROG -c "pwrite -S 0xdc -b 10000 250000 10000" $SCRATCH_MNT/foo $XFS_IO_PROG -c "pwrite -S 0xff -b 10000 300000 10000" $SCRATCH_MNT/foo
# will be used for incremental send to be able to issue clone operations $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/clones_snap
$BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
$FSSUM_PROG -A -f -w $tmp/1.fssum $SCRATCH_MNT/mysnap1
$FSSUM_PROG -A -f -w $tmp/2.fssum -x $SCRATCH_MNT/mysnap2/mysnap1 \
-x $SCRATCH_MNT/mysnap2/clones_snap $SCRATCH_MNT/mysnap2
$FSSUM_PROG -A -f -w $tmp/clones.fssum $SCRATCH_MNT/clones_snap \
-x $SCRATCH_MNT/clones_snap/mysnap1 -x $SCRATCH_MNT/clones_snap/mysnap2
$BTRFS_UTIL_PROG send $SCRATCH_MNT/mysnap1 -f $tmp/1.snap
$BTRFS_UTIL_PROG send $SCRATCH_MNT/clones_snap -f $tmp/clones.snap
$BTRFS_UTIL_PROG send -p $SCRATCH_MNT/mysnap1 \
-c $SCRATCH_MNT/clones_snap $SCRATCH_MNT/mysnap2 -f $tmp/2.snap _scratch_unmount
_scratch_mkfs
_scratch_mount
$BTRFS_UTIL_PROG receive $SCRATCH_MNT -f $tmp/1.snap $FSSUM_PROG -r $tmp/1.fssum $SCRATCH_MNT/mysnap1 2>> $seqres.full
$BTRFS_UTIL_PROG receive $SCRATCH_MNT -f $tmp/clones.snap $FSSUM_PROG -r $tmp/clones.fssum $SCRATCH_MNT/clones_snap 2>> $seqres.full
$BTRFS_UTIL_PROG receive $SCRATCH_MNT -f $tmp/2.snap $FSSUM_PROG -r $tmp/2.fssum $SCRATCH_MNT/mysnap2 2>> $seqres.full
---
V2: Updated commit message and the comment.
fs/btrfs/send.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
fs/btrfs/send.c +10 -0
@@ -1295,6 +1295,16 @@ verbose_printk(KERN_DEBUG "btrfs: find_extent_clone: data_offset=%llu, " }if (cur_clone_root) { +if (compressed !=BTRFS_COMPRESS_NONE ) { +/* +* Offsets given by iterate_extent_inodes() are relative +* to the start of the extent, we need to add logical +* offset from the file extent item. +* (See why at backref.c:check_extent_in_eb()) +*/ + cur_clone_root->offset +=btrfs_file_extent_offset (eb, + fi); + } *found = cur_clone_root; ret =0 ; }else {
Signature · 1 line
1.7.9.5