From patchwork Mon Aug 31 19:49:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Adamson X-Patchwork-Id: 7101271 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id BD622BF036 for ; Mon, 31 Aug 2015 19:50:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D2C8920553 for ; Mon, 31 Aug 2015 19:50:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D787D20557 for ; Mon, 31 Aug 2015 19:50:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753985AbbHaTuW (ORCPT ); Mon, 31 Aug 2015 15:50:22 -0400 Received: from mx144.netapp.com ([216.240.21.25]:13094 "EHLO mx144.netapp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752309AbbHaTuW (ORCPT ); Mon, 31 Aug 2015 15:50:22 -0400 X-IronPort-AV: E=Sophos;i="5.17,443,1437462000"; d="scan'208";a="65419807" Received: from vmwexchts03-prd.hq.netapp.com ([10.122.105.31]) by mx144-out.netapp.com with ESMTP; 31 Aug 2015 12:50:22 -0700 Received: from smtp1.corp.netapp.com (10.57.156.124) by VMWEXCHTS03-PRD.hq.netapp.com (10.122.105.31) with Microsoft SMTP Server id 15.0.1076.9; Mon, 31 Aug 2015 12:50:21 -0700 Received: from rhel7-1-snap3-3.localdomain (dros-16.vpn.netapp.com [10.55.66.171]) by smtp1.corp.netapp.com (8.13.1/8.13.1/NTAP-1.6) with ESMTP id t7VJoJHp019457; Mon, 31 Aug 2015 12:50:20 -0700 (PDT) From: To: CC: , , , Andy Adamson Subject: [PATCH 01/16] VFS: Separate cross fs check from vfs_copy_file_range Date: Mon, 31 Aug 2015 15:49:51 -0400 Message-ID: <1441050606-40897-2-git-send-email-andros@netapp.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1441050606-40897-1-git-send-email-andros@netapp.com> References: <1441050606-40897-1-git-send-email-andros@netapp.com> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Andy Adamson 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 --- 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);