From patchwork Sat Oct 13 00:07:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 10639613 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 BCA961869 for ; Sat, 13 Oct 2018 00:07:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A7A542B78F for ; Sat, 13 Oct 2018 00:07:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9C4792B7A3; Sat, 13 Oct 2018 00:07:46 +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=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 133F32B78F for ; Sat, 13 Oct 2018 00:07:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4CEB76B027F; Fri, 12 Oct 2018 20:07:44 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 47FAD6B0280; Fri, 12 Oct 2018 20:07:44 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 397636B0281; Fri, 12 Oct 2018 20:07:44 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by kanga.kvack.org (Postfix) with ESMTP id 10ABF6B0280 for ; Fri, 12 Oct 2018 20:07:44 -0400 (EDT) Received: by mail-qk1-f198.google.com with SMTP id v198-v6so13353484qka.16 for ; Fri, 12 Oct 2018 17:07:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:subject:from:to:cc:date :message-id:in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=XyX+a0OwgmoCuUQlM5FRUIUGIs9diILaZiWpCujlIew=; b=I/biwuD5GSgCDCbdN/Q0b7ZHiAxS2iJ/kM/Rq4Csc9hWIvHM5zIppMoYeVtMwxhZzY /PrCbye8yi4MCX4iyiJwvn3nM9zRt1MBN9r61vSLzmfwyf9tN9loDLvAh23Dj6K+D7Pt 2aryHbhckWCLwLlL2xmeBBxV6b/yAUVI5jSJoU6B4rt0MMMQIxP4dSK0voE94EYElBWL sTeD1YkdCtmAwKKizoqzgLvFqkqUVfUbz8vED67KpQeUKsPToGRMbkxKuIXvdLAaJUwl BGXNOVRzffL5PcUW281QdX0hXlCvocr0d7OjJS+TDfk6vsCZp6rKy6cBmq80WbWh9na+ O7vA== X-Gm-Message-State: ABuFfoi9VtQR30V053MB1UV048TgSIGq6JeodQ4nLlR2rY2dl3uYDtUK pQykF+I48XcV++EtyFXfeK11vk+3h6xpZf+TWFU21StOHayudbcJfrsNT31OnP5bAt8Wg31fE11 ZaNmQzYnMvGkN/xIb+SRV1i64rMqyRGWRFIB57WgbJ/nsP2BM+2cBNUIYS4KH/Oj9ag== X-Received: by 2002:a37:4855:: with SMTP id v82-v6mr7526452qka.10.1539389263813; Fri, 12 Oct 2018 17:07:43 -0700 (PDT) X-Google-Smtp-Source: ACcGV63tRWf9/7NT1daVDlMULMmgT3n0cYYormNoHCU/2LQEXuxujMKgmh5+OrGdPUu6CP2rUVd3 X-Received: by 2002:a37:4855:: with SMTP id v82-v6mr7526428qka.10.1539389263232; Fri, 12 Oct 2018 17:07:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539389263; cv=none; d=google.com; s=arc-20160816; b=mDWZf737UpZxIJ/1Ov+d3qNRjvyNBkU8SlKQaD2H7FCMUUMu18SCrH2mjHkJJcJPy0 ceOCMBPOXMOkhIrYRlcxuW91u0n1byeCaS4WPerzM/eqEtskeDq0yaEgLatk/Z1/nkny jxFoIdXIlmMNyoG5qX8HPrAYZu3Tl4igyj5mDo6qZ4oJhaQ43oVGBSwKhYrCnDLzGJTR 7Ln6pgGKQVfsaiJIhwwak3NrOBK4xeDRS2P7ntGnq2eeSSeD+ISET680Gf+wEKAZxAdw iM7wB/qBQuUym0mchZH9sbX2FhPHnDmAJSWQEjSfpPX9xCyyenUywmazz7SSo44GSBpZ 81xQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:subject:dkim-signature; bh=XyX+a0OwgmoCuUQlM5FRUIUGIs9diILaZiWpCujlIew=; b=dYYb4LzgY3mt1Qf/XVUcwgVeJbx683wUmrhHvszPil/furBEd8vBxdtGBLWheVhcje ucTd6twSCc3FcJYu5UibVAZS+K6eDxaA7URciSxchfPjw8otkAMk3/5xq6Uk2c53ENU3 VCqXLYOhUPjxTxMySl69+Ed0uez0LupsLmNRXHb8eXxuIqrxJbnqgItLRd8husR8QWzk C4MZulOSKVuicC50F9IqAsqLJxfPjySy2G50o71ntMdIxfaOsNPLWFjLi6q439+Y6rmD dha6nFeskmFc/o3xmqQNePZZKmQZ02t4ve+PaSzaNjtJXQSl7X6ha8n9TxFILHMf+fM8 I6Xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=Rd75H4KU; spf=pass (google.com: domain of darrick.wong@oracle.com designates 156.151.31.86 as permitted sender) smtp.mailfrom=darrick.wong@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from userp2130.oracle.com (userp2130.oracle.com. [156.151.31.86]) by mx.google.com with ESMTPS id r141-v6si1939687qke.122.2018.10.12.17.07.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Oct 2018 17:07:43 -0700 (PDT) Received-SPF: pass (google.com: domain of darrick.wong@oracle.com designates 156.151.31.86 as permitted sender) client-ip=156.151.31.86; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=Rd75H4KU; spf=pass (google.com: domain of darrick.wong@oracle.com designates 156.151.31.86 as permitted sender) smtp.mailfrom=darrick.wong@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w9D04KRw143951; Sat, 13 Oct 2018 00:07:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=XyX+a0OwgmoCuUQlM5FRUIUGIs9diILaZiWpCujlIew=; b=Rd75H4KUtot55vJqqDqttjfoxizywdaBfCSQ3pbPE2n5xYGzt88Nt4sOiKC1M37g5tvl KwOXVbALvV6SHPvyjOzUJEvq0K/e7niDLzLkRL5s2ZjmfxfTyXYAYIVzdoesKRAy+03L 0NKr9eUxoNlb+06UOetcYnXX2Xui4aX5SN3t5EtwcRixx6cqWb5R6pISy37nlvt3v6+M zz2N/i6Xtw05Waa38g2C2MookBW4m6nDLpuRSjRuFhPF/sLqItZ7OyOIrj/m7xM3Rmo6 zfedQhPZZKPk0kvmw/mPCz5nEtDVxptnMjtHfBfIpKHvc2huP24mf/4VGYCHfYXp+j6h sQ== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2130.oracle.com with ESMTP id 2mxmfudpym-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 13 Oct 2018 00:07:41 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w9D07dOu019930 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 13 Oct 2018 00:07:40 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w9D07dWM019143; Sat, 13 Oct 2018 00:07:39 GMT Received: from localhost (/10.159.251.254) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 13 Oct 2018 00:07:39 +0000 Subject: [PATCH 16/25] vfs: make remapping to source file eof more explicit From: "Darrick J. Wong" To: david@fromorbit.com, darrick.wong@oracle.com Cc: sandeen@redhat.com, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, Amir Goldstein , linux-unionfs@vger.kernel.org, linux-xfs@vger.kernel.org, linux-mm@kvack.org, linux-btrfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, ocfs2-devel@oss.oracle.com Date: Fri, 12 Oct 2018 17:07:37 -0700 Message-ID: <153938925737.8361.3995899966552253527.stgit@magnolia> In-Reply-To: <153938912912.8361.13446310416406388958.stgit@magnolia> References: <153938912912.8361.13446310416406388958.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9044 signatures=668706 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=637 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810130000 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Darrick J. Wong Create a RFR_TO_SRC_EOF flag to explicitly declare that the caller wants the remap implementation to remap to the end of the source file, once the files are locked. Signed-off-by: Darrick J. Wong Reviewed-by: Amir Goldstein --- fs/ioctl.c | 3 ++- fs/nfsd/vfs.c | 4 +++- fs/read_write.c | 13 ++++++++----- include/linux/fs.h | 8 +++++++- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/fs/ioctl.c b/fs/ioctl.c index 505275ec5596..088cf240ca10 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -224,6 +224,7 @@ static long ioctl_file_clone(struct file *dst_file, unsigned long srcfd, { struct fd src_file = fdget(srcfd); loff_t cloned; + unsigned int remap_flags = olen == 0 ? RFR_TO_SRC_EOF : 0; int ret; if (!src_file.file) @@ -232,7 +233,7 @@ static long ioctl_file_clone(struct file *dst_file, unsigned long srcfd, if (src_file.file->f_path.mnt != dst_file->f_path.mnt) goto fdput; cloned = vfs_clone_file_range(src_file.file, off, dst_file, destoff, - olen, 0); + olen, remap_flags); if (cloned < 0) ret = cloned; else if (olen && cloned != olen) diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 726fc5b2b27a..0dc65047df1a 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -542,8 +542,10 @@ __be32 nfsd4_clone_file_range(struct file *src, u64 src_pos, struct file *dst, u64 dst_pos, u64 count) { loff_t cloned; + unsigned int remap_flags = count == 0 ? RFR_TO_SRC_EOF : 0; - cloned = vfs_clone_file_range(src, src_pos, dst, dst_pos, count, 0); + cloned = vfs_clone_file_range(src, src_pos, dst, dst_pos, count, + remap_flags); if (count && cloned != count) cloned = -EINVAL; return nfserrno(cloned < 0 ? cloned : 0); diff --git a/fs/read_write.c b/fs/read_write.c index 81e0f969da59..c02fc5144d15 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1746,15 +1746,18 @@ int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, if (!S_ISREG(inode_in->i_mode) || !S_ISREG(inode_out->i_mode)) return -EINVAL; - /* Zero length dedupe exits immediately; reflink goes to EOF. */ - if (*len == 0) { + /* + * If the caller asked to go all the way to the end of the source file, + * set *len now that we have the file locked. + */ + if (remap_flags & RFR_TO_SRC_EOF) { loff_t isize = i_size_read(inode_in); - if (is_dedupe || pos_in == isize) - return 0; if (pos_in > isize) return -EINVAL; *len = isize - pos_in; + if (*len == 0) + return 0; } /* Check that we don't violate system file offset limits. */ @@ -1844,7 +1847,7 @@ loff_t do_clone_file_range(struct file *file_in, loff_t pos_in, struct inode *inode_out = file_inode(file_out); loff_t ret; - WARN_ON_ONCE(remap_flags); + WARN_ON_ONCE(remap_flags & ~(RFR_TO_SRC_EOF)); if (S_ISDIR(inode_in->i_mode) || S_ISDIR(inode_out->i_mode)) return -EISDIR; diff --git a/include/linux/fs.h b/include/linux/fs.h index d77b8d90d65e..b9c314f9d5a4 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1725,10 +1725,15 @@ struct block_device_operations; * These flags control the behavior of the remap_file_range function pointer. * * RFR_SAME_DATA: only remap if contents identical (i.e. deduplicate) + * RFR_TO_SRC_EOF: remap to the end of the source file */ #define RFR_SAME_DATA (1 << 0) +#define RFR_TO_SRC_EOF (1 << 1) -#define RFR_VALID_FLAGS (RFR_SAME_DATA) +#define RFR_VALID_FLAGS (RFR_SAME_DATA | RFR_TO_SRC_EOF) + +/* Implemented by the VFS, so these are advisory. */ +#define RFR_VFS_FLAGS (RFR_TO_SRC_EOF) /* * Filesystem remapping implementations should call this helper on their @@ -1739,6 +1744,7 @@ struct block_device_operations; static inline bool remap_check_flags(unsigned int remap_flags, unsigned int supported_flags) { + remap_flags &= ~RFR_VFS_FLAGS; return (remap_flags & ~(supported_flags & RFR_VALID_FLAGS)) == 0; }