linux/fs/btrfs
Robbie Ko 040ee6120c Btrfs: send, improve clone range
Improve clone_range in two scenarios.

1. Remove the limit of inode size when find clone inodes We can do
   partial clone, so there is no need to limit the size of the candidate
   inode.  When clone a range, we clone the legal range only by bytenr,
   offset, len, inode size.

2. In the scenarios of rewrite or clone_range, data_offset rarely
   matches exactly, so the chance of a clone is missed.

e.g.
    1. Write a 1M file
        dd if=/dev/zero of=1M bs=1M count=1

    2. Clone 1M file
       cp --reflink 1M clone

    3. Rewrite 4k on the clone file
       dd if=/dev/zero of=clone bs=4k count=1 conv=notrunc

    The disk layout is as follows:
    item 16 key (257 EXTENT_DATA 0) itemoff 15353 itemsize 53
	extent data disk byte 1103101952 nr 1048576
	extent data offset 0 nr 1048576 ram 1048576
	extent compression(none)
    ...
    item 22 key (258 EXTENT_DATA 0) itemoff 14959 itemsize 53
	extent data disk byte 1104150528 nr 4096
	extent data offset 0 nr 4096 ram 4096
	extent compression(none)
    item 23 key (258 EXTENT_DATA 4096) itemoff 14906 itemsize 53
	extent data disk byte 1103101952 nr 1048576
	extent data offset 4096 nr 1044480 ram 1048576
	extent compression(none)

When send, inode 258 file offset 4096~1048576 (item 23) has a chance to
clone_range, but because data_offset does not match inode 257 (item 16),
it causes missed clone and can only transfer actual data.

Improve the problem by judging whether the current data_offset has
overlap with the file extent item, and if so, adjusting offset and
extent_len so that we can clone correctly.

Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Robbie Ko <robbieko@synology.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-04-29 19:02:35 +02:00
..
tests btrfs: inode: Verify inode mode to avoid NULL pointer dereference 2019-04-29 19:02:32 +02:00
acl.c
async-thread.c
async-thread.h
backref.c btrfs: use BUG() instead of BUG_ON(1) 2019-04-29 19:02:28 +02:00
backref.h
btrfs_inode.h btrfs: use common file type conversion 2019-04-29 19:02:29 +02:00
check-integrity.c
check-integrity.h
compression.c btrfs: Use less confusing condition for uptodate parameter to btrfs_writepage_endio_finish_ordered 2019-04-29 19:02:24 +02:00
compression.h
ctree.c btrfs: get fs_info from eb in btrfs_verify_level_key 2019-04-29 19:02:31 +02:00
ctree.h btrfs: tree-checker: Verify inode item 2019-04-29 19:02:32 +02:00
dedupe.h
delayed-inode.c btrfs: get fs_info from eb in btrfs_leaf_free_space 2019-04-29 19:02:30 +02:00
delayed-inode.h
delayed-ref.c
delayed-ref.h
dev-replace.c
dev-replace.h
dir-item.c
disk-io.c btrfs: qgroup: remove obsolete fs_info members 2019-04-29 19:02:31 +02:00
disk-io.h btrfs: get fs_info from eb in btrfs_verify_level_key 2019-04-29 19:02:31 +02:00
export.c
export.h
extent_io.c btrfs: get fs_info from eb in leaf_data_end 2019-04-29 19:02:30 +02:00
extent_io.h btrfs: get fs_info from eb in repair_eb_io_failure 2019-04-29 19:02:29 +02:00
extent_map.c
extent_map.h
extent-tree.c btrfs: get fs_info from eb in clean_tree_block 2019-04-29 19:02:30 +02:00
file-item.c btrfs: get fs_info from eb in btrfs_leaf_free_space 2019-04-29 19:02:30 +02:00
file.c btrfs: get fs_info from eb in btrfs_leaf_free_space 2019-04-29 19:02:30 +02:00
free-space-cache.c
free-space-cache.h
free-space-tree.c btrfs: get fs_info from eb in clean_tree_block 2019-04-29 19:02:30 +02:00
free-space-tree.h
inode-item.c
inode-map.c
inode-map.h
inode.c btrfs: inode: Verify inode mode to avoid NULL pointer dereference 2019-04-29 19:02:32 +02:00
ioctl.c btrfs: Perform locking/unlocking in btrfs_remap_file_range() 2019-04-29 19:02:29 +02:00
Kconfig
locking.c btrfs: switch extent_buffer::lock_nested to bool 2019-04-29 19:02:21 +02:00
locking.h
lzo.c
Makefile
math.h
ordered-data.c btrfs: Switch memory allocations in async csum calculation path to kvmalloc 2019-04-25 14:17:38 +02:00
ordered-data.h
orphan.c
print-tree.c btrfs: get fs_info from eb in btrfs_leaf_free_space 2019-04-29 19:02:30 +02:00
print-tree.h
props.c btrfs: prop: open code btrfs_set_prop in inherit_prop 2019-04-29 19:02:35 +02:00
props.h btrfs: refactor btrfs_set_prop and add btrfs_set_prop_trans 2019-04-29 19:02:19 +02:00
qgroup.c btrfs: get fs_info from eb in clean_tree_block 2019-04-29 19:02:30 +02:00
qgroup.h
raid56.c for-5.1-rc2-tag 2019-03-26 10:32:13 -07:00
raid56.h
rcu-string.h
reada.c
ref-verify.c
ref-verify.h
relocation.c btrfs: fix panic during relocation after ENOSPC before writeback happens 2019-04-29 19:02:24 +02:00
root-tree.c btrfs: Don't panic when we can't find a root key 2019-04-29 19:02:17 +02:00
scrub.c btrfs: scrub: return EAGAIN when fs is closing 2019-04-29 19:02:17 +02:00
send.c Btrfs: send, improve clone range 2019-04-29 19:02:35 +02:00
send.h
struct-funcs.c
super.c btrfs: drop unused parameter in mount_subvol 2019-04-29 19:02:35 +02:00
sysfs.c
sysfs.h
transaction.c btrfs: Introduce extent_io_tree::owner to distinguish different io_trees 2019-04-29 19:02:18 +02:00
transaction.h Btrfs: remove no longer used 'sync' member from transaction handle 2019-04-29 19:02:18 +02:00
tree-checker.c btrfs: tree-checker: get fs_info from eb in check_inode_item 2019-04-29 19:02:35 +02:00
tree-checker.h btrfs: Move btrfs_check_chunk_valid() to tree-check.[ch] and export it 2019-04-29 19:02:31 +02:00
tree-defrag.c
tree-log.c btrfs: get fs_info from eb in clean_tree_block 2019-04-29 19:02:30 +02:00
tree-log.h
ulist.c
ulist.h
uuid-tree.c btrfs: Turn an 'else if' into an 'else' in btrfs_uuid_tree_add 2019-04-29 19:02:19 +02:00
volumes.c btrfs: tree-checker: Verify dev item 2019-04-29 19:02:32 +02:00
volumes.h btrfs: tree-checker: Verify dev item 2019-04-29 19:02:32 +02:00
xattr.c btrfs: get fs_info from eb in btrfs_leaf_free_space 2019-04-29 19:02:30 +02:00
xattr.h
zlib.c
zstd.c btrfs: zstd: remove indirect calls for local functions 2019-04-29 19:02:18 +02:00