diff mbox

[1/9] vfs: add COPY_FILE_CLONE_ONLY flag

Message ID 1445728636-10109-2-git-send-email-tao.peng@primarydata.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Peng Tao Oct. 24, 2015, 11:17 p.m. UTC
To tell file system not to return partial success in the
.copy_file_range method. This is useful to implement the
clone (or reflink) functionality.

COPY_FILE_CLONE_ONLY is added only to include/linux/fs.h
and thus is not exposed to users. We can replace it with
something like Anna's COPY_FR_REFLINK in uapi/fs.h when
implementing new user visiable APIs like sys_clone.

Signed-off-by: Peng Tao <tao.peng@primarydata.com>
---
 fs/read_write.c    | 9 +++++----
 include/linux/fs.h | 3 +++
 2 files changed, 8 insertions(+), 4 deletions(-)

Comments

Christoph Hellwig Nov. 13, 2015, 8:58 a.m. UTC | #1
On Sun, Oct 25, 2015 at 07:17:08AM +0800, Peng Tao wrote:
> To tell file system not to return partial success in the
> .copy_file_range method. This is useful to implement the
> clone (or reflink) functionality.

The return value is only part of it, the other part is to
make it atomic.  Thus I don't think overloading copy_file_range
is a good idea - we should have a seaprate .clone_file_range that
is called by the btrfs ioctls moved to the core, and have
vfs_copy_file_range use .clone_file_range if that exists, and
if none of the potentially conflicting future flags like
COPY_FALLOC are present.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/read_write.c b/fs/read_write.c
index d2da7e4..da11a7f 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -1349,8 +1349,9 @@  static ssize_t vfs_copy_fr_copy(struct file *file_in, loff_t pos_in,
 
 /*
  * copy_file_range() differs from regular file read and write in that it
- * specifically allows return partial success.  When it does so is up to
- * the copy_file_range method.
+ * specifically allows returning partial success when COPY_FILE_CLONE_ONLY
+ * is not set in the flags argument, in which case it is up to the file system
+ * to decide whether it wants to do so in the copy_file_range method.
  */
 ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in,
 			    struct file *file_out, loff_t pos_out,
@@ -1360,7 +1361,7 @@  ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in,
 	struct inode *inode_out = file_inode(file_out);
 	ssize_t ret;
 
-	if (flags != 0)
+	if (flags && flags != COPY_FILE_CLONE_ONLY)
 		return -EINVAL;
 
 	if (!(file_in->f_mode & FMODE_READ) ||
@@ -1385,7 +1386,7 @@  ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in,
 	if (file_out->f_op->copy_file_range)
 		ret = file_out->f_op->copy_file_range(file_in, pos_in, file_out,
 						      pos_out, len, flags);
-	if (ret == -EOPNOTSUPP)
+	if (ret == -EOPNOTSUPP && !(flags & COPY_FILE_CLONE_ONLY))
 		ret = vfs_copy_fr_copy(file_in, pos_in, file_out, pos_out, len);
 
 	if (ret > 0) {
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 6220307..1c430fd 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1610,6 +1610,9 @@  struct block_device_operations;
 
 struct iov_iter;
 
+/* Tell file system not to return partial success in copy_file_range method */
+#define COPY_FILE_CLONE_ONLY		(1 << 0)
+
 struct file_operations {
 	struct module *owner;
 	loff_t (*llseek) (struct file *, loff_t, int);