From patchwork Fri Oct 19 15:30:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Kornievskaia X-Patchwork-Id: 10649689 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 73824109C for ; Fri, 19 Oct 2018 15:30:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6502128434 for ; Fri, 19 Oct 2018 15:30:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6339C280B0; Fri, 19 Oct 2018 15:30:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7D4428478 for ; Fri, 19 Oct 2018 15:30:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727560AbeJSXgy (ORCPT ); Fri, 19 Oct 2018 19:36:54 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:38689 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726667AbeJSXgy (ORCPT ); Fri, 19 Oct 2018 19:36:54 -0400 Received: by mail-qt1-f196.google.com with SMTP id r22-v6so2165054qtm.5; Fri, 19 Oct 2018 08:30:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bwnpzjEJDuRVSD8Zir+yppo6qbIf0giK1d8Vukajepo=; b=f7od7lPr13IMyRNiVORa2DDWgrkfehtCW1psHzQTd9CZEWXzbb2rRXQyPTKOXvgnHQ cQegUhgs4eZmbw/6HKBKhdAv/eiG4MxnpvaE//BdFy59Hpr/OK6Cbv6NTUBw/G3BNXtG JZKn8J5G3hFiRJDYnejuIc1y7m6obdStJS+NlH38eRP+lF9jqPoqiDyieJScxRXOOSkt 4msi7njRsH4J8wBLqOrR692SR7ZT1tYYzz/T2DtZxgwXjDoRjLvK8XJbjeMsjK7+uvC3 163KUnWGL86SUiZvvBA2+D3sSAzzzyqdbAA6Xj2aHfkJXQDU6fg7DHkb5LknvfWCEq5S MNeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bwnpzjEJDuRVSD8Zir+yppo6qbIf0giK1d8Vukajepo=; b=hbScjAoJcUTzlEx5J7tyP3OL+hS0JjSMaPy86kJca+MH2vw4z9yl73N+M3P1e98vhK SE92BNk+hKHTYkwJoPAdrxoPpVkNIsmxbgrBjykqiol6WCed6zRcG9BOZoYvvimkSKzn hW+oCcS1/kpjBmZqFAfaABdQt9sBkq0BP/1F2qdEGEoDBMdx2dZxI+Kp2/6Ljs6ew1Mc /b6D0hMbUViNfwyI0PDcITlCIRJt7hdFind3d0k6WXLgrVl+FwUviw0YRjqgDRjoLDpk Tkj+xAqe52hpQbVs1KZ0xlo6bNjfC+p5bjEe/mutHLBrs5ID/4VKQ1I8Hln3TkbwNH8Y wxHw== X-Gm-Message-State: ABuFfoieMhJz5M6XTZDm3iwtenyLeiclFhcdEarnrhuDMtidErp3ZrRd Fz7wSMj7+PEWi3zuQAX46DB+6l2b X-Google-Smtp-Source: AJdET5eWdwFGLXg7tGOH0ut6kQ1hBBU5pDpu3S23wc5o+QzdsjZHJliqsuYfXA/pMekW7iE3C2G8IA== X-Received: by 2002:aed:31c6:: with SMTP id 64-v6mr1051017qth.120.1539963018068; Fri, 19 Oct 2018 08:30:18 -0700 (PDT) Received: from Olgas-MBP-195.attlocal.net (172-10-226-31.lightspeed.livnmi.sbcglobal.net. [172.10.226.31]) by smtp.gmail.com with ESMTPSA id m6-v6sm15141324qta.50.2018.10.19.08.30.16 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 19 Oct 2018 08:30:17 -0700 (PDT) From: Olga Kornievskaia To: linux-fsdevel@vger.kernel.org Cc: linux-nfs@vger.kernel.org, fweimer@redhat.com, smfrench@gmail.com Subject: [PATCH v1 02/11] VFS permit cross device vfs_copy_file_range Date: Fri, 19 Oct 2018 11:30:18 -0400 Message-Id: <20181019153018.32507-2-olga.kornievskaia@gmail.com> X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: <20181019153018.32507-1-olga.kornievskaia@gmail.com> References: <20181019153018.32507-1-olga.kornievskaia@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Olga Kornievskaia Allow copy_file_range to copy between different superblocks but only of the same file system types. This feature was of interest to CIFS as well as NFS. This feature is needed by NFSv4.2 to perform file copy operation on the same server or file copy between different NFSv4.2 servers. If a file system's fileoperations copy_file_range operation prohibits cross-device copies, fall back to do_splice_direct. This would be needed for the NFS (destination) server side implementation of the file copy and currently for CIFS. Besides NFS, there is only 1 implementor of the copy_file_range FS operation -- CIFS. CIFS assumes incoming file descriptors are both CIFS but it will check if they are coming from different servers and return error code to fall back to do_splice_direct. NFS will allow for copies between different NFS servers. Adding to the vfs.txt documentation to explicitly warn about allowing for different superblocks of the same file type to be passed into the copy_file_range for the future users of copy_file_range method. Signed-off-by: Olga Kornievskaia --- Documentation/filesystems/vfs.txt | 4 +++- fs/read_write.c | 13 ++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Documentation/filesystems/vfs.txt b/Documentation/filesystems/vfs.txt index a6c6a8a..5e520de 100644 --- a/Documentation/filesystems/vfs.txt +++ b/Documentation/filesystems/vfs.txt @@ -958,7 +958,9 @@ otherwise noted. fallocate: called by the VFS to preallocate blocks or punch a hole. - copy_file_range: called by the copy_file_range(2) system call. + copy_file_range: called by copy_file_range(2) system call. This method + works on two file descriptors that might reside on + different superblocks of the same type of file system. clone_file_range: called by the ioctl(2) system call for FICLONERANGE and FICLONE commands. diff --git a/fs/read_write.c b/fs/read_write.c index c60790f..474e740 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1578,10 +1578,6 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, (file_out->f_flags & O_APPEND)) return -EBADF; - /* this could be relaxed once a method supports cross-fs copies */ - if (inode_in->i_sb != inode_out->i_sb) - return -EXDEV; - if (len == 0) return 0; @@ -1591,7 +1587,8 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, * Try cloning first, this is supported by more file systems, and * more efficient if both clone and copy are supported (e.g. NFS). */ - if (file_in->f_op->clone_file_range) { + if (inode_in->i_sb == inode_out->i_sb && + file_in->f_op->clone_file_range) { ret = file_in->f_op->clone_file_range(file_in, pos_in, file_out, pos_out, len); if (ret == 0) { @@ -1600,10 +1597,12 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, } } - if (file_out->f_op->copy_file_range) { + if (file_out->f_op->copy_file_range && + (file_in->f_op->copy_file_range == + 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 && ret != -EXDEV) goto done; }