From patchwork Sat Oct 24 23:17:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Tao X-Patchwork-Id: 7480741 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 366ED9F36A for ; Sat, 24 Oct 2015 15:30:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 58DD22070B for ; Sat, 24 Oct 2015 15:30:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 645F4206EF for ; Sat, 24 Oct 2015 15:30:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752651AbbJXP3T (ORCPT ); Sat, 24 Oct 2015 11:29:19 -0400 Received: from mail-pa0-f43.google.com ([209.85.220.43]:35719 "EHLO mail-pa0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752355AbbJXP2x (ORCPT ); Sat, 24 Oct 2015 11:28:53 -0400 Received: by pasz6 with SMTP id z6so144427212pas.2 for ; Sat, 24 Oct 2015 08:28:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=primarydata_com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yU4On9HHwBXHBJlDxovvi5MvIGFK93B5p/clW6yO238=; b=TcGRxcXy0zS+si75Fu8g9LVsHe1a5SZfqMRZhjrGrfwIAoFjzGvLedtWE8h+gXoS0Z RexHe0BwaYzqA150suAzWcuI2TglmuoDtb1soQDZ+535jHwA5+LoypPycqpk2l5JRvCM 3+hRDyCKTf4sqUNYoWK82JoaHZpIIg36UIZeT0yndvz9S1PVNJcSHn9ab7mRksgHlmZD AEV2Tdop/CtZLu0F4zwHtv4//7AInZrLyodLRf4Tr4j3w6sWY0VR3XUhva2wjEznddyj smC22otrc85kgnojnnFZ4D0K2NikvtzqLOsR0o29VN4C3+zRNKR+ElbaLZ4Y69/ayT5q ahuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=yU4On9HHwBXHBJlDxovvi5MvIGFK93B5p/clW6yO238=; b=iqdQd7cUHhaSphZ/p0FUY0fFMqipOECDaf5eXNtcLhiUN4BWNLYILa3tW5OMzvHT9S ZmC6zjp0RcCaAnbT/DWrix48tCiXzUaaIsq9nJs2yzyy/jGQ81HU3yUwfnjOjmwvlRF+ zjm9MJ0ScmmNZsqeOpLls4RnN6W/P3won5/lk4/F5SMfiuGnQPhP1RA4UUvf5iCPrpXU y1FsIFCJddwXyoOArs6H8LuZdtUVT/ls6Nmab2kjspCJedrDUplMk0juzForVMOqubog 9eqA3P/sSjZZtXW7wFAR4uc3G+Jhc316kAhxgS7fClp8FobZcsOedQp/boqtjTANLxyN aIhw== X-Gm-Message-State: ALoCoQkKS3tAhY7FI4iZ7UlJf40BR1V5lvcR02J/1VKmJr3bfEbs3GBXhoXaxXVkk+FGsVu+RLW3 X-Received: by 10.66.158.201 with SMTP id ww9mr11672098pab.33.1445700532472; Sat, 24 Oct 2015 08:28:52 -0700 (PDT) Received: from lear.localdomain (ec2-54-65-164-9.ap-northeast-1.compute.amazonaws.com. [54.65.164.9]) by smtp.gmail.com with ESMTPSA id nj1sm24764918pbc.2.2015.10.24.08.28.46 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Oct 2015 08:28:51 -0700 (PDT) From: Peng Tao To: linux-fsdevel@vger.kernel.org Cc: Trond Myklebust , Anna Schumaker , Christoph Hellwig , Zach Brown , Darren Hart , Jeff Layton , bfields@fieldses.org, "Darrick J. Wong" , viro@zeniv.linux.org.uk, linux-nfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-cifs@vger.kernel.org, Steve French , Peng Tao Subject: [PATCH 1/9] vfs: add COPY_FILE_CLONE_ONLY flag Date: Sun, 25 Oct 2015 07:17:08 +0800 Message-Id: <1445728636-10109-2-git-send-email-tao.peng@primarydata.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1445728636-10109-1-git-send-email-tao.peng@primarydata.com> References: <1445728636-10109-1-git-send-email-tao.peng@primarydata.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, DATE_IN_FUTURE_06_12, DKIM_SIGNED, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 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 --- fs/read_write.c | 9 +++++---- include/linux/fs.h | 3 +++ 2 files changed, 8 insertions(+), 4 deletions(-) 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);