Commit a61e1e0d authored by Filipe Manana's avatar Filipe Manana Committed by David Sterba

Btrfs: simplify inline extent handling when doing reflinks

We can not reflink parts of an inline extent, we must always reflink the
whole inline extent. We know that inline extents always start at file
offset 0 and that can never represent an amount of data larger then the
filesystem's sector size (both compressed and uncompressed). We also have
had the constraints that reflink operations must have a start offset that
is aligned to the sector size and an end offset that is also aligned or
it ends the inode's i_size, so there's no way for user space to be able
to do a reflink operation that will refer to only a part of an inline
extent.

Initially there was a bug in the inlining code that could allow compressed
inline extents that encoded more than 1 page, but that was fixed in 2008
by commit 70b99e69 ("Btrfs: Compression corner fixes") since that
was problematic.

So remove all the extent cloning code that deals with the possibility
of cloning only partial inline extents.
Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 6a177381
...@@ -73,9 +73,8 @@ static int clone_copy_inline_extent(struct inode *dst, ...@@ -73,9 +73,8 @@ static int clone_copy_inline_extent(struct inode *dst,
struct btrfs_key *new_key, struct btrfs_key *new_key,
const u64 drop_start, const u64 drop_start,
const u64 datal, const u64 datal,
const u64 skip,
const u64 size, const u64 size,
char *inline_data) const char *inline_data)
{ {
struct btrfs_fs_info *fs_info = btrfs_sb(dst->i_sb); struct btrfs_fs_info *fs_info = btrfs_sb(dst->i_sb);
struct btrfs_root *root = BTRFS_I(dst)->root; struct btrfs_root *root = BTRFS_I(dst)->root;
...@@ -171,12 +170,6 @@ static int clone_copy_inline_extent(struct inode *dst, ...@@ -171,12 +170,6 @@ static int clone_copy_inline_extent(struct inode *dst,
if (ret) if (ret)
return ret; return ret;
if (skip) {
const u32 start = btrfs_file_extent_calc_inline_size(0);
memmove(inline_data + start, inline_data + start + skip, datal);
}
write_extent_buffer(path->nodes[0], inline_data, write_extent_buffer(path->nodes[0], inline_data,
btrfs_item_ptr_offset(path->nodes[0], btrfs_item_ptr_offset(path->nodes[0],
path->slots[0]), path->slots[0]),
...@@ -240,7 +233,6 @@ static int btrfs_clone(struct inode *src, struct inode *inode, ...@@ -240,7 +233,6 @@ static int btrfs_clone(struct inode *src, struct inode *inode,
struct btrfs_key new_key; struct btrfs_key new_key;
u64 disko = 0, diskl = 0; u64 disko = 0, diskl = 0;
u64 datao = 0, datal = 0; u64 datao = 0, datal = 0;
u8 comp;
u64 drop_start; u64 drop_start;
/* Note the key will change type as we walk through the tree */ /* Note the key will change type as we walk through the tree */
...@@ -283,7 +275,6 @@ static int btrfs_clone(struct inode *src, struct inode *inode, ...@@ -283,7 +275,6 @@ static int btrfs_clone(struct inode *src, struct inode *inode,
extent = btrfs_item_ptr(leaf, slot, extent = btrfs_item_ptr(leaf, slot,
struct btrfs_file_extent_item); struct btrfs_file_extent_item);
comp = btrfs_file_extent_compression(leaf, extent);
type = btrfs_file_extent_type(leaf, extent); type = btrfs_file_extent_type(leaf, extent);
if (type == BTRFS_FILE_EXTENT_REG || if (type == BTRFS_FILE_EXTENT_REG ||
type == BTRFS_FILE_EXTENT_PREALLOC) { type == BTRFS_FILE_EXTENT_PREALLOC) {
...@@ -365,23 +356,18 @@ static int btrfs_clone(struct inode *src, struct inode *inode, ...@@ -365,23 +356,18 @@ static int btrfs_clone(struct inode *src, struct inode *inode,
if (ret) if (ret)
goto out; goto out;
} else if (type == BTRFS_FILE_EXTENT_INLINE) { } else if (type == BTRFS_FILE_EXTENT_INLINE) {
u64 skip = 0; /*
u64 trim = 0; * Inline extents always have to start at file offset 0
* and can never be bigger then the sector size. We can
if (off > key.offset) { * never clone only parts of an inline extent, since all
skip = off - key.offset; * reflink operations must start at a sector size aligned
new_key.offset += skip; * offset, and the length must be aligned too or end at
} * the i_size (which implies the whole inlined data).
*/
if (key.offset + datal > off + len) ASSERT(key.offset == 0);
trim = key.offset + datal - (off + len); ASSERT(datal <= fs_info->sectorsize);
if (key.offset != 0 || datal > fs_info->sectorsize)
if (comp && (skip || trim)) { return -EUCLEAN;
ret = -EINVAL;
goto out;
}
size -= skip + trim;
datal -= skip + trim;
/* /*
* If our extent is inline, we know we will drop or * If our extent is inline, we know we will drop or
...@@ -399,7 +385,7 @@ static int btrfs_clone(struct inode *src, struct inode *inode, ...@@ -399,7 +385,7 @@ static int btrfs_clone(struct inode *src, struct inode *inode,
ret = clone_copy_inline_extent(inode, trans, path, ret = clone_copy_inline_extent(inode, trans, path,
&new_key, drop_start, &new_key, drop_start,
datal, skip, size, buf); datal, size, buf);
if (ret) { if (ret) {
if (ret != -EOPNOTSUPP) if (ret != -EOPNOTSUPP)
btrfs_abort_transaction(trans, ret); btrfs_abort_transaction(trans, ret);
...@@ -543,17 +529,6 @@ static noinline int btrfs_clone_files(struct file *file, struct file *file_src, ...@@ -543,17 +529,6 @@ static noinline int btrfs_clone_files(struct file *file, struct file *file_src,
u64 len = olen; u64 len = olen;
u64 bs = fs_info->sb->s_blocksize; u64 bs = fs_info->sb->s_blocksize;
/*
* TODO:
* - split compressed inline extents. annoying: we need to
* decompress into destination's address_space (the file offset
* may change, so source mapping won't do), then recompress (or
* otherwise reinsert) a subrange.
*
* - split destination inode's inline extents. The inline extents can
* be either compressed or non-compressed.
*/
/* /*
* VFS's generic_remap_file_range_prep() protects us from cloning the * VFS's generic_remap_file_range_prep() protects us from cloning the
* eof block into the middle of a file, which would result in corruption * eof block into the middle of a file, which would result in corruption
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment