From patchwork Wed Oct 10 00:13:57 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: 10633633 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 C7C3846E4 for ; Wed, 10 Oct 2018 00:14:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B69E1284C9 for ; Wed, 10 Oct 2018 00:14:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AA86128F95; Wed, 10 Oct 2018 00:14:09 +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 1845F28ED7 for ; Wed, 10 Oct 2018 00:14:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1431B6B0283; Tue, 9 Oct 2018 20:14:08 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0F4716B0284; Tue, 9 Oct 2018 20:14:08 -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 EFC556B0285; Tue, 9 Oct 2018 20:14:07 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) by kanga.kvack.org (Postfix) with ESMTP id ABDBD6B0283 for ; Tue, 9 Oct 2018 20:14:07 -0400 (EDT) Received: by mail-pf1-f200.google.com with SMTP id z28-v6so3093609pff.4 for ; Tue, 09 Oct 2018 17:14:07 -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=sepu+uz6Ad3Fwupju4VHtusxEpK/OgdYrTXJ06uLL6w=; b=UB7iMAxRg8e8npWPaE+7CGwHEST+pUuT6ULbx506FaPLHqG9rHVE7GstEBi5Xf5TxO LWG/pprlKvS8dnW15Pdd98kM8CtCnE4UBdxbZvgUD2Nio2xNscgxxhf4dKzngISvnzxT 8FbXARsNDboKjZSrLRPOTVd+cVD4dSGn/ABXWEBImG8+WzULOC/CmcvPDZhjOx7HnQCA flSyfyLxeEm1tnYLssbg6OpOFPIa7BMNYtGB4zv+Q4JnCIDYmcLK06tVgHscMZ5wbx3D uGzBN2pfUYkdi0TRMqikQlOUfmAIJbl8m5S3yG7We3caR6ASfoG/I3841kd0/DHm0Zo9 h+tA== X-Gm-Message-State: ABuFfohBz61BN0mYUAQH7tII3SA2H+R8e9D0eeyOilj4xNHyt6WA6+el 7VqKIhm+xl/aQURWIxxq/f21aDFFjYGj63QNIEVEyUuuUpb59NpEaRq1dfXTeCIHQuilHEwc01S CCilsEZmHXmBOwa4nM0bXCsozfcCaFJwok3OvNKlcddCeK74se9KGnDeS7iTpyR000A== X-Received: by 2002:a65:45c9:: with SMTP id m9-v6mr22348892pgr.212.1539130447360; Tue, 09 Oct 2018 17:14:07 -0700 (PDT) X-Google-Smtp-Source: ACcGV63LH05HgTMHbHkcCdsphCgEYedApwH2yXZ33k0NyNJBeSEMa5b/+q9vSUon5JEglUjmDi/z X-Received: by 2002:a65:45c9:: with SMTP id m9-v6mr22348849pgr.212.1539130446635; Tue, 09 Oct 2018 17:14:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539130446; cv=none; d=google.com; s=arc-20160816; b=eaLfpFRv9riUviA6pDYngoLDbhg78/HKMJ9AinuUea9O4/X5XaCeU9zUGjcCO693SR o/Gtbui34JWwI3Kf3P2CasX0PZN2u620tEtPyAKbt/6UfjrVdeSYmblVBIEhgfq3iaOS /CTPIogW7t4V4RNI0RKd7vye7I/DoEgeTTXHz1ARoO94jo7J8QMc1JlF8eXOjaSciohd ZineMKXEH3SLgWgS8l6Bi5iI11ih6Y6ZN89c2iTjhecd/RvthYLmxDY7HYcoZ9iT1s55 yw3LZblL6I7GQcam79pnv/AfG7QPdr8Fa3nm86kmgZE8fx76hNVqTQCR8fzZMrxD3YT5 Sdcw== 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=sepu+uz6Ad3Fwupju4VHtusxEpK/OgdYrTXJ06uLL6w=; b=Gyi+omtrPQkEIYtyFTNVjYelsF2WhNyUJO/i1YeLo0PTI2WanBWqH+pFw3b2KAx5vv KgNpKu+ZvWrKyCC2zPMrk349HFCaPRB3z1ovsdGZej9L3UomLc5uhBHtG+sjMy35MpGu eCBR4b61ppAoP5ZiOCquBodxyKVZKaZUF3mQjCw7i3yDMoiJQC1mMALAtT8OVv895I/k XWHcbAcm9DIZll433kMqsNF3kV7WtuD3wd/3JjdFQpmsm6sr9EqZkuhEQqNVBQiAOs1D L+SLI13zM2AEvLCs267CXZs+VGuiDLaP2RzmgR8VJkIzooWKRgT6ru9wsCk+srds/TO/ fkSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=g80Y82tn; spf=pass (google.com: domain of darrick.wong@oracle.com designates 156.151.31.85 as permitted sender) smtp.mailfrom=darrick.wong@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from userp2120.oracle.com (userp2120.oracle.com. [156.151.31.85]) by mx.google.com with ESMTPS id d31-v6si24205256pla.256.2018.10.09.17.14.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Oct 2018 17:14:06 -0700 (PDT) Received-SPF: pass (google.com: domain of darrick.wong@oracle.com designates 156.151.31.85 as permitted sender) client-ip=156.151.31.85; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=g80Y82tn; spf=pass (google.com: domain of darrick.wong@oracle.com designates 156.151.31.85 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 (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w9A0E5VP086629; Wed, 10 Oct 2018 00:14:05 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=sepu+uz6Ad3Fwupju4VHtusxEpK/OgdYrTXJ06uLL6w=; b=g80Y82tnglyS3C3gvVf1T0r1qR9ba0nGUPhubTvNBWbNICNUsu4O4PiAtk+NFBLn/SPO AiTQWqdNgP6milUUFPYQYt1MKnIIkY9BaKa9KISZM3LCqNLHiNC6Eh7Sk3PRCI3EnAHv 1C0ekLnwfk1oRpVCsFoc89kbiBAgzWzybuaKw3ketP9mKB2OdzGpacRZHtl6AoU7Mw6G eGZmeuIRWBO7HwVNFNgsuKaeq4DgBujkqtsoZl+A2HjAFkElAApgcJsFkZtZS5iQGXS/ 8ghkcwKquPkj+TVOhLFexOt1IetX+GChmdnCASlogLUbBn1MKbd2KYvv3Ni/bYJm2S8r Ow== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2mxnpr0p7y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Oct 2018 00:14:05 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w9A0Dxod004803 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Oct 2018 00:13:59 GMT Received: from abhmp0020.oracle.com (abhmp0020.oracle.com [141.146.116.26]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w9A0Dxr3003971; Wed, 10 Oct 2018 00:13:59 GMT Received: from localhost (/10.159.249.114) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 10 Oct 2018 00:13:59 +0000 Subject: [PATCH 17/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, 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: Tue, 09 Oct 2018 17:13:57 -0700 Message-ID: <153913043746.32295.17463515265798256890.stgit@magnolia> In-Reply-To: <153913023835.32295.13962696655740190941.stgit@magnolia> References: <153913023835.32295.13962696655740190941.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9041 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=577 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810100001 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 | 3 ++- fs/read_write.c | 13 +++++++------ include/linux/fs.h | 2 ++ 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/fs/ioctl.c b/fs/ioctl.c index 505275ec5596..7fec997abd2f 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 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, 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..d1f2ae08adf6 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -542,8 +542,9 @@ __be32 nfsd4_clone_file_range(struct file *src, u64 src_pos, struct file *dst, u64 dst_pos, u64 count) { loff_t cloned; + unsigned int 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, 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 479eb810c8e6..a628fd9a47cf 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1748,11 +1748,12 @@ int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, isize = i_size_read(inode_in); - /* Zero length dedupe exits immediately; reflink goes to EOF. */ - if (*len == 0) { - if (is_dedupe || pos_in == isize) - return 0; - if (pos_in > isize) + /* + * 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) { + if (pos_in >= isize) return -EINVAL; *len = isize - pos_in; } @@ -1828,7 +1829,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 5c1bf1c35bc6..9f90dcd4df3b 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1725,8 +1725,10 @@ struct block_device_operations; * These flags control the behavior of the remap_file_range function pointer. * * RFR_IDENTICAL_DATA: only remap if contents identical (i.e. deduplicate) + * RFR_TO_SRC_EOF: remap to the end of the source file */ #define RFR_IDENTICAL_DATA (1 << 0) +#define RFR_TO_SRC_EOF (1 << 1) struct iov_iter;