All of lore.kernel.org
 help / color / mirror / Atom feed
From: <andros@netapp.com>
To: <trond.myklebust@primarydata.com>
Cc: <anna.schumaker@netapp.com>, <bfields@fieldses.org>,
	<linux-nfs@vger.kernel.org>, Andy Adamson <andros@netapp.com>
Subject: [PATCH Version 2 01/16] VFS: Separate cross fs check from vfs_copy_file_range
Date: Fri, 4 Sep 2015 13:29:23 -0400	[thread overview]
Message-ID: <1441387778-16465-2-git-send-email-andros@netapp.com> (raw)
In-Reply-To: <1441387778-16465-1-git-send-email-andros@netapp.com>

From: Andy Adamson <andros@netapp.com>

Move the high level vfs_copy_file_range entrypoint restriction that limits
copy offloading to files on the same mount and super to
a helper function to be called by copy_file_range methods.

Signed-off-by: Andy Adamson <andros@netapp.com>
---
 fs/read_write.c    | 34 +++++++++++++++++++++++-----------
 include/linux/fs.h |  1 +
 2 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/fs/read_write.c b/fs/read_write.c
index e564a6b..da28205 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -1330,6 +1330,29 @@ COMPAT_SYSCALL_DEFINE4(sendfile64, int, out_fd, int, in_fd,
 #endif
 
 /*
+ * copy_offload_same_fs(). Test for file system copy_file_range methods
+ * that support only copy offloading to files on the same mount point
+ * and super (and not to the same file).
+ */
+ssize_t copy_offload_same_fs(struct file *file_in, struct file *file_out)
+{
+	struct inode *inode_in = file_inode(file_in);
+	struct inode *inode_out = file_inode(file_out);
+
+	/* forbid copy not on the same mount point and super */
+	if (inode_in->i_sb != inode_out->i_sb ||
+	    file_in->f_path.mnt != file_out->f_path.mnt)
+		return -EXDEV;
+
+	/* forbid ranges in the same file */
+	if (inode_in == inode_out)
+		return -EINVAL;
+
+	return 0;
+}
+EXPORT_SYMBOL(copy_offload_same_fs);
+
+/*
  * 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.
@@ -1339,7 +1362,6 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in,
 			    size_t len, int flags)
 {
 	struct inode *inode_in;
-	struct inode *inode_out;
 	ssize_t ret;
 
 	if (flags)
@@ -1362,22 +1384,12 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in,
 		return -EINVAL;
 
 	inode_in = file_inode(file_in);
-	inode_out = file_inode(file_out);
 
 	/* make sure offsets don't wrap and the input is inside i_size */
 	if (pos_in + len < pos_in || pos_out + len < pos_out ||
 	    pos_in + len > i_size_read(inode_in))
 		return -EINVAL;
 
-	/* this could be relaxed once a method supports cross-fs copies */
-	if (inode_in->i_sb != inode_out->i_sb ||
-	    file_in->f_path.mnt != file_out->f_path.mnt)
-		return -EXDEV;
-
-	/* forbid ranges in the same file */
-	if (inode_in == inode_out)
-		return -EINVAL;
-
 	ret = mnt_want_write_file(file_out);
 	if (ret)
 		return ret;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index c97aed8..1c29f2f 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1685,6 +1685,7 @@ extern ssize_t vfs_readv(struct file *, const struct iovec __user *,
 		unsigned long, loff_t *);
 extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
 		unsigned long, loff_t *);
+extern ssize_t copy_offload_same_fs(struct file *, struct file *);
 extern ssize_t vfs_copy_file_range(struct file *, loff_t , struct file *,
 				   loff_t, size_t, int);
 
-- 
1.8.3.1


  reply	other threads:[~2015-09-04 17:29 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-04 17:29 [PATCH Version 2 00/16] NFSv4.2: Add support for inter-server to server COPY andros
2015-09-04 17:29 ` andros [this message]
2015-09-04 17:29 ` [PATCH Version 2 02/16] BTRFS: Use VFS copy offload helper andros
2015-09-04 17:29 ` [PATCH Version 2 03/16] VFS SQUASH use file_out instead of file_in for copy_file_range andros
2015-09-04 17:29 ` [PATCH Version 2 04/16] NFS COPY xdr changes andros
2015-09-04 17:29 ` [PATCH Version 2 05/16] NFS add same file check and flush source and destination for COPY andros
2015-09-04 17:29 ` [PATCH Version 2 06/16] NFS add inter ssc functions to nfs42proc andros
2015-09-04 17:29 ` [PATCH Version 2 07/16] NFS add COPY_NOTIFY operation andros
2015-09-04 17:29 ` [PATCH Version 2 08/16] NFSD add ca_source_server<> to COPY andros
2015-09-04 17:29 ` [PATCH Version 2 09/16] NFSD add COPY_NOTIFY operation andros
2015-09-04 17:29 ` [PATCH Version 2 10/16] NFS add ca_source_server<> to COPY andros
2015-09-04 17:29 ` [PATCH Version 2 11/16] NFSD generalize nfsd4_compound_state flag names andros
2015-09-04 17:29 ` [PATCH Version 2 12/16] NFSD: allow inter server COPY to have a STALE source server fh andros
2015-09-04 17:29 ` [PATCH Version 2 13/16] NFSD add nfs4 inter ssc to nfsd4_copy andros
2015-09-04 17:29 ` [PATCH Version 2 14/16] NFS in copy use stateid returned by copy_notify andros
2015-09-04 17:29 ` [PATCH Version 2 15/16] NFS always use openstateid in COPY_NOTIFY andros
2015-09-04 17:29 ` [PATCH Version 2 16/16] NFSD: extra stateid checking in read for interserver copy andros
2015-10-02 14:45 ` [PATCH Version 2 00/16] NFSv4.2: Add support for inter-server to server COPY J. Bruce Fields

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1441387778-16465-2-git-send-email-andros@netapp.com \
    --to=andros@netapp.com \
    --cc=anna.schumaker@netapp.com \
    --cc=bfields@fieldses.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=trond.myklebust@primarydata.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.