@@ -3251,7 +3251,8 @@ int btrfs_dirty_pages(struct inode *inode, struct page **pages,
struct extent_state **cached);
int btrfs_fdatawrite_range(struct inode *inode, loff_t start, loff_t end);
s64 btrfs_clone_file_range(struct file *file_in, loff_t pos_in,
- struct file *file_out, loff_t pos_out, u64 len);
+ struct file *file_out, loff_t pos_out, u64 len,
+ unsigned int flags);
/* tree-defrag.c */
int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
@@ -4351,7 +4351,8 @@ static noinline int btrfs_clone_files(struct file *file, struct file *file_src,
}
s64 btrfs_clone_file_range(struct file *src_file, loff_t off,
- struct file *dst_file, loff_t destoff, u64 len)
+ struct file *dst_file, loff_t destoff, u64 len,
+ unsigned int flags)
{
int ret;
@@ -181,7 +181,8 @@ static long nfs42_fallocate(struct file *filep, int mode, loff_t offset, loff_t
}
static s64 nfs42_clone_file_range(struct file *src_file, loff_t src_off,
- struct file *dst_file, loff_t dst_off, u64 count)
+ struct file *dst_file, loff_t dst_off, u64 count,
+ unsigned int flags)
{
struct inode *dst_inode = file_inode(dst_file);
struct nfs_server *server = NFS_SERVER(dst_inode);
@@ -2531,7 +2531,8 @@ static s64 ocfs2_file_clone_range(struct file *file_in,
loff_t pos_in,
struct file *file_out,
loff_t pos_out,
- u64 len)
+ u64 len,
+ unsigned int flags)
{
int ret;
@@ -4843,7 +4843,7 @@ int ocfs2_reflink_remap_range(struct file *file_in,
goto out_unlock;
ret = vfs_clone_file_prep(file_in, pos_in, file_out, pos_out,
- &len, is_dedupe);
+ &len, is_dedupe ? CLONERANGE_DEDUPE : 0);
if (ret <= 0)
goto out_unlock;
@@ -488,7 +488,8 @@ static ssize_t ovl_copy_file_range(struct file *file_in, loff_t pos_in,
}
static s64 ovl_clone_file_range(struct file *file_in, loff_t pos_in,
- struct file *file_out, loff_t pos_out, u64 len)
+ struct file *file_out, loff_t pos_out, u64 len,
+ unsigned int flags)
{
int ret;
@@ -1592,7 +1592,8 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in,
s64 cloned;
cloned = file_in->f_op->clone_file_range(file_in, pos_in,
- file_out, pos_out, min(MAX_RW_COUNT, len));
+ file_out, pos_out, min(MAX_RW_COUNT, len),
+ CLONERANGE_SHORT);
if (cloned >= 0) {
ret = cloned;
goto done;
@@ -1721,13 +1722,14 @@ static int clone_verify_area(struct file *file, loff_t pos, u64 len, bool write)
*/
int vfs_clone_file_prep(struct file *file_in, loff_t pos_in,
struct file *file_out, loff_t pos_out,
- u64 *len, bool is_dedupe)
+ u64 *len, unsigned int flags)
{
struct inode *inode_in = file_inode(file_in);
struct inode *inode_out = file_inode(file_out);
uint64_t nlen;
loff_t isize;
bool same_inode = (inode_in == inode_out);
+ bool is_dedupe = (flags & CLONERANGE_DEDUPE);
int ret;
/* Don't touch certain kinds of inodes */
@@ -1802,6 +1804,7 @@ int vfs_clone_file_range(struct file *file_in, loff_t pos_in,
struct inode *inode_in = file_inode(file_in);
struct inode *inode_out = file_inode(file_out);
s64 cloned;
+ unsigned int flags = 0;
int ret;
if (S_ISDIR(inode_in->i_mode) || S_ISDIR(inode_out->i_mode))
@@ -1834,7 +1837,7 @@ int vfs_clone_file_range(struct file *file_in, loff_t pos_in,
return ret;
cloned = file_in->f_op->clone_file_range(file_in, pos_in,
- file_out, pos_out, len);
+ file_out, pos_out, len, flags);
if (cloned < 0)
return cloned;
else if (len && cloned != len)
@@ -925,7 +925,8 @@ xfs_file_clone_range(
loff_t pos_in,
struct file *file_out,
loff_t pos_out,
- u64 len)
+ u64 len,
+ unsigned int flags)
{
int ret;
@@ -1278,7 +1278,7 @@ xfs_reflink_remap_prep(
goto out_unlock;
ret = vfs_clone_file_prep(file_in, pos_in, file_out, pos_out,
- &len, is_dedupe);
+ &len, is_dedupe ? CLONERANGE_DEDUPE : 0);
if (ret <= 0)
goto out_unlock;
@@ -1761,7 +1761,7 @@ struct file_operations {
loff_t, size_t, unsigned int);
s64 (*clone_file_range)(struct file *file_in, loff_t pos_in,
struct file *file_out, loff_t pos_out,
- u64 count);
+ u64 count, unsigned int flags);
s64 (*dedupe_file_range)(struct file *file_in, loff_t pos_in,
struct file *file_out, loff_t pos_out,
u64 count);
@@ -1827,9 +1827,15 @@ extern ssize_t vfs_readv(struct file *, const struct iovec __user *,
unsigned long, loff_t *, rwf_t);
extern ssize_t vfs_copy_file_range(struct file *, loff_t , struct file *,
loff_t, size_t, unsigned int);
+/* Caller can handle a shortened operation. */
+#define CLONERANGE_SHORT (1 << 0)
+/* End operation at the source file's EOF. */
+#define CLONERANGE_EOF (1 << 1)
+/* Operation is actually dedupe, not clone. */
+#define CLONERANGE_DEDUPE (1 << 2)
extern int vfs_clone_file_prep(struct file *file_in, loff_t pos_in,
struct file *file_out, loff_t pos_out,
- u64 *count, bool is_dedupe);
+ u64 *count, unsigned int flags);
extern int vfs_clone_file_range(struct file *file_in, loff_t pos_in,
struct file *file_out, loff_t pos_out, u64 len);
extern int vfs_dedupe_file_range_compare(struct inode *src, loff_t srcoff,