Btrfs: allow clone of an arbitrary file range
authorSage Weil <sage@newdream.net>
Wed, 12 Nov 2008 19:32:25 +0000 (14:32 -0500)
committerChris Mason <chris.mason@oracle.com>
Wed, 12 Nov 2008 19:32:25 +0000 (14:32 -0500)
commitc5c9cd4d1b827fe545ed2a945e91e3a6909f3886
tree5dae28d8cd871952b105cdc2822ef4e54f1f02f3
parent2ed6d66408527be0d1c6131d44cec7e86008ba26
Btrfs: allow clone of an arbitrary file range

This patch adds an additional CLONE_RANGE ioctl to clone an arbitrary
(block-aligned) file range to another file.  The original CLONE ioctl
becomes a special case of cloning the entire file range.  The logic is a
bit more complex now since ranges may be cloned to different offsets, and
because we may only be cloning the beginning or end of a particular extent
or checksum item.

An additional sanity check ensures the source and destination files aren't
the same (which would previously deadlock), although eventually this could
be extended to allow the duplication of file data at a different offset
within the same file.

Any extents within the destination range in the target file are dropped.

We currently do not cope with the case where a compressed inline extent
needs to be split.  This will probably require decompressing the extent
into a temporary address_space, and inserting just the cloned portion as a
new compressed inline extent.  For now, just return -EINVAL in this case.
Note that this never comes up in the more common case of cloning an entire
file.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
fs/btrfs/ioctl.c
fs/btrfs/ioctl.h