From patchwork Tue Oct 16 03:10:03 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: 10642695 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 2515318FD for ; Tue, 16 Oct 2018 03:10:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 10ACF29866 for ; Tue, 16 Oct 2018 03:10:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 03FBA29883; Tue, 16 Oct 2018 03:10:16 +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 91F0729866 for ; Tue, 16 Oct 2018 03:10:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 99E526B0006; Mon, 15 Oct 2018 23:10:14 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 94D426B0007; Mon, 15 Oct 2018 23:10:14 -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 83EAF6B0008; Mon, 15 Oct 2018 23:10:14 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by kanga.kvack.org (Postfix) with ESMTP id 44A016B0006 for ; Mon, 15 Oct 2018 23:10:14 -0400 (EDT) Received: by mail-pl1-f198.google.com with SMTP id l7-v6so17163620plg.6 for ; Mon, 15 Oct 2018 20:10:14 -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=SGDSArbiullpYs/XPOG6T2xvgHyk5haCgm1b67adURI=; b=py0y+e5ywYa1PFaodI6UHk9DGE/iIob+kTmCzLBICNXOFRh7roUmCj7BLyhAX9JHmy FOePz/Iuc1gAsq3VOaGDM4vE66V23ZnRvHXU2yZfKc2r6vkiy/SnqB50K8oyB/hVa5SA gy3ITUhiDG643bQhJ7QXBe3UnkU1Xrz6MbgjHMnxH8HnzMoGz+yZbq+Ck0krAeaV4BCH tyiRSs0sTSdvJRAwN2+fesZnShebRWJivtR1DG1tbzx2X68WNUsxQ+8un+dh/oYKHzgy BFP4+SuAxdumLSBDNqke22Bh6LZe26+IuYopTpU2SfU9tL/c4tFMO6be3tJ/mMM/uDsb VGHw== X-Gm-Message-State: ABuFfoi6YikcZBc2O1TmKrRn22dodSyMU78/4ssU1jgDXFe8keeQe4lj /L6DllvU5bGWeJWn+fxav1BPXFfMChYE+Krw+9eHIhMOCov/n8RnvednRX0GKPHVfWuedPjbkDe xAeJn5WGZkVTloMVEg+xxF0hShfPssfHG9c5crPZKaqra491c6t+3sCGB9oZV0gjymg== X-Received: by 2002:a62:564e:: with SMTP id k75-v6mr20270720pfb.33.1539659413946; Mon, 15 Oct 2018 20:10:13 -0700 (PDT) X-Google-Smtp-Source: ACcGV62JoIfdQOjLN/l1HVRRkn9JQ5UKpH41EonnAt7UNOtg1/iN+iqBfKZxjgkDvui1Y9N6at99 X-Received: by 2002:a62:564e:: with SMTP id k75-v6mr20270686pfb.33.1539659413219; Mon, 15 Oct 2018 20:10:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539659413; cv=none; d=google.com; s=arc-20160816; b=N9g7xbmJmwC/69mZBzbLjvysr/43QLBdzSfnukD4LmpBX5UMrTlzFKo/bw8AXO7dD0 eLGge85X2BZUx7fulGY527cxyNpNuZEyaT9o0aplnZF66k45NeRvRXgPtTWbAh1ErRCp U0ZHrqtEpchNyVd2R/mM1QK66fq7SusSs+w9p7okoCTR03jSERpRem9sV6N9W1wfuqyR kRxKBl+au+agEWcIAc71y0m24AJrFYYO7XiZFSGTVHNBmfuIj1mZLfMveESSv9xu7XKT 5fxeY0g4tCGIAcdriKOF5bt095VW4yoLPFjUd7bsn3Sm+Lymj0/GYet2WH7g0//6ZupT cYtQ== 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=SGDSArbiullpYs/XPOG6T2xvgHyk5haCgm1b67adURI=; b=k4vifbVJTaJac68m0efJbkrCwIjr3BohsdkV1WSWPwzVZDvxdoyjqHfE2cWS3TIMNK bkL3gA1oIwsU4ESGO4ScsMSGh67OPz9gf6fS0QEQGokYCESjOUT0ZHsFRKdOg4JZTHtb MwnS4pkmKD7RlFstMN3QpjIbN/VLeqQOAmGFbH2GjSi01CBui+SzLTioTm9OGFVqYPQh wQy44x0FdtjYyo15TB2Fq7YQKftYC2t49poUk4H6RN3firLQR4x2FXE3I+VaKJ8yboF+ L/VgtDTD5L4YqeZ53n5T2bXrKkQyITAolODVAqUeTvjDxiAhrfwtVFMyDt3u5rcKH3MU +SKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=Uw9E7nnM; 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 i187-v6si9434492pfc.25.2018.10.15.20.10.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 20:10:13 -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=Uw9E7nnM; 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 w9G38XLF044702; Tue, 16 Oct 2018 03:10:12 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=SGDSArbiullpYs/XPOG6T2xvgHyk5haCgm1b67adURI=; b=Uw9E7nnMu3ge5iFXy0pq2s9r2VZXkGrqjt4de4omMzWo3/eHvqHkfqn932/4hZ5zvNfl 6IsgXeavJq7RZwf73sZcM8Ce5oI3H1/XLsbOgFcBB+ozlcNTu6e2c0i+Vds0aH/UJX5K BVufzAjo+TpYtdq985oyTVKGduGmoC14LHj7+mxHWawPsXywRuDjyJVKyg78TKVgeoIc LvEga2CyCYPKkmUXMfBbN3gCmn5c6GsBZxAZ3KZmWyGbEPVKNJWhpgbsRIGkR2G7B6ln xYYSfYv13VeS71XlcmD/2qq8krNNDuvP5ZZ00gj2nyPC1E1PNtacHwv6zPVjjCIzp30J Sg== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2130.oracle.com with ESMTP id 2n384tx1de-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:10:12 +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 w9G3A5Sd007582 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:10:06 GMT Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w9G3A5L2003597; Tue, 16 Oct 2018 03:10:05 GMT Received: from localhost (/10.159.227.150) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 15 Oct 2018 20:10:04 -0700 Subject: [PATCH 01/26] xfs: add a per-xfs trace_printk macro 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: Mon, 15 Oct 2018 20:10:03 -0700 Message-ID: <153965940329.1256.12407610006092032283.stgit@magnolia> In-Reply-To: <153965939489.1256.7400115244528045860.stgit@magnolia> References: <153965939489.1256.7400115244528045860.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9047 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=967 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810160026 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 Add a "xfs_tprintk" macro so that developers can use trace_printk to print out arbitrary debugging information with the XFS device name attached to the trace output. Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_error.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/xfs/xfs_error.h b/fs/xfs/xfs_error.h index 246d3e989c6c..5caa8bdf6c38 100644 --- a/fs/xfs/xfs_error.h +++ b/fs/xfs/xfs_error.h @@ -76,6 +76,11 @@ extern int xfs_errortag_set(struct xfs_mount *mp, unsigned int error_tag, unsigned int tag_value); extern int xfs_errortag_add(struct xfs_mount *mp, unsigned int error_tag); extern int xfs_errortag_clearall(struct xfs_mount *mp); + +/* trace printk version of xfs_err and friends */ +#define xfs_tprintk(mp, fmt, args...) \ + trace_printk("dev %d:%d " fmt, MAJOR((mp)->m_super->s_dev), \ + MINOR((mp)->m_super->s_dev), ##args) #else #define xfs_errortag_init(mp) (0) #define xfs_errortag_del(mp) @@ -83,6 +88,7 @@ extern int xfs_errortag_clearall(struct xfs_mount *mp); #define xfs_errortag_set(mp, tag, val) (ENOSYS) #define xfs_errortag_add(mp, tag) (ENOSYS) #define xfs_errortag_clearall(mp) (ENOSYS) +#define xfs_tprintk(mp, fmt, args...) do { } while (0) #endif /* DEBUG */ /* From patchwork Tue Oct 16 03:10:10 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: 10642697 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 B3D053B73 for ; Tue, 16 Oct 2018 03:10:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A0EC829866 for ; Tue, 16 Oct 2018 03:10:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 948DC29883; Tue, 16 Oct 2018 03:10:18 +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 303DB29866 for ; Tue, 16 Oct 2018 03:10:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1DC606B0008; Mon, 15 Oct 2018 23:10:16 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1122E6B000A; Mon, 15 Oct 2018 23:10:16 -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 F41936B000C; Mon, 15 Oct 2018 23:10:15 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by kanga.kvack.org (Postfix) with ESMTP id CC8C76B0008 for ; Mon, 15 Oct 2018 23:10:15 -0400 (EDT) Received: by mail-qt1-f198.google.com with SMTP id k14-v6so9293971qta.23 for ; Mon, 15 Oct 2018 20:10:15 -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=L870gkqD6S3aDKdn3eAOJVgjX5eONlTDEgfFmDNElAY=; b=hrmjQrusksZMSf1u8b8Pksp659W/ykhNJ45jcVfPydHtC9u0BSD5cggBoPj5RwlXaI XihfkmZoeJbkUIskxfLst6MH+Df36DECIqz+USbEHbJgsEGOVLQUx2IyD+GdFY/a6Omh UPDV1st4HyGRuPsAhO7yt4Qv6UKfKlgqoyeja5SiQ4W3DX0WrHGWQvmyWbKA12iR0t4F EeCelNRU9JTpsZ+VNEfE5fRnDBM48asUbT++d/vPbTaHGLD2gS2alh/ULo3W0yB1i/L3 SZ4vYDxTDjQ1R8kMex4i1x0WAPxgg6iWgCgLjo2h3lLglQ4nAXcHP/ZV71IB2+bKTBtD L/cA== X-Gm-Message-State: ABuFfoglBjRXUbQehjjwt1UhJYh4R4KBN9pXmBagnOHA/BeJ9HnliKww Qfd0j43PQRvTaGrn7SIvb9KMNq7FD9GGyfiIkVTWAPl91S6Segzu8/joRpdJva4AQSu1Pp13qJU l9BFmtiOpsyU8yzKZkM6DzCfXU7UrxLOOtoXlJO3EKVnny9IOLYyDddd/KLeGWVnFgA== X-Received: by 2002:ac8:1307:: with SMTP id e7-v6mr19279896qtj.22.1539659415561; Mon, 15 Oct 2018 20:10:15 -0700 (PDT) X-Google-Smtp-Source: ACcGV61zU0lpbfq8rGwWDcrIMGhLcC9zNnUH/NuAtyuw6xw8tADi4BNoBVbIAvrEb6vNHwpfifCW X-Received: by 2002:ac8:1307:: with SMTP id e7-v6mr19279879qtj.22.1539659415105; Mon, 15 Oct 2018 20:10:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539659415; cv=none; d=google.com; s=arc-20160816; b=ZOOADnSMSXWODOGJh14ozqq46eyWA0yYt+FM48cFxL6gvrHfC4alc8MRkZIJ30ysye Qw+uVeZRKeSiWB0HUWzhgiTkOYmw0T4SMY5GI6AEkgRhpo1DsJIYrHCOlmtXB7OPBDz8 GY730aSsgo/otlzcOcG+7lGavH8lNJk9RP9zUbxX8EFaSFENfrRRdLEMLWsVT87JH8IA 337OswttAbt/tJjdQHj54r/Rw4igDfmzjaResQHFr3IiVXm5YhjovvUFBmPMbpU42sqN 30Ib9UZ222Zka10LwUmxcTkVqCZFTgk5FG/XWGwjdOhL/EXBFTLJKjPIVGsS6RejO+/M nunQ== 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=L870gkqD6S3aDKdn3eAOJVgjX5eONlTDEgfFmDNElAY=; b=QdDOyOj7Nf00Pu+fDUM40pUw7u6yZMTTgVnx1IxtEQmy+13iTRlg/qnezeMi5xJNyS IG+bd4OCB8qVRrE3v3POlwV+Vm0CCBci1hzI8FS3AVpoQ7XMSvHOj/7gM2pV1JxO88cz mUln3VhlebjV/PJ1hUPuHUl1TGPd1oUG5S9sz5Ck5QhO7yCL8fuqlOvuxZxeQ+pA7uKY 1u7JkdBzfpGi1ZAy1JNpzWyVNENP3rvAXI/B2ox17B4pqer4jxwml9ajJUx+8vppCE6F 4OrJI2ZIhLEZsXcfo616y9bt6wrlomJ6Vxcym0p+2+MJskkO3P7aVQeaLWZWMxYXQGXY IWfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=XllOKrY8; 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 a9-v6si7327607qkj.205.2018.10.15.20.10.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 20:10:15 -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=XllOKrY8; 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 w9G38kvf194463; Tue, 16 Oct 2018 03:10:13 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=L870gkqD6S3aDKdn3eAOJVgjX5eONlTDEgfFmDNElAY=; b=XllOKrY8cAytaoxC4m7J4MhD/VdVQ9hegLBpkA75zanOZcciXNTm8leAc61pDxkQcvNC CSAMKK3iD47qi8iNCHt01kco1AmXgi3jSeD3SkHlkceVTbLQ7xzQw3M12bozwRKjPHq8 qGnVv86cP2PpchaHnoYiJrjEoVNiTPGQbx82O/v5ZewIrC0i1vh6KzYTJrKjdkJ4r5Lo qEMGJmXlkXgdKcxgeH+cz2zPgHUGjcKRx3MLf6sDWA5AUdGo25ok21K4BbuhaImh/MSY y1wTMUKqfK7W4VENPsOE+2S5SaQqfKi47B1qvtQGgWr6i2//ClmtA1/u0yUfOPryQ9pi Rg== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2n39br5raa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:10:13 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3ACcC009182 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:10:12 GMT Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3ABpj004884; Tue, 16 Oct 2018 03:10:11 GMT Received: from localhost (/10.159.227.150) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 15 Oct 2018 20:10:11 -0700 Subject: [PATCH 02/26] vfs: vfs_clone_file_prep_inodes should return EINVAL for a clone from beyond EOF 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, Christoph Hellwig , ocfs2-devel@oss.oracle.com Date: Mon, 15 Oct 2018 20:10:10 -0700 Message-ID: <153965941007.1256.17570514092450613034.stgit@magnolia> In-Reply-To: <153965939489.1256.7400115244528045860.stgit@magnolia> References: <153965939489.1256.7400115244528045860.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9047 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=771 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810160026 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 vfs_clone_file_prep_inodes cannot return 0 if it is asked to remap from a zero byte file because that's what btrfs does. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/read_write.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index 8a2737f0d61d..260797b01851 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1740,10 +1740,7 @@ int vfs_clone_file_prep_inodes(struct inode *inode_in, loff_t pos_in, if (!S_ISREG(inode_in->i_mode) || !S_ISREG(inode_out->i_mode)) return -EINVAL; - /* Are we going all the way to the end? */ isize = i_size_read(inode_in); - if (isize == 0) - return 0; /* Zero length dedupe exits immediately; reflink goes to EOF. */ if (*len == 0) { From patchwork Tue Oct 16 03:10:16 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: 10642719 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 8BE023B73 for ; Tue, 16 Oct 2018 03:10:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 779F129866 for ; Tue, 16 Oct 2018 03:10:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6B91C29883; Tue, 16 Oct 2018 03:10:26 +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 94A8C29866 for ; Tue, 16 Oct 2018 03:10:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7067D6B000C; Mon, 15 Oct 2018 23:10:24 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6DC5E6B000D; Mon, 15 Oct 2018 23:10:24 -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 5A57D6B000E; Mon, 15 Oct 2018 23:10:24 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by kanga.kvack.org (Postfix) with ESMTP id 1221E6B000C for ; Mon, 15 Oct 2018 23:10:24 -0400 (EDT) Received: by mail-pf1-f199.google.com with SMTP id c28-v6so8806930pfe.4 for ; Mon, 15 Oct 2018 20:10:24 -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=zrdKK22K4yPwdg97C40ayFoftWNqhnfImZiJAlzmShI=; b=EZ23By7i3ONyVspLWm+0iatVRdiAwf1UJTGLO7mf728IgBMHsPVPhE/EIkNOVQDvFj dN3OFh7+zWACzkx6a1aa+RxS5+n8Z7pyGjoOhtSjcZbmxrH3wpzqyJn4ReWmIeyrr5Xz GzDBQbrNfduqdBAM3w/5zs0ATa7pxE+2lyVI01Wu5TJ3yQt6jucVsKv05tltl8fFV1gL GzlI1dFeQe4TP17NCpMFtNE5t0d9SnkPs7PcQroeaBR4dNOIPvLiKK/kDeNaZ2+b/QgV 71I6v6cZ3BoRGyQhFgZ0LqyNYcIyMn2o9SHr2Wn7U8AaJgzXGJV8tAVvv2ophK5DuidM 54YA== X-Gm-Message-State: ABuFfoj2s8tDzxf2VA6iYGmDUsfEs/p7EWXeeKvTJ441bnGTSZgydGmJ Wcps3V3fZCDdw6iXTv9eJJaxUonchuL0LPzX+wGDxP39LDF0LN2lCwcbuA6LhezVJyEmpicszrd MncIYCw7DxI6jjyPELFX0Mevp/buOp8r1wfCq9y6FszB//z63yStcMPcJqj5t5IHm+Q== X-Received: by 2002:a62:1693:: with SMTP id 141-v6mr11834899pfw.183.1539659423706; Mon, 15 Oct 2018 20:10:23 -0700 (PDT) X-Google-Smtp-Source: ACcGV60dTKVRGz27WgVjicqmnXZz2EaUrj/hHrDlmMEiFY5nPb2AAey4rLFx1I6f+9naKPA46PZQ X-Received: by 2002:a62:1693:: with SMTP id 141-v6mr11834838pfw.183.1539659422647; Mon, 15 Oct 2018 20:10:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539659422; cv=none; d=google.com; s=arc-20160816; b=kSkmlFO8vObe5d1YAZvskrnzLOewzHNkzXnrno+NSLU55ILqcKsPdpUlfEvRoQSoi6 fQkD8jePcbvcmExQgg5x0KluI1znscZa3uuu3dyWAv2FxBbYC+cQ2/v33OJYCM8J3s6I IXhBA1G9nyrx36I4aJw9DJu/LpqTzw7lSOnLbR2XOp/CALUL9/ZJyWD2YS5sHbJij3yF UDDty7XqJaxtd1gmMZCBzeyT+HU9a2ivKR6UYFbBIKO+a533rBxDVe2P8DFr3kG/7QPC Zwt3qufs9bdmvlgeVaV82FpwCk3C/3Ynb5J6V2RGmrPAr5XO3XJ+Wn2bolLRb0ggRWXU Frfg== 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=zrdKK22K4yPwdg97C40ayFoftWNqhnfImZiJAlzmShI=; b=nnB9rP+CgoXRJqKN4YBuwNcSQkRH0Unxmp+V1EL9Pz3GFCZy3F6y1uBvEm6X8o9k4H sg5NyQvi4YrmQOP7QQegM+OtkvOYUtHGjlGoGIOg024mTGljhiWkmzprgWhIL0CksNP8 x6HkgKds908eI5GlVHpu3mjN8viRvbvgtK0FDBQFd6qEzSulLW97I7GdSiQFOvsRRvIl qfRZlaCgzsd4HOKM98h+Kr3ATs7quB3MJ5TXpjSJg49QE6Xg/DbUJgAMUdOdyLlusquf YDZF+tzHZFmWec+htIC3XPYlm5D1A+O9B019UtstoLKwEkWrINGHTxOEp7k6Tn23xN+O uO4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=P9VNhjNP; 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 193-v6si12002962pgc.264.2018.10.15.20.10.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 20:10:22 -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=P9VNhjNP; 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 w9G38vu5044856; Tue, 16 Oct 2018 03:10:20 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=zrdKK22K4yPwdg97C40ayFoftWNqhnfImZiJAlzmShI=; b=P9VNhjNPSL7ZhnM58NkYwqWwN88oot/vSELzQBbcIi6yYDGL6Qd/LHLEIq/2F/Mn5d7c 0GpQ959Y9SECsPUg8dePE5ttuoWDE9Yo/gn0YgGcnHqwkOe9DulGG+Eo2yfE3enqJawz BHzFsKOzsBFwVdm2KuwnZHMY1LB4j/CWPo86I8iEwLqGv0j5SsiWlsQOfLAdlTe9w+Pf u+hAlnAFQk6uw2UB8k7nokFmhWh3EBgELEvkc9Y9tNfFDHXDAdMsNN6LY0eCBg+WtB9b rVzVjHcKdqD2qIfl0SLojG+TyShrSftAMyWt5HexQlidaJVV+y7RxliWjKlD6FUO16hi bA== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2130.oracle.com with ESMTP id 2n384tx1gk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:10:20 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3AJOW009678 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:10:19 GMT Received: from abhmp0020.oracle.com (abhmp0020.oracle.com [141.146.116.26]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w9G3AIGh002302; Tue, 16 Oct 2018 03:10:18 GMT Received: from localhost (/10.159.227.150) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 15 Oct 2018 20:10:18 -0700 Subject: [PATCH 03/26] vfs: check file ranges before cloning files 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, Christoph Hellwig , ocfs2-devel@oss.oracle.com Date: Mon, 15 Oct 2018 20:10:16 -0700 Message-ID: <153965941688.1256.14812185868033156908.stgit@magnolia> In-Reply-To: <153965939489.1256.7400115244528045860.stgit@magnolia> References: <153965939489.1256.7400115244528045860.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9047 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=975 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810160026 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 Move the file range checks from vfs_clone_file_prep into a separate generic_remap_checks function so that all the checks are collected in a central location. This forms the basis for adding more checks from generic_write_checks that will make cloning's input checking more consistent with write input checking. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Amir Goldstein --- fs/ocfs2/refcounttree.c | 2 + fs/read_write.c | 55 +++++++++---------------------------- fs/xfs/xfs_reflink.c | 2 + include/linux/fs.h | 9 ++++-- mm/filemap.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 90 insertions(+), 47 deletions(-) diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c index 7a5ee145c733..19e03936c5e1 100644 --- a/fs/ocfs2/refcounttree.c +++ b/fs/ocfs2/refcounttree.c @@ -4850,7 +4850,7 @@ int ocfs2_reflink_remap_range(struct file *file_in, (OCFS2_I(inode_out)->ip_flags & OCFS2_INODE_SYSTEM_FILE)) goto out_unlock; - ret = vfs_clone_file_prep_inodes(inode_in, pos_in, inode_out, pos_out, + ret = vfs_clone_file_prep(file_in, pos_in, file_out, pos_out, &len, is_dedupe); if (ret <= 0) goto out_unlock; diff --git a/fs/read_write.c b/fs/read_write.c index 260797b01851..d6e8e242a15f 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1717,13 +1717,12 @@ static int clone_verify_area(struct file *file, loff_t pos, u64 len, bool write) * Returns: 0 for "nothing to clone", 1 for "something to clone", or * the usual negative error code. */ -int vfs_clone_file_prep_inodes(struct inode *inode_in, loff_t pos_in, - struct inode *inode_out, loff_t pos_out, - u64 *len, bool is_dedupe) +int vfs_clone_file_prep(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + u64 *len, bool is_dedupe) { - loff_t bs = inode_out->i_sb->s_blocksize; - loff_t blen; - loff_t isize; + struct inode *inode_in = file_inode(file_in); + struct inode *inode_out = file_inode(file_out); bool same_inode = (inode_in == inode_out); int ret; @@ -1740,10 +1739,10 @@ int vfs_clone_file_prep_inodes(struct inode *inode_in, loff_t pos_in, if (!S_ISREG(inode_in->i_mode) || !S_ISREG(inode_out->i_mode)) return -EINVAL; - isize = i_size_read(inode_in); - /* Zero length dedupe exits immediately; reflink goes to EOF. */ if (*len == 0) { + loff_t isize = i_size_read(inode_in); + if (is_dedupe || pos_in == isize) return 0; if (pos_in > isize) @@ -1751,36 +1750,11 @@ int vfs_clone_file_prep_inodes(struct inode *inode_in, loff_t pos_in, *len = isize - pos_in; } - /* Ensure 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 > isize) - return -EINVAL; - - /* Don't allow dedupe past EOF in the dest file */ - if (is_dedupe) { - loff_t disize; - - disize = i_size_read(inode_out); - if (pos_out >= disize || pos_out + *len > disize) - return -EINVAL; - } - - /* If we're linking to EOF, continue to the block boundary. */ - if (pos_in + *len == isize) - blen = ALIGN(isize, bs) - pos_in; - else - blen = *len; - - /* Only reflink if we're aligned to block boundaries */ - if (!IS_ALIGNED(pos_in, bs) || !IS_ALIGNED(pos_in + blen, bs) || - !IS_ALIGNED(pos_out, bs) || !IS_ALIGNED(pos_out + blen, bs)) - return -EINVAL; - - /* Don't allow overlapped reflink within the same file */ - if (same_inode) { - if (pos_out + blen > pos_in && pos_out < pos_in + blen) - return -EINVAL; - } + /* Check that we don't violate system file offset limits. */ + ret = generic_remap_checks(file_in, pos_in, file_out, pos_out, len, + is_dedupe); + if (ret) + return ret; /* Wait for the completion of any pending IOs on both files */ inode_dio_wait(inode_in); @@ -1813,7 +1787,7 @@ int vfs_clone_file_prep_inodes(struct inode *inode_in, loff_t pos_in, return 1; } -EXPORT_SYMBOL(vfs_clone_file_prep_inodes); +EXPORT_SYMBOL(vfs_clone_file_prep); int do_clone_file_range(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, u64 len) @@ -1851,9 +1825,6 @@ int do_clone_file_range(struct file *file_in, loff_t pos_in, if (ret) return ret; - if (pos_in + len > i_size_read(inode_in)) - return -EINVAL; - ret = file_in->f_op->clone_file_range(file_in, pos_in, file_out, pos_out, len); if (!ret) { diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index 42ea7bab9144..281d5f53f2ec 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -1326,7 +1326,7 @@ xfs_reflink_remap_prep( if (IS_DAX(inode_in) || IS_DAX(inode_out)) goto out_unlock; - ret = vfs_clone_file_prep_inodes(inode_in, pos_in, inode_out, pos_out, + ret = vfs_clone_file_prep(file_in, pos_in, file_out, pos_out, len, is_dedupe); if (ret <= 0) goto out_unlock; diff --git a/include/linux/fs.h b/include/linux/fs.h index 897eae8faee1..ba93a6e7dac4 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1825,9 +1825,9 @@ extern ssize_t vfs_readv(struct file *, const struct iovec __user *, unsigned long, loff_t *, rwf_t); extern ssize_t vfs_copy_file_range(struct file *, loff_t , struct file *, loff_t, size_t, unsigned int); -extern int vfs_clone_file_prep_inodes(struct inode *inode_in, loff_t pos_in, - struct inode *inode_out, loff_t pos_out, - u64 *len, bool is_dedupe); +extern int vfs_clone_file_prep(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + u64 *count, bool is_dedupe); extern int do_clone_file_range(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, u64 len); extern int vfs_clone_file_range(struct file *file_in, loff_t pos_in, @@ -2967,6 +2967,9 @@ extern int sb_min_blocksize(struct super_block *, int); extern int generic_file_mmap(struct file *, struct vm_area_struct *); extern int generic_file_readonly_mmap(struct file *, struct vm_area_struct *); extern ssize_t generic_write_checks(struct kiocb *, struct iov_iter *); +extern int generic_remap_checks(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + uint64_t *count, bool is_dedupe); extern ssize_t generic_file_read_iter(struct kiocb *, struct iov_iter *); extern ssize_t __generic_file_write_iter(struct kiocb *, struct iov_iter *); extern ssize_t generic_file_write_iter(struct kiocb *, struct iov_iter *); diff --git a/mm/filemap.c b/mm/filemap.c index 52517f28e6f4..47e6bfd45a91 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2974,6 +2974,75 @@ inline ssize_t generic_write_checks(struct kiocb *iocb, struct iov_iter *from) } EXPORT_SYMBOL(generic_write_checks); +/* + * Performs necessary checks before doing a clone. + * + * Can adjust amount of bytes to clone. + * Returns appropriate error code that caller should return or + * zero in case the clone should be allowed. + */ +int generic_remap_checks(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + uint64_t *req_count, bool is_dedupe) +{ + struct inode *inode_in = file_in->f_mapping->host; + struct inode *inode_out = file_out->f_mapping->host; + uint64_t count = *req_count; + uint64_t bcount; + loff_t size_in, size_out; + loff_t bs = inode_out->i_sb->s_blocksize; + + /* The start of both ranges must be aligned to an fs block. */ + if (!IS_ALIGNED(pos_in, bs) || !IS_ALIGNED(pos_out, bs)) + return -EINVAL; + + /* Ensure offsets don't wrap. */ + if (pos_in + count < pos_in || pos_out + count < pos_out) + return -EINVAL; + + size_in = i_size_read(inode_in); + size_out = i_size_read(inode_out); + + /* Dedupe requires both ranges to be within EOF. */ + if (is_dedupe && + (pos_in >= size_in || pos_in + count > size_in || + pos_out >= size_out || pos_out + count > size_out)) + return -EINVAL; + + /* Ensure the infile range is within the infile. */ + if (pos_in >= size_in) + return -EINVAL; + count = min(count, size_in - (uint64_t)pos_in); + + /* + * If the user wanted us to link to the infile's EOF, round up to the + * next block boundary for this check. + * + * Otherwise, make sure the count is also block-aligned, having + * already confirmed the starting offsets' block alignment. + */ + if (pos_in + count == size_in) { + bcount = ALIGN(size_in, bs) - pos_in; + } else { + if (!IS_ALIGNED(count, bs)) + return -EINVAL; + + bcount = count; + } + + /* Don't allow overlapped cloning within the same file. */ + if (inode_in == inode_out && + pos_out + bcount > pos_in && + pos_out < pos_in + bcount) + return -EINVAL; + + /* For now we don't support changing the length. */ + if (*req_count != count) + return -EINVAL; + + return 0; +} + int pagecache_write_begin(struct file *file, struct address_space *mapping, loff_t pos, unsigned len, unsigned flags, struct page **pagep, void **fsdata) From patchwork Tue Oct 16 03:10:23 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: 10642723 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 491AF3C13 for ; Tue, 16 Oct 2018 03:10:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 318DF29897 for ; Tue, 16 Oct 2018 03:10:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 25EF92988C; Tue, 16 Oct 2018 03:10:30 +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 BE8EB29867 for ; Tue, 16 Oct 2018 03:10:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 99EFB6B000E; Mon, 15 Oct 2018 23:10:28 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 94D956B0010; Mon, 15 Oct 2018 23:10:28 -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 7CA466B0266; Mon, 15 Oct 2018 23:10:28 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by kanga.kvack.org (Postfix) with ESMTP id 375E76B000E for ; Mon, 15 Oct 2018 23:10:28 -0400 (EDT) Received: by mail-pg1-f198.google.com with SMTP id s141-v6so15982400pgs.23 for ; Mon, 15 Oct 2018 20:10:28 -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=9TmCiNqyohhxt1dJj5u/Q03E/B3TZZ5o2UAiPujWx+4=; b=PuN9E2XzON6Hk7Ac2gtKlKdW93AI1vwYOpxAnj3451p43E+GBfqsaF1CZF5UXuXRan LdIFvUzMv6KrywjiuZdNL/qdsMrumHT33YBgxXN6X5d5i6/BDtD9F60RWiq1ARlyhruB /4UW+qSPskpkftJ0VaHlxkzywIaSbJzI8/ICQgFEFAPv2HeyLkYdCypyL4FMqdY5JN1G atAz0k+knsryillelui/1qm1IlL/TP9H4pdPrpEXIeYRXgbd9XWPZN8F2LiqpMzdLSp4 hvkInrOY9HHRM1hv/j0Wi7ha6OxhcDNpBs5GYesb4hH6g5rjIwifAaiwOrmC2tDQU40H wDkw== X-Gm-Message-State: ABuFfohCxjEk7fd0+dVLN+twf8Jnm2v8K13us2ijm3Uh1kn2Cg5eu0yk tcQT/IUaGd+izPHtqYTDoI25auLjPTXak1A64lsTUGhugprsUPJHqDhs48LnAl9k4LXhByzEZ/W eD6KIAKozBBmiNBSXn85YpY4kDW076fGnsemXBvUM8aH2/zGNBYlbKTkGBRMGUpARnQ== X-Received: by 2002:a62:f20f:: with SMTP id m15-v6mr19989606pfh.244.1539659427915; Mon, 15 Oct 2018 20:10:27 -0700 (PDT) X-Google-Smtp-Source: ACcGV62sIpsqf1GwgRh36ch5QF/4d8Ds+3caK1r9XUVs6RuuvzwIKCpFSRQI9289Eq/+ZqjMooOK X-Received: by 2002:a62:f20f:: with SMTP id m15-v6mr19989579pfh.244.1539659427241; Mon, 15 Oct 2018 20:10:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539659427; cv=none; d=google.com; s=arc-20160816; b=EzWftZQaNwnBFKZRYm/AXiH9VRrrIy32/XEuMtMMmDwN0UNiunVK0iiB3yhAu0vJ0A W5XstPPnVP3ABDfxYVqDXfRRFmUS1qc765ofJUzvWs306HJAXdZMUjKNeY/oKOBP5mUP Bkv8erketax+9viau4GWuEgv8uY1lr6Totp2QH6ahHvn/TM12V5w7sHVz1+nLpk0c8Bb MsV0/hL1IrTbrBJkVsMOqkCM8QjtBU8TYsM/GI1YoQ/pte+0wTINUKv+YUxKaGpXdNql nh4YCUecwjA811VpXL2oDaOirNFumEjKm1QR6n5mPXgzJjuzhj7iDglRDbvUaA9TjDGa dmbA== 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=9TmCiNqyohhxt1dJj5u/Q03E/B3TZZ5o2UAiPujWx+4=; b=U3d5TRaAcCQsaBekMzyJz402ZweLXVDEPzGksXmXZLNZuvMflygW5tiKVhA9CzBDDr EwsinrnglEJBWUAGah/8orLPh7yZEiAKGgrQCLqIhawknBK0vFZon3cXJzjqLfoF8RDH yG135XsmvZu1tI9vifoL7WgJ794wrGibR0E+N6PP59bpKPx6rbq3ninbaq/Ao+7duuhq GY+pLy/7LKLc+enuiDd+gBZJHIz8vtV9qRRkijH8nOMNrxlJqghtFBHpF1LWozBllea+ QkRp7xU+UXw3eA/qxdfsiIqNhJyjpEsmYvSBnc7fRzFOwcGMLl7SFasdzhFS69vqZEbc 1fLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=UWnzf5Oe; spf=pass (google.com: domain of darrick.wong@oracle.com designates 141.146.126.78 as permitted sender) smtp.mailfrom=darrick.wong@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from aserp2120.oracle.com (aserp2120.oracle.com. [141.146.126.78]) by mx.google.com with ESMTPS id k20-v6si12820625pgh.168.2018.10.15.20.10.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 20:10:27 -0700 (PDT) Received-SPF: pass (google.com: domain of darrick.wong@oracle.com designates 141.146.126.78 as permitted sender) client-ip=141.146.126.78; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=UWnzf5Oe; spf=pass (google.com: domain of darrick.wong@oracle.com designates 141.146.126.78 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 (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w9G38V3G053356; Tue, 16 Oct 2018 03:10:26 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=9TmCiNqyohhxt1dJj5u/Q03E/B3TZZ5o2UAiPujWx+4=; b=UWnzf5OetYhC/N6GwSnj1SwvwpGgZ0AFuFI2wZpc6uC4WTdAGlH7iw5f6ZRhkPEODcqv 3ERpdeuEP+L7K4svdepRObSCSAY/7fGo8TBTHmXfT4LH0maD8DtSDjdifuccoelVV3o8 jnoWlx+PAJnPwmYyXkDTfQkoWuEZczQxUsGiA0VErwK8tfqx5WcEtr2RRSV0hXx74h2m 9C3yAL9G/fO8UxJwVLqwzawzA3z1k15XoLr1RL4w8m7YXk3VWCbe8rarzCQV56obsRoc W1crIkRzCw8lWOxJYdJu2Z+60xPpdc19vh1015s+ZuYO9FTdiK+43tbrZ7h9vN4YXMTi Qg== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2120.oracle.com with ESMTP id 2n38npwuv7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:10:26 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3APWh028429 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:10:25 GMT Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w9G3APO0002366; Tue, 16 Oct 2018 03:10:25 GMT Received: from localhost (/10.159.227.150) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 15 Oct 2018 20:10:25 -0700 Subject: [PATCH 04/26] vfs: exit early from zero length remap operations 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: Mon, 15 Oct 2018 20:10:23 -0700 Message-ID: <153965942391.1256.1491987046439132016.stgit@magnolia> In-Reply-To: <153965939489.1256.7400115244528045860.stgit@magnolia> References: <153965939489.1256.7400115244528045860.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9047 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=544 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810160026 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 If a remap caller asks us to remap to the source file's EOF and the source file has zero bytes, exit early. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/read_write.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/read_write.c b/fs/read_write.c index d6e8e242a15f..2456da3f8a41 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1748,6 +1748,8 @@ int vfs_clone_file_prep(struct file *file_in, loff_t pos_in, 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. */ From patchwork Tue Oct 16 03:10:30 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: 10642745 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 9AA97112B for ; Tue, 16 Oct 2018 03:10:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8745A29867 for ; Tue, 16 Oct 2018 03:10:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7AEC92988C; Tue, 16 Oct 2018 03:10: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 D8E5029867 for ; Tue, 16 Oct 2018 03:10:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 668446B026A; Mon, 15 Oct 2018 23:10:43 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 61A5C6B026B; Mon, 15 Oct 2018 23:10:43 -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 3FB0F6B026C; Mon, 15 Oct 2018 23:10:43 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by kanga.kvack.org (Postfix) with ESMTP id F0ED16B026A for ; Mon, 15 Oct 2018 23:10:42 -0400 (EDT) Received: by mail-pg1-f197.google.com with SMTP id w15-v6so16161735pge.2 for ; Mon, 15 Oct 2018 20:10:42 -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=5eu3BWWTXWnKtqnmkgUDN4s2jZ2fNj7azSAvuPl2YO0=; b=phr8h8LOdc0de9eJJ7unsg4xhVdF4Tyy7anVsnehCW08FHsb/TGMBGsRLBQ/3WyGv3 dNg0hkv40tT+Jf3YG5mCWXszN+iO9cq/wSfpi3YPRiWE0Hq4gtfhPcoXH9VTdJ2iIXs7 uKFTS+meGLcJcvTc2mzw1nrv/Jy5WhSU9u/0Lbmbv75iTdUvGay4SLnXVr05orMTSJh8 Lv8s91O8QXa+k25OHZVBpDBem5mpsRBcPKWLqVRS//gUDV51K8gAmWhjwTC7mTGfekIN FV6ddiyWZlJQ21kp8BDTWZeRhXG7d0GFbVW9Jkq3pGLBWMeP89pUE9zXjxJqw/hJ6q46 ciqQ== X-Gm-Message-State: ABuFfohEwxLwLIcALa7n1bRg/X+SLIugroSSDdLQR2RLmr1QBZz1+Rbk lTh0Yz3n17N/rojzgijKTtqVreQbGkA/nHo7BtPmCOceOXfZ8q2D69IBg+NlOUJK1O/86SeifnF 0bteKChbVLzabkQdPXygtGTjcDz7Rh7YtfcAt18VM+5f3dX0yBgoO5Gg49GDboxAkCg== X-Received: by 2002:a65:4145:: with SMTP id x5-v6mr18435050pgp.309.1539659442612; Mon, 15 Oct 2018 20:10:42 -0700 (PDT) X-Google-Smtp-Source: ACcGV60QT6DZCzZD25Egz+6pxPzOwXKsSX6X5FrLpIWlOb+Q1TcF6+8TTF0SuDJ0H73uRDDHL6Fw X-Received: by 2002:a65:4145:: with SMTP id x5-v6mr18435022pgp.309.1539659441830; Mon, 15 Oct 2018 20:10:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539659441; cv=none; d=google.com; s=arc-20160816; b=cOWqsIgYvcizA4IE05jZIx0aVutkPaKQTUVMt0iLRLEqBtqkHfEcGyrxI3nNbuFwQa nqG56e0cbk29JHnCHT2RnQK30aX4gZynqNwu0aiwQ0vsHUxJz9gV+/gbsVfVQsapeqD0 DuW9mRCXserb4WDloENiyLnfG0YL2hYtWYQu5JWSBia0LCfa76b95QIAT78WkWWiUocf J+XSXOJtRlIaBnSlITy2x2TSBv7Eln2xreAoohWptkUU+bVMApbewSNkb/6aLXNXNT45 F3ucdN9vNDX8LpfZwlImTcRgIt3K66+1cifkPGb+Hh0E4zoa/5WdrmHuOLMYWZNxV13G dK7Q== 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=5eu3BWWTXWnKtqnmkgUDN4s2jZ2fNj7azSAvuPl2YO0=; b=qhooKiF9s/DLK1VpNdOpWl4uwD//cAty6I9rIqep3Fkkv/WkPuqJkmWOzlmo+h8IB5 2X+wfyf+Xt4TI44VwBKBVZ5ovVSzSUXVt+obb0U78SOz8UkdAfXFZBomSL3Romp+8+Qa DpGPFMVZsFNdH1W4cInFfCyIBLfd7Rf4AfAjzf+mU4jrHnscLAZgZDcNTKN9Iwo7HWtG ZmbHieD4F6V8TNokEkJV77UDG28acWxDAJ2ylYyJUyfq1Tk158bHEEW4JrZDxrwQXLCM quPaaczTrWa8zIpigin51gUr7Xk8M70SGZlGfJt4mQKAUO37dwn+FAtE0cba2iha/EKI L7uA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b="WmRiD6H/"; spf=pass (google.com: domain of darrick.wong@oracle.com designates 141.146.126.78 as permitted sender) smtp.mailfrom=darrick.wong@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from aserp2120.oracle.com (aserp2120.oracle.com. [141.146.126.78]) by mx.google.com with ESMTPS id f10-v6si12920816pgl.148.2018.10.15.20.10.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 20:10:41 -0700 (PDT) Received-SPF: pass (google.com: domain of darrick.wong@oracle.com designates 141.146.126.78 as permitted sender) client-ip=141.146.126.78; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b="WmRiD6H/"; spf=pass (google.com: domain of darrick.wong@oracle.com designates 141.146.126.78 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 (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w9G38Tar053313; Tue, 16 Oct 2018 03:10:39 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=5eu3BWWTXWnKtqnmkgUDN4s2jZ2fNj7azSAvuPl2YO0=; b=WmRiD6H/JOP7jYhQwOlVje+i+ETuilfxpewXFRKf6ZP88jdx+CNv1fToYZrnHpIRQZCC cnkWiRl7SeyihP2e+MJUHD0NjjhZq2RXOyYjhLDUOS5i24KMNR3RD+9DdXGFAn/xgygX GZPX3To4YCXFd9kf9YT8od5fEydfRhgg6/X/xwceftvSQgd7xkqiXNHEB3ea1Beua5NJ uTmFI2kJE1cfpchbnrzdRlqn33cqye5AjlBSrX4JusVJp5RlxSLv06cRIPXWUMPAhTrt d+QFCu3gI4eATezsx9ymqnbGE9hQhneAde1U0SU+Hg43pF7dm5n00UnrVo0pFF4z+YWM kg== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2120.oracle.com with ESMTP id 2n38npwuw4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:10:39 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3AXRP010240 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:10:33 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3AWXw009132; Tue, 16 Oct 2018 03:10:32 GMT Received: from localhost (/10.159.227.150) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 15 Oct 2018 20:10:32 -0700 Subject: [PATCH 05/26] vfs: strengthen checking of file range inputs to generic_remap_checks 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, Christoph Hellwig , ocfs2-devel@oss.oracle.com Date: Mon, 15 Oct 2018 20:10:30 -0700 Message-ID: <153965943066.1256.17049880978132186525.stgit@magnolia> In-Reply-To: <153965939489.1256.7400115244528045860.stgit@magnolia> References: <153965939489.1256.7400115244528045860.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9047 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=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810160026 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 File range remapping, if allowed to run past the destination file's EOF, is an optimization on a regular file write. Regular file writes that extend the file length are subject to various constraints which are not checked by range cloning. This is a correctness problem because we're never allowed to touch ranges that the page cache can't support (s_maxbytes); we're not supposed to deal with large offsets (MAX_NON_LFS) if O_LARGEFILE isn't set; and we must obey resource limits (RLIMIT_FSIZE). Therefore, add these checks to the new generic_remap_checks function so that we curtail unexpected behavior. Signed-off-by: Darrick J. Wong Reviewed-by: Amir Goldstein Reviewed-by: Christoph Hellwig --- mm/filemap.c | 91 ++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 32 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 47e6bfd45a91..08ad210fee49 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2915,6 +2915,49 @@ struct page *read_cache_page_gfp(struct address_space *mapping, } EXPORT_SYMBOL(read_cache_page_gfp); +static int generic_access_check_limits(struct file *file, loff_t pos, + loff_t *count) +{ + struct inode *inode = file->f_mapping->host; + + /* Don't exceed the LFS limits. */ + if (unlikely(pos + *count > MAX_NON_LFS && + !(file->f_flags & O_LARGEFILE))) { + if (pos >= MAX_NON_LFS) + return -EFBIG; + *count = min(*count, (loff_t)MAX_NON_LFS - pos); + } + + /* + * Don't operate on ranges the page cache doesn't support. + * + * If we have written data it becomes a short write. If we have + * exceeded without writing data we send a signal and return EFBIG. + * Linus frestrict idea will clean these up nicely.. + */ + if (unlikely(pos >= inode->i_sb->s_maxbytes)) + return -EFBIG; + + *count = min(*count, inode->i_sb->s_maxbytes - pos); + return 0; +} + +static int generic_write_check_limits(struct file *file, loff_t pos, + loff_t *count) +{ + unsigned long limit = rlimit(RLIMIT_FSIZE); + + if (limit != RLIM_INFINITY) { + if (pos >= limit) { + send_sig(SIGXFSZ, current, 0); + return -EFBIG; + } + *count = min(*count, (loff_t)limit - pos); + } + + return generic_access_check_limits(file, pos, count); +} + /* * Performs necessary checks before doing a write * @@ -2926,8 +2969,8 @@ inline ssize_t generic_write_checks(struct kiocb *iocb, struct iov_iter *from) { struct file *file = iocb->ki_filp; struct inode *inode = file->f_mapping->host; - unsigned long limit = rlimit(RLIMIT_FSIZE); - loff_t pos; + loff_t count; + int ret; if (!iov_iter_count(from)) return 0; @@ -2936,40 +2979,15 @@ inline ssize_t generic_write_checks(struct kiocb *iocb, struct iov_iter *from) if (iocb->ki_flags & IOCB_APPEND) iocb->ki_pos = i_size_read(inode); - pos = iocb->ki_pos; - if ((iocb->ki_flags & IOCB_NOWAIT) && !(iocb->ki_flags & IOCB_DIRECT)) return -EINVAL; - if (limit != RLIM_INFINITY) { - if (iocb->ki_pos >= limit) { - send_sig(SIGXFSZ, current, 0); - return -EFBIG; - } - iov_iter_truncate(from, limit - (unsigned long)pos); - } + count = iov_iter_count(from); + ret = generic_write_check_limits(file, iocb->ki_pos, &count); + if (ret) + return ret; - /* - * LFS rule - */ - if (unlikely(pos + iov_iter_count(from) > MAX_NON_LFS && - !(file->f_flags & O_LARGEFILE))) { - if (pos >= MAX_NON_LFS) - return -EFBIG; - iov_iter_truncate(from, MAX_NON_LFS - (unsigned long)pos); - } - - /* - * Are we about to exceed the fs block limit ? - * - * If we have written data it becomes a short write. If we have - * exceeded without writing data we send a signal and return EFBIG. - * Linus frestrict idea will clean these up nicely.. - */ - if (unlikely(pos >= inode->i_sb->s_maxbytes)) - return -EFBIG; - - iov_iter_truncate(from, inode->i_sb->s_maxbytes - pos); + iov_iter_truncate(from, count); return iov_iter_count(from); } EXPORT_SYMBOL(generic_write_checks); @@ -2991,6 +3009,7 @@ int generic_remap_checks(struct file *file_in, loff_t pos_in, uint64_t bcount; loff_t size_in, size_out; loff_t bs = inode_out->i_sb->s_blocksize; + int ret; /* The start of both ranges must be aligned to an fs block. */ if (!IS_ALIGNED(pos_in, bs) || !IS_ALIGNED(pos_out, bs)) @@ -3014,6 +3033,14 @@ int generic_remap_checks(struct file *file_in, loff_t pos_in, return -EINVAL; count = min(count, size_in - (uint64_t)pos_in); + ret = generic_access_check_limits(file_in, pos_in, &count); + if (ret) + return ret; + + ret = generic_write_check_limits(file_out, pos_out, &count); + if (ret) + return ret; + /* * If the user wanted us to link to the infile's EOF, round up to the * next block boundary for this check. From patchwork Tue Oct 16 03:10: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: 10642743 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 DA856112B for ; Tue, 16 Oct 2018 03:10:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C6C5B29867 for ; Tue, 16 Oct 2018 03:10:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BADA22988C; Tue, 16 Oct 2018 03:10:43 +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 36A8429867 for ; Tue, 16 Oct 2018 03:10:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 447126B0266; Mon, 15 Oct 2018 23:10:42 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3F7446B0269; Mon, 15 Oct 2018 23:10:42 -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 2E60F6B026A; Mon, 15 Oct 2018 23:10:42 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by kanga.kvack.org (Postfix) with ESMTP id E50D66B0266 for ; Mon, 15 Oct 2018 23:10:41 -0400 (EDT) Received: by mail-pf1-f198.google.com with SMTP id f4-v6so22279476pff.2 for ; Mon, 15 Oct 2018 20:10:41 -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=SHexZ7j4NahuPkzJw7xdjRTs2Ez8K2Od8tzKdBj+sBY=; b=sumvIeIE5cWGeLsS1SZsCb45KEx06+QroKKOubSChSA/jAkZqQDllQlF04Qqp9jFjn 2zFnp7r0db0PJUrIo5cyED5OKF6oNobDLxNrGOV1R4QBBNEapYHPJJHxlAVnZfayEbm7 2gUtefG2WmhIFrkxOhS9Bi+BiKSc77SAjZ5Q979CSY1M3d2xeRti6DOh9CN0vcmg93/V 5aTCYCYOFaQvdR3bbSR46fGr5sHxkgG3M9svsccAn2Dgb7Vo0CtiYIybIc1P1GVNPEE3 T37xIWeDozHGtl7WikTH/Kr3SYKUvE+toRYJhg2zuxPmRhSqppz9PKzT8GUdmxMsb/fy eYUw== X-Gm-Message-State: ABuFfohBmirJ5Tkpg8DLkXkKr3EFwfQ1SSVXGeVlym5M/QmwSFWlroAj typf/2hKxosa4sClbmfICB4X1bTNi0AN5P8npouOLXBG8X/DVtPhDxsmUMN4AFeiVG6MfJMRNS7 Jcvsk4dvcKmc/fU52aicvkkoEvx3DQ7/uZDd4u6+kCh01TxMblNP6EOe3zOn1YxGJJw== X-Received: by 2002:a65:4385:: with SMTP id m5-v6mr17570625pgp.219.1539659441593; Mon, 15 Oct 2018 20:10:41 -0700 (PDT) X-Google-Smtp-Source: ACcGV63WBbDmDUFCmk76d4aN8REHxmiLA9dnzD5pP9X4ptJWgd9tzjUf+AVOfIiZ6GE8wqPi3+9v X-Received: by 2002:a65:4385:: with SMTP id m5-v6mr17570597pgp.219.1539659440838; Mon, 15 Oct 2018 20:10:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539659440; cv=none; d=google.com; s=arc-20160816; b=SjZCtGv+c8htFvFGi0qTXFCcNJQzE1yKmk4+byGvTg6HZY2zzXSPDMuRwiQurLfGSH CkDEZr9Rca3hsdyzUHN4cCC+cgKI189GuWn5rBf87ecuICXd88TXT6/1iKNvKrsdE65s Cvv3i0SGl4O4sFm+RdzpfXWIyOz/6HXqa7VvwSpd4cP97Xsf3CGDiL/Fgfikl1B+t2xx 6BCR9Jo8SM1mWx9/btjBe7rm1WonM9WfSVaWPFhNk1jryr30G7E/07MM4Kmc+4/Dil2n yQXmDPl4G7Db5lKmhVQMvgMrZ08/eO4MoIUhRii3Q83tTIHVr9Zeg5AfTh1TqcQSIc3y 0H7A== 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=SHexZ7j4NahuPkzJw7xdjRTs2Ez8K2Od8tzKdBj+sBY=; b=s2vGinLvPp66lnDSWhTbBQ+rOXmgi0qv99hAwGHOacEtwMHEXRAnrMxKqQ02JbrPuy XjrZ3qctbVyLpB4WBYBbj29vu1DhKmeStryOuegC4PMgAzT9GSXp7v5cvkLtPyKRRMJm z8pD3nagUGsExC/70nkBpKdbiWPo+TP62b/EOwpXxr1Ul3GgXehP/heE5EE93e8OdhH0 mvlDe2tt9r3L3KSS5BCnVnpcGqno5GYeCao9A7uaQBiG4X6AhNCkgMJ/sp1K++yXkWw+ /ICxsJP99NOqSdOWZPeA8XPontUA2uyGvSMYBZt751wQZkJjefwBC+p2t1BNc7j1L2YB 7/+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=H0ukRTz8; spf=pass (google.com: domain of darrick.wong@oracle.com designates 141.146.126.78 as permitted sender) smtp.mailfrom=darrick.wong@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from aserp2120.oracle.com (aserp2120.oracle.com. [141.146.126.78]) by mx.google.com with ESMTPS id g3-v6si12568405pgj.74.2018.10.15.20.10.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 20:10:40 -0700 (PDT) Received-SPF: pass (google.com: domain of darrick.wong@oracle.com designates 141.146.126.78 as permitted sender) client-ip=141.146.126.78; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=H0ukRTz8; spf=pass (google.com: domain of darrick.wong@oracle.com designates 141.146.126.78 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 (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w9G38WEU053380; Tue, 16 Oct 2018 03:10:40 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=SHexZ7j4NahuPkzJw7xdjRTs2Ez8K2Od8tzKdBj+sBY=; b=H0ukRTz8fmbz+UNjUlWTynWGl8FmMJlmvVkeCt3iD2KS+3j13JoPAZ6DxpdIPgbwnhAi 4SiVZpLOD6yNMXxBGPvKgCRJUsSHv9fqyoZ6taQJfBJLBSk6GnfNaD8M/Zkf3KEpgHFr Bo5cYCuQ97yAJWM5URMC/34YVkaUnIcq6HKXWT0WTeKWL9cB1qVaz828uLlbV9raHXdT rqsqRRp0cCgp5CkqKQ/k0FxAYXw6rhZLudyGP9v3Jdk1vA5AXpbakT36k1MnIjDxBxjw XJ61fLF8ccZ4JRT+cGgHGRpSXgi9qBcK6co9110eKq26CfNLQn+WAAFWbHkLnuCOWHGW Lg== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2120.oracle.com with ESMTP id 2n38npwuw6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:10:39 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3AdSi010257 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:10:39 GMT Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w9G3Advo002407; Tue, 16 Oct 2018 03:10:39 GMT Received: from localhost (/10.159.227.150) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 15 Oct 2018 20:10:39 -0700 Subject: [PATCH 06/26] vfs: avoid problematic remapping requests into partial EOF block 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, Christoph Hellwig , ocfs2-devel@oss.oracle.com Date: Mon, 15 Oct 2018 20:10:37 -0700 Message-ID: <153965943770.1256.12251598427341926061.stgit@magnolia> In-Reply-To: <153965939489.1256.7400115244528045860.stgit@magnolia> References: <153965939489.1256.7400115244528045860.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9047 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=786 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810160026 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 A deduplication data corruption is exposed in XFS and btrfs. It is caused by extending the block match range to include the partial EOF block, but then allowing unknown data beyond EOF to be considered a "match" to data in the destination file because the comparison is only made to the end of the source file. This corrupts the destination file when the source extent is shared with it. The VFS remapping prep functions only support whole block dedupe, but we still need to appear to support whole file dedupe correctly. Hence if the dedupe request includes the last block of the souce file, don't include it in the actual dedupe operation. If the rest of the range dedupes successfully, then reject the entire request. A subsequent patch will enable us to shorten dedupe requests correctly. When reflinking sub-file ranges, a data corruption can occur when the source file range includes a partial EOF block. This shares the unknown data beyond EOF into the second file at a position inside EOF, exposing stale data in the second file. If the reflink request includes the last block of the souce file, only proceed with the reflink operation if it lands at or past the destination file's current EOF. If it lands within the destination file EOF, reject the entire request with -EINVAL and make the caller go the hard way. A subsequent patch will enable us to shorten reflink requests correctly. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/read_write.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/fs/read_write.c b/fs/read_write.c index 2456da3f8a41..0f0a6efdd502 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1708,6 +1708,34 @@ static int clone_verify_area(struct file *file, loff_t pos, u64 len, bool write) return security_file_permission(file, write ? MAY_WRITE : MAY_READ); } +/* + * Ensure that we don't remap a partial EOF block in the middle of something + * else. Assume that the offsets have already been checked for block + * alignment. + * + * For deduplication we always scale down to the previous block because we + * can't meaningfully compare post-EOF contents. + * + * For clone we only link a partial EOF block above the destination file's EOF. + */ +static int generic_remap_check_len(struct inode *inode_in, + struct inode *inode_out, + loff_t pos_out, + u64 *len, + bool is_dedupe) +{ + u64 blkmask = i_blocksize(inode_in) - 1; + + if ((*len & blkmask) == 0) + return 0; + + if (is_dedupe) + *len &= ~blkmask; + else if (pos_out + *len < i_size_read(inode_out)) + return -EINVAL; + + return 0; +} /* * Check that the two inodes are eligible for cloning, the ranges make @@ -1787,6 +1815,11 @@ int vfs_clone_file_prep(struct file *file_in, loff_t pos_in, return -EBADE; } + ret = generic_remap_check_len(inode_in, inode_out, pos_out, len, + is_dedupe); + if (ret) + return ret; + return 1; } EXPORT_SYMBOL(vfs_clone_file_prep); From patchwork Tue Oct 16 03:10:44 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: 10642763 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 2E20E3B73 for ; Tue, 16 Oct 2018 03:10:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1BF8729867 for ; Tue, 16 Oct 2018 03:10:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0FDDA298A8; Tue, 16 Oct 2018 03:10:52 +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 ACDD729867 for ; Tue, 16 Oct 2018 03:10:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7F06F6B026C; Mon, 15 Oct 2018 23:10:50 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 79F616B026D; Mon, 15 Oct 2018 23:10:50 -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 6B4946B026E; Mon, 15 Oct 2018 23:10:50 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by kanga.kvack.org (Postfix) with ESMTP id 2E6626B026C for ; Mon, 15 Oct 2018 23:10:50 -0400 (EDT) Received: by mail-pg1-f197.google.com with SMTP id e24-v6so16118049pga.16 for ; Mon, 15 Oct 2018 20:10:50 -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=DsB/GfHe8rY/6K9TRDqJFG41++LpUZSoAdzvXmeEYVk=; b=hMOe4fj5d+ure/XK2zqUBWtMESfs/bhYFtxovBeHkzVZ7rtmsBRsdW+rF/htkC+egX /Dj6GhU8Q9TDEP/1kdHGMKktC1IwWzNYjezMuBuT+ieR5QCNM+JEn77p4r7iLxoBx6cC fKIXxKJ4mYkGDByqI8W6/2e83+vInmAJ3xZDxSgmVBbCKUfuB6zfMJItXvM2IC4d/VsD qNIsVOiWImVQXRPy9Jq77JWNjj1k//MUYw2vO8xUU64drmnAhsYSw/DMbNO+sdgAejOI 69L1L6ZulolfE4UtSLMwlhLzc7EAi4WW4neubD4DSTrYUEqzH0QXYjnKDbMxUGUDFpGm ewaw== X-Gm-Message-State: ABuFfoixfPNYZSLOFvrMVjnuuLFGp71yJjhKv8HRUPQBfdEeTa9JSwRm uGhA3FUEo/Uw/aABe+ShYqj2LhKthS+XjA+Z85ssljXjoP5GVrKrtRfixIfgJfEbhHzFrc1ODDq UT73KbIX7cBoLoD6I/+0Y9BJ3ijnhEa6rvUeQmpPLqNGfI3iZNh3Q94hoe5EI1ZDMVA== X-Received: by 2002:a63:4e18:: with SMTP id c24-v6mr14041072pgb.6.1539659449864; Mon, 15 Oct 2018 20:10:49 -0700 (PDT) X-Google-Smtp-Source: ACcGV62sU0OWBWbaQXv9rofp29ByKpXNTg8X1JyzlvmjXPJdGeAaCGl1x6Rw0Oh9F2efU4X3pZSL X-Received: by 2002:a63:4e18:: with SMTP id c24-v6mr14041050pgb.6.1539659449317; Mon, 15 Oct 2018 20:10:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539659449; cv=none; d=google.com; s=arc-20160816; b=0bMC1Tbdq/TdPLEE6huW+roKZfQHZUy0mAxU+i9LA8gxhKt4UmqiXP4IXzwKsAvqrb 2WscdFGeygJ7Bh6SFGGkdnpVM5cBME1hw0m05uxtcswbppjXDqZi1C5uZH9SQ6Za/56O ZJqX7F1f+lc46863cJinaxlquBQs5d2tEdd3chheWKJAJrk49IrS+M076XjKsmBMjs1j q3WWjGJudXvqL3DzR+YGwcUsyn7sXsOuLN+J8arwzYsANUaleLw1CVRliYXoAps4wdhH A6Etwpkd+X0woPKhLvATSWgu0MlhY0U8dojAXcgJlYRc1a+0pwWKw5eiDyE59bNusBs1 Njlw== 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=DsB/GfHe8rY/6K9TRDqJFG41++LpUZSoAdzvXmeEYVk=; b=myM18rMduQiuYGZkLlaCiJnr3lw6HLVPhU+lL+846WPIbF4IL83v6APTEpp+2rhjFY aeMUiYHOrxc/Q66S0dZxdjecFbfa0ll15YRl+jsXF1ozCFC/pcu7Ut4yKJWyGJZXgfCa 0dR8J6VAoqJxIdkv4qXiUORfI7fAidEce4ZIzZhns8FxTgWXpyZAXMLd1XMvljSVCJ8A ngCGrqZFbKCtlxRv3wcMmsbrtW/FDzAvRvPFiiiFbsZo60PrXW/Q3gtwoXcBy0Nxf3GR EgE1CqNjg0mWGErwo/7wdANmDBQL/+H6KOlP9TFMVXNEjzTxPFEEwvh6GcS0XHE1r2b5 HI6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=B3DtSJGk; 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 w24-v6si11843229plp.110.2018.10.15.20.10.49 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 20:10:49 -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=B3DtSJGk; 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 w9G38Tlk044633; Tue, 16 Oct 2018 03:10:47 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=DsB/GfHe8rY/6K9TRDqJFG41++LpUZSoAdzvXmeEYVk=; b=B3DtSJGkuK54Rbl73cfmQCqzlcavzgWdUCNjlOGpYEDPTi+4hCIZETHNyZFqjXQ6aGqp CQISGI96pQqKbOHl2AJVFc7yiixXp+1TSLggIvHAUjYpYPRW6xGvGHbI0a4UwZDFW7Tt l2BrgiYjsaGBmolrqwMP8tWR6e5fKQRHH6mYSAROMMPvfINfl7/VysrmmTLGNgb9gXEH CQ0iNCI6NIba96ROQ0OkANqAVH8ep7zQpNw0Ckyc1Au76IkUed5QowwwIAGHtzbwsB4y W5TCYKt5F2Tg0coTbxI7TMSI+QFVVk4SqYH13bDe4li/86qj8Zq8NkWgKB6LGNHeVRnH ng== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2n384tx1kc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:10:47 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3Ak0x029351 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:10:46 GMT Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w9G3AkSu002531; Tue, 16 Oct 2018 03:10:46 GMT Received: from localhost (/10.159.227.150) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 15 Oct 2018 20:10:46 -0700 Subject: [PATCH 07/26] vfs: skip zero-length dedupe requests 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, Christoph Hellwig , ocfs2-devel@oss.oracle.com Date: Mon, 15 Oct 2018 20:10:44 -0700 Message-ID: <153965944451.1256.13419242995682379278.stgit@magnolia> In-Reply-To: <153965939489.1256.7400115244528045860.stgit@magnolia> References: <153965939489.1256.7400115244528045860.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9047 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=750 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810160026 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 Don't bother calling the filesystem for a zero-length dedupe request; we can return zero and exit. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Amir Goldstein --- fs/read_write.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/read_write.c b/fs/read_write.c index 0f0a6efdd502..f5395d8da741 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -2009,6 +2009,11 @@ int vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos, if (!dst_file->f_op->dedupe_file_range) goto out_drop_write; + if (len == 0) { + ret = 0; + goto out_drop_write; + } + ret = dst_file->f_op->dedupe_file_range(src_file, src_pos, dst_file, dst_pos, len); out_drop_write: From patchwork Tue Oct 16 03:10:51 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: 10642777 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 497B018FD for ; Tue, 16 Oct 2018 03:11:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36D6A29883 for ; Tue, 16 Oct 2018 03:11:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2B47C298A3; Tue, 16 Oct 2018 03:11:00 +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 A278329883 for ; Tue, 16 Oct 2018 03:10:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 753FF6B026E; Mon, 15 Oct 2018 23:10:58 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 703846B026F; Mon, 15 Oct 2018 23:10:58 -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 5A6556B0271; Mon, 15 Oct 2018 23:10:58 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by kanga.kvack.org (Postfix) with ESMTP id 18F196B026E for ; Mon, 15 Oct 2018 23:10:58 -0400 (EDT) Received: by mail-pl1-f198.google.com with SMTP id t9-v6so17129196plq.15 for ; Mon, 15 Oct 2018 20:10:58 -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=EVBOjpjVeZ0uqv5Ytj51D02SOvbvYZvIxgFPH2/97ks=; b=lb4U9fh0/T25nnlP14YW6fUPBNu2o4N8MviaQslmg/dlkR5bGUp7P9QwADch+iwSwF y1Fwe2q4s3s2osKskqtXm2Ks7DGRmtkJCW9tpevW78dAxhBcRHoJNxIcThI/3XQ/5tE9 AyIAgf1L7NOtUF5cwA7EDLXzoPb4R9y/tF4rBfB6rwuCYiA76s17QtXeJKlIL7nijL7c 5yZ/WDgN16a0tjTSMmBNZSG6133ISVSw1A58NlVHrGEPhzcy7UwkaoF2rJZ8QnBqN70S 7oIudSJXpOmpQOIl/x2xjr3EwJRbek47tWZA6/dg+4Nb4CVvtkeCsgeeg5H7vcgcmNGn c9+w== X-Gm-Message-State: ABuFfojBlbFcvHEKkMCS5P3Y8b5CoD1+p5iw9lM41wUYhVdbSalnKJ02 SdtMVckNRGl8RDFdyEpzix1KnGSUk/uL7EFsMZnDcf9f5RiIO2f0fdS2AGT2+AK7xZHAsHVNMQq NJb2hVcTLtfsauiQygrX7cUiQRrc0Dmq5c90LoZjpdHV0NmJC+IjwUoHeJUdYSvFN5A== X-Received: by 2002:a17:902:aa48:: with SMTP id c8-v6mr20092549plr.100.1539659457764; Mon, 15 Oct 2018 20:10:57 -0700 (PDT) X-Google-Smtp-Source: ACcGV62B2852cXyWov04gnhehM1K+KKhQOAWSysErgpGfhRKRuprQVDiVb6svHvOPfTA29MlORF+ X-Received: by 2002:a17:902:aa48:: with SMTP id c8-v6mr20092512plr.100.1539659456992; Mon, 15 Oct 2018 20:10:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539659456; cv=none; d=google.com; s=arc-20160816; b=wYxlH04ozJKOq1Z4SI9VJOaXPe7lWd6YbHS2qtLAsjyCokJ9QqW1DQ/0uQy0uL8Rgf 1NAlpoOcsyk0xJ5kCruXRhDNbYoRfzlPeP7b+rYII6tlfguhKpC+b7z5EX6KCZ8CUrjh oD84xoGaJGeXzMTVa0xOo4CF9bko8sG/9pEucx/IYENUBUoR1P/iwWyXTj3mWEfSPwhp ynhvxzvSC7sBhSznsk403RR4dCcHBg/xn4bMJcseXG4uGIizisYizbPnH0JnhvinVEjg VaRAlE3D2W5uurUFi1ds5V1wYuXSZNcCgpDo72/xBqtZ6DD29hscZmE2651x03k4fAK3 YiVA== 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=EVBOjpjVeZ0uqv5Ytj51D02SOvbvYZvIxgFPH2/97ks=; b=Ic3b5siOJVrCeYvflaBh1yRbLHeK6jaAQj44zvTDJeTz7tOOcPqzQxA6XKYhFroNs2 QyuSHojp1kjMjquCD5DmFKzEVKOo2zKpKi3YNHilgoMtxpOql5oUsfEYbYXKbv6m8kyw S9j80Z8v4hSuRRbhDdLa2zPgzmrMz1J6cY3u2okI781VCfmVak4LABiTOND0oFiZim1j /EyZoEniW9tWv28j4+AG1pSiB5nnx4gHaya3bsH9CdOrMfoVrNp/fQtFOKMbO//dOmJL O6o30x6syKu5zKfX+xyjnjWc0Gp0yDWodpLp5D+eIKzlbiy5ZNd5uZqpG4jP3dD5+wy7 Rn6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=jehnLmBx; spf=pass (google.com: domain of darrick.wong@oracle.com designates 141.146.126.78 as permitted sender) smtp.mailfrom=darrick.wong@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from aserp2120.oracle.com (aserp2120.oracle.com. [141.146.126.78]) by mx.google.com with ESMTPS id e10-v6si11793983pgo.44.2018.10.15.20.10.56 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 20:10:56 -0700 (PDT) Received-SPF: pass (google.com: domain of darrick.wong@oracle.com designates 141.146.126.78 as permitted sender) client-ip=141.146.126.78; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=jehnLmBx; spf=pass (google.com: domain of darrick.wong@oracle.com designates 141.146.126.78 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 (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w9G38Tv9053326; Tue, 16 Oct 2018 03:10:54 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=EVBOjpjVeZ0uqv5Ytj51D02SOvbvYZvIxgFPH2/97ks=; b=jehnLmBx9h/7vq0UO4WgR2MkYmrq915VuGIZ8013Avw2TsIpgewmlhzaqsXrS4A6rBnw ogfQgWOGOIQMaGJ186mIkeXhFNx6gzH/YnLd/wxcp8bXAyJBI7kshemk6BqWKYw8wUXI nmGmWDc3EWSe9miPvwWqNBUG/Fqrgy60NwTCCYnVyhfYDVDJZVGA3K4A1NHCdekHxX+4 a01Sf7B0oYVhJJklddBRYYU467Uh5uyzkNQuKaNRoZr5te4HgcV4wxBp+ebTRa23QWpM pPq4guHllomumVZhSSkzaK958rzXIjHzm8c8Bq7HU3DoG7Ydwo9DBzrTqQiE1pf/OxsB jg== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2120.oracle.com with ESMTP id 2n38npwuwq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:10:54 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3ArwQ012025 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:10:54 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3Arr4009185; Tue, 16 Oct 2018 03:10:53 GMT Received: from localhost (/10.159.227.150) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 15 Oct 2018 20:10:52 -0700 Subject: [PATCH 08/26] vfs: rename vfs_clone_file_prep to be more descriptive 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: Mon, 15 Oct 2018 20:10:51 -0700 Message-ID: <153965945139.1256.17779918536496926662.stgit@magnolia> In-Reply-To: <153965939489.1256.7400115244528045860.stgit@magnolia> References: <153965939489.1256.7400115244528045860.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9047 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=747 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810160026 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 The vfs_clone_file_prep is a generic function to be called by filesystem implementations only. Rename the prefix to generic_ and make it more clear that it applies to remap operations, not just clones. Signed-off-by: Darrick J. Wong Reviewed-by: Amir Goldstein --- fs/ocfs2/refcounttree.c | 2 +- fs/read_write.c | 8 ++++---- fs/xfs/xfs_reflink.c | 2 +- include/linux/fs.h | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c index 19e03936c5e1..36c56dfbe485 100644 --- a/fs/ocfs2/refcounttree.c +++ b/fs/ocfs2/refcounttree.c @@ -4850,7 +4850,7 @@ int ocfs2_reflink_remap_range(struct file *file_in, (OCFS2_I(inode_out)->ip_flags & OCFS2_INODE_SYSTEM_FILE)) goto out_unlock; - ret = vfs_clone_file_prep(file_in, pos_in, file_out, pos_out, + ret = generic_remap_file_range_prep(file_in, pos_in, file_out, pos_out, &len, is_dedupe); if (ret <= 0) goto out_unlock; diff --git a/fs/read_write.c b/fs/read_write.c index f5395d8da741..aca75a97a695 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1745,9 +1745,9 @@ static int generic_remap_check_len(struct inode *inode_in, * Returns: 0 for "nothing to clone", 1 for "something to clone", or * the usual negative error code. */ -int vfs_clone_file_prep(struct file *file_in, loff_t pos_in, - struct file *file_out, loff_t pos_out, - u64 *len, bool is_dedupe) +int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + u64 *len, bool is_dedupe) { struct inode *inode_in = file_inode(file_in); struct inode *inode_out = file_inode(file_out); @@ -1822,7 +1822,7 @@ int vfs_clone_file_prep(struct file *file_in, loff_t pos_in, return 1; } -EXPORT_SYMBOL(vfs_clone_file_prep); +EXPORT_SYMBOL(generic_remap_file_range_prep); int do_clone_file_range(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, u64 len) diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index 281d5f53f2ec..a7757a128a78 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -1326,7 +1326,7 @@ xfs_reflink_remap_prep( if (IS_DAX(inode_in) || IS_DAX(inode_out)) goto out_unlock; - ret = vfs_clone_file_prep(file_in, pos_in, file_out, pos_out, + ret = generic_remap_file_range_prep(file_in, pos_in, file_out, pos_out, len, is_dedupe); if (ret <= 0) goto out_unlock; diff --git a/include/linux/fs.h b/include/linux/fs.h index ba93a6e7dac4..55729e1c2e75 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1825,9 +1825,9 @@ extern ssize_t vfs_readv(struct file *, const struct iovec __user *, unsigned long, loff_t *, rwf_t); extern ssize_t vfs_copy_file_range(struct file *, loff_t , struct file *, loff_t, size_t, unsigned int); -extern int vfs_clone_file_prep(struct file *file_in, loff_t pos_in, - struct file *file_out, loff_t pos_out, - u64 *count, bool is_dedupe); +extern int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + u64 *count, bool is_dedupe); extern int do_clone_file_range(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, u64 len); extern int vfs_clone_file_range(struct file *file_in, loff_t pos_in, From patchwork Tue Oct 16 03:10:58 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: 10642811 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 3955618FD for ; Tue, 16 Oct 2018 03:11:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24DFC2988C for ; Tue, 16 Oct 2018 03:11:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1937E2989B; Tue, 16 Oct 2018 03:11:13 +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 A658E29897 for ; Tue, 16 Oct 2018 03:11:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A12486B0271; Mon, 15 Oct 2018 23:11:11 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9C2536B0272; Mon, 15 Oct 2018 23:11:11 -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 863C66B0273; Mon, 15 Oct 2018 23:11:11 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by kanga.kvack.org (Postfix) with ESMTP id 45CB26B0271 for ; Mon, 15 Oct 2018 23:11:11 -0400 (EDT) Received: by mail-pg1-f197.google.com with SMTP id b7-v6so16145349pgt.10 for ; Mon, 15 Oct 2018 20:11:11 -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=lbgR3wOuOLZGLL8/c8R4UCc54EWHiKBjm/iFOf5M+sk=; b=rEfUXhW9/07VWvUOTTL8k/fp/WOhaLhYwHwSFO9YygLhv7nPZYn281PmQieq35iofD Ewkxy24+ueqxxwqklPeTo/bM/dxkYixGHrUwRtrIf32kkB9PjvTD9eoElqbx9V4CTgYf gAPcaIjR+xFdv7djbQRYd8HZSltIyEVe8pea87RR9pOWResy+0Z5qeZzbaN9FLxue75U vet1KgX9kQTCG2tSHrHW43apNHjTZi7TtoSuRSspmp+j4pakBAIB4yOfyWlx976HkDnh gsfzeEGIdrM/83HgriikTeM4jhHBUV77J/Sa6lxp6o7aOFQBv6lo02k359B6q1wPckWt nccA== X-Gm-Message-State: ABuFfojLx6pRfsZ1j9Vgnqbd2iyXmiXOIs65jK4q9gCvkjEikMR8ks5+ mz8ApnJwOCuF9FLY8NFv6gcnGY6zSGqlJftl7BknsbEIewgLTOc8fYaPfQTwPT3Z/d03XJFVGsY XJS6eSmc4FLbTATdTC+bIvsptYACeUAsPRlLxMC6k4T2iSLqxwRa/KYCEUsba9d9dOA== X-Received: by 2002:a17:902:8a93:: with SMTP id p19-v6mr19426253plo.41.1539659470909; Mon, 15 Oct 2018 20:11:10 -0700 (PDT) X-Google-Smtp-Source: ACcGV60/AGnMGLc+vikUBstacCrhe46ze9EzmJRI0jzjAZXEdSQO6LKQxSjH0MNrn+afq/5SbXFH X-Received: by 2002:a17:902:8a93:: with SMTP id p19-v6mr19426232plo.41.1539659470298; Mon, 15 Oct 2018 20:11:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539659470; cv=none; d=google.com; s=arc-20160816; b=Gnc4ALQXuTHKVxwdST62e9mX1ePrb1i1RSNoXmgQNa9xW4tNKIBCs9aM+on/EGRjEp 6YT9qIDOJwhhxy2IHVvez5/m58AKbpcyr3xgGDJ0ap2lHwPej5Uxzjfw9+VMx+NXaV4B kcEpH2SwvmV9XUuiffHpwVDs+XWmYaFHhziK8W5oey9+NlUPHAXxwPY7p4uPbixRq6kA hllXm8m3CZCNMUjDp80APpKLcoPbyeTWao8DqGXTfhRX5jY0t+1l7YiXov9rL4RIvTCn MEsFF1ZIADiBOeWkxofrj5q86ZJXUNmXG7jTH2h+Hz8xmk6aIxZDjBZRoICIsEnxvRZm eYQw== 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=lbgR3wOuOLZGLL8/c8R4UCc54EWHiKBjm/iFOf5M+sk=; b=g1JK8ZUjRClNxybunS/M71qnPZtswewzOZVDhtHvAtEmaxkMcJ7n+Bj36HIC3+0aAo LvbPQ1ICNj1UuTOHvDHf3Oe6t+7WGfh1ADdfCKuKCeZap8IYpNPJ+ifsl0r79jlMIjpR oaW2kiFkqYSH8hJGyD7xVa8aY+Kz6dcJVFZfXWYjp0w5BPDT1d5fuqpjqy0qFRGcMQp7 jdJhAgPM+BuZptqra+SeYBtAZeeJfggXKtj8u8v84mWQNcqWOBy9ZzsqQAKarV7mXNrg gQAGQqE5OsxfLZ9ACE4ZWQc//rZ/H8qL0OcRPHvx+oLxVIETLFFBxaoPqNQhSIFkNOMW kM8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=CLJP3nk3; 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 s12-v6si12442127pfk.213.2018.10.15.20.11.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 20:11:10 -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=CLJP3nk3; 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 w9G38Tvk044640; Tue, 16 Oct 2018 03:11:08 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=lbgR3wOuOLZGLL8/c8R4UCc54EWHiKBjm/iFOf5M+sk=; b=CLJP3nk3ZTAlz6+QdMB5a+jvV9WEbxvUXSfGLF94I3hUY3lhsXFVAbVmUStXlh/FmiX2 0BmyoJ/zCRkMvGAmMqnrmLwHAQMhUsia2VOGL/9OKrCvlok74Ju7cehCD8XwvopdwCwr ydRBPvn1CzYBucGpNXKoVaEg7420L/YXDOVd8K8KJRUr6TksXnK0CO2mN50tN4qxDWQE 90JdIwJVx/aN5WiofXW2Md89xm/zbAFkq8rZmJxXPta9b4gKiIxRnUXe3APmQagjJwmq +CGhhJGZMOIpSBnFDaNbR+DFODliCbUvSDBCJWlHJ6FbLrbeltbuOh+y0Cxs5Nm+C41R jQ== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2130.oracle.com with ESMTP id 2n384tx1mn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:11:08 +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 w9G3B27v012387 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:11:02 GMT Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w9G3B0Aw003992; Tue, 16 Oct 2018 03:11:00 GMT Received: from localhost (/10.159.227.150) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 15 Oct 2018 20:10:59 -0700 Subject: [PATCH 09/26] vfs: rename clone_verify_area to remap_verify_area 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: Mon, 15 Oct 2018 20:10:58 -0700 Message-ID: <153965945819.1256.12048748621963848640.stgit@magnolia> In-Reply-To: <153965939489.1256.7400115244528045860.stgit@magnolia> References: <153965939489.1256.7400115244528045860.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9047 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=709 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810160026 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 Since we use clone_verify_area for both clone and dedupe range checks, rename the function to make it clear that it's for both. Signed-off-by: Darrick J. Wong Reviewed-by: Amir Goldstein --- fs/read_write.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index aca75a97a695..734c5661fb69 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1686,7 +1686,7 @@ SYSCALL_DEFINE6(copy_file_range, int, fd_in, loff_t __user *, off_in, return ret; } -static int clone_verify_area(struct file *file, loff_t pos, u64 len, bool write) +static int remap_verify_area(struct file *file, loff_t pos, u64 len, bool write) { struct inode *inode = file_inode(file); @@ -1852,11 +1852,11 @@ int do_clone_file_range(struct file *file_in, loff_t pos_in, if (!file_in->f_op->clone_file_range) return -EOPNOTSUPP; - ret = clone_verify_area(file_in, pos_in, len, false); + ret = remap_verify_area(file_in, pos_in, len, false); if (ret) return ret; - ret = clone_verify_area(file_out, pos_out, len, true); + ret = remap_verify_area(file_out, pos_out, len, true); if (ret) return ret; @@ -1989,7 +1989,7 @@ int vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos, if (ret) return ret; - ret = clone_verify_area(dst_file, dst_pos, len, true); + ret = remap_verify_area(dst_file, dst_pos, len, true); if (ret < 0) goto out_drop_write; @@ -2051,7 +2051,7 @@ int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same) if (!S_ISREG(src->i_mode)) goto out; - ret = clone_verify_area(file, off, len, false); + ret = remap_verify_area(file, off, len, false); if (ret < 0) goto out; ret = 0; From patchwork Tue Oct 16 03:11:05 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: 10642823 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 A85D814E2 for ; Tue, 16 Oct 2018 03:11:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 93B3E29883 for ; Tue, 16 Oct 2018 03:11:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 873E1298B1; Tue, 16 Oct 2018 03:11:17 +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 300F929883 for ; Tue, 16 Oct 2018 03:11:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AFFA16B0273; Mon, 15 Oct 2018 23:11:13 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AAF8B6B0274; Mon, 15 Oct 2018 23:11:13 -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 901CC6B0275; Mon, 15 Oct 2018 23:11:13 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by kanga.kvack.org (Postfix) with ESMTP id 3789D6B0273 for ; Mon, 15 Oct 2018 23:11:13 -0400 (EDT) Received: by mail-pl1-f198.google.com with SMTP id g6-v6so17177038plo.0 for ; Mon, 15 Oct 2018 20:11:13 -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=ksSDaZK56IBs8nkRyCd89EK1XZDHt07gd8/yg80fkrk=; b=nL2z5iL7Gpsoz3lufbABBW3JwmYfd6GrpcECo1MZRmIi9L9fIJmd8wnTWUYPTL5GA4 4y9li0P3errVXgDGujt48cFyP+QBtGmyZTwqm95VAOodKtbNbHcSuZthA5INRW5/JcZa NRazmslo2MwJb9/zEMn3sE4k1yKGu04rguuNCstfSrVjJNO0UWjRMu9GFC4nfrAkTIzm 1SVKf4JHJqWo/SRDYzlMiEs0SqM9W3VobJ4n+jWuoCWIcgwY3/9uVkz2w5ynRolaTwS6 059Y/m1eEuoX/BmrF6bGBL3WN/xsHNNhm4rFQxy147DFHZFNNOWoWXWJEy5PKRpcqact TenA== X-Gm-Message-State: ABuFfoidnTCE/Tbc1ZgktZ3Ovl5ZGjW8EST85XtT4zv/3HG/Zw4Tv/kE qCuhHaMaulB+ieHpfj3w7eENKzPAo+L/E/SZOY41WISKWixayXDDsqLBr+JOi27exODq6DVMNAp KFHuF22+9urAMkR26oCO6seVbYJTMJXNuVLoEG57Gdszp4AfGhpuwhFlXStAMtLvxwA== X-Received: by 2002:a17:902:8202:: with SMTP id x2-v6mr19670233pln.192.1539659472823; Mon, 15 Oct 2018 20:11:12 -0700 (PDT) X-Google-Smtp-Source: ACcGV62Ej1jgaDZdqIyoyG6HEH4Pj4wlq287t9uUEZ96zXjKSBE+m97CnkpxQ+JjZpY11MrnHaJW X-Received: by 2002:a17:902:8202:: with SMTP id x2-v6mr19670184pln.192.1539659471397; Mon, 15 Oct 2018 20:11:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539659471; cv=none; d=google.com; s=arc-20160816; b=058S398lARpk7JPNQuh7pME+IxVr5kPecq3KQYWwHV0yUL9/09g2EPn7vm+lwxutPm jM/C1S42uF/FBiU9ZZ4Ee4c8gv3+DvZpKFtrY7HNH/xKhT1UiNNSIyy/EcXNEOaXpePd v0JoYrec2Yx/v7KJgoNyMdfE6eHX3mV0AxW8KSJwfu9tuwuuU/imjOkvMl1O0ocMGGse 1OD4jdHTAQwEz8kSPPZBV+m6vyqyq+nDjn49Q4c5hzGG7VsYDyJqNDavjw589Aayg1b4 1BZL15HKoMJ30XtsxNRf4VvBXEc7ubi6OMFNhGMRRuhs1oxymp0LJC1SMgpJuUNThygJ 99zA== 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=ksSDaZK56IBs8nkRyCd89EK1XZDHt07gd8/yg80fkrk=; b=BejMP6fk806B+AjPdTcsvP1eXyuBs2M6lPNagfeH19f+Xw5XR8YzEB1I7tioUaA/I2 oPFrx9gOrhsVgje4gMaOTBSIFweIjzTK3PEkKw5d2tnI9DFNRcwY+kb/yoE54OgwFYCb /WUnBUPS+3pdxcSt+SVOItUDrpKDrYe/IRW2N8KnxyScWGloY4MRMKZHjdr+v2YGZ04L PeZsd27EuYu3hyH9yefdG8M0kWy58aKCXqr53rnPhkclJokfQ2P5VUlrn23ehLeUTpjU UoaLKl5WCXurG3AuQejuCnU0WMH+ZyU09X36TSidiGi7BoAscuC8bnnw4U+8SUI9xJOr id3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=mqiXrGzp; 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 s12-v6si12442156pfk.213.2018.10.15.20.11.11 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 20:11:11 -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=mqiXrGzp; 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 w9G38XC1044698; Tue, 16 Oct 2018 03:11:09 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=ksSDaZK56IBs8nkRyCd89EK1XZDHt07gd8/yg80fkrk=; b=mqiXrGzpgh0BkuvoVXoauNLotDSYuvBWKXYPrQ4oez0yxb+8AakCz25+K7p2oJaWagwJ LE+8v5sp5B6/i+Ds+taTJW9MaH2GYZ3VnjJVng6JzTH/Vx6mPReEBRKs+yMMRdrO/5Yf TaS3o10oA7o8UV7KvKJwDFQpKPjz7ZVgW0GlKNjS0imHoXml331qlhUW9jfD/tn9wxvj 54vW9gQpa3FxR3ECZ1d+Gs1MwL/0MR3yo4E2KQN73gWck+nU0I7aeJPg7t5ZmZij2sa6 Z0BfxomvZdy9APBK0i7l1gkTb+8ker4L8tIi2otC+jdGbSldbqCQdABgW8iw0dMiWgm8 uw== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2130.oracle.com with ESMTP id 2n384tx1mp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:11:09 +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 w9G3B7UK012675 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:11:08 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w9G3B77Y004058; Tue, 16 Oct 2018 03:11:07 GMT Received: from localhost (/10.159.227.150) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 15 Oct 2018 20:11:06 -0700 Subject: [PATCH 10/26] vfs: combine the clone and dedupe into a single remap_file_range 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: Mon, 15 Oct 2018 20:11:05 -0700 Message-ID: <153965946503.1256.14921970220584184352.stgit@magnolia> In-Reply-To: <153965939489.1256.7400115244528045860.stgit@magnolia> References: <153965939489.1256.7400115244528045860.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9047 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=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810160026 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 Combine the clone_file_range and dedupe_file_range operations into a single remap_file_range file operation dispatch since they're fundamentally the same operation. The differences between the two can be made in the prep functions. Signed-off-by: Darrick J. Wong Reviewed-by: Amir Goldstein Reviewed-by: Christoph Hellwig --- Documentation/filesystems/vfs.txt | 13 +++++------ fs/btrfs/ctree.h | 8 ++----- fs/btrfs/file.c | 3 +- fs/btrfs/ioctl.c | 45 +++++++++++++++++++------------------ fs/cifs/cifsfs.c | 22 +++++++++++------- fs/nfs/nfs4file.c | 10 ++++++-- fs/ocfs2/file.c | 24 +++++++------------- fs/overlayfs/file.c | 30 ++++++++++++++----------- fs/read_write.c | 18 +++++++-------- fs/xfs/xfs_file.c | 23 ++++++------------- include/linux/fs.h | 20 +++++++++++++--- 11 files changed, 110 insertions(+), 106 deletions(-) diff --git a/Documentation/filesystems/vfs.txt b/Documentation/filesystems/vfs.txt index a6c6a8af48a2..bb3183334ab9 100644 --- a/Documentation/filesystems/vfs.txt +++ b/Documentation/filesystems/vfs.txt @@ -883,8 +883,9 @@ struct file_operations { unsigned (*mmap_capabilities)(struct file *); #endif ssize_t (*copy_file_range)(struct file *, loff_t, struct file *, loff_t, size_t, unsigned int); - int (*clone_file_range)(struct file *, loff_t, struct file *, loff_t, u64); - int (*dedupe_file_range)(struct file *, loff_t, struct file *, loff_t, u64); + int (*remap_file_range)(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + u64 len, unsigned int remap_flags); int (*fadvise)(struct file *, loff_t, loff_t, int); }; @@ -960,11 +961,9 @@ otherwise noted. copy_file_range: called by the copy_file_range(2) system call. - clone_file_range: called by the ioctl(2) system call for FICLONERANGE and - FICLONE commands. - - dedupe_file_range: called by the ioctl(2) system call for FIDEDUPERANGE - command. + remap_file_range: called by the ioctl(2) system call for FICLONERANGE and + FICLONE and FIDEDUPERANGE commands to remap file ranges. Note that + a zero length implies "remap to end of source file". fadvise: possibly called by the fadvise64() system call. diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 2cddfe7806a4..124a05662fc2 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -3218,9 +3218,6 @@ void btrfs_get_block_group_info(struct list_head *groups_list, struct btrfs_ioctl_space_info *space); void btrfs_update_ioctl_balance_args(struct btrfs_fs_info *fs_info, struct btrfs_ioctl_balance_args *bargs); -int btrfs_dedupe_file_range(struct file *src_file, loff_t src_loff, - struct file *dst_file, loff_t dst_loff, - u64 olen); /* file.c */ int __init btrfs_auto_defrag_init(void); @@ -3250,8 +3247,9 @@ int btrfs_dirty_pages(struct inode *inode, struct page **pages, size_t num_pages, loff_t pos, size_t write_bytes, struct extent_state **cached); int btrfs_fdatawrite_range(struct inode *inode, loff_t start, loff_t end); -int btrfs_clone_file_range(struct file *file_in, loff_t pos_in, - struct file *file_out, loff_t pos_out, u64 len); +int btrfs_remap_file_range(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, u64 len, + unsigned int remap_flags); /* tree-defrag.c */ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans, diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 2be00e873e92..9a963f061393 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -3269,8 +3269,7 @@ const struct file_operations btrfs_file_operations = { #ifdef CONFIG_COMPAT .compat_ioctl = btrfs_compat_ioctl, #endif - .clone_file_range = btrfs_clone_file_range, - .dedupe_file_range = btrfs_dedupe_file_range, + .remap_file_range = btrfs_remap_file_range, }; void __cold btrfs_auto_defrag_exit(void) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index d60b6caf09e8..bfd99c66723e 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -3627,26 +3627,6 @@ static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen, return ret; } -int btrfs_dedupe_file_range(struct file *src_file, loff_t src_loff, - struct file *dst_file, loff_t dst_loff, - u64 olen) -{ - struct inode *src = file_inode(src_file); - struct inode *dst = file_inode(dst_file); - u64 bs = BTRFS_I(src)->root->fs_info->sb->s_blocksize; - - if (WARN_ON_ONCE(bs < PAGE_SIZE)) { - /* - * Btrfs does not support blocksize < page_size. As a - * result, btrfs_cmp_data() won't correctly handle - * this situation without an update. - */ - return -EINVAL; - } - - return btrfs_extent_same(src, src_loff, olen, dst, dst_loff); -} - static int clone_finish_inode_update(struct btrfs_trans_handle *trans, struct inode *inode, u64 endoff, @@ -4348,9 +4328,30 @@ static noinline int btrfs_clone_files(struct file *file, struct file *file_src, return ret; } -int btrfs_clone_file_range(struct file *src_file, loff_t off, - struct file *dst_file, loff_t destoff, u64 len) +int btrfs_remap_file_range(struct file *src_file, loff_t off, + struct file *dst_file, loff_t destoff, u64 len, + unsigned int remap_flags) { + if (remap_flags & ~(REMAP_FILE_DEDUP | REMAP_FILE_ADVISORY)) + return -EINVAL; + + if (remap_flags & REMAP_FILE_DEDUP) { + struct inode *src = file_inode(src_file); + struct inode *dst = file_inode(dst_file); + u64 bs = BTRFS_I(src)->root->fs_info->sb->s_blocksize; + + if (WARN_ON_ONCE(bs < PAGE_SIZE)) { + /* + * Btrfs does not support blocksize < page_size. As a + * result, btrfs_cmp_data() won't correctly handle + * this situation without an update. + */ + return -EINVAL; + } + + return btrfs_extent_same(src, off, len, dst, destoff); + } + return btrfs_clone_files(dst_file, src_file, off, len, destoff); } diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index 7065426b3280..e8144d0dcde2 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -975,8 +975,9 @@ const struct inode_operations cifs_symlink_inode_ops = { .listxattr = cifs_listxattr, }; -static int cifs_clone_file_range(struct file *src_file, loff_t off, - struct file *dst_file, loff_t destoff, u64 len) +static int cifs_remap_file_range(struct file *src_file, loff_t off, + struct file *dst_file, loff_t destoff, u64 len, + unsigned int remap_flags) { struct inode *src_inode = file_inode(src_file); struct inode *target_inode = file_inode(dst_file); @@ -986,6 +987,9 @@ static int cifs_clone_file_range(struct file *src_file, loff_t off, unsigned int xid; int rc; + if (remap_flags & ~REMAP_FILE_ADVISORY) + return -EINVAL; + cifs_dbg(FYI, "clone range\n"); xid = get_xid(); @@ -1134,7 +1138,7 @@ const struct file_operations cifs_file_ops = { .llseek = cifs_llseek, .unlocked_ioctl = cifs_ioctl, .copy_file_range = cifs_copy_file_range, - .clone_file_range = cifs_clone_file_range, + .remap_file_range = cifs_remap_file_range, .setlease = cifs_setlease, .fallocate = cifs_fallocate, }; @@ -1153,7 +1157,7 @@ const struct file_operations cifs_file_strict_ops = { .llseek = cifs_llseek, .unlocked_ioctl = cifs_ioctl, .copy_file_range = cifs_copy_file_range, - .clone_file_range = cifs_clone_file_range, + .remap_file_range = cifs_remap_file_range, .setlease = cifs_setlease, .fallocate = cifs_fallocate, }; @@ -1172,7 +1176,7 @@ const struct file_operations cifs_file_direct_ops = { .splice_write = iter_file_splice_write, .unlocked_ioctl = cifs_ioctl, .copy_file_range = cifs_copy_file_range, - .clone_file_range = cifs_clone_file_range, + .remap_file_range = cifs_remap_file_range, .llseek = cifs_llseek, .setlease = cifs_setlease, .fallocate = cifs_fallocate, @@ -1191,7 +1195,7 @@ const struct file_operations cifs_file_nobrl_ops = { .llseek = cifs_llseek, .unlocked_ioctl = cifs_ioctl, .copy_file_range = cifs_copy_file_range, - .clone_file_range = cifs_clone_file_range, + .remap_file_range = cifs_remap_file_range, .setlease = cifs_setlease, .fallocate = cifs_fallocate, }; @@ -1209,7 +1213,7 @@ const struct file_operations cifs_file_strict_nobrl_ops = { .llseek = cifs_llseek, .unlocked_ioctl = cifs_ioctl, .copy_file_range = cifs_copy_file_range, - .clone_file_range = cifs_clone_file_range, + .remap_file_range = cifs_remap_file_range, .setlease = cifs_setlease, .fallocate = cifs_fallocate, }; @@ -1227,7 +1231,7 @@ const struct file_operations cifs_file_direct_nobrl_ops = { .splice_write = iter_file_splice_write, .unlocked_ioctl = cifs_ioctl, .copy_file_range = cifs_copy_file_range, - .clone_file_range = cifs_clone_file_range, + .remap_file_range = cifs_remap_file_range, .llseek = cifs_llseek, .setlease = cifs_setlease, .fallocate = cifs_fallocate, @@ -1239,7 +1243,7 @@ const struct file_operations cifs_dir_ops = { .read = generic_read_dir, .unlocked_ioctl = cifs_ioctl, .copy_file_range = cifs_copy_file_range, - .clone_file_range = cifs_clone_file_range, + .remap_file_range = cifs_remap_file_range, .llseek = generic_file_llseek, .fsync = cifs_dir_fsync, }; diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c index 4288a6ecaf75..ae5780ce41dc 100644 --- a/fs/nfs/nfs4file.c +++ b/fs/nfs/nfs4file.c @@ -180,8 +180,9 @@ static long nfs42_fallocate(struct file *filep, int mode, loff_t offset, loff_t return nfs42_proc_allocate(filep, offset, len); } -static int nfs42_clone_file_range(struct file *src_file, loff_t src_off, - struct file *dst_file, loff_t dst_off, u64 count) +static int nfs42_remap_file_range(struct file *src_file, loff_t src_off, + struct file *dst_file, loff_t dst_off, u64 count, + unsigned int remap_flags) { struct inode *dst_inode = file_inode(dst_file); struct nfs_server *server = NFS_SERVER(dst_inode); @@ -190,6 +191,9 @@ static int nfs42_clone_file_range(struct file *src_file, loff_t src_off, bool same_inode = false; int ret; + if (remap_flags & ~REMAP_FILE_ADVISORY) + return -EINVAL; + /* check alignment w.r.t. clone_blksize */ ret = -EINVAL; if (bs) { @@ -262,7 +266,7 @@ const struct file_operations nfs4_file_operations = { .copy_file_range = nfs4_copy_file_range, .llseek = nfs4_file_llseek, .fallocate = nfs42_fallocate, - .clone_file_range = nfs42_clone_file_range, + .remap_file_range = nfs42_remap_file_range, #else .llseek = nfs_file_llseek, #endif diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c index 9fa35cb6f6e0..0b757a24567c 100644 --- a/fs/ocfs2/file.c +++ b/fs/ocfs2/file.c @@ -2527,24 +2527,18 @@ static loff_t ocfs2_file_llseek(struct file *file, loff_t offset, int whence) return offset; } -static int ocfs2_file_clone_range(struct file *file_in, +static int ocfs2_remap_file_range(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, - u64 len) + u64 len, + unsigned int remap_flags) { - return ocfs2_reflink_remap_range(file_in, pos_in, file_out, pos_out, - len, false); -} + if (remap_flags & ~(REMAP_FILE_DEDUP | REMAP_FILE_ADVISORY)) + return -EINVAL; -static int ocfs2_file_dedupe_range(struct file *file_in, - loff_t pos_in, - struct file *file_out, - loff_t pos_out, - u64 len) -{ return ocfs2_reflink_remap_range(file_in, pos_in, file_out, pos_out, - len, true); + len, remap_flags & REMAP_FILE_DEDUP); } const struct inode_operations ocfs2_file_iops = { @@ -2586,8 +2580,7 @@ const struct file_operations ocfs2_fops = { .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .fallocate = ocfs2_fallocate, - .clone_file_range = ocfs2_file_clone_range, - .dedupe_file_range = ocfs2_file_dedupe_range, + .remap_file_range = ocfs2_remap_file_range, }; const struct file_operations ocfs2_dops = { @@ -2633,8 +2626,7 @@ const struct file_operations ocfs2_fops_no_plocks = { .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .fallocate = ocfs2_fallocate, - .clone_file_range = ocfs2_file_clone_range, - .dedupe_file_range = ocfs2_file_dedupe_range, + .remap_file_range = ocfs2_remap_file_range, }; const struct file_operations ocfs2_dops_no_plocks = { diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c index 986313da0c88..fffb36fd5920 100644 --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -489,26 +489,31 @@ static ssize_t ovl_copy_file_range(struct file *file_in, loff_t pos_in, OVL_COPY); } -static int ovl_clone_file_range(struct file *file_in, loff_t pos_in, - struct file *file_out, loff_t pos_out, u64 len) +static int ovl_remap_file_range(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + u64 len, unsigned int remap_flags) { - return ovl_copyfile(file_in, pos_in, file_out, pos_out, len, 0, - OVL_CLONE); -} + enum ovl_copyop op; + + if (remap_flags & ~(REMAP_FILE_DEDUP | REMAP_FILE_ADVISORY)) + return -EINVAL; + + if (remap_flags & REMAP_FILE_DEDUP) + op = OVL_DEDUPE; + else + op = OVL_CLONE; -static int ovl_dedupe_file_range(struct file *file_in, loff_t pos_in, - struct file *file_out, loff_t pos_out, u64 len) -{ /* * Don't copy up because of a dedupe request, this wouldn't make sense * most of the time (data would be duplicated instead of deduplicated). */ - if (!ovl_inode_upper(file_inode(file_in)) || - !ovl_inode_upper(file_inode(file_out))) + if (op == OVL_DEDUPE && + (!ovl_inode_upper(file_inode(file_in)) || + !ovl_inode_upper(file_inode(file_out)))) return -EPERM; return ovl_copyfile(file_in, pos_in, file_out, pos_out, len, 0, - OVL_DEDUPE); + op); } const struct file_operations ovl_file_operations = { @@ -525,6 +530,5 @@ const struct file_operations ovl_file_operations = { .compat_ioctl = ovl_compat_ioctl, .copy_file_range = ovl_copy_file_range, - .clone_file_range = ovl_clone_file_range, - .dedupe_file_range = ovl_dedupe_file_range, + .remap_file_range = ovl_remap_file_range, }; diff --git a/fs/read_write.c b/fs/read_write.c index 734c5661fb69..766bdcb381f3 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1588,9 +1588,9 @@ 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) { - ret = file_in->f_op->clone_file_range(file_in, pos_in, - file_out, pos_out, len); + if (file_in->f_op->remap_file_range) { + ret = file_in->f_op->remap_file_range(file_in, pos_in, + file_out, pos_out, len, 0); if (ret == 0) { ret = len; goto done; @@ -1849,7 +1849,7 @@ int do_clone_file_range(struct file *file_in, loff_t pos_in, (file_out->f_flags & O_APPEND)) return -EBADF; - if (!file_in->f_op->clone_file_range) + if (!file_in->f_op->remap_file_range) return -EOPNOTSUPP; ret = remap_verify_area(file_in, pos_in, len, false); @@ -1860,8 +1860,8 @@ int do_clone_file_range(struct file *file_in, loff_t pos_in, if (ret) return ret; - ret = file_in->f_op->clone_file_range(file_in, pos_in, - file_out, pos_out, len); + ret = file_in->f_op->remap_file_range(file_in, pos_in, + file_out, pos_out, len, 0); if (!ret) { fsnotify_access(file_in); fsnotify_modify(file_out); @@ -2006,7 +2006,7 @@ int vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos, goto out_drop_write; ret = -EINVAL; - if (!dst_file->f_op->dedupe_file_range) + if (!dst_file->f_op->remap_file_range) goto out_drop_write; if (len == 0) { @@ -2014,8 +2014,8 @@ int vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos, goto out_drop_write; } - ret = dst_file->f_op->dedupe_file_range(src_file, src_pos, - dst_file, dst_pos, len); + ret = dst_file->f_op->remap_file_range(src_file, src_pos, dst_file, + dst_pos, len, REMAP_FILE_DEDUP); out_drop_write: mnt_drop_write_file(dst_file); diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 61a5ad2600e8..2ad94d508f80 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -920,27 +920,19 @@ xfs_file_fallocate( } STATIC int -xfs_file_clone_range( +xfs_file_remap_range( struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, - u64 len) + u64 len, + unsigned int remap_flags) { - return xfs_reflink_remap_range(file_in, pos_in, file_out, pos_out, - len, false); -} + if (remap_flags & ~(REMAP_FILE_DEDUP | REMAP_FILE_ADVISORY)) + return -EINVAL; -STATIC int -xfs_file_dedupe_range( - struct file *file_in, - loff_t pos_in, - struct file *file_out, - loff_t pos_out, - u64 len) -{ return xfs_reflink_remap_range(file_in, pos_in, file_out, pos_out, - len, true); + len, remap_flags & REMAP_FILE_DEDUP); } STATIC int @@ -1175,8 +1167,7 @@ const struct file_operations xfs_file_operations = { .fsync = xfs_file_fsync, .get_unmapped_area = thp_get_unmapped_area, .fallocate = xfs_file_fallocate, - .clone_file_range = xfs_file_clone_range, - .dedupe_file_range = xfs_file_dedupe_range, + .remap_file_range = xfs_file_remap_range, }; const struct file_operations xfs_dir_file_operations = { diff --git a/include/linux/fs.h b/include/linux/fs.h index 55729e1c2e75..794d1b83eded 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1721,6 +1721,19 @@ struct block_device_operations; #define NOMMU_VMFLAGS \ (NOMMU_MAP_READ | NOMMU_MAP_WRITE | NOMMU_MAP_EXEC) +/* + * These flags control the behavior of the remap_file_range function pointer. + * If it is called with len == 0 that means "remap to end of source file". + * + * REMAP_FILE_DEDUP: only remap if contents identical (i.e. deduplicate) + */ +#define REMAP_FILE_DEDUP (1 << 0) + +/* All valid REMAP_FILE flags */ +#define REMAP_FILE_VALID_FLAGS (REMAP_FILE_DEDUP) + +/* REMAP_FILE flags taken care of by the vfs. */ +#define REMAP_FILE_ADVISORY (0) struct iov_iter; @@ -1759,10 +1772,9 @@ struct file_operations { #endif ssize_t (*copy_file_range)(struct file *, loff_t, struct file *, loff_t, size_t, unsigned int); - int (*clone_file_range)(struct file *, loff_t, struct file *, loff_t, - u64); - int (*dedupe_file_range)(struct file *, loff_t, struct file *, loff_t, - u64); + int (*remap_file_range)(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + u64 len, unsigned int remap_flags); int (*fadvise)(struct file *, loff_t, loff_t, int); } __randomize_layout; From patchwork Tue Oct 16 03:11:12 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: 10642837 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 5664F17D2 for ; Tue, 16 Oct 2018 03:11:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4038A212DB for ; Tue, 16 Oct 2018 03:11:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 30C6D2988C; Tue, 16 Oct 2018 03:11:22 +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 5C146212DB for ; Tue, 16 Oct 2018 03:11:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CACA16B0275; Mon, 15 Oct 2018 23:11:19 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C5B316B0276; Mon, 15 Oct 2018 23:11:19 -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 B22E66B0277; Mon, 15 Oct 2018 23:11:19 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by kanga.kvack.org (Postfix) with ESMTP id 8A56D6B0275 for ; Mon, 15 Oct 2018 23:11:19 -0400 (EDT) Received: by mail-qt1-f199.google.com with SMTP id j60-v6so22954169qtb.8 for ; Mon, 15 Oct 2018 20:11:19 -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=ufw8W7mPrmpLra0J7s1MmX4U818cevYIGQfOZevEvFE=; b=IrWcdAeA1KAjWuEe8hDp/0RC5+QjRsEcxPwLKRXznIVB7w+rypAVjmWaU2uoRk59Ht in18HRElgAOH3esbFOCVfws5j0RLVir4ohPmE/47crqjb6FMg92qh+iX+q8NGZVgAfca rkgxrvAKjeZ34ggr8HaCMpTuom9EmQX5L7/jfVY49i8lLrJ+Ms9uUvzsFAa7ilZpOKSY wbAgEFqRpmgq2VrZPQnbjWThtZuZmOtrFoH23EUiUzOUNLlilh9zghW0clQUbk3O+2fO n+h4KH1XgONSDMQg6hXF0DtTwW0YkRJnJyk9JOf8ipgdKD57Sl4zfDfnyU5b7uNs2pMH VMXQ== X-Gm-Message-State: ABuFfohfaiyF0Qg1rQmHfUydDkA2IB6Bof+vtKlDKzKL28uOPNfdLsea sq4d0P23MTWYM4cAgKiIv4Ohgj0TW+R3VgJk1lkx0bkF2gSHjOmoF6+c+O/CxbURgRkDN7TeabO xFBZEGhXdMMmKIe+CZxu+nD+l+nnpdtcHr9lQ/4ndgFExEMxOAe+WRumWyGC9k9V+pw== X-Received: by 2002:a37:94c6:: with SMTP id w189-v6mr18570174qkd.277.1539659479306; Mon, 15 Oct 2018 20:11:19 -0700 (PDT) X-Google-Smtp-Source: ACcGV618joBbpWQUtVdA0N2kdct3fCBmH458H8bPrtrQ6uFg3QMmYE1wTvfU8lTv9ot2LtCjugp/ X-Received: by 2002:a37:94c6:: with SMTP id w189-v6mr18570146qkd.277.1539659478441; Mon, 15 Oct 2018 20:11:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539659478; cv=none; d=google.com; s=arc-20160816; b=nUqIFifHcndgsw/Scb2R6obKaEldwzBp8ofntLemnvm58AM67an3XyBcStSS9XJLnr kLXeU9i+X+lu1CFYPoGCHw8Pu5xFxAxjjgmreb/mpoBfaI9hCTIBQ7MNXPZbwsj2MsYh glZkaF4nXiXOXe+vTTp4kG8zf1SrJTVqLbemhsi9gMpDjKTwwPgv4NuPzu2Fg7cG3551 eUBgwiOgdngIqN9ljKC6kjR8+inR+0P6fr064b67n/J3bggVTx/Ml2xWxZxdNi032b74 u1j0XAN6CqgVEfPzStwzmZgdmqcmgmCUE9XNyDfC9Bo3gqDHKKvFwmrhvuNxUw9/rAe+ xGBA== 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=ufw8W7mPrmpLra0J7s1MmX4U818cevYIGQfOZevEvFE=; b=PQwSAB458Xm+AQsFJNXvW93p11FT9hhhdbq0KUAYpdVdSmLj6uTTAP60jeE669MBlw LNKndoJVlF+IyRqXCQVUACwH/buTxhadJieKTf7SvDkbhxxbP3dXjhH9iDUJwzMiNUW+ A4jRB2pqGvWimPQEXrT1UHpr/mOxM6mbB+0Pyq0/jb9NZPGsQZlqmUD7lB5jbnnSL6FU k0b03IxUi8muEpp48vf1P/UhB0YFtA3TfuUprcTMfd7dqW+88uT63np5Kp85A2batPqi aZA3Jh60a+Ep6t9lad3yvMkbV3LM+lOG6BUzOhOhpSFHMmIbhlY/Y1fu2n4nIGCHtlKd sUqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=aYabyVyQ; 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 75-v6si1536354qkv.68.2018.10.15.20.11.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 20:11:18 -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=aYabyVyQ; 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 w9G39XqD194641; Tue, 16 Oct 2018 03:11:16 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=ufw8W7mPrmpLra0J7s1MmX4U818cevYIGQfOZevEvFE=; b=aYabyVyQlq1DtI1o6Ff2/y7K4acMZ+OaFB2ns5yCS2KHsg7JtP44Fa94qCGfm7pCVlFO jPV+amd16vZRAF7+SfbcSPGoXoI1padqRp8aOzX8nQuYBUluzOoETTVvTY+jI/K+j+o+ oFuH5FQqaEXkQvmigqXMKgfg9+aUHra/pfPqJwecKNH/T3dt1yfVvcRH4HV62EC+PCQ8 C3BuShQ2Ii/cYDI3Oqxo06uiZoVPXlu30TQGNTR71AYNF+DReKwmKQbC4TTsJNDEqQYp awgbuN+YQOKbN7l8UZhe4sltPR/Mflt4y3NVxGRwY4g+i9BaEFp8V+q5BkLpjVIi2MvY iA== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2120.oracle.com with ESMTP id 2n39br5rhy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:11:16 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3BE6I030534 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:11:15 GMT Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3BEQN009419; Tue, 16 Oct 2018 03:11:14 GMT Received: from localhost (/10.159.227.150) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 15 Oct 2018 20:11:13 -0700 Subject: [PATCH 11/26] vfs: pass remap flags to generic_remap_file_range_prep 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: Mon, 15 Oct 2018 20:11:12 -0700 Message-ID: <153965947208.1256.13169150057249233851.stgit@magnolia> In-Reply-To: <153965939489.1256.7400115244528045860.stgit@magnolia> References: <153965939489.1256.7400115244528045860.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9047 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=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810160026 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 Plumb the remap flags through the filesystem from the vfs function dispatcher all the way to the prep function to prepare for behavior changes in subsequent patches. Signed-off-by: Darrick J. Wong Reviewed-by: Amir Goldstein Reviewed-by: Christoph Hellwig --- fs/ocfs2/file.c | 2 +- fs/ocfs2/refcounttree.c | 4 ++-- fs/ocfs2/refcounttree.h | 2 +- fs/read_write.c | 14 +++++++------- fs/xfs/xfs_file.c | 2 +- fs/xfs/xfs_reflink.c | 21 +++++++++++---------- fs/xfs/xfs_reflink.h | 3 ++- include/linux/fs.h | 2 +- 8 files changed, 26 insertions(+), 24 deletions(-) diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c index 0b757a24567c..9809b0e5746f 100644 --- a/fs/ocfs2/file.c +++ b/fs/ocfs2/file.c @@ -2538,7 +2538,7 @@ static int ocfs2_remap_file_range(struct file *file_in, return -EINVAL; return ocfs2_reflink_remap_range(file_in, pos_in, file_out, pos_out, - len, remap_flags & REMAP_FILE_DEDUP); + len, remap_flags); } const struct inode_operations ocfs2_file_iops = { diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c index 36c56dfbe485..df9781567ec0 100644 --- a/fs/ocfs2/refcounttree.c +++ b/fs/ocfs2/refcounttree.c @@ -4825,7 +4825,7 @@ int ocfs2_reflink_remap_range(struct file *file_in, struct file *file_out, loff_t pos_out, u64 len, - bool is_dedupe) + unsigned int remap_flags) { struct inode *inode_in = file_inode(file_in); struct inode *inode_out = file_inode(file_out); @@ -4851,7 +4851,7 @@ int ocfs2_reflink_remap_range(struct file *file_in, goto out_unlock; ret = generic_remap_file_range_prep(file_in, pos_in, file_out, pos_out, - &len, is_dedupe); + &len, remap_flags); if (ret <= 0) goto out_unlock; diff --git a/fs/ocfs2/refcounttree.h b/fs/ocfs2/refcounttree.h index 4af55bf4b35b..d2c5f526edff 100644 --- a/fs/ocfs2/refcounttree.h +++ b/fs/ocfs2/refcounttree.h @@ -120,6 +120,6 @@ int ocfs2_reflink_remap_range(struct file *file_in, struct file *file_out, loff_t pos_out, u64 len, - bool is_dedupe); + unsigned int remap_flags); #endif /* OCFS2_REFCOUNTTREE_H */ diff --git a/fs/read_write.c b/fs/read_write.c index 766bdcb381f3..201381689284 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1722,14 +1722,14 @@ static int generic_remap_check_len(struct inode *inode_in, struct inode *inode_out, loff_t pos_out, u64 *len, - bool is_dedupe) + unsigned int remap_flags) { u64 blkmask = i_blocksize(inode_in) - 1; if ((*len & blkmask) == 0) return 0; - if (is_dedupe) + if (remap_flags & REMAP_FILE_DEDUP) *len &= ~blkmask; else if (pos_out + *len < i_size_read(inode_out)) return -EINVAL; @@ -1747,7 +1747,7 @@ static int generic_remap_check_len(struct inode *inode_in, */ int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, - u64 *len, bool is_dedupe) + u64 *len, unsigned int remap_flags) { struct inode *inode_in = file_inode(file_in); struct inode *inode_out = file_inode(file_out); @@ -1771,7 +1771,7 @@ int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, if (*len == 0) { loff_t isize = i_size_read(inode_in); - if (is_dedupe || pos_in == isize) + if ((remap_flags & REMAP_FILE_DEDUP) || pos_in == isize) return 0; if (pos_in > isize) return -EINVAL; @@ -1782,7 +1782,7 @@ int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, /* Check that we don't violate system file offset limits. */ ret = generic_remap_checks(file_in, pos_in, file_out, pos_out, len, - is_dedupe); + (remap_flags & REMAP_FILE_DEDUP)); if (ret) return ret; @@ -1804,7 +1804,7 @@ int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, /* * Check that the extents are the same. */ - if (is_dedupe) { + if (remap_flags & REMAP_FILE_DEDUP) { bool is_same = false; ret = vfs_dedupe_file_range_compare(inode_in, pos_in, @@ -1816,7 +1816,7 @@ int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, } ret = generic_remap_check_len(inode_in, inode_out, pos_out, len, - is_dedupe); + remap_flags); if (ret) return ret; diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 2ad94d508f80..20314eb4677a 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -932,7 +932,7 @@ xfs_file_remap_range( return -EINVAL; return xfs_reflink_remap_range(file_in, pos_in, file_out, pos_out, - len, remap_flags & REMAP_FILE_DEDUP); + len, remap_flags); } STATIC int diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index a7757a128a78..29aab196ce7e 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -921,13 +921,14 @@ xfs_reflink_update_dest( struct xfs_inode *dest, xfs_off_t newlen, xfs_extlen_t cowextsize, - bool is_dedupe) + unsigned int remap_flags) { struct xfs_mount *mp = dest->i_mount; struct xfs_trans *tp; int error; - if (is_dedupe && newlen <= i_size_read(VFS_I(dest)) && cowextsize == 0) + if ((remap_flags & REMAP_FILE_DEDUP) && + newlen <= i_size_read(VFS_I(dest)) && cowextsize == 0) return 0; error = xfs_trans_alloc(mp, &M_RES(mp)->tr_ichange, 0, 0, 0, &tp); @@ -948,7 +949,7 @@ xfs_reflink_update_dest( dest->i_d.di_flags2 |= XFS_DIFLAG2_COWEXTSIZE; } - if (!is_dedupe) { + if (!(remap_flags & REMAP_FILE_DEDUP)) { xfs_trans_ichgtime(tp, dest, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); } @@ -1296,7 +1297,7 @@ xfs_reflink_remap_prep( struct file *file_out, loff_t pos_out, u64 *len, - bool is_dedupe) + unsigned int remap_flags) { struct inode *inode_in = file_inode(file_in); struct xfs_inode *src = XFS_I(inode_in); @@ -1327,7 +1328,7 @@ xfs_reflink_remap_prep( goto out_unlock; ret = generic_remap_file_range_prep(file_in, pos_in, file_out, pos_out, - len, is_dedupe); + len, remap_flags); if (ret <= 0) goto out_unlock; @@ -1336,7 +1337,7 @@ xfs_reflink_remap_prep( * from the source file so we don't try to dedupe the partial * EOF block. */ - if (is_dedupe) { + if (remap_flags & REMAP_FILE_DEDUP) { *len &= ~blkmask; } else if (*len & blkmask) { /* @@ -1372,7 +1373,7 @@ xfs_reflink_remap_prep( PAGE_ALIGN(pos_out + *len) - 1); /* If we're altering the file contents... */ - if (!is_dedupe) { + if (!(remap_flags & REMAP_FILE_DEDUP)) { /* * ...update the timestamps (which will grab the ilock again * from xfs_fs_dirty_inode, so we have to call it before we @@ -1410,7 +1411,7 @@ xfs_reflink_remap_range( struct file *file_out, loff_t pos_out, u64 len, - bool is_dedupe) + unsigned int remap_flags) { struct inode *inode_in = file_inode(file_in); struct xfs_inode *src = XFS_I(inode_in); @@ -1430,7 +1431,7 @@ xfs_reflink_remap_range( /* Prepare and then clone file data. */ ret = xfs_reflink_remap_prep(file_in, pos_in, file_out, pos_out, - &len, is_dedupe); + &len, remap_flags); if (ret <= 0) return ret; @@ -1457,7 +1458,7 @@ xfs_reflink_remap_range( cowextsize = src->i_d.di_cowextsize; ret = xfs_reflink_update_dest(dest, pos_out + len, cowextsize, - is_dedupe); + remap_flags); out_unlock: xfs_reflink_remap_unlock(file_in, file_out); diff --git a/fs/xfs/xfs_reflink.h b/fs/xfs/xfs_reflink.h index c585ad9552b2..6f82d628bf17 100644 --- a/fs/xfs/xfs_reflink.h +++ b/fs/xfs/xfs_reflink.h @@ -28,7 +28,8 @@ extern int xfs_reflink_end_cow(struct xfs_inode *ip, xfs_off_t offset, xfs_off_t count); extern int xfs_reflink_recover_cow(struct xfs_mount *mp); extern int xfs_reflink_remap_range(struct file *file_in, loff_t pos_in, - struct file *file_out, loff_t pos_out, u64 len, bool is_dedupe); + struct file *file_out, loff_t pos_out, u64 len, + unsigned int remap_flags); extern int xfs_reflink_inode_has_shared_extents(struct xfs_trans *tp, struct xfs_inode *ip, bool *has_shared); extern int xfs_reflink_clear_inode_flag(struct xfs_inode *ip, diff --git a/include/linux/fs.h b/include/linux/fs.h index 794d1b83eded..c2800953937a 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1839,7 +1839,7 @@ extern ssize_t vfs_copy_file_range(struct file *, loff_t , struct file *, loff_t, size_t, unsigned int); extern int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, - u64 *count, bool is_dedupe); + u64 *count, unsigned int remap_flags); extern int do_clone_file_range(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, u64 len); extern int vfs_clone_file_range(struct file *file_in, loff_t pos_in, From patchwork Tue Oct 16 03:11:19 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: 10642849 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 077C817D2 for ; Tue, 16 Oct 2018 03:11:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E92C5212DB for ; Tue, 16 Oct 2018 03:11:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DCD852988C; Tue, 16 Oct 2018 03:11:27 +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 6BD36212DB for ; Tue, 16 Oct 2018 03:11:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EF38B6B0277; Mon, 15 Oct 2018 23:11:25 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id ECABA6B0278; Mon, 15 Oct 2018 23:11:25 -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 D94026B0279; Mon, 15 Oct 2018 23:11:25 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by kanga.kvack.org (Postfix) with ESMTP id AE6FC6B0277 for ; Mon, 15 Oct 2018 23:11:25 -0400 (EDT) Received: by mail-qk1-f200.google.com with SMTP id l75-v6so22094111qke.23 for ; Mon, 15 Oct 2018 20:11:25 -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=3p9QiOkfa8h9mw3zC6wMgXppY9cjHOCTYbdPvwFdVO8=; b=roCLF4qMWjf/crc0uHHQ9eMBpXVAdtXO7u2XPwxqSHXWurmONZh5wIhlQUGcmoVy8A J+t2pwJRkaTRRWVEiTxjlip776HR7zm4h2RAqX5dfrVIAVyni+nN5z3efETzuk5ZskQV 97g+Z+nOU/8y847sqYNR21xnHXjStHKu+XA2zhwNgzSRmycMATspK+PcM5GA3U5DXU9Y 3fUeed2wqk55gXeNzzHtF2JoCpcjnouD2ur8fzKCO4F8cy4v7zExIONl8ImxDCvR+jSZ FxKbknKnNvga1RCEuXUHQcaiXNskkHTPv5hM+f4a8T43UyvUXxBG/XvFG39bfPPWKYKc QbBw== X-Gm-Message-State: ABuFfog4HHmfyhR/6odpESlrpac3XO+euNC/OHNOdCIh5BOjVK+OwMmT sHfgpTaqbe1ksGxM6NQn9Wol1IKSut0FiWOfLUPQUDgZ808blP78kmnu1wTNce7hUsIFnGLfpb3 Qu6t6mKHZiqrY+M5bvM+JIYq7rsfyMN1u8P+ebE6yNx8GlfjRrWCxHepukHJy6+nTwQ== X-Received: by 2002:ac8:435b:: with SMTP id a27-v6mr18475668qtn.295.1539659485500; Mon, 15 Oct 2018 20:11:25 -0700 (PDT) X-Google-Smtp-Source: ACcGV62pXNCINEzzQ7JLzfdVvp5BHpSDaN3ltF4qbxoGDaGgivHwb0a861uT1hb6nRoO28V6Nc/1 X-Received: by 2002:ac8:435b:: with SMTP id a27-v6mr18475650qtn.295.1539659485040; Mon, 15 Oct 2018 20:11:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539659485; cv=none; d=google.com; s=arc-20160816; b=a3R5w9sBiBFA/I8Bx/V4gLASmq4kife/kM7R8F7bEp109Z4ZmCT5oLPnvIj+ZSKpzI PTfXWW34hfXB80hyG4eDUQVNX4g1QDZ2mvbIfrICfZn5ByhY6LeXqqpXn01YIV2ZGFYA EDV+a+nVB6RBCzsdZy6QknmHuzdI47g2QEDo0LDsS2+FNs0Dt5KxyMA2bLWrfzZmppst xYfxqMs/biUVrXjdlNvcn2wLidUVhG8HTSGgH9G/v28fkMecxjvEkRFIGtQiEG8JD0qA sWoUR0ly/3gHpyog1Uh8Mp3eecP3rlDJtSXk2KZ42L75DetT2S67QCTsZiLxLIPKS34q SRYA== 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=3p9QiOkfa8h9mw3zC6wMgXppY9cjHOCTYbdPvwFdVO8=; b=f49pH45SMm1b9jhwUmDYzSTAykVH4kpMg9/SOQJ8raBQen/rSvSy6uiiKc++k+BKJ1 7LAHxGOl2DO2y+jMsBxCTh9zSlezsMpy8rV3XfggQrmNU1ttggs3AUGGW6w4eskEH6x9 6i+EzRgdD5OlOzZ1BYo1+Wf0bHuuBcsy/jMWwHGn1WBeSNbKT5ZW9BBas2jtVeKXvr3v 31WMrlQSWd4uXBTTEzZajn41jc+IuORZL9ZLgDydzXUc+C29MZ63UaVfTvm9F7UqKD7j w1xsfLXZ+XI7JSQdkjTlELAgV01mTXLh0A/KM98t4nqUqS9ndbXgLQ1NHP4w4eVdK+VC B+mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=K76nLdhT; 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 n7si3545865qvp.165.2018.10.15.20.11.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 20:11:25 -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=K76nLdhT; 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 w9G38gOw194183; Tue, 16 Oct 2018 03:11:23 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=3p9QiOkfa8h9mw3zC6wMgXppY9cjHOCTYbdPvwFdVO8=; b=K76nLdhT6z9//J9WzFChKCPByxZCJ3bcnKeQCRf7+O3k8IYOKZC23DpxdiJrv+Bk5xXQ xa1Nvo5eEQJMrMX15uCsVKr1pQV98+F+iZlkV7KaPHC/7FYkFKQmR+Tifepl9n/Ggx+B lHJ+ft5aXUUCXWDmlkwcMZ2vpeW/PKb3JxGpgjZygVNltJJXUp8JEfevSY1LyVnaW/5v 7hlLCmyTT6urnozlcbkCG0H2eKFUh9QLA/O/VoUvUZBhcCf3VbHSF2MHIpJbu5xRVw1k hKNnk7U2qw2NgyALk9dlvHm4ufqEHatYvfxg8G6JaIuIeI7YQTBVh9wdJHfmROQbOaPH 2w== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2120.oracle.com with ESMTP id 2n39br5rj5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:11:23 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3BLJR030688 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:11:21 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w9G3BKo0004163; Tue, 16 Oct 2018 03:11:20 GMT Received: from localhost (/10.159.227.150) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 15 Oct 2018 20:11:20 -0700 Subject: [PATCH 12/26] vfs: pass remap flags to generic_remap_checks 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: Mon, 15 Oct 2018 20:11:19 -0700 Message-ID: <153965947897.1256.9976516083702922569.stgit@magnolia> In-Reply-To: <153965939489.1256.7400115244528045860.stgit@magnolia> References: <153965939489.1256.7400115244528045860.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9047 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=470 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810160026 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 Pass the same remap flags to generic_remap_checks for consistency. Signed-off-by: Darrick J. Wong Reviewed-by: Amir Goldstein Reviewed-by: Christoph Hellwig --- fs/read_write.c | 2 +- include/linux/fs.h | 2 +- mm/filemap.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index 201381689284..ebcbfc4f2907 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1782,7 +1782,7 @@ int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, /* Check that we don't violate system file offset limits. */ ret = generic_remap_checks(file_in, pos_in, file_out, pos_out, len, - (remap_flags & REMAP_FILE_DEDUP)); + remap_flags); if (ret) return ret; diff --git a/include/linux/fs.h b/include/linux/fs.h index c2800953937a..1aa3bc1bb092 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2981,7 +2981,7 @@ extern int generic_file_readonly_mmap(struct file *, struct vm_area_struct *); extern ssize_t generic_write_checks(struct kiocb *, struct iov_iter *); extern int generic_remap_checks(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, - uint64_t *count, bool is_dedupe); + uint64_t *count, unsigned int remap_flags); extern ssize_t generic_file_read_iter(struct kiocb *, struct iov_iter *); extern ssize_t __generic_file_write_iter(struct kiocb *, struct iov_iter *); extern ssize_t generic_file_write_iter(struct kiocb *, struct iov_iter *); diff --git a/mm/filemap.c b/mm/filemap.c index 08ad210fee49..b0f1f6d93d9c 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3001,7 +3001,7 @@ EXPORT_SYMBOL(generic_write_checks); */ int generic_remap_checks(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, - uint64_t *req_count, bool is_dedupe) + uint64_t *req_count, unsigned int remap_flags) { struct inode *inode_in = file_in->f_mapping->host; struct inode *inode_out = file_out->f_mapping->host; @@ -3023,7 +3023,7 @@ int generic_remap_checks(struct file *file_in, loff_t pos_in, size_out = i_size_read(inode_out); /* Dedupe requires both ranges to be within EOF. */ - if (is_dedupe && + if ((remap_flags & REMAP_FILE_DEDUP) && (pos_in >= size_in || pos_in + count > size_in || pos_out >= size_out || pos_out + count > size_out)) return -EINVAL; From patchwork Tue Oct 16 03:19:26 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: 10642875 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 871E317D2 for ; Tue, 16 Oct 2018 03:19:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC7DF29ABC for ; Tue, 16 Oct 2018 03:19:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DE3DD299BC; Tue, 16 Oct 2018 03:19:36 +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 67BBC299BC for ; Tue, 16 Oct 2018 03:19:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3F18D6B0279; Mon, 15 Oct 2018 23:19:35 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3A2A26B027A; Mon, 15 Oct 2018 23:19:35 -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 269BA6B027B; Mon, 15 Oct 2018 23:19:35 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by kanga.kvack.org (Postfix) with ESMTP id DC2B36B0279 for ; Mon, 15 Oct 2018 23:19:34 -0400 (EDT) Received: by mail-pl1-f197.google.com with SMTP id f59-v6so17185626plb.5 for ; Mon, 15 Oct 2018 20:19:34 -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=2Mwz+Jm1Vv6DSly8RfSjLjmTysY9FOE+4U51VEcOuGA=; b=i2pii+QHhOuDVy/oESSaAf/3sh/EOH99YOyLoh3ZR9GkzRHlcblss4ZVvqk85lrM7G 2aeIMxYunWxO0v1EA/rwOoxzqGe/w5IHQXY1BUay/f18XbuIkHx+bhmibMu6uwqrAYEM f4APEGHO2g12eFDhL9yrqgkXoVgTlHSvel99I/1MmOi9xYEtuYwMc1mtdoCVhbzDemKS 8Lb0t+maYIRh2yNXj561SmnTnLtAI/fGNYDhe8rifJ3FpaAGFpnyJTPEbq+3GvHWFMp6 9fho37llu5W2bgk4M4jb879IFBrdneyiZ5r0NC6Tr/PSzfmJ3dvnmDmXq8Ykk5fC8PmR 2NbQ== X-Gm-Message-State: ABuFfoj7VwRz5W3w6Yfb0QByDyqv/8dnWVhcrE6Fd8rCoiHI/WZKuE8N +PIPohCazVl6NqDKSgc0aycOrs8Kt8fvanEc2dTf1UmqnMhVmYdZXvzOFSgV1ePpDCy+W6bnTI/ DOfcymt9hXN/wfTqUahkbhXEI06XpM5ycDhbrrMgrpHNCcEev4RDgcZBQCk1qCAI9hg== X-Received: by 2002:a17:902:9a07:: with SMTP id v7-v6mr19147657plp.14.1539659974253; Mon, 15 Oct 2018 20:19:34 -0700 (PDT) X-Google-Smtp-Source: ACcGV630UFWCi0iXyB7vi/vmICsu24UDCmtJz/WxUjhQsM/GqeW3oS9evCVJ/gnj8pC2+r9tcyMQ X-Received: by 2002:a17:902:9a07:: with SMTP id v7-v6mr19147625plp.14.1539659973417; Mon, 15 Oct 2018 20:19:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539659973; cv=none; d=google.com; s=arc-20160816; b=M+pOq+K2NQZZ4ZqfA/qsUQvrX57Hn11d3+pLzMex51F/xQ2Zh8DpopFJnftrQuy6L+ ZzptF1MsH9ersGMjSA9FpHxTCqdgDjnOSptdNas/0sj6rwozqCxWFPuOS6WG5B46w+y9 8XYYBcYYUvxs1R1x5i/WKSzX+H5CLLw6lLocAv2s9xkihV5+IdLPag967PpaoePDynEE FD6MQtoH6wD8MgsQLtBCVeZXVfXAUCvWdmWNWGaEQ048+9C3E1djuZY6Mzr3ZKywf7oH K2SAgHryC5OTgrJlM4k0+Zyr60PJfZQEgKnLZGt5cDNjHDIjJ3UTD7xd5a4lUOuYrnkH eonQ== 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=2Mwz+Jm1Vv6DSly8RfSjLjmTysY9FOE+4U51VEcOuGA=; b=bZ+f4GPk9FrR3ceItmgXsUAzBnI3FaOd7V7WIS3oDcttZUbdN7D0TZD3Z2yWWKYygw GJqPpy5MIwUMRRl9lLuyPt/gk3+MCebcvLZYLtkCm/h5LQLH0sr80T9OOpGvn+QBDntI tDZXj0MZqsFE8QZg1uBSvjrE3ANvN/ukEiOArfHCmcOKuKX0TJ0mqtItqel4PuIJIJ4i eDqZo7Dlar3qJLHqLAXS5YwPJMr6+2NEe/kdLjDoU0Fl0RrcYJxYRbwUv3kh6/2FZg33 QvsrTw6gU5xJ0iO+gRt1vR4IorfjrFfOFhFdadxZbRTrJeh9vml7M5zc36U2wVH8Zt/a hDLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=QyfeosX1; spf=pass (google.com: domain of darrick.wong@oracle.com designates 141.146.126.78 as permitted sender) smtp.mailfrom=darrick.wong@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from aserp2120.oracle.com (aserp2120.oracle.com. [141.146.126.78]) by mx.google.com with ESMTPS id l91-v6si12934147plb.315.2018.10.15.20.19.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 20:19:33 -0700 (PDT) Received-SPF: pass (google.com: domain of darrick.wong@oracle.com designates 141.146.126.78 as permitted sender) client-ip=141.146.126.78; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=QyfeosX1; spf=pass (google.com: domain of darrick.wong@oracle.com designates 141.146.126.78 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 (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w9G3JMpO060270; Tue, 16 Oct 2018 03:19:31 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=2Mwz+Jm1Vv6DSly8RfSjLjmTysY9FOE+4U51VEcOuGA=; b=QyfeosX11lkm+R6FJaSex5a7QxpympeeUy+dEEs9LKcGmvkOjbmr5b5J42Y4L8kKr8jP MWHQFqrh7+0Btd+SC4wQED5K+Z7Qao9bJJuFGTprbpx7sofYa7z8KCZXd+7Ij4P7EK7K Cf8tB5t/gAlpy1jcqWV+QKaLlLUtV1HRm9m+rcUt90RHgqeIcq3QMawvy3a2XTE4v0UE Oo3BAZ/uV/C3sUdMJ0/03DTL9bkT0Klnm3D4tD8cmX79Rf3eoAVBfw6w+O18hAEHE40G 5qhtdTc/xjY9MDG3MQXzblfJtk8pVlt2ZitpFkBAoaLtI84yG1vMR1/rdJltfHCrfRYQ /w== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2120.oracle.com with ESMTP id 2n38npwvev-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:19:30 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3JTuR003181 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:19:29 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w9G3JSGX007232; Tue, 16 Oct 2018 03:19:28 GMT Received: from localhost (/10.159.227.150) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 15 Oct 2018 20:19:28 -0700 Subject: [PATCH 13/26] vfs: create generic_remap_file_range_touch to update inode metadata 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: Mon, 15 Oct 2018 20:19:26 -0700 Message-ID: <153965996673.3607.133184523000924340.stgit@magnolia> In-Reply-To: <153965939489.1256.7400115244528045860.stgit@magnolia> References: <153965939489.1256.7400115244528045860.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9047 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=853 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810160028 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 new VFS helper to handle inode metadata updates when remapping into a file. If the operation can possibly alter the file contents, we must update the ctime and mtime and remove security privileges, just like we do for regular file writes. Wire up ocfs2 to ensure consistent behavior. Signed-off-by: Darrick J. Wong Reviewed-by: Amir Goldstein --- fs/read_write.c | 28 ++++++++++++++++++++++++++++ fs/xfs/xfs_reflink.c | 23 ----------------------- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index ebcbfc4f2907..3f6392f1d5d4 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1737,6 +1737,30 @@ static int generic_remap_check_len(struct inode *inode_in, return 0; } +/* Update inode timestamps and remove security privileges when remapping. */ +static int generic_remap_file_range_target(struct file *file, + unsigned int remap_flags) +{ + int ret; + + /* If can't alter the file contents, we're done. */ + if (remap_flags & REMAP_FILE_DEDUP) + return 0; + + /* Update the timestamps, since we can alter file contents. */ + if (!(file->f_mode & FMODE_NOCMTIME)) { + ret = file_update_time(file); + if (ret) + return ret; + } + + /* + * Clear the security bits if the process is not being run by root. + * This keeps people from modifying setuid and setgid binaries. + */ + return file_remove_privs(file); +} + /* * Check that the two inodes are eligible for cloning, the ranges make * sense, and then flush all dirty data. Caller must ensure that the @@ -1820,6 +1844,10 @@ int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, if (ret) return ret; + ret = generic_remap_file_range_target(file_out, remap_flags); + if (ret) + return ret; + return 1; } EXPORT_SYMBOL(generic_remap_file_range_prep); diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index 29aab196ce7e..2d7dd8b28d7c 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -1372,29 +1372,6 @@ xfs_reflink_remap_prep( truncate_inode_pages_range(&inode_out->i_data, pos_out, PAGE_ALIGN(pos_out + *len) - 1); - /* If we're altering the file contents... */ - if (!(remap_flags & REMAP_FILE_DEDUP)) { - /* - * ...update the timestamps (which will grab the ilock again - * from xfs_fs_dirty_inode, so we have to call it before we - * take the ilock). - */ - if (!(file_out->f_mode & FMODE_NOCMTIME)) { - ret = file_update_time(file_out); - if (ret) - goto out_unlock; - } - - /* - * ...clear the security bits if the process is not being run - * by root. This keeps people from modifying setuid and setgid - * binaries. - */ - ret = file_remove_privs(file_out); - if (ret) - goto out_unlock; - } - return 1; out_unlock: xfs_reflink_remap_unlock(file_in, file_out); From patchwork Tue Oct 16 03:19:33 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: 10642889 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 9A94E5CAF for ; Tue, 16 Oct 2018 03:19:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 84F0729AF7 for ; Tue, 16 Oct 2018 03:19:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 75DC929AFD; Tue, 16 Oct 2018 03:19:44 +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 1590229AFD for ; Tue, 16 Oct 2018 03:19:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0C0C16B027A; Mon, 15 Oct 2018 23:19:42 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F39A16B027D; Mon, 15 Oct 2018 23:19:41 -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 DB5706B027E; Mon, 15 Oct 2018 23:19:41 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by kanga.kvack.org (Postfix) with ESMTP id 86A2E6B027A for ; Mon, 15 Oct 2018 23:19:41 -0400 (EDT) Received: by mail-pl1-f200.google.com with SMTP id c4-v6so17128241plz.20 for ; Mon, 15 Oct 2018 20:19:41 -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=nesA5JY6mqKDsd7ZyfRy+faA8oQ5iyhcx7Osw/99+C0=; b=juzcnrrVmSdWR78HHUT7yufkSWsBbXTvWJdNbee+KSPiT2sMw+6OX9VityJ4YPwzF+ Z7AHjK20pKGMw8chIR38JpJPvoAF8QZu5rH9c0ll9uBZNa8jgi/aNJxIt4dBxlvn0ELv 8NqUNFKOopV9iAA85At+6+34WJp2PM54d5fvoPV8WyC0XHvx6f/xzicsZ+CdWWke9qWr erLCsQL/JPQxykftK7sRwmnPZ60yT/T1RIAqeEy09gwZ0W2QdoJmqdVdzUx7eKYETltZ 32CDvH6bbtJ8r55mtoqh2wS3Kn9Z2K2qe9q7FU04TgHtzTAu03Gj+Cz/TtpIzGgv3c20 9XLA== X-Gm-Message-State: ABuFfogTtplDO0fWctsPkeo41tKD5zTKwKotZ6t4KZc9aMTiBV1gTiLF 10B3PFI2FdNCcndzGFYKgCDUQNnIBF3FyGLNfIsMS45MsElbm/OdiD7RlHOQDmGwnpqPHIUhKjQ iOKu+6r/d2zo3UQHuL1z5NJ6Og6Rz8QJG7e2P+8PM09s/Tomn6DGV05tH5J0KyjluIg== X-Received: by 2002:a17:902:5602:: with SMTP id h2-v6mr19504191pli.220.1539659981155; Mon, 15 Oct 2018 20:19:41 -0700 (PDT) X-Google-Smtp-Source: ACcGV62Xp3AopwB+wBjPMLAc0QHF2YWRsZQt9eJgQ76hYna9Arw2CStahe8pn6v8mFGvri/v9aRI X-Received: by 2002:a17:902:5602:: with SMTP id h2-v6mr19504123pli.220.1539659979510; Mon, 15 Oct 2018 20:19:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539659979; cv=none; d=google.com; s=arc-20160816; b=MBKkfK1vXqb8TIer5l/MT4+Lwu7lxOHEB2ivFNPZqwVQdzIZu0d4eo5nRE1DbLZNmJ cLzdx28WPrX+K0HXAV5/laCsoswd3PLQAM6wDKhnONRoTwVOnYBJF3fKS2ItqEW9neSd YieMWkLMxwHSJ6SUft7stchQu1GPZhraDTQo9l7ilpxqXJ43uIUm0EVMsFLSwzm30iV1 S9bM8SIqH3nMSwF8iqyJhqL9AldDfUn3epY8MhGHaNHSeVu3U6nTSFVoUP6u7ssNIgnm EEcJpMUGoCifxGGcmV37SZxl9spRusDsodbtcLwBYZh5Zp9nmmVROiIrsw24J6LnLLFm Ql4A== 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=nesA5JY6mqKDsd7ZyfRy+faA8oQ5iyhcx7Osw/99+C0=; b=HpptQU6x6ch6IiTrDGCGqKnt1XaijPZkNqMa1bOXIcfze9BuNWYELwcWGZ7dd5rzYa Q3fOlqV0b8Mdx8r0cGbBr5AjOmHMws3kp2kSBU4kupDe3rBjanHC/n+U2+vm4fspsJHT pyPMkL/Zc87brodltGB/frmBWq5a6FIsGgn3u4RqtzplRC+MQuvoYS6LmSY1OoVf/PUa hrNDyThdHP6uedNjhcWYbhTE/zv9ZwxQ0I8+0sgvSZLVwhYyPIWORXL9gfo6PNfL9hk8 O0G+l9bEdy2eXwOmumC1NhXIfYn6R6kuOPDwEdabWc9FEwL7D4zBzT2LwqieUlQvEeBE k11g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=WeWv5c6c; 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 j5-v6si12155366plk.145.2018.10.15.20.19.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 20:19:39 -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=WeWv5c6c; 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 w9G3J0s1005214; Tue, 16 Oct 2018 03:19:37 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=nesA5JY6mqKDsd7ZyfRy+faA8oQ5iyhcx7Osw/99+C0=; b=WeWv5c6cXTeU0i/GwGf4SbaLHjypMeuaqK0WuQx/MoHxzZQhgFVVSNvaFUsOsd3nu2cZ y2IyUO/Iv7PQ6cuTGz99Y1CSgy+d8vPiiTc19DEo+hNcehQtBGM2tlbdYO7hiru4vAty y4x39gXjV+UEVr6wCb+u5Rc9DR+/HMSPkR3a+XN23evYshS567twltTixrQziHfNeRx0 wB5OVptbvk8H6U+Qql8zhA6lXQ3g8Kwv9DOQXy7/TzC49/ngpS6ynKeLnnGL2QEHHpg4 rU+0iD5aiIL6B/4pKSXmcT/1l98hp+jM/lfSz18xSEVE98Qg/AFSllosvA1mqWtwLPKL Sw== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2120.oracle.com with ESMTP id 2n39br5s1q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:19:37 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3JZaX016563 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:19:36 GMT Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3JZur010449; Tue, 16 Oct 2018 03:19:35 GMT Received: from localhost (/10.159.227.150) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 15 Oct 2018 20:19:35 -0700 Subject: [PATCH 14/26] vfs: make remap_file_range functions take and return bytes completed 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: Mon, 15 Oct 2018 20:19:33 -0700 Message-ID: <153965997357.3607.11758898576797485849.stgit@magnolia> In-Reply-To: <153965939489.1256.7400115244528045860.stgit@magnolia> References: <153965939489.1256.7400115244528045860.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9047 signatures=668706 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=941 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810160028 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 Change the remap_file_range functions to take a number of bytes to operate upon and return the number of bytes they operated on. This is a requirement for allowing fs implementations to return short clone/dedupe results to the user, which will enable us to obey resource limits in a graceful manner. A subsequent patch will enable copy_file_range to signal to the ->clone_file_range implementation that it can handle a short length, which will be returned in the function's return value. For now the short return is not implemented anywhere so the behavior won't change -- either copy_file_range manages to clone the entire range or it tries an alternative. Neither clone ioctl can take advantage of this, alas. Signed-off-by: Darrick J. Wong Reviewed-by: Amir Goldstein --- Documentation/filesystems/vfs.txt | 6 ++--- fs/btrfs/ctree.h | 6 ++--- fs/btrfs/ioctl.c | 13 ++++++---- fs/cifs/cifsfs.c | 6 ++--- fs/ioctl.c | 10 +++++++- fs/nfs/nfs4file.c | 6 ++--- fs/nfsd/vfs.c | 8 +++++- fs/ocfs2/file.c | 16 ++++++------ fs/ocfs2/refcounttree.c | 2 +- fs/ocfs2/refcounttree.h | 2 +- fs/overlayfs/copy_up.c | 6 ++--- fs/overlayfs/file.c | 12 +++++---- fs/read_write.c | 49 ++++++++++++++++++++----------------- fs/xfs/xfs_file.c | 9 +++++-- fs/xfs/xfs_reflink.c | 4 ++- fs/xfs/xfs_reflink.h | 2 +- include/linux/fs.h | 27 +++++++++++--------- mm/filemap.c | 2 +- 18 files changed, 106 insertions(+), 80 deletions(-) diff --git a/Documentation/filesystems/vfs.txt b/Documentation/filesystems/vfs.txt index bb3183334ab9..8ba47d9d6cae 100644 --- a/Documentation/filesystems/vfs.txt +++ b/Documentation/filesystems/vfs.txt @@ -883,9 +883,9 @@ struct file_operations { unsigned (*mmap_capabilities)(struct file *); #endif ssize_t (*copy_file_range)(struct file *, loff_t, struct file *, loff_t, size_t, unsigned int); - int (*remap_file_range)(struct file *file_in, loff_t pos_in, - struct file *file_out, loff_t pos_out, - u64 len, unsigned int remap_flags); + loff_t (*remap_file_range)(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + loff_t len, unsigned int remap_flags); int (*fadvise)(struct file *, loff_t, loff_t, int); }; diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 124a05662fc2..771a961d77ad 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -3247,9 +3247,9 @@ int btrfs_dirty_pages(struct inode *inode, struct page **pages, size_t num_pages, loff_t pos, size_t write_bytes, struct extent_state **cached); int btrfs_fdatawrite_range(struct inode *inode, loff_t start, loff_t end); -int btrfs_remap_file_range(struct file *file_in, loff_t pos_in, - struct file *file_out, loff_t pos_out, u64 len, - unsigned int remap_flags); +loff_t btrfs_remap_file_range(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + loff_t len, unsigned int remap_flags); /* tree-defrag.c */ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans, diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index bfd99c66723e..b0c513e10977 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -4328,10 +4328,12 @@ static noinline int btrfs_clone_files(struct file *file, struct file *file_src, return ret; } -int btrfs_remap_file_range(struct file *src_file, loff_t off, - struct file *dst_file, loff_t destoff, u64 len, +loff_t btrfs_remap_file_range(struct file *src_file, loff_t off, + struct file *dst_file, loff_t destoff, loff_t len, unsigned int remap_flags) { + int ret; + if (remap_flags & ~(REMAP_FILE_DEDUP | REMAP_FILE_ADVISORY)) return -EINVAL; @@ -4349,10 +4351,11 @@ int btrfs_remap_file_range(struct file *src_file, loff_t off, return -EINVAL; } - return btrfs_extent_same(src, off, len, dst, destoff); + ret = btrfs_extent_same(src, off, len, dst, destoff); + } else { + ret = btrfs_clone_files(dst_file, src_file, off, len, destoff); } - - return btrfs_clone_files(dst_file, src_file, off, len, destoff); + return ret < 0 ? ret : len; } static long btrfs_ioctl_default_subvol(struct file *file, void __user *argp) diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index e8144d0dcde2..5ca71c6c8be2 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -975,8 +975,8 @@ const struct inode_operations cifs_symlink_inode_ops = { .listxattr = cifs_listxattr, }; -static int cifs_remap_file_range(struct file *src_file, loff_t off, - struct file *dst_file, loff_t destoff, u64 len, +static loff_t cifs_remap_file_range(struct file *src_file, loff_t off, + struct file *dst_file, loff_t destoff, loff_t len, unsigned int remap_flags) { struct inode *src_inode = file_inode(src_file); @@ -1029,7 +1029,7 @@ static int cifs_remap_file_range(struct file *src_file, loff_t off, unlock_two_nondirectories(src_inode, target_inode); out: free_xid(xid); - return rc; + return rc < 0 ? rc : len; } ssize_t cifs_file_copychunk_range(unsigned int xid, diff --git a/fs/ioctl.c b/fs/ioctl.c index 2005529af560..72537b68c272 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -223,6 +223,7 @@ static long ioctl_file_clone(struct file *dst_file, unsigned long srcfd, u64 off, u64 olen, u64 destoff) { struct fd src_file = fdget(srcfd); + loff_t cloned; int ret; if (!src_file.file) @@ -230,7 +231,14 @@ static long ioctl_file_clone(struct file *dst_file, unsigned long srcfd, ret = -EXDEV; if (src_file.file->f_path.mnt != dst_file->f_path.mnt) goto fdput; - ret = vfs_clone_file_range(src_file.file, off, dst_file, destoff, olen); + cloned = vfs_clone_file_range(src_file.file, off, dst_file, destoff, + olen); + if (cloned < 0) + ret = cloned; + else if (olen && cloned != olen) + ret = -EINVAL; + else + ret = 0; fdput: fdput(src_file); return ret; diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c index ae5780ce41dc..46d691ba04bc 100644 --- a/fs/nfs/nfs4file.c +++ b/fs/nfs/nfs4file.c @@ -180,8 +180,8 @@ static long nfs42_fallocate(struct file *filep, int mode, loff_t offset, loff_t return nfs42_proc_allocate(filep, offset, len); } -static int nfs42_remap_file_range(struct file *src_file, loff_t src_off, - struct file *dst_file, loff_t dst_off, u64 count, +static loff_t nfs42_remap_file_range(struct file *src_file, loff_t src_off, + struct file *dst_file, loff_t dst_off, loff_t count, unsigned int remap_flags) { struct inode *dst_inode = file_inode(dst_file); @@ -244,7 +244,7 @@ static int nfs42_remap_file_range(struct file *src_file, loff_t src_off, inode_unlock(src_inode); } out: - return ret; + return ret < 0 ? ret : count; } #endif /* CONFIG_NFS_V4_2 */ diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index b53e76391e52..ac6cb6101cbe 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -541,8 +541,12 @@ __be32 nfsd4_set_nfs4_label(struct svc_rqst *rqstp, struct svc_fh *fhp, __be32 nfsd4_clone_file_range(struct file *src, u64 src_pos, struct file *dst, u64 dst_pos, u64 count) { - return nfserrno(vfs_clone_file_range(src, src_pos, dst, dst_pos, - count)); + loff_t cloned; + + cloned = vfs_clone_file_range(src, src_pos, dst, dst_pos, count); + if (count && cloned != count) + cloned = -EINVAL; + return nfserrno(cloned < 0 ? cloned : 0); } ssize_t nfsd_copy_file_range(struct file *src, u64 src_pos, struct file *dst, diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c index 9809b0e5746f..fbaeafe44b5f 100644 --- a/fs/ocfs2/file.c +++ b/fs/ocfs2/file.c @@ -2527,18 +2527,18 @@ static loff_t ocfs2_file_llseek(struct file *file, loff_t offset, int whence) return offset; } -static int ocfs2_remap_file_range(struct file *file_in, - loff_t pos_in, - struct file *file_out, - loff_t pos_out, - u64 len, - unsigned int remap_flags) +static loff_t ocfs2_remap_file_range(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + loff_t len, unsigned int remap_flags) { + int ret; + if (remap_flags & ~(REMAP_FILE_DEDUP | REMAP_FILE_ADVISORY)) return -EINVAL; - return ocfs2_reflink_remap_range(file_in, pos_in, file_out, pos_out, - len, remap_flags); + ret = ocfs2_reflink_remap_range(file_in, pos_in, file_out, pos_out, + len, remap_flags); + return ret < 0 ? ret : len; } const struct inode_operations ocfs2_file_iops = { diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c index df9781567ec0..6a42c04ac0ab 100644 --- a/fs/ocfs2/refcounttree.c +++ b/fs/ocfs2/refcounttree.c @@ -4824,7 +4824,7 @@ int ocfs2_reflink_remap_range(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, - u64 len, + loff_t len, unsigned int remap_flags) { struct inode *inode_in = file_inode(file_in); diff --git a/fs/ocfs2/refcounttree.h b/fs/ocfs2/refcounttree.h index d2c5f526edff..eb65c1d0843c 100644 --- a/fs/ocfs2/refcounttree.h +++ b/fs/ocfs2/refcounttree.h @@ -119,7 +119,7 @@ int ocfs2_reflink_remap_range(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, - u64 len, + loff_t len, unsigned int remap_flags); #endif /* OCFS2_REFCOUNTTREE_H */ diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c index 1cc797a08a5b..8750b7235516 100644 --- a/fs/overlayfs/copy_up.c +++ b/fs/overlayfs/copy_up.c @@ -125,6 +125,7 @@ static int ovl_copy_up_data(struct path *old, struct path *new, loff_t len) struct file *new_file; loff_t old_pos = 0; loff_t new_pos = 0; + loff_t cloned; int error = 0; if (len == 0) @@ -141,11 +142,10 @@ static int ovl_copy_up_data(struct path *old, struct path *new, loff_t len) } /* Try to use clone_file_range to clone up within the same fs */ - error = do_clone_file_range(old_file, 0, new_file, 0, len); - if (!error) + cloned = do_clone_file_range(old_file, 0, new_file, 0, len); + if (cloned == len) goto out; /* Couldn't clone, so now we try to copy the data */ - error = 0; /* FIXME: copy up sparse files efficiently */ while (len) { diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c index fffb36fd5920..6c3fec6168e9 100644 --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -434,14 +434,14 @@ enum ovl_copyop { OVL_DEDUPE, }; -static ssize_t ovl_copyfile(struct file *file_in, loff_t pos_in, +static loff_t ovl_copyfile(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, - u64 len, unsigned int flags, enum ovl_copyop op) + loff_t len, unsigned int flags, enum ovl_copyop op) { struct inode *inode_out = file_inode(file_out); struct fd real_in, real_out; const struct cred *old_cred; - ssize_t ret; + loff_t ret; ret = ovl_real_fdget(file_out, &real_out); if (ret) @@ -489,9 +489,9 @@ static ssize_t ovl_copy_file_range(struct file *file_in, loff_t pos_in, OVL_COPY); } -static int ovl_remap_file_range(struct file *file_in, loff_t pos_in, - struct file *file_out, loff_t pos_out, - u64 len, unsigned int remap_flags) +static loff_t ovl_remap_file_range(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + loff_t len, unsigned int remap_flags) { enum ovl_copyop op; diff --git a/fs/read_write.c b/fs/read_write.c index 3f6392f1d5d4..906e78be5001 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1589,10 +1589,13 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, * more efficient if both clone and copy are supported (e.g. NFS). */ if (file_in->f_op->remap_file_range) { - ret = file_in->f_op->remap_file_range(file_in, pos_in, - file_out, pos_out, len, 0); - if (ret == 0) { - ret = len; + loff_t cloned; + + cloned = file_in->f_op->remap_file_range(file_in, pos_in, + file_out, pos_out, + min_t(loff_t, MAX_RW_COUNT, len), 0); + if (cloned > 0) { + ret = cloned; goto done; } } @@ -1686,11 +1689,12 @@ SYSCALL_DEFINE6(copy_file_range, int, fd_in, loff_t __user *, off_in, return ret; } -static int remap_verify_area(struct file *file, loff_t pos, u64 len, bool write) +static int remap_verify_area(struct file *file, loff_t pos, loff_t len, + bool write) { struct inode *inode = file_inode(file); - if (unlikely(pos < 0)) + if (unlikely(pos < 0 || len < 0)) return -EINVAL; if (unlikely((loff_t) (pos + len) < 0)) @@ -1721,7 +1725,7 @@ static int remap_verify_area(struct file *file, loff_t pos, u64 len, bool write) static int generic_remap_check_len(struct inode *inode_in, struct inode *inode_out, loff_t pos_out, - u64 *len, + loff_t *len, unsigned int remap_flags) { u64 blkmask = i_blocksize(inode_in) - 1; @@ -1771,7 +1775,7 @@ static int generic_remap_file_range_target(struct file *file, */ int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, - u64 *len, unsigned int remap_flags) + loff_t *len, unsigned int remap_flags) { struct inode *inode_in = file_inode(file_in); struct inode *inode_out = file_inode(file_out); @@ -1852,12 +1856,12 @@ int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, } EXPORT_SYMBOL(generic_remap_file_range_prep); -int do_clone_file_range(struct file *file_in, loff_t pos_in, - struct file *file_out, loff_t pos_out, u64 len) +loff_t do_clone_file_range(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, loff_t len) { struct inode *inode_in = file_inode(file_in); struct inode *inode_out = file_inode(file_out); - int ret; + loff_t ret; if (S_ISDIR(inode_in->i_mode) || S_ISDIR(inode_out->i_mode)) return -EISDIR; @@ -1890,19 +1894,19 @@ int do_clone_file_range(struct file *file_in, loff_t pos_in, ret = file_in->f_op->remap_file_range(file_in, pos_in, file_out, pos_out, len, 0); - if (!ret) { - fsnotify_access(file_in); - fsnotify_modify(file_out); - } + if (ret < 0) + return ret; + fsnotify_access(file_in); + fsnotify_modify(file_out); return ret; } EXPORT_SYMBOL(do_clone_file_range); -int vfs_clone_file_range(struct file *file_in, loff_t pos_in, - struct file *file_out, loff_t pos_out, u64 len) +loff_t vfs_clone_file_range(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, loff_t len) { - int ret; + loff_t ret; file_start_write(file_out); ret = do_clone_file_range(file_in, pos_in, file_out, pos_out, len); @@ -2008,10 +2012,11 @@ int vfs_dedupe_file_range_compare(struct inode *src, loff_t srcoff, } EXPORT_SYMBOL(vfs_dedupe_file_range_compare); -int vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos, - struct file *dst_file, loff_t dst_pos, u64 len) +loff_t vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos, + struct file *dst_file, loff_t dst_pos, + loff_t len) { - s64 ret; + loff_t ret; ret = mnt_want_write_file(dst_file); if (ret) @@ -2060,7 +2065,7 @@ int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same) int i; int ret; u16 count = same->dest_count; - int deduped; + loff_t deduped; if (!(file->f_mode & FMODE_READ)) return -EINVAL; diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 20314eb4677a..38fde4e11714 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -919,20 +919,23 @@ xfs_file_fallocate( return error; } -STATIC int +STATIC loff_t xfs_file_remap_range( struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, - u64 len, + loff_t len, unsigned int remap_flags) { + int ret; + if (remap_flags & ~(REMAP_FILE_DEDUP | REMAP_FILE_ADVISORY)) return -EINVAL; - return xfs_reflink_remap_range(file_in, pos_in, file_out, pos_out, + ret = xfs_reflink_remap_range(file_in, pos_in, file_out, pos_out, len, remap_flags); + return ret < 0 ? ret : len; } STATIC int diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index 2d7dd8b28d7c..3dbe5fb7e9c0 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -1296,7 +1296,7 @@ xfs_reflink_remap_prep( loff_t pos_in, struct file *file_out, loff_t pos_out, - u64 *len, + loff_t *len, unsigned int remap_flags) { struct inode *inode_in = file_inode(file_in); @@ -1387,7 +1387,7 @@ xfs_reflink_remap_range( loff_t pos_in, struct file *file_out, loff_t pos_out, - u64 len, + loff_t len, unsigned int remap_flags) { struct inode *inode_in = file_inode(file_in); diff --git a/fs/xfs/xfs_reflink.h b/fs/xfs/xfs_reflink.h index 6f82d628bf17..c3c46c276fe1 100644 --- a/fs/xfs/xfs_reflink.h +++ b/fs/xfs/xfs_reflink.h @@ -28,7 +28,7 @@ extern int xfs_reflink_end_cow(struct xfs_inode *ip, xfs_off_t offset, xfs_off_t count); extern int xfs_reflink_recover_cow(struct xfs_mount *mp); extern int xfs_reflink_remap_range(struct file *file_in, loff_t pos_in, - struct file *file_out, loff_t pos_out, u64 len, + struct file *file_out, loff_t pos_out, loff_t len, unsigned int remap_flags); extern int xfs_reflink_inode_has_shared_extents(struct xfs_trans *tp, struct xfs_inode *ip, bool *has_shared); diff --git a/include/linux/fs.h b/include/linux/fs.h index 1aa3bc1bb092..f1d082af34d0 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1772,9 +1772,9 @@ struct file_operations { #endif ssize_t (*copy_file_range)(struct file *, loff_t, struct file *, loff_t, size_t, unsigned int); - int (*remap_file_range)(struct file *file_in, loff_t pos_in, - struct file *file_out, loff_t pos_out, - u64 len, unsigned int remap_flags); + loff_t (*remap_file_range)(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + loff_t len, unsigned int remap_flags); int (*fadvise)(struct file *, loff_t, loff_t, int); } __randomize_layout; @@ -1839,19 +1839,22 @@ extern ssize_t vfs_copy_file_range(struct file *, loff_t , struct file *, loff_t, size_t, unsigned int); extern int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, - u64 *count, unsigned int remap_flags); -extern int do_clone_file_range(struct file *file_in, loff_t pos_in, - struct file *file_out, loff_t pos_out, u64 len); -extern int vfs_clone_file_range(struct file *file_in, loff_t pos_in, - struct file *file_out, loff_t pos_out, u64 len); + loff_t *count, + unsigned int remap_flags); +extern loff_t do_clone_file_range(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + loff_t len); +extern loff_t vfs_clone_file_range(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + loff_t len); extern int vfs_dedupe_file_range_compare(struct inode *src, loff_t srcoff, struct inode *dest, loff_t destoff, loff_t len, bool *is_same); extern int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same); -extern int vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos, - struct file *dst_file, loff_t dst_pos, - u64 len); +extern loff_t vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos, + struct file *dst_file, loff_t dst_pos, + loff_t len); struct super_operations { @@ -2981,7 +2984,7 @@ extern int generic_file_readonly_mmap(struct file *, struct vm_area_struct *); extern ssize_t generic_write_checks(struct kiocb *, struct iov_iter *); extern int generic_remap_checks(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, - uint64_t *count, unsigned int remap_flags); + loff_t *count, unsigned int remap_flags); extern ssize_t generic_file_read_iter(struct kiocb *, struct iov_iter *); extern ssize_t __generic_file_write_iter(struct kiocb *, struct iov_iter *); extern ssize_t generic_file_write_iter(struct kiocb *, struct iov_iter *); diff --git a/mm/filemap.c b/mm/filemap.c index b0f1f6d93d9c..1e93269efafe 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3001,7 +3001,7 @@ EXPORT_SYMBOL(generic_write_checks); */ int generic_remap_checks(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, - uint64_t *req_count, unsigned int remap_flags) + loff_t *req_count, unsigned int remap_flags) { struct inode *inode_in = file_in->f_mapping->host; struct inode *inode_out = file_out->f_mapping->host; From patchwork Tue Oct 16 03:19:40 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: 10642893 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 1225217D2 for ; Tue, 16 Oct 2018 03:19:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F2C03299BC for ; Tue, 16 Oct 2018 03:19:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E619D29ABC; Tue, 16 Oct 2018 03:19:54 +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 998C6299BC for ; Tue, 16 Oct 2018 03:19:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9970F6B027D; Mon, 15 Oct 2018 23:19:52 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9464C6B027E; Mon, 15 Oct 2018 23:19:52 -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 836406B027F; Mon, 15 Oct 2018 23:19:52 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by kanga.kvack.org (Postfix) with ESMTP id 4276C6B027D for ; Mon, 15 Oct 2018 23:19:52 -0400 (EDT) Received: by mail-pg1-f197.google.com with SMTP id q143-v6so15993481pgq.12 for ; Mon, 15 Oct 2018 20:19:52 -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=NXYVyyHmVmlKAp63WiEk80Yd1QK+kCWi9LT++yfOJrk=; b=KKWwXZFKtQ56uTq/uqjuxGO2Cqz42/wQwyomPH686bHRRymO8SfhFa8a+pu6JQEsvN NiA8A3dJVWbcbNfSHGQNvOA1jutZBO3QiXDacw571q/J8vCHnb6DDTinYqAkVkNniV5g bfsbgkAftj1T6sdyN/Ok5JAr2wrpzR/e3hBg9gSU48yHqUoj8LC7PhmnTLvkgIwR8vmU MF1kGQ/G/6rto0r4eyggtCSwTvscx6BklNNmrSO+zXdUCxW7gX8foeUfWVewpgQw0nRm HiXBvgnzMq0EhRi5AP2ZtI82qNzR7tKwREWVBPdMBOKoeDK8A79blDerWVdBo5xTcr43 Na3g== X-Gm-Message-State: ABuFfohaD+LJ5SA76zHGyJkXzdn8ToT9WDoRivYge8obfnmkK2NZpT0p 5/Smw7m5KXCb97XkaJkI2U/mEiyguYEGG+92lqdpnfzim0To/wCGNo8PUYSixZsvSAu5NjK1WI8 TQ11WrQYMXXfBiESzqcNciX7Gn97Qd/4KjuG77cIcxjrWyVGlvA043bQYT+yv7VPrcw== X-Received: by 2002:a63:fc23:: with SMTP id j35-v6mr17764776pgi.1.1539659991916; Mon, 15 Oct 2018 20:19:51 -0700 (PDT) X-Google-Smtp-Source: ACcGV62kWOfh2Epra0y9lp+0cHPzeu3nRLnYdvzUkiLwRbDLCmOFFPbvlG26S1DQbnfT19o37bEe X-Received: by 2002:a63:fc23:: with SMTP id j35-v6mr17764747pgi.1.1539659991132; Mon, 15 Oct 2018 20:19:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539659991; cv=none; d=google.com; s=arc-20160816; b=m82KRHSu0EeQmTvMzc/uQvw+1GKyrVItSYwdQBz1ki08487x8dRWOSS8FG5pLFRl6f egzF2ma/EHDCI76SvYRYbJC9+nh8g9tTJBuqEVWcvOpQPgch2f4ia0bqmPaY95K49Be6 IWZQYx2ZekKZUSybJpveQzaDN7EbpJ3E27H48al4hDa83dmtg12OrBGoBxysHr4du/4a mJtV9URp9kNM+rEyTFJy98Z9Ax1ToIgSc0qNRNF8v942A4ZmCP3fza9MpslszSkf/asl xL/+RyObyKiIsVugdudNGRV3YkYukeHsYrhabQ1TGDv2XN+k65fF1e57oF7jzi/YaXoG 2eBw== 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=NXYVyyHmVmlKAp63WiEk80Yd1QK+kCWi9LT++yfOJrk=; b=zap1sy28vvjTh/wuqKkSxziJ/UqoFMSZ8md1l8dwe44gu0ehmu68NYycB0GJr5GV95 Sry5lsAX0F4xQ621vEEoIO0ZubDuAylH/S9VfN74YUwt0dIgDIJ6QgTIT6v8Acp/Y3/7 P1hflJuLOQ8awqAWRhQjY6gDObqRMtc49GTk8BTvsx8Ph7uzxgfmHnsP6GhIIQaEfXRU JOmHAAr6hu/+ltsvMXIiT2gsh+BktBZYL3eoQEEsUeDDO3M2QWzRp6eYDTO9s6JHOwSL hsrmeKOPwgCePvkJrYTXnxq1Iuj58dANocEUWYMJYMwdfFcC45yAeudgC8YbWnhu1nuO oeaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=w28UYpsZ; 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 x15-v6si12308410pln.425.2018.10.15.20.19.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 20:19:51 -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=w28UYpsZ; 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 w9G3Jk1p051787; Tue, 16 Oct 2018 03:19:49 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=NXYVyyHmVmlKAp63WiEk80Yd1QK+kCWi9LT++yfOJrk=; b=w28UYpsZn0QESdH6ooyHsPZ7SFyfEzPzSns19jRH38/Vee7C0yf6PuVnceIkXt/lejSE sFCuXREQc7f8VH6Scyue7ZbjOQlRLd4nrvOZOshg5xFzrNMgJXASe8SnorqNcl5bWmwr 2jL5WT8MSyJzm8ajHTvhDJFQZ7dtyxBKfSJ5fzVvx84/cWkhc4yEisGY+pvXrhgowCtu 1JEoEe0D9X56WLyCn4TMVgBZGS79kIVIEAFtkf6P51FW0KuZjGd/gDxfM1Pq38FpAGAQ D/ZY/8H605hj020q4u2aGX6Jjn+Dc3BJS99i9WWeZF6z78hu8od1tdmiNtJASyVA4a0C Zw== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2n384tx27s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:19:48 +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 w9G3Jheg003413 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:19:43 GMT Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3JgO5012319; Tue, 16 Oct 2018 03:19:42 GMT Received: from localhost (/10.159.227.150) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 15 Oct 2018 20:19:42 -0700 Subject: [PATCH 15/26] vfs: plumb remap flags through the vfs clone functions 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: Mon, 15 Oct 2018 20:19:40 -0700 Message-ID: <153965998059.3607.7952535159459274693.stgit@magnolia> In-Reply-To: <153965939489.1256.7400115244528045860.stgit@magnolia> References: <153965939489.1256.7400115244528045860.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9047 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=584 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810160028 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 Plumb a remap_flags argument through the {do,vfs}_clone_file_range functions so that clone can take advantage of it. Signed-off-by: Darrick J. Wong Reviewed-by: Amir Goldstein --- fs/ioctl.c | 2 +- fs/nfsd/vfs.c | 2 +- fs/overlayfs/copy_up.c | 2 +- fs/overlayfs/file.c | 6 +++--- fs/read_write.c | 13 +++++++++---- include/linux/fs.h | 4 ++-- 6 files changed, 17 insertions(+), 12 deletions(-) diff --git a/fs/ioctl.c b/fs/ioctl.c index 72537b68c272..505275ec5596 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -232,7 +232,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); + olen, 0); if (cloned < 0) ret = cloned; else if (olen && cloned != olen) diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index ac6cb6101cbe..726fc5b2b27a 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -543,7 +543,7 @@ __be32 nfsd4_clone_file_range(struct file *src, u64 src_pos, struct file *dst, { loff_t cloned; - cloned = vfs_clone_file_range(src, src_pos, dst, dst_pos, count); + cloned = vfs_clone_file_range(src, src_pos, dst, dst_pos, count, 0); if (count && cloned != count) cloned = -EINVAL; return nfserrno(cloned < 0 ? cloned : 0); diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c index 8750b7235516..5f82fece64a0 100644 --- a/fs/overlayfs/copy_up.c +++ b/fs/overlayfs/copy_up.c @@ -142,7 +142,7 @@ static int ovl_copy_up_data(struct path *old, struct path *new, loff_t len) } /* Try to use clone_file_range to clone up within the same fs */ - cloned = do_clone_file_range(old_file, 0, new_file, 0, len); + cloned = do_clone_file_range(old_file, 0, new_file, 0, len, 0); if (cloned == len) goto out; /* Couldn't clone, so now we try to copy the data */ diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c index 6c3fec6168e9..0393815c8971 100644 --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -462,7 +462,7 @@ static loff_t ovl_copyfile(struct file *file_in, loff_t pos_in, case OVL_CLONE: ret = vfs_clone_file_range(real_in.file, pos_in, - real_out.file, pos_out, len); + real_out.file, pos_out, len, flags); break; case OVL_DEDUPE: @@ -512,8 +512,8 @@ static loff_t ovl_remap_file_range(struct file *file_in, loff_t pos_in, !ovl_inode_upper(file_inode(file_out)))) return -EPERM; - return ovl_copyfile(file_in, pos_in, file_out, pos_out, len, 0, - op); + return ovl_copyfile(file_in, pos_in, file_out, pos_out, len, + remap_flags, op); } const struct file_operations ovl_file_operations = { diff --git a/fs/read_write.c b/fs/read_write.c index 906e78be5001..791b406e8264 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1857,12 +1857,15 @@ int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, EXPORT_SYMBOL(generic_remap_file_range_prep); loff_t do_clone_file_range(struct file *file_in, loff_t pos_in, - struct file *file_out, loff_t pos_out, loff_t len) + struct file *file_out, loff_t pos_out, + loff_t len, unsigned int remap_flags) { struct inode *inode_in = file_inode(file_in); struct inode *inode_out = file_inode(file_out); loff_t ret; + WARN_ON_ONCE(remap_flags); + if (S_ISDIR(inode_in->i_mode) || S_ISDIR(inode_out->i_mode)) return -EISDIR; if (!S_ISREG(inode_in->i_mode) || !S_ISREG(inode_out->i_mode)) @@ -1893,7 +1896,7 @@ loff_t do_clone_file_range(struct file *file_in, loff_t pos_in, return ret; ret = file_in->f_op->remap_file_range(file_in, pos_in, - file_out, pos_out, len, 0); + file_out, pos_out, len, remap_flags); if (ret < 0) return ret; @@ -1904,12 +1907,14 @@ loff_t do_clone_file_range(struct file *file_in, loff_t pos_in, EXPORT_SYMBOL(do_clone_file_range); loff_t vfs_clone_file_range(struct file *file_in, loff_t pos_in, - struct file *file_out, loff_t pos_out, loff_t len) + struct file *file_out, loff_t pos_out, + loff_t len, unsigned int remap_flags) { loff_t ret; file_start_write(file_out); - ret = do_clone_file_range(file_in, pos_in, file_out, pos_out, len); + ret = do_clone_file_range(file_in, pos_in, file_out, pos_out, len, + remap_flags); file_end_write(file_out); return ret; diff --git a/include/linux/fs.h b/include/linux/fs.h index f1d082af34d0..bc353a5224a4 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1843,10 +1843,10 @@ extern int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, unsigned int remap_flags); extern loff_t do_clone_file_range(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, - loff_t len); + loff_t len, unsigned int remap_flags); extern loff_t vfs_clone_file_range(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, - loff_t len); + loff_t len, unsigned int remap_flags); extern int vfs_dedupe_file_range_compare(struct inode *src, loff_t srcoff, struct inode *dest, loff_t destoff, loff_t len, bool *is_same); From patchwork Tue Oct 16 03:19:47 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: 10642901 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 D639C18FD for ; Tue, 16 Oct 2018 03:19:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3ADD29ABC for ; Tue, 16 Oct 2018 03:19:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B846E29AD2; Tue, 16 Oct 2018 03:19:56 +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 45832299BC for ; Tue, 16 Oct 2018 03:19:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BE7326B027E; Mon, 15 Oct 2018 23:19:53 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B42AA6B0280; Mon, 15 Oct 2018 23:19:53 -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 9E2C36B0281; Mon, 15 Oct 2018 23:19:53 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) by kanga.kvack.org (Postfix) with ESMTP id 52CFE6B0280 for ; Mon, 15 Oct 2018 23:19:53 -0400 (EDT) Received: by mail-pg1-f199.google.com with SMTP id e24-v6so16127965pga.16 for ; Mon, 15 Oct 2018 20:19:53 -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=WeQ7JuRHLil+2Ip19vpZXJfw1JCjZG3ATcT72KvtVeA=; b=NrI199nOxTq3cI0uZPHN8ewP2XZQ/0bSe5Bt5PZMI8ubsa0OX1JirPzNCDd7IF12J5 wZ9UjjF+SKoP46wAmqvSty5IzDAXivaCVyIULub0GTon8d2TjQ3eRFVuN6Zil0rk8WUL roSy5Y9D67GSX0ucM+d3gpwDPXutmZM9JKbgrzoqS44iQADkL0owKHQ1R87IJ99nsjGo 7vDMLM9jm1/nUFdaZjyjctCTFIu1yQFxspn25+KDTNpV8xWOV+k9ghlpWI1m+KhCncqf 4Xo3uhM2OvrKnJTMk4brgsqiqALBHnM3PsakVm3ALtxp00h2g2qPikHohNwmDgN5IHGG Pecw== X-Gm-Message-State: ABuFfojb8jxCpTAHkTzLU5+KGKLJqisZTxweX0GrjlWM0p42L+Pzrl4b Nier/5VHAelL2GXC1AKXH55mALHXA2AwColst71qkaSfRMU5X7kN/YLGRTUM+yebAKZQ0sU86eQ H9BlVV9OvIdOGunE7wY3kRwEJf0vW2dUnQBfmwtKIz+b3Khv+WnLaXURGoMqhl4A+rg== X-Received: by 2002:a17:902:760b:: with SMTP id k11-v6mr19840573pll.103.1539659993025; Mon, 15 Oct 2018 20:19:53 -0700 (PDT) X-Google-Smtp-Source: ACcGV63HK+0Xiq7BDnbOYlh8K4SSt+IwchpfnezzxTaVASgkKWO1+GkqYFraC7P6AoUXJ40Ee3CZ X-Received: by 2002:a17:902:760b:: with SMTP id k11-v6mr19840540pll.103.1539659992368; Mon, 15 Oct 2018 20:19:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539659992; cv=none; d=google.com; s=arc-20160816; b=N7PzUtLWMupb8+xDGtiCj9Lh0QeLBwhRfCbpA0nIHumFNi9tBY2gLKyCoPlQ7vPQD7 EbXFPWBs+/prOGVMSpctfVC7wdDCDDUoQwqKpnky0OrnB1mTpBYqKbzv/IRH+WiuMwKt PypkMnq+H/i8I0F9rZiEg3X3AxpcDvFqymnSpMd6CLWXBEoOlDqRiDRNL/fsXtqZSplA Mt/s2GkXDMi0VhHzwvYCY0V1Y1q/NFLMn9Pn2nvytLAPZtJINlk8sCwstXGwHjZEVC8B iLrzu/Mj4Gl2fcUZRMoqpDtHdTbmLxwSEzxRNQUy/widv1QxjwRavy5mfEulZEYNg+uM eSvw== 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=WeQ7JuRHLil+2Ip19vpZXJfw1JCjZG3ATcT72KvtVeA=; b=ozzpkR5MJG8/MRlFFExccM7/4yDQBhzzGT58eCoIBB7U7JiObc/1AO9yVeWChov8g9 Ul6AmVUgvJMjEwRHcMetYMBFNio0MS+mfh5i0zbFfNjv8wNgzafsJuCCYhJ6g05YqeoE ByLqRY3CjAc9rtdmlpvC/CwGK9Vgii4i0L+Y4Qb98v5YVifK1NfMVoxljrvwmuxFtjo8 PN0W8iYkTGfMAtzS/7f2DM/gAflWhZekWYiw1R4LxkWpIBnjzUzbfCLxIPlE71cqVzMd co5zHL127RtWYOH6EHRHJyIEGsghEy3oUklEUFZyJRX/NvqcKhQosNONTXeQP73wfcDU bM8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=ErLVYyAB; 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 w1-v6si12511005plz.23.2018.10.15.20.19.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 20:19:52 -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=ErLVYyAB; 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 w9G3JosX051805; Tue, 16 Oct 2018 03:19:50 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=WeQ7JuRHLil+2Ip19vpZXJfw1JCjZG3ATcT72KvtVeA=; b=ErLVYyABB1Y44zzHfgXVm6Og51DOVo2KhuIaLJ11buXmEt0uX1uHS3pojIufl9PPAykG aIc0A5WhguXvrkV11EWIXBN6n43gZP/ONu5EJfHIGONTEJ9mjQ/7VGsdelbjNs3Qot+F LRlqY0cz7wtGavnkT0VHE8HD4talmY+q/O6EDGG7Xr5i4AKdkVUnMcDiGWhkA6xrld/M mJ+FaPakCUgQLKMkQ/Z/rNJR6fEd+WtIDvCfSBBo+wh1UjB5xZbhj0bDeEXxgrcjQXdY c7TeemQ6SB73bBTC4XnLJiGSzPuq4m7n8Xfz/JIU14x91EnicGiCVOK7fh97Mn0OR7pO 0w== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2n384tx27v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:19:50 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3Jnm1003664 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:19:49 GMT Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w9G3JnGF006837; Tue, 16 Oct 2018 03:19:49 GMT Received: from localhost (/10.159.227.150) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 15 Oct 2018 20:19:49 -0700 Subject: [PATCH 16/26] vfs: plumb remap flags through the vfs dedupe functions 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: Mon, 15 Oct 2018 20:19:47 -0700 Message-ID: <153965998743.3607.1661657709759570842.stgit@magnolia> In-Reply-To: <153965939489.1256.7400115244528045860.stgit@magnolia> References: <153965939489.1256.7400115244528045860.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9047 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=518 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810160028 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 Plumb a remap_flags argument through the vfs_dedupe_file_range_one functions so that dedupe can take advantage of it. Signed-off-by: Darrick J. Wong Reviewed-by: Amir Goldstein --- fs/overlayfs/file.c | 3 ++- fs/read_write.c | 9 ++++++--- include/linux/fs.h | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c index 0393815c8971..84dd957efa24 100644 --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -467,7 +467,8 @@ static loff_t ovl_copyfile(struct file *file_in, loff_t pos_in, case OVL_DEDUPE: ret = vfs_dedupe_file_range_one(real_in.file, pos_in, - real_out.file, pos_out, len); + real_out.file, pos_out, len, + flags); break; } revert_creds(old_cred); diff --git a/fs/read_write.c b/fs/read_write.c index 791b406e8264..f6ab5beb935a 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -2019,10 +2019,12 @@ EXPORT_SYMBOL(vfs_dedupe_file_range_compare); loff_t vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos, struct file *dst_file, loff_t dst_pos, - loff_t len) + loff_t len, unsigned int remap_flags) { loff_t ret; + WARN_ON_ONCE(remap_flags & ~(REMAP_FILE_DEDUP)); + ret = mnt_want_write_file(dst_file); if (ret) return ret; @@ -2053,7 +2055,7 @@ loff_t vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos, } ret = dst_file->f_op->remap_file_range(src_file, src_pos, dst_file, - dst_pos, len, REMAP_FILE_DEDUP); + dst_pos, len, remap_flags | REMAP_FILE_DEDUP); out_drop_write: mnt_drop_write_file(dst_file); @@ -2121,7 +2123,8 @@ int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same) } deduped = vfs_dedupe_file_range_one(file, off, dst_file, - info->dest_offset, len); + info->dest_offset, len, + 0); if (deduped == -EBADE) info->status = FILE_DEDUPE_RANGE_DIFFERS; else if (deduped < 0) diff --git a/include/linux/fs.h b/include/linux/fs.h index bc353a5224a4..c0ae85a7bd9d 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1854,7 +1854,7 @@ extern int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same); extern loff_t vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos, struct file *dst_file, loff_t dst_pos, - loff_t len); + loff_t len, unsigned int remap_flags); struct super_operations { From patchwork Tue Oct 16 03:19:54 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: 10642937 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 8CEC117D2 for ; Tue, 16 Oct 2018 03:20:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 76F9929AA8 for ; Tue, 16 Oct 2018 03:20:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A4A029B48; Tue, 16 Oct 2018 03:20:18 +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 512DF29AA8 for ; Tue, 16 Oct 2018 03:20:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 021CE6B0280; Mon, 15 Oct 2018 23:20:02 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F125F6B0282; Mon, 15 Oct 2018 23:20:01 -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 E034D6B0283; Mon, 15 Oct 2018 23:20:01 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by kanga.kvack.org (Postfix) with ESMTP id 9D36C6B0280 for ; Mon, 15 Oct 2018 23:20:01 -0400 (EDT) Received: by mail-pg1-f197.google.com with SMTP id e6-v6so16117803pge.5 for ; Mon, 15 Oct 2018 20:20:01 -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=SxxelvM9Mhs/thMFIyphjK7HMbNrvjZhnvUfpeQTw9o=; b=dreV39YE5htxEkaQ6C+BYgX60ClipVuj1LZL6c1LgiI5BkuAqut60UgaC2ZY9OXuOD HS/oEMlEkahbgrMSEHYXY5woqGV1VvEcs2a5NlA8whXnkaNbmre/R9pT6IHiJaRpUKLM RwI9KZOPTFqwcEWxsADUgu/BtOdvEcJ31NeKF5iv/JCZX3qqEaJiuAyQgfpwY19xtsRO 54xPA87zr/6+LF1h9vgCfeF6Vpq3WdvibW56EJ1xcusO6Vw0vmPUoTAqj1qIZtkxhaH0 TTQXT1QzX02aVcR5NEatMxtSVkXkJPBKq1pWmxYrCrdAhBfovNd2F1pgQTBWh17e74qJ V4lg== X-Gm-Message-State: ABuFfohZcJFgx89qIkEWBK7K2ZoVFaPuOz1cczjzbSkVfAwfnrtmxgIh 39HehXW2NzViLiodQG3YNcrT54aOh8IC3n8BgN4vYDTjNluFPHHJ+P9npW5IwFeXLd5BFiQEQeW UYTOmYNZ59FbjSIGnLqX4U4IZwdvr1B1z3ZSBbNHIVy16fSezfgjA++mLJphpF6sGdw== X-Received: by 2002:a63:2e47:: with SMTP id u68-v6mr18778965pgu.294.1539660001305; Mon, 15 Oct 2018 20:20:01 -0700 (PDT) X-Google-Smtp-Source: ACcGV60pAmJEQ8AmJvc3lOg99v8alRBlvoghQg6FZk6VZYisJBdgH5Z43sYqRK5FeanQICDKnIU2 X-Received: by 2002:a63:2e47:: with SMTP id u68-v6mr18778926pgu.294.1539660000418; Mon, 15 Oct 2018 20:20:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539660000; cv=none; d=google.com; s=arc-20160816; b=CHnEn2b4wVCdhSampHF7JHZlV9twE71NyCqaf45uN7qPdH760mKLNCDyMTSDGT2BB/ l9RI+GiPiIha2JaPFEuI4uucecUkHQ0luNIsPXTpqPShSviFfB/EwC3UCtIPSDfO1/Tg 32Uh7rENbExfa9eL8wkrSz5ei/TlAsTQVq/v4uoJ4hkL3xMmTfec6XeUJGpXy1JHCq3O hceMs61Qt9aVZA9Iugnghp3PdK/dD9O0cpz0g09YaCnr8OjAnwXTafH3rWaLDZ1vaNgs dRbBR2JP1bufa/MY/K4VFZ3jxcPPdo4mYReY/790btjCbO1cCaaWeYIhkUSKSJItFm3D KLrg== 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=SxxelvM9Mhs/thMFIyphjK7HMbNrvjZhnvUfpeQTw9o=; b=fyvgi544prG0ZuyNtk1cgzGBJya+WQ2PbFpQNkGDR8o+RsBk41EY5CfkWCh5JM6u7K mNaCHxPY/Ies9cnpqwaM/3gvaxAhxpbLcEd50B76h5TYmnC+ybDnfdNjW3gdSsxl5pDM +G2UWsVe3jgapd/XGWZJa8eN8MgkP9jxeKFGcsYYgu1m4iWRD4/vggLsif54smIK+r3X lJQ+PRNR0NxqQgaA2OkXsZ5cE+3+z7qtCT3fldAJbvEV6KB8Ygd+bVbiI1hN0VFTIPKS 5TKXv70V0YR29lh24VFig+SZSvdBVNni/H08c6myz9cOlhbOPqwGLRNsHRiqyVxMhCnC 0mxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=u0a1psOV; 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 m63-v6si11832523pld.379.2018.10.15.20.20.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 20:20:00 -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=u0a1psOV; 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 w9G3J8UF051365; Tue, 16 Oct 2018 03:19:57 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=SxxelvM9Mhs/thMFIyphjK7HMbNrvjZhnvUfpeQTw9o=; b=u0a1psOVYfQuU0VE0ParteRBbVJ7OAR5sMDVRQqSrnJRlbXb6uvwDgEkBDTzVuDgRDm9 K/oeZoJaQCo7UYIOm9r3jvNo+mPpvsR4jkstV+qmxFaDcOWRWcKliOStKkizL1KDuetE C4vcETfUGYzYUtHR0yf+TID24atjgBz38Nzx7oUWBfD6ZwHN3rg6ah/rpt/d3YUABLfy y07BBEUMuZM8JHpeqZhgdJYxtAlU1Bpgi5xlpE3tYytAKWlKLq8pYBREOuufi2vlnZNv +whmoAFXpGb3lw5AHYqv/hgPNn8KVR3EEhcEqsIBvQT+a+lQSMXv3/w20QDnx4XzRYEA WA== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2130.oracle.com with ESMTP id 2n384tx287-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:19:57 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3JuxD027717 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:19:56 GMT Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w9G3Juvi006963; Tue, 16 Oct 2018 03:19:56 GMT Received: from localhost (/10.159.227.150) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 15 Oct 2018 20:19:55 -0700 Subject: [PATCH 17/26] vfs: enable remap callers that can handle short operations 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: Mon, 15 Oct 2018 20:19:54 -0700 Message-ID: <153965999426.3607.3221368918901209000.stgit@magnolia> In-Reply-To: <153965939489.1256.7400115244528045860.stgit@magnolia> References: <153965939489.1256.7400115244528045860.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9047 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=985 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810160028 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 Plumb in a remap flag that enables the filesystem remap handler to shorten remapping requests for callers that can handle it. Now copy_file_range can report partial success (in case we run up against alignment problems, resource limits, etc.). We also enable CAN_SHORTEN for fideduperange to maintain existing userspace-visible behavior where xfs/btrfs shorten the dedupe range to avoid stale post-eof data exposure. Signed-off-by: Darrick J. Wong Reviewed-by: Amir Goldstein --- fs/read_write.c | 28 ++++++++++++++++++++-------- include/linux/fs.h | 7 +++++-- mm/filemap.c | 16 ++++++++++++---- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index f6ab5beb935a..ee9314b7bfc3 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1593,7 +1593,8 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, cloned = file_in->f_op->remap_file_range(file_in, pos_in, file_out, pos_out, - min_t(loff_t, MAX_RW_COUNT, len), 0); + min_t(loff_t, MAX_RW_COUNT, len), + REMAP_FILE_CAN_SHORTEN); if (cloned > 0) { ret = cloned; goto done; @@ -1721,6 +1722,8 @@ static int remap_verify_area(struct file *file, loff_t pos, loff_t len, * can't meaningfully compare post-EOF contents. * * For clone we only link a partial EOF block above the destination file's EOF. + * + * Shorten the request if possible. */ static int generic_remap_check_len(struct inode *inode_in, struct inode *inode_out, @@ -1729,16 +1732,24 @@ static int generic_remap_check_len(struct inode *inode_in, unsigned int remap_flags) { u64 blkmask = i_blocksize(inode_in) - 1; + loff_t new_len = *len; if ((*len & blkmask) == 0) return 0; - if (remap_flags & REMAP_FILE_DEDUP) - *len &= ~blkmask; - else if (pos_out + *len < i_size_read(inode_out)) - return -EINVAL; + if ((remap_flags & REMAP_FILE_DEDUP) || + pos_out + *len < i_size_read(inode_out)) + new_len &= ~blkmask; - return 0; + if (new_len == *len) + return 0; + + if (remap_flags & REMAP_FILE_CAN_SHORTEN) { + *len = new_len; + return 0; + } + + return (remap_flags & REMAP_FILE_DEDUP) ? -EBADE : -EINVAL; } /* Update inode timestamps and remove security privileges when remapping. */ @@ -2023,7 +2034,8 @@ loff_t vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos, { loff_t ret; - WARN_ON_ONCE(remap_flags & ~(REMAP_FILE_DEDUP)); + WARN_ON_ONCE(remap_flags & ~(REMAP_FILE_DEDUP | + REMAP_FILE_CAN_SHORTEN)); ret = mnt_want_write_file(dst_file); if (ret) @@ -2124,7 +2136,7 @@ int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same) deduped = vfs_dedupe_file_range_one(file, off, dst_file, info->dest_offset, len, - 0); + REMAP_FILE_CAN_SHORTEN); if (deduped == -EBADE) info->status = FILE_DEDUPE_RANGE_DIFFERS; else if (deduped < 0) diff --git a/include/linux/fs.h b/include/linux/fs.h index c0ae85a7bd9d..594fe4ba0b15 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1726,14 +1726,17 @@ struct block_device_operations; * If it is called with len == 0 that means "remap to end of source file". * * REMAP_FILE_DEDUP: only remap if contents identical (i.e. deduplicate) + * REMAP_FILE_CAN_SHORTEN: caller can handle a shortened request */ #define REMAP_FILE_DEDUP (1 << 0) +#define REMAP_FILE_CAN_SHORTEN (1 << 1) /* All valid REMAP_FILE flags */ -#define REMAP_FILE_VALID_FLAGS (REMAP_FILE_DEDUP) +#define REMAP_FILE_VALID_FLAGS (REMAP_FILE_DEDUP | \ + REMAP_FILE_CAN_SHORTEN) /* REMAP_FILE flags taken care of by the vfs. */ -#define REMAP_FILE_ADVISORY (0) +#define REMAP_FILE_ADVISORY (REMAP_FILE_CAN_SHORTEN) struct iov_iter; diff --git a/mm/filemap.c b/mm/filemap.c index 1e93269efafe..898eb358f7d2 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3051,8 +3051,12 @@ int generic_remap_checks(struct file *file_in, loff_t pos_in, if (pos_in + count == size_in) { bcount = ALIGN(size_in, bs) - pos_in; } else { - if (!IS_ALIGNED(count, bs)) - return -EINVAL; + if (!IS_ALIGNED(count, bs)) { + if (remap_flags & REMAP_FILE_CAN_SHORTEN) + count = ALIGN_DOWN(count, bs); + else + return -EINVAL; + } bcount = count; } @@ -3063,10 +3067,14 @@ int generic_remap_checks(struct file *file_in, loff_t pos_in, pos_out < pos_in + bcount) return -EINVAL; - /* For now we don't support changing the length. */ - if (*req_count != count) + /* + * We shortened the request but the caller can't deal with that, so + * bounce the request back to userspace. + */ + if (*req_count != count && !(remap_flags & REMAP_FILE_CAN_SHORTEN)) return -EINVAL; + *req_count = count; return 0; } From patchwork Tue Oct 16 03:20:01 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: 10642941 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 D08FC3B73 for ; Tue, 16 Oct 2018 03:20:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB38E28F69 for ; Tue, 16 Oct 2018 03:20:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B99A629AF7; Tue, 16 Oct 2018 03:20:20 +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 0C95628F69 for ; Tue, 16 Oct 2018 03:20:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E77F96B0282; Mon, 15 Oct 2018 23:20:18 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E28106B0284; Mon, 15 Oct 2018 23:20:18 -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 D170E6B0285; Mon, 15 Oct 2018 23:20:18 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by kanga.kvack.org (Postfix) with ESMTP id 8F50E6B0282 for ; Mon, 15 Oct 2018 23:20:18 -0400 (EDT) Received: by mail-pf1-f197.google.com with SMTP id t28-v6so8425258pfk.21 for ; Mon, 15 Oct 2018 20:20:18 -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=3RnIvhLytdj37r84vkiSfu8xIM8r3J/39i5oVdOkz+c=; b=JypSAWFnJlXFIZ8hwY0Y+fVQFDyp1JN3qkNmoQHAc2rFXoAYpkFXq0EtswY/x0CZJZ +lrl0wBFfFNMoA+G/zr+2z2tcMYVrY49WgcZ2TD+lNKFxcQMczFpJEYiXRN6Pu+t/6Iz ZAsPIJ7r7uvcImGpX0tWtmfneR4xosCNyUsTMZl07sTlCMY8tcrpkLabz95jCfdNmaeS +jsM32aZF7+hdwFjlwnHzkxPlgYBr8K6AhaA50SF0ALWMthpXq4r0JozbW8PZCkBb1fS ybjj2i1E2+6wrsAj7U+xE9MqIXw0bGSry5UrM2VWUX3GgqbnZOKCppTSSS8vTFr1cciw vFkg== X-Gm-Message-State: ABuFfoiMkZtVQzfJXs1oWOvHhlrufQgHVMvP2CjJaVHLG5D7Xv/IUlW1 KQamArv3x0vuWdL3Th7aUw8vl6iWlr/Bbgx0nF+LfnEMhEDBwxJq19NeyM9rWpBFIMyYxIk4JBD N2J5wLCw6P4J34M7oj2741ySuDp5wjgTyqjmyB2tgm099x9wht9SVpnQsbai6tUQ3NA== X-Received: by 2002:a63:c84c:: with SMTP id l12-v6mr18297352pgi.77.1539660018225; Mon, 15 Oct 2018 20:20:18 -0700 (PDT) X-Google-Smtp-Source: ACcGV60jw7nrzmbahz7u2OuH3WBh4J5ccjOY+V0pAeEnUIvKtbo5krE07cJNgTEa7AoUP6swMTAV X-Received: by 2002:a63:c84c:: with SMTP id l12-v6mr18297325pgi.77.1539660017432; Mon, 15 Oct 2018 20:20:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539660017; cv=none; d=google.com; s=arc-20160816; b=bm5foD4GkOWDw/WwVaSAnXVJulYSsQ7LdPoCBm6episBogTd5GROQwbGmZlj775DdK NznHPqGHu2A824es0xXSQNt8SOV3goytzsqeTOK8W7vuW3teRdpR14kSviAQGPYJ6joj gShmPWOqO/eXshxdEKYo6U9q6J317J4pVETFSJi03sHiwn5JO205mobINNIA75C1LWHt nWAzI85svUebz+7OpyVGL+QEe5uVi/L+Zw7SlNhwETPEgV4hQ9rN0R5bWiWHnAQLtkzg W3Qh0ed+ieWIM4urMx7D5xPPZD/IWIDoSdZ9K5FR6PwQm9iBv7U1Y8VBY7cm2PsTtRDQ Q+NQ== 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=3RnIvhLytdj37r84vkiSfu8xIM8r3J/39i5oVdOkz+c=; b=kX6n8rJZPE5SIE8RBuyTiwqma4ubIh9hyukfUkhvYV0acsDt5r0nKcPN3Iudfx6pdR /ezY5Ybmojasr8m/I0lLWy0UF2SdnmJcS6jmMF7TMBkPzgoL9cuXYc0V7K4e+xrJAu8p nIYUosdzmIEMAgacEMAWZdc9f3SpDTupO/rBDFm9SCOIiWo86BOJVl9RP8SOpxddjRAP gHcHltbFcM/8b6sJDcGpnpFYmYO3rqimIkVqbqw+VfnrtdP8DnN0+ujBMHbhS7fqoe4D gimXMO38H4Q4YZlQuaudMCpkvVgCi6k/9Qva7YLxBbMYE2lp+nN4WX+k9OPTzpxzUJWW HkBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=DTeeOtLa; spf=pass (google.com: domain of darrick.wong@oracle.com designates 141.146.126.78 as permitted sender) smtp.mailfrom=darrick.wong@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from aserp2120.oracle.com (aserp2120.oracle.com. [141.146.126.78]) by mx.google.com with ESMTPS id l22-v6si12974970pfj.188.2018.10.15.20.20.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 20:20:17 -0700 (PDT) Received-SPF: pass (google.com: domain of darrick.wong@oracle.com designates 141.146.126.78 as permitted sender) client-ip=141.146.126.78; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=DTeeOtLa; spf=pass (google.com: domain of darrick.wong@oracle.com designates 141.146.126.78 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 (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w9G3J3ZU059899; Tue, 16 Oct 2018 03:20:15 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=3RnIvhLytdj37r84vkiSfu8xIM8r3J/39i5oVdOkz+c=; b=DTeeOtLaiXEyCRxXp8jphRXhnlx07zXM5EhtbbNqv7nkzwk2kXD2I9LRRqkQEZudNe7M ybysyu7SkS2S/GzlEmR4GtXB0QtBvhJVemA2CRmwRUQ4D4jIQMbJ78bR6j4L3tEJ/zw0 JN44XeQiEQW7BtQ8CE+ngZg9XZIrAmHjU+Tx0fIh89QNL671klZk6VCFfVDDUl0QTIbk malo6iDz6agsTNfae1Yup1akB7XI+7oaFk2jhP+ZoLpKmE/Fannk2Y0F+lEvhMXi/E0I VBhVHHWZ4PJc7RkqIS0l/z5m+NQOUcdXbyO+FuSfLDlNDC3rkvW4+9ypTwzjT1dTZzVo 2Q== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2120.oracle.com with ESMTP id 2n38npwvgr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:20:15 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3K93X031816 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:20:09 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3K9jd010700; Tue, 16 Oct 2018 03:20:09 GMT Received: from localhost (/10.159.227.150) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 15 Oct 2018 20:20:09 -0700 Subject: [PATCH 18/26] vfs: hide file range comparison function 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, Christoph Hellwig , ocfs2-devel@oss.oracle.com Date: Mon, 15 Oct 2018 20:20:01 -0700 Message-ID: <153966000107.3607.12091185924532913135.stgit@magnolia> In-Reply-To: <153965939489.1256.7400115244528045860.stgit@magnolia> References: <153965939489.1256.7400115244528045860.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9047 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=633 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810160028 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 There are no callers of vfs_dedupe_file_range_compare, so we might as well make it a static helper and remove the export. Signed-off-by: Darrick J. Wong Reviewed-by: Amir Goldstein Reviewed-by: Christoph Hellwig --- fs/read_write.c | 187 +++++++++++++++++++++++++--------------------------- include/linux/fs.h | 3 - 2 files changed, 91 insertions(+), 99 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index ee9314b7bfc3..450e038e8617 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1776,6 +1776,97 @@ static int generic_remap_file_range_target(struct file *file, return file_remove_privs(file); } +/* + * Read a page's worth of file data into the page cache. Return the page + * locked. + */ +static struct page *vfs_dedupe_get_page(struct inode *inode, loff_t offset) +{ + struct page *page; + + page = read_mapping_page(inode->i_mapping, offset >> PAGE_SHIFT, NULL); + if (IS_ERR(page)) + return page; + if (!PageUptodate(page)) { + put_page(page); + return ERR_PTR(-EIO); + } + lock_page(page); + return page; +} + +/* + * Compare extents of two files to see if they are the same. + * Caller must have locked both inodes to prevent write races. + */ +static int vfs_dedupe_file_range_compare(struct inode *src, loff_t srcoff, + struct inode *dest, loff_t destoff, + loff_t len, bool *is_same) +{ + loff_t src_poff; + loff_t dest_poff; + void *src_addr; + void *dest_addr; + struct page *src_page; + struct page *dest_page; + loff_t cmp_len; + bool same; + int error; + + error = -EINVAL; + same = true; + while (len) { + src_poff = srcoff & (PAGE_SIZE - 1); + dest_poff = destoff & (PAGE_SIZE - 1); + cmp_len = min(PAGE_SIZE - src_poff, + PAGE_SIZE - dest_poff); + cmp_len = min(cmp_len, len); + if (cmp_len <= 0) + goto out_error; + + src_page = vfs_dedupe_get_page(src, srcoff); + if (IS_ERR(src_page)) { + error = PTR_ERR(src_page); + goto out_error; + } + dest_page = vfs_dedupe_get_page(dest, destoff); + if (IS_ERR(dest_page)) { + error = PTR_ERR(dest_page); + unlock_page(src_page); + put_page(src_page); + goto out_error; + } + src_addr = kmap_atomic(src_page); + dest_addr = kmap_atomic(dest_page); + + flush_dcache_page(src_page); + flush_dcache_page(dest_page); + + if (memcmp(src_addr + src_poff, dest_addr + dest_poff, cmp_len)) + same = false; + + kunmap_atomic(dest_addr); + kunmap_atomic(src_addr); + unlock_page(dest_page); + unlock_page(src_page); + put_page(dest_page); + put_page(src_page); + + if (!same) + break; + + srcoff += cmp_len; + destoff += cmp_len; + len -= cmp_len; + } + + *is_same = same; + return 0; + +out_error: + return error; +} + /* * Check that the two inodes are eligible for cloning, the ranges make * sense, and then flush all dirty data. Caller must ensure that the @@ -1932,102 +2023,6 @@ loff_t vfs_clone_file_range(struct file *file_in, loff_t pos_in, } EXPORT_SYMBOL(vfs_clone_file_range); -/* - * Read a page's worth of file data into the page cache. Return the page - * locked. - */ -static struct page *vfs_dedupe_get_page(struct inode *inode, loff_t offset) -{ - struct address_space *mapping; - struct page *page; - pgoff_t n; - - n = offset >> PAGE_SHIFT; - mapping = inode->i_mapping; - page = read_mapping_page(mapping, n, NULL); - if (IS_ERR(page)) - return page; - if (!PageUptodate(page)) { - put_page(page); - return ERR_PTR(-EIO); - } - lock_page(page); - return page; -} - -/* - * Compare extents of two files to see if they are the same. - * Caller must have locked both inodes to prevent write races. - */ -int vfs_dedupe_file_range_compare(struct inode *src, loff_t srcoff, - struct inode *dest, loff_t destoff, - loff_t len, bool *is_same) -{ - loff_t src_poff; - loff_t dest_poff; - void *src_addr; - void *dest_addr; - struct page *src_page; - struct page *dest_page; - loff_t cmp_len; - bool same; - int error; - - error = -EINVAL; - same = true; - while (len) { - src_poff = srcoff & (PAGE_SIZE - 1); - dest_poff = destoff & (PAGE_SIZE - 1); - cmp_len = min(PAGE_SIZE - src_poff, - PAGE_SIZE - dest_poff); - cmp_len = min(cmp_len, len); - if (cmp_len <= 0) - goto out_error; - - src_page = vfs_dedupe_get_page(src, srcoff); - if (IS_ERR(src_page)) { - error = PTR_ERR(src_page); - goto out_error; - } - dest_page = vfs_dedupe_get_page(dest, destoff); - if (IS_ERR(dest_page)) { - error = PTR_ERR(dest_page); - unlock_page(src_page); - put_page(src_page); - goto out_error; - } - src_addr = kmap_atomic(src_page); - dest_addr = kmap_atomic(dest_page); - - flush_dcache_page(src_page); - flush_dcache_page(dest_page); - - if (memcmp(src_addr + src_poff, dest_addr + dest_poff, cmp_len)) - same = false; - - kunmap_atomic(dest_addr); - kunmap_atomic(src_addr); - unlock_page(dest_page); - unlock_page(src_page); - put_page(dest_page); - put_page(src_page); - - if (!same) - break; - - srcoff += cmp_len; - destoff += cmp_len; - len -= cmp_len; - } - - *is_same = same; - return 0; - -out_error: - return error; -} -EXPORT_SYMBOL(vfs_dedupe_file_range_compare); - loff_t vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos, struct file *dst_file, loff_t dst_pos, loff_t len, unsigned int remap_flags) diff --git a/include/linux/fs.h b/include/linux/fs.h index 594fe4ba0b15..92eec706172f 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1850,9 +1850,6 @@ extern loff_t do_clone_file_range(struct file *file_in, loff_t pos_in, extern loff_t vfs_clone_file_range(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, loff_t len, unsigned int remap_flags); -extern int vfs_dedupe_file_range_compare(struct inode *src, loff_t srcoff, - struct inode *dest, loff_t destoff, - loff_t len, bool *is_same); extern int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same); extern loff_t vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos, From patchwork Tue Oct 16 03:20:14 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: 10642943 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 606CF18BC for ; Tue, 16 Oct 2018 03:20:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D94128F69 for ; Tue, 16 Oct 2018 03:20:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4200A29AD5; Tue, 16 Oct 2018 03:20:23 +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 BF2D228F69 for ; Tue, 16 Oct 2018 03:20:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B6BB46B0284; Mon, 15 Oct 2018 23:20:19 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B44986B0286; Mon, 15 Oct 2018 23:20:19 -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 A0E886B0287; Mon, 15 Oct 2018 23:20:19 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by kanga.kvack.org (Postfix) with ESMTP id 5493D6B0284 for ; Mon, 15 Oct 2018 23:20:19 -0400 (EDT) Received: by mail-pg1-f198.google.com with SMTP id 17-v6so15981948pgs.18 for ; Mon, 15 Oct 2018 20:20:19 -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=abN8AwQSn2h//7+1QLn+2XgmD6/XEIQ+bkobomWt214=; b=OsREW+qvmDinO8Q7Ksl8d3zloXhrk6xfI7JMnrdIoSdYFJzBuuVaYyDvLUMc6CUnVv m2T6avzgeUuxhG+ZPNaJGS1h9eqQeejkMB655UG66wye7EhqEPQVXoT3VRnXSq9b0Ij2 XkVbxupTzbTXF4PxtQzReK/82nfMnyYeJHhs+B4QOneEzI4WdbFoL+JLIWnpF8mJFNaU 94NwPNZPjL+WAxd7kA09qK0fetee83VyAxaqPdsirgIVI5uFnPVv8Iqz70mU/vHFmmPO FtC5x6I3crfnGGnvBAyeZV6zPqtPnuGh+won1OU8BRjK3FwFEfARNiU3IYRqM5HWtWd8 EaHg== X-Gm-Message-State: ABuFfoicaldF3mAhSszfM8yCtQhHdoAwMxVHEDXkjaZpJPK39I4KR0ne YIlWXpLheHSBNs3k8vP7B7hhTWFe5yalum7pJs4mDvNq3FMED3sRu2oZGSN/Yr+FNUqKKly96RO 96pNhGKNeg4xCeln6JI+Nkuj+eGeWM+BCFzXSj//98Lp2uUlzTcSmmJ31dwZMWl4sww== X-Received: by 2002:a62:c2c1:: with SMTP id w62-v6mr20056504pfk.35.1539660019019; Mon, 15 Oct 2018 20:20:19 -0700 (PDT) X-Google-Smtp-Source: ACcGV63fBhYg+uDe4LDqwgYxIjmCiKZy/tzPSw1+Em8OV4cvJCY6gE6UVg3DA2Jcayo7RhErG2jB X-Received: by 2002:a62:c2c1:: with SMTP id w62-v6mr20056474pfk.35.1539660018278; Mon, 15 Oct 2018 20:20:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539660018; cv=none; d=google.com; s=arc-20160816; b=Aa7xIRO2deMZt224J62Bu5ohuD3oERL2G9nq430hTjjsfcMet6MEwGXipkUmUmdrZ2 EoRXe1rtNeDCNm/6ize+gNgZ0o/WInHkHL0SLZnc5+mdyO4PwKBbs2FWvZdPJ55jppft sYEKd8U6wmdzGKuoupJrdN68kXZkyv/oFL5JnlL3RSGpIciuxn2mZF14/NRRluD5QxGT 8uIS9AqksJFkSVkhneNJHYjVQqYyuwXmCO6t3/t07OGG1FqUTq3kFL7PQouJrsEPQRd6 HpCSolh4kH90ocd+PeCasSywamHa18dvXr2fzZbj3xM9BsXfSEGwPUyERwhUV9RyVoKr aiGw== 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=abN8AwQSn2h//7+1QLn+2XgmD6/XEIQ+bkobomWt214=; b=PO38fGKCugJRSzh6JByZNbgDh6fku+HkkD//6F32VEHBYAE3Hn30QDb5vJmbJNAaNe Sk/W58tjy6u1cL+TboX/2yAxdGufHIzCaHnF0QcI1mt1otoSdTTZtHjr3rfRKo9qUe5S bCyRqk00ZdNreVrR6Lr94AgwxYG6YXh260Q4eL9J7852BqOcHaPvLSTxzZdB7XNNAjdq zfbbt5enapha/uMLOpESJeR3Ita7U6tqQAge23WRZSVe7LEA7mDaiRtB1WkOHCLZNhEN Vc9ZwFeXh0EWvsd8u1GutefQv8mf6Ip2RedJUXdkoYoipFb3MZgEING5aRc6LxGvWJe0 4e4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=4F3Pha7h; 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 l4-v6si12652639pgf.344.2018.10.15.20.20.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 20:20:18 -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=4F3Pha7h; 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 w9G3J3t3051349; Tue, 16 Oct 2018 03:20:17 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=abN8AwQSn2h//7+1QLn+2XgmD6/XEIQ+bkobomWt214=; b=4F3Pha7hMa3VhAthE5Z860g/br/Gi8WnzbTAtKS1wN0FITMrzGjzdkvXtkHntann4wrH qxpzeXa8cgweJ4IcmcGSTb+HNaUYUiNgqgC0+QI5wF0bZAE7aq0AcS82Fz6x/Uktpr+n oVJ2CmvQbJIkGTm007MCGEQ2XaM81n+pOPcpjRYfXjxSHQCTJIBamYzTtn8ybbnCtFEI m9zfkQ8JyBQ5penywEO/CdbnM5iWuzCWSDYTOaeciwPvoU9T1KnAO2aXj7e5JWXuc0cw j4+92AP3J77xDHpjsCIXyACVLuQKfWqsYSPntcZs0+1yN32BrU8RiSN66aXS11Ylssbo hA== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2n384tx29c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:20:17 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3KGQF004814 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:20:16 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3KGAa010715; Tue, 16 Oct 2018 03:20:16 GMT Received: from localhost (/10.159.227.150) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 15 Oct 2018 20:20:16 -0700 Subject: [PATCH 19/26] vfs: clean up generic_remap_file_range_prep return value 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: Mon, 15 Oct 2018 20:20:14 -0700 Message-ID: <153966001458.3607.5940191707393894977.stgit@magnolia> In-Reply-To: <153965939489.1256.7400115244528045860.stgit@magnolia> References: <153965939489.1256.7400115244528045860.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9047 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=851 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810160028 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 Since the remap prep function can update the length of the remap request, we can change this function to return the usual return status instead of the odd behavior it has now. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/ocfs2/refcounttree.c | 2 +- fs/read_write.c | 6 +++--- fs/xfs/xfs_reflink.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c index 6a42c04ac0ab..46bbd315c39f 100644 --- a/fs/ocfs2/refcounttree.c +++ b/fs/ocfs2/refcounttree.c @@ -4852,7 +4852,7 @@ int ocfs2_reflink_remap_range(struct file *file_in, ret = generic_remap_file_range_prep(file_in, pos_in, file_out, pos_out, &len, remap_flags); - if (ret <= 0) + if (ret < 0 || len == 0) goto out_unlock; /* Lock out changes to the allocation maps and remap. */ diff --git a/fs/read_write.c b/fs/read_write.c index 450e038e8617..37a7d3fe35d8 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1872,8 +1872,8 @@ static int vfs_dedupe_file_range_compare(struct inode *src, loff_t srcoff, * sense, and then flush all dirty data. Caller must ensure that the * inodes have been locked against any other modifications. * - * Returns: 0 for "nothing to clone", 1 for "something to clone", or - * the usual negative error code. + * If there's an error, then the usual negative error code is returned. + * Otherwise returns 0 with *len set to the request length. */ int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, @@ -1954,7 +1954,7 @@ int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, if (ret) return ret; - return 1; + return 0; } EXPORT_SYMBOL(generic_remap_file_range_prep); diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index 3dbe5fb7e9c0..9b1ea42c81d1 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -1329,7 +1329,7 @@ xfs_reflink_remap_prep( ret = generic_remap_file_range_prep(file_in, pos_in, file_out, pos_out, len, remap_flags); - if (ret <= 0) + if (ret < 0 || *len == 0) goto out_unlock; /* @@ -1409,7 +1409,7 @@ xfs_reflink_remap_range( /* Prepare and then clone file data. */ ret = xfs_reflink_remap_prep(file_in, pos_in, file_out, pos_out, &len, remap_flags); - if (ret <= 0) + if (ret < 0 || len == 0) return ret; trace_xfs_reflink_remap_range(src, pos_in, len, dest, pos_out); From patchwork Tue Oct 16 03:20:21 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: 10642961 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 E021918BC for ; Tue, 16 Oct 2018 03:20:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC861298AF for ; Tue, 16 Oct 2018 03:20:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C130229AD5; Tue, 16 Oct 2018 03:20:27 +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 545DD298AF for ; Tue, 16 Oct 2018 03:20:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 131996B0287; Mon, 15 Oct 2018 23:20:26 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0E4026B0288; Mon, 15 Oct 2018 23:20:26 -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 EEBDD6B0289; Mon, 15 Oct 2018 23:20:25 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by kanga.kvack.org (Postfix) with ESMTP id AE31B6B0287 for ; Mon, 15 Oct 2018 23:20:25 -0400 (EDT) Received: by mail-pl1-f197.google.com with SMTP id s24-v6so17059992plp.12 for ; Mon, 15 Oct 2018 20:20:25 -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=PyBPAavOIq55658ZH1Sj+FtMrq4d/FyfXvZlBhg5/0I=; b=IzLhtDcPpBUiTR4o2QJ1R5uXZDF8Rw3TXDijDjfgZJDN4YIJP/lgUc9O0FtNSxArp/ sVniuexEXSuDBq1Lm2bkezp1kYbprZs4f66VIt5xK8ci1m5PlW5E2p9XIrppgrjCTM9V XuYWscDXzGuI42I1+S1TtJRu94Yjke/qVoLuYbhNelsuRcC6AMCYe06ulMyNp3ELIKcJ E6aiP6/Y63Xue6J4mwF6fbJ/wOii2Qc1jj+MbeSk4CoP8xNp67uMbjQSHbzqXg5yfQbD L/pXho20lfpTGXf9UAM3VEKTlbjHw3AW0pCa8EXB8Dd88FZhRb/Oi4DWKZqeJZCkrxmT eHWw== X-Gm-Message-State: ABuFfohdKtpoX8RHq0IWDhNZKlYZes8p5iFQCS+1NSh6nSJ8o7/qM+sH zpZoaH4Iu4WI6G80hxsKj9irLp1huDDW6UBhPGyxv21fcza0RhA4nBaSuVi67Xwnhik/JyRApcq nRBKKH9ANVTnICq7aoke11xMHOHGnF6baLJQ0sKeIOsru41+NXwPtROtHp1IZbgzzww== X-Received: by 2002:a65:4145:: with SMTP id x5-v6mr18460028pgp.309.1539660025379; Mon, 15 Oct 2018 20:20:25 -0700 (PDT) X-Google-Smtp-Source: ACcGV60RvTc+M037YdWyrjxz8PhXAVfFANX+/wCMXlKCq6vrkUZpKtPUOm6Dh2+huUTr84uVQN+4 X-Received: by 2002:a65:4145:: with SMTP id x5-v6mr18460001pgp.309.1539660024788; Mon, 15 Oct 2018 20:20:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539660024; cv=none; d=google.com; s=arc-20160816; b=JMvlYVVRugbMkFJZ2keO/TYOEL0F0ienKUdgeG46pbphEbJiuhD7aXhwLUYjppoy2R 8EogVEOtx9HjE3Ax1IALy1TWqMXSkpQw9/0fakTWaVsx2l6q8f3X9YC8SlHGO9EhOKqV e9+sZlw99L/E3S/rjYyfBvC73I/9vn2PFEJwERwg4Aj7CWVtzRa6RmcPZ6+6mawP2Xvf 1pXx2EsorcmGsPPVjf9eEkmmIkuxPbfP0H+gt6097cB7X2AMXVgDvYecmMO0nlmcusd9 gYTWMdsqSbMSli/YB4+CbJuU1ytqXT/EA6bAuw7H441LCh63EHE11u/6/nKvhLGNy99i 1gtg== 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=PyBPAavOIq55658ZH1Sj+FtMrq4d/FyfXvZlBhg5/0I=; b=P43dvDtHaX3WFpDhgnoSP7gXasP3syqGVCZ6n2JlLnlA02EdyDAdrvAF6M0dM1P29n VHSVI8xbm4jJ+IMIc+Lhrf6Fe1/w1PCFYOcJBwgjhNqWM7Q2CAmBvPzfV5CwvNorIVnB Mlt3JR1PEygYgMwX+OtjZuIA5E1Vf+P5Qzo1sFFaTR02nXszD9JProY1fMvNvods1pNn +iONhGTAC3zTNKIMuVzUJAmqZaXpLrxcp+42u/vb1ElPEQ3gg03CfCv0lhfsLOLo2NXi R9pUr6d+YS/iasnXGQhQWnphrVN7SIm/biGEo3Uc0kKT100WQeBji0iuRE0rffZWIdek MVug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b="3/ATnRlF"; 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 z138-v6si14311689pfc.181.2018.10.15.20.20.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 20:20:24 -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="3/ATnRlF"; 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 w9G3J3t4051349; Tue, 16 Oct 2018 03:20:24 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=PyBPAavOIq55658ZH1Sj+FtMrq4d/FyfXvZlBhg5/0I=; b=3/ATnRlF0+K3juooAcYQQkcfgKZy7Qsol0XStB+WNT/h/ZmfR4RSs36kpd1rMHfXPMWB 4VCmI+OdxEDK+1aQkwjR5/Ioya8Z31FwYwM/qYojKk5EYJgGU1DyGjHvgLgMgal3N5rp zrSuPDKQGNoQHe3OwrYIrob24OWMl8lm7OsQAMLC/0l7jcNJU+nDIud2NrfRqB6nE2PE hqB2AX0V9LMmv/mZ5dwu1ZotvA36FWhcgQiPR0S16djsNiQo1FwlixIKGFJcnfLwKWpG r9WsUMC3CbdNNYpg3zKPMeCFMnQ/pbbCcunRZeRYsMtk3QrByoaTmMEwoobJmZq5ko/x RQ== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2130.oracle.com with ESMTP id 2n384tx29q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:20:24 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3KNdc032476 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:20:23 GMT Received: from abhmp0020.oracle.com (abhmp0020.oracle.com [141.146.116.26]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w9G3KNGr007142; Tue, 16 Oct 2018 03:20:23 GMT Received: from localhost (/10.159.227.150) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 15 Oct 2018 20:20:22 -0700 Subject: [PATCH 20/26] ocfs2: truncate page cache for clone destination file before remapping 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: Mon, 15 Oct 2018 20:20:21 -0700 Message-ID: <153966002134.3607.2095885321354295269.stgit@magnolia> In-Reply-To: <153965939489.1256.7400115244528045860.stgit@magnolia> References: <153965939489.1256.7400115244528045860.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9047 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=801 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810160028 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 When cloning blocks into another file, truncate the page cache before we start remapping blocks so that concurrent reads wait for us to finish. Signed-off-by: Darrick J. Wong --- fs/ocfs2/refcounttree.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c index 46bbd315c39f..2a5c96bc9677 100644 --- a/fs/ocfs2/refcounttree.c +++ b/fs/ocfs2/refcounttree.c @@ -4861,14 +4861,12 @@ int ocfs2_reflink_remap_range(struct file *file_in, down_write_nested(&OCFS2_I(inode_out)->ip_alloc_sem, SINGLE_DEPTH_NESTING); - ret = ocfs2_reflink_remap_blocks(inode_in, in_bh, pos_in, inode_out, - out_bh, pos_out, len); - /* Zap any page cache for the destination file's range. */ - if (!ret) - truncate_inode_pages_range(&inode_out->i_data, pos_out, - PAGE_ALIGN(pos_out + len) - 1); + truncate_inode_pages_range(&inode_out->i_data, pos_out, + PAGE_ALIGN(pos_out + len) - 1); + ret = ocfs2_reflink_remap_blocks(inode_in, in_bh, pos_in, inode_out, + out_bh, pos_out, len); up_write(&OCFS2_I(inode_in)->ip_alloc_sem); if (!same_inode) up_write(&OCFS2_I(inode_out)->ip_alloc_sem); From patchwork Tue Oct 16 03:20:28 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: 10642977 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 0E08B17D2 for ; Tue, 16 Oct 2018 03:20:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EEFE128E72 for ; Tue, 16 Oct 2018 03:20:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E3138298AF; Tue, 16 Oct 2018 03:20:34 +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 7CF0A28E72 for ; Tue, 16 Oct 2018 03:20:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5A09A6B0289; Mon, 15 Oct 2018 23:20:33 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 526666B028A; Mon, 15 Oct 2018 23:20:33 -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 3F0D76B028B; Mon, 15 Oct 2018 23:20:33 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) by kanga.kvack.org (Postfix) with ESMTP id F19EE6B0289 for ; Mon, 15 Oct 2018 23:20:32 -0400 (EDT) Received: by mail-pg1-f199.google.com with SMTP id s15-v6so16233832pgv.9 for ; Mon, 15 Oct 2018 20:20:32 -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=HOYBOBGpflqwSaMT4PmSGK8TNSkXTGNQVQO8YcwuUKs=; b=AfMW/JOlYgjnzptq/KyS+dCaYDVpQ0opYb+eiw86DMegVgBXlDZDWK7W8iXTdWVjTb 26QhMMjQKJHIIX4160W7CVrYMeea44tzZNmslh5CFgkpTQkhbHLwVmzAtKbZc+PId9cE aW7imhD7pHIjlNk+tUS2Fj1HK2LDjmDV9rQjuLKMH4q50rIoVAs6IyRCqel2yru6M872 irsfSC0i0s0tihk0dJ64JxF6hSdbSnXTgpwJmpO1DxQgk/pDeMRzvnOCLOpCMsVZgKn4 E7infl7nMtTEp1gx/VpZD0OhyIP8VmYxfSTMzPyxMjMi8j/fbc+oYJRoIaZVhJV8TPFV tJNw== X-Gm-Message-State: ABuFfoit0xHSfZPnPFsnuGftzLjMf92lgPTbbSwHwMxvGAMMMvsmXF6V mkKVAIun8bkYcmyzDQRCuJrX+IMuCx+HnZXrqIvUTWxLKo9HjHVN+dXeQhS3d6fpmfG2IRFlE6T Pm2r5M9VAydQTak5qM+IT1e/rMYC8RSlM3bBIDu4xam6fXsDMqeZcUeZNrCSLt+JASA== X-Received: by 2002:a62:ce83:: with SMTP id y125-v6mr20346172pfg.201.1539660032665; Mon, 15 Oct 2018 20:20:32 -0700 (PDT) X-Google-Smtp-Source: ACcGV63WMqPgL4gOSL2nH3MQlzgtlpCPOzm/WFhSK5/Y+Rlk9FCyfV4f7aCu/c9F1bhUO1UUSNDv X-Received: by 2002:a62:ce83:: with SMTP id y125-v6mr20346134pfg.201.1539660031990; Mon, 15 Oct 2018 20:20:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539660031; cv=none; d=google.com; s=arc-20160816; b=OMAlwZ7H/wue2JY3YWJEWI31o/Tmv+afvilRR7ow4G3GajtEXwMVgz3w0PP4xZ2nWV wMcCg4Q5xMZcL9n0C/4DBWpCnqL4u7nZeWCrKy3Dc0gwNLxBVlwwLXvaQSzZyUjAy101 zGQf7rzI/MiRPKRwODZIDDZDmHKqNmCIXlCNWBpQegrxIl6t5ww+FE/TmZ8AbbJx3d28 y5n8wM8QjFa6s5O/sm7l6tGwwAF3nHZKV1HutKzzWfj5IZ6xjNWUpriABh8jkbr84dbU GOiaM6ew8pj+Gy2Pxq/Lzp98LS1SPcLHEjfRbZKyl8y9fxSlMS0PqB9PFwp89AAne0FB Fj1g== 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=HOYBOBGpflqwSaMT4PmSGK8TNSkXTGNQVQO8YcwuUKs=; b=V3mNMpeGkSBZJBg0R0mQKT7X4amfp3Zb2LECitpngOaeFGKQtpWlUIDcZI6qRfRtMH MbkracM8zJ3Wwa4Pfarr6qXnyoeuuua2as/CN/NbzGEkI7wL2n1e53rLejibQr4eFsyW RgW5wrfC1T7LcnLcgyttRdqtCvv8cEPosChRGflRiJxCpnAd+2qHnXM6XtmKe2Ab1M+s 7/tGSFduQEX5scqG9V0QEEy0TclKnyYSo6tB0ZRgHpnsmrWZbdtfBFN9l464FpCN8fxK A4laMEuGwZGKgozc+CVFHcckElBbZltaxpzQmCFsIeJurj5rfhnSQGc4lgB3UFuJFT8v sGPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=iBSICVn4; 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 u12-v6si12241318pls.150.2018.10.15.20.20.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 20:20:31 -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=iBSICVn4; 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 w9G3JosY051805; Tue, 16 Oct 2018 03:20:31 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=HOYBOBGpflqwSaMT4PmSGK8TNSkXTGNQVQO8YcwuUKs=; b=iBSICVn4f9CkaRFFiOxk2xB6Y4NFF+6yJTm0g85Ac8gHYjxhbKJs7hWy8xzvr7mKImeN V8N/wYDDl1S13EN4709ZB0nQAF8wsAYGdoekttm+crepR3b6VUelYUjwEkVk+2M2dmkE /NrZoJh7gZznmDo77tU5l+ACD1JK6isq55m/9n1bZIL2yfrzyllpmvz+a9kSwvHjAprS xnCZpHestWVzu6VTXPrnQ9Vx/Gvt87rXQCnZvXJKNng5vnVDpq5Xb0r7b4lKU3p1w4ou LKNboZS0vnvnnvsb33r/PNcDLrVmTu+Vm4nYEN+hh1Qw9oIzM0Z+g3ghIe5EwM1584l8 Cw== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2130.oracle.com with ESMTP id 2n384tx29t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:20:31 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3KUJf029604 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:20:30 GMT Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3KTFY012664; Tue, 16 Oct 2018 03:20:30 GMT Received: from localhost (/10.159.227.150) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 15 Oct 2018 20:20:29 -0700 Subject: [PATCH 21/26] ocfs2: fix pagecache truncation prior to reflink 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: Mon, 15 Oct 2018 20:20:28 -0700 Message-ID: <153966002809.3607.17959416355714610983.stgit@magnolia> In-Reply-To: <153965939489.1256.7400115244528045860.stgit@magnolia> References: <153965939489.1256.7400115244528045860.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9047 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=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810160028 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 Prior to remapping blocks, it is necessary to remove pages from the destination file's page cache. Unfortunately, the truncation is not aggressive enough -- if page size > block size, we'll end up zeroing subpage blocks instead of removing them. So, round the start offset down and the end offset up to page boundaries. We already wrote all the dirty data so the larger range should be fine. Signed-off-by: Darrick J. Wong --- fs/ocfs2/refcounttree.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c index 2a5c96bc9677..7c709229e108 100644 --- a/fs/ocfs2/refcounttree.c +++ b/fs/ocfs2/refcounttree.c @@ -4862,8 +4862,9 @@ int ocfs2_reflink_remap_range(struct file *file_in, SINGLE_DEPTH_NESTING); /* Zap any page cache for the destination file's range. */ - truncate_inode_pages_range(&inode_out->i_data, pos_out, - PAGE_ALIGN(pos_out + len) - 1); + truncate_inode_pages_range(&inode_out->i_data, + round_down(pos_out, PAGE_SIZE), + round_up(pos_out + len, PAGE_SIZE) - 1); ret = ocfs2_reflink_remap_blocks(inode_in, in_bh, pos_in, inode_out, out_bh, pos_out, len); From patchwork Tue Oct 16 03:20:34 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: 10642989 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 A907917D2 for ; Tue, 16 Oct 2018 03:20:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 933E528E72 for ; Tue, 16 Oct 2018 03:20:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 87655298AF; Tue, 16 Oct 2018 03:20:47 +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 DEBFA28E72 for ; Tue, 16 Oct 2018 03:20:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A820F6B028A; Mon, 15 Oct 2018 23:20:45 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A313F6B028C; Mon, 15 Oct 2018 23:20:45 -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 8F8566B028D; Mon, 15 Oct 2018 23:20:45 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) by kanga.kvack.org (Postfix) with ESMTP id 4ECA96B028A for ; Mon, 15 Oct 2018 23:20:45 -0400 (EDT) Received: by mail-pg1-f199.google.com with SMTP id h9-v6so16021856pgs.11 for ; Mon, 15 Oct 2018 20:20:45 -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=6J/QYq4s6QFaJLMu3nSz4IUXRy/yndbu5A+K+2UxqS4=; b=A8B6XUKBAaDWBTC03zFF68Ia+aWPo/m5KYVZKoFozBwoljOqZaRnwWtF1+YguL3ipw g+RQkuAnZ/b0u8WQV5DMLKifa5r3Xl+YWyVSWFl2TS7qAskzZE20pHL//5UuSn3AEF5I s9MnS/hipGQFMuV9CL1oSlUBYl4RtzGnI8e+q7fd8j64dHjKSYVbGzW98O5EhEYfSRd1 DIWSsQG/RKHfxBh4Ia3BGgHTyOMmhjkNF1P76j0C8K3jZSCXsrH0/3kjxc+1oRc90eTg jD2ETFVYKL3/zaHKfNB/7A42Ezgu4j/or/fqiHowjz9L/wdsf0szpD4R42N/pyYfx30r rtyg== X-Gm-Message-State: ABuFfogemqtJGerhWyDhrly9RhZqhhRJaY/qeWY75EfoTlsT6Fi4IagJ 5N0Irha2oqps/AKrcApsBCwuSw5PqJmqjDNFTx6hSr+bVHwAFmzxP0oXZYGrT8VWiQhgHx7747M hr2QoxGbPZIIhQEOv+PUnvR31iX3K82fxtTZZjbC8q/rEIA/s/LQcNXD+wzVl0i6lJg== X-Received: by 2002:a62:2542:: with SMTP id l63-v6mr20766261pfl.64.1539660044976; Mon, 15 Oct 2018 20:20:44 -0700 (PDT) X-Google-Smtp-Source: ACcGV63frlRDQ6YKh4FUsapLulvgeSe8wo81vBFNT4OTQhKeOyjVsbZVZC9fUve27lOustjLEN1S X-Received: by 2002:a62:2542:: with SMTP id l63-v6mr20766220pfl.64.1539660044044; Mon, 15 Oct 2018 20:20:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539660044; cv=none; d=google.com; s=arc-20160816; b=axOz/aL+mRuHx0opCye+8EEpTGNjpGXQ5rz+chrjtYGp+R/vnCW1CEccodiCuIq+D+ tef0ZMZt88JALeHocvzhWBlXQtlFYhzhuWARlBZZgedxIho6XnxlakhcLDUMIbD9ZXl0 SHQ97i2/dsGcRfUcPxqdo2wsm26G9B/UfZuwVCvDiPG7DgQiq/Tg71eDNpts9lrK9owx F1ybTKQXD459D1i0mLWwseu+csOcxk8CI9Dn4psuCJsAtFgKb9pg57FLcqfuZTnAMIHq fH9a7RRTtEaJxcBlNTE55nJksTuRjo7WiuKodgYYEGpfx7ko0G1kuGtihHaU8+0arpv+ GYWQ== 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=6J/QYq4s6QFaJLMu3nSz4IUXRy/yndbu5A+K+2UxqS4=; b=i2EHXy3rRmwHpHizNPt8/zzEscExeouMApqRnEsui/sRvfKMiH1SMjEuCONHATDeBO w/CD0LbnPYVIwl1Jh29vRPaO4XET0gRDcblBSuiF9x9dOn6nlBcT7XQin29ezHF0l+qE Oi6dIzd0fpTd1o2lhqcx0Ot79ctjIV74X6JetVyNXibSQ7sB0uko4rS1+VMtuI17jb4+ Y6C5dfPVFm3vle8XzCMJjzYql0VnZoUQWnwoqCWEsDbKYIJ2SpkjZFlK8czf7sDQrE5o FgTVRS3Xr2vs4+e4PPFU1CdNbT7YkjJm6EbB5U6a+Vs1UWrlw/wNxFbPlnAowseJIdCC x2sA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=nsTiqJYf; 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 3-v6si12718509plp.173.2018.10.15.20.20.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 20:20:44 -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=nsTiqJYf; 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 w9G3JgPx051754; Tue, 16 Oct 2018 03:20:43 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=6J/QYq4s6QFaJLMu3nSz4IUXRy/yndbu5A+K+2UxqS4=; b=nsTiqJYf8DbHsWPFpINf1TvJ9AQitIAf/Pag+2v7bqSahknDyTk+C4DfY8GMcgbhDrqP xn7/6aO6Q9SS5MWKdkIFM7qPIKSS8GKZDET+ITq6sNt4tCL3T1NDkTgsYGez67KDWtlv MuhtSriyDv44prRbIBEF5bTsbyZEYI3wHDdsJq9MygcwV+peMOEpZ6rM6Dx9jEtkmOB1 bdSB4NeE7AISCEdppBceCnV5jA2Yd7nW1TcV1fTQMR6tPoyCyyUDTv0i5z8zBRucZKq/ q7HWfMLazG05qaMnZIpVihkd5aqxfWi5dDx5gymgbSVIGA4HE/1fiRNj231CE9Vp304l PQ== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2n384tx2a5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:20:43 +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 w9G3KblU005285 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:20:37 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 w9G3KaG5012678; Tue, 16 Oct 2018 03:20:36 GMT Received: from localhost (/10.159.227.150) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 15 Oct 2018 20:20:36 -0700 Subject: [PATCH 22/26] ocfs2: support partial clone range and dedupe range 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: Mon, 15 Oct 2018 20:20:34 -0700 Message-ID: <153966003484.3607.3682046712485244493.stgit@magnolia> In-Reply-To: <153965939489.1256.7400115244528045860.stgit@magnolia> References: <153965939489.1256.7400115244528045860.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9047 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=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810160028 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 Change the ocfs2 remap code to allow for returning partial results. Signed-off-by: Darrick J. Wong --- fs/ocfs2/file.c | 7 +---- fs/ocfs2/refcounttree.c | 72 +++++++++++++++++++++++++---------------------- fs/ocfs2/refcounttree.h | 12 ++++---- 3 files changed, 46 insertions(+), 45 deletions(-) diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c index fbaeafe44b5f..8125c5ccf821 100644 --- a/fs/ocfs2/file.c +++ b/fs/ocfs2/file.c @@ -2531,14 +2531,11 @@ static loff_t ocfs2_remap_file_range(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, loff_t len, unsigned int remap_flags) { - int ret; - if (remap_flags & ~(REMAP_FILE_DEDUP | REMAP_FILE_ADVISORY)) return -EINVAL; - ret = ocfs2_reflink_remap_range(file_in, pos_in, file_out, pos_out, - len, remap_flags); - return ret < 0 ? ret : len; + return ocfs2_reflink_remap_range(file_in, pos_in, file_out, pos_out, + len, remap_flags); } const struct inode_operations ocfs2_file_iops = { diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c index 7c709229e108..c7409578657b 100644 --- a/fs/ocfs2/refcounttree.c +++ b/fs/ocfs2/refcounttree.c @@ -4507,14 +4507,14 @@ static int ocfs2_reflink_update_dest(struct inode *dest, } /* Remap the range pos_in:len in s_inode to pos_out:len in t_inode. */ -static int ocfs2_reflink_remap_extent(struct inode *s_inode, - struct buffer_head *s_bh, - loff_t pos_in, - struct inode *t_inode, - struct buffer_head *t_bh, - loff_t pos_out, - loff_t len, - struct ocfs2_cached_dealloc_ctxt *dealloc) +static loff_t ocfs2_reflink_remap_extent(struct inode *s_inode, + struct buffer_head *s_bh, + loff_t pos_in, + struct inode *t_inode, + struct buffer_head *t_bh, + loff_t pos_out, + loff_t len, + struct ocfs2_cached_dealloc_ctxt *dealloc) { struct ocfs2_extent_tree s_et; struct ocfs2_extent_tree t_et; @@ -4522,8 +4522,9 @@ static int ocfs2_reflink_remap_extent(struct inode *s_inode, struct buffer_head *ref_root_bh = NULL; struct ocfs2_refcount_tree *ref_tree; struct ocfs2_super *osb; + loff_t remapped_bytes = 0; loff_t pstart, plen; - u32 p_cluster, num_clusters, slast, spos, tpos; + u32 p_cluster, num_clusters, slast, spos, tpos, remapped_clus = 0; unsigned int ext_flags; int ret = 0; @@ -4605,30 +4606,34 @@ static int ocfs2_reflink_remap_extent(struct inode *s_inode, next_loop: spos += num_clusters; tpos += num_clusters; + remapped_clus += num_clusters; } -out: - return ret; + goto out; out_unlock_refcount: ocfs2_unlock_refcount_tree(osb, ref_tree, 1); brelse(ref_root_bh); - return ret; +out: + remapped_bytes = ocfs2_clusters_to_bytes(t_inode->i_sb, remapped_clus); + remapped_bytes = min_t(loff_t, len, remapped_bytes); + + return remapped_bytes > 0 ? remapped_bytes : ret; } /* Set up refcount tree and remap s_inode to t_inode. */ -static int ocfs2_reflink_remap_blocks(struct inode *s_inode, - struct buffer_head *s_bh, - loff_t pos_in, - struct inode *t_inode, - struct buffer_head *t_bh, - loff_t pos_out, - loff_t len) +static loff_t ocfs2_reflink_remap_blocks(struct inode *s_inode, + struct buffer_head *s_bh, + loff_t pos_in, + struct inode *t_inode, + struct buffer_head *t_bh, + loff_t pos_out, + loff_t len) { struct ocfs2_cached_dealloc_ctxt dealloc; struct ocfs2_super *osb; struct ocfs2_dinode *dis; struct ocfs2_dinode *dit; - int ret; + loff_t ret; osb = OCFS2_SB(s_inode->i_sb); dis = (struct ocfs2_dinode *)s_bh->b_data; @@ -4700,7 +4705,7 @@ static int ocfs2_reflink_remap_blocks(struct inode *s_inode, /* Actually remap extents now. */ ret = ocfs2_reflink_remap_extent(s_inode, s_bh, pos_in, t_inode, t_bh, pos_out, len, &dealloc); - if (ret) { + if (ret < 0) { mlog_errno(ret); goto out; } @@ -4820,18 +4825,19 @@ static void ocfs2_reflink_inodes_unlock(struct inode *s_inode, } /* Link a range of blocks from one file to another. */ -int ocfs2_reflink_remap_range(struct file *file_in, - loff_t pos_in, - struct file *file_out, - loff_t pos_out, - loff_t len, - unsigned int remap_flags) +loff_t ocfs2_reflink_remap_range(struct file *file_in, + loff_t pos_in, + struct file *file_out, + loff_t pos_out, + loff_t len, + unsigned int remap_flags) { struct inode *inode_in = file_inode(file_in); struct inode *inode_out = file_inode(file_out); struct ocfs2_super *osb = OCFS2_SB(inode_in->i_sb); struct buffer_head *in_bh = NULL, *out_bh = NULL; bool same_inode = (inode_in == inode_out); + loff_t remapped = 0; ssize_t ret; if (!ocfs2_refcount_tree(osb)) @@ -4866,12 +4872,13 @@ int ocfs2_reflink_remap_range(struct file *file_in, round_down(pos_out, PAGE_SIZE), round_up(pos_out + len, PAGE_SIZE) - 1); - ret = ocfs2_reflink_remap_blocks(inode_in, in_bh, pos_in, inode_out, - out_bh, pos_out, len); + remapped = ocfs2_reflink_remap_blocks(inode_in, in_bh, pos_in, + inode_out, out_bh, pos_out, len); up_write(&OCFS2_I(inode_in)->ip_alloc_sem); if (!same_inode) up_write(&OCFS2_I(inode_out)->ip_alloc_sem); - if (ret) { + if (remapped < 0) { + ret = remapped; mlog_errno(ret); goto out_unlock; } @@ -4889,10 +4896,7 @@ int ocfs2_reflink_remap_range(struct file *file_in, goto out_unlock; } - ocfs2_reflink_inodes_unlock(inode_in, in_bh, inode_out, out_bh); - return 0; - out_unlock: ocfs2_reflink_inodes_unlock(inode_in, in_bh, inode_out, out_bh); - return ret; + return remapped > 0 ? remapped : ret; } diff --git a/fs/ocfs2/refcounttree.h b/fs/ocfs2/refcounttree.h index eb65c1d0843c..9e64daba395d 100644 --- a/fs/ocfs2/refcounttree.h +++ b/fs/ocfs2/refcounttree.h @@ -115,11 +115,11 @@ int ocfs2_reflink_ioctl(struct inode *inode, const char __user *oldname, const char __user *newname, bool preserve); -int ocfs2_reflink_remap_range(struct file *file_in, - loff_t pos_in, - struct file *file_out, - loff_t pos_out, - loff_t len, - unsigned int remap_flags); +loff_t ocfs2_reflink_remap_range(struct file *file_in, + loff_t pos_in, + struct file *file_out, + loff_t pos_out, + loff_t len, + unsigned int remap_flags); #endif /* OCFS2_REFCOUNTTREE_H */ From patchwork Tue Oct 16 03:20:41 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: 10643001 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 AEDB518BC for ; Tue, 16 Oct 2018 03:20:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 99D1C28E72 for ; Tue, 16 Oct 2018 03:20:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8DB89298AF; Tue, 16 Oct 2018 03:20:54 +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 C055B28E72 for ; Tue, 16 Oct 2018 03:20:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 701056B028C; Mon, 15 Oct 2018 23:20:52 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6AEED6B028E; Mon, 15 Oct 2018 23:20:52 -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 5829D6B028F; Mon, 15 Oct 2018 23:20:52 -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 0B4CF6B028C for ; Mon, 15 Oct 2018 23:20:52 -0400 (EDT) Received: by mail-pf1-f200.google.com with SMTP id a72-v6so6458732pfj.14 for ; Mon, 15 Oct 2018 20:20:52 -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=yAZ/1PPkeVRlAU93kCg6O9O78UCd/8KO5hoqJKQC2Ek=; b=MiqmB3+WfrpuiniA55ivlkfzkuUhm0aYEzVGcU5TnIJZ33QgXYYnIBi33ARnrWIs5q 8e+t2XhV9xaynPhybbVhIuTSelULFHx129IGuJGFd16VQx5PcE8+/TQAtJMYtN4x7VD9 hD2lOsNToCBql153NHVvxbH7NwdechUG5YB0qkrHGrRZrQYRRPO9RMy6f9mGJaL2qC97 9V3gXOEo9yxIhXxRXD03yx6UvAkn86FnuLGZbjm2OVOr9t+ebtI3GiejOqQjqLWJOkt7 uWnQq/sxdMIdIhZKNc9SOkipD5qj4JAoRVsdipVfyAM8JfYI3I+Fm7kgfOqADx4acLl4 MKyA== X-Gm-Message-State: ABuFfohsgPorj9Gdsj47lpyiDIUygnDnQZFajLBYKPNayfuYWRSLtdR5 l7bQtSSQuYtNZnIbu7QPoqPp+odggIvhK2wx+1qD9IYXKXko0Od6ES17elkoCMwlc0VUtE673yN 9Y8U/Y8OM7xRglhJ/kk/BLdiDBL7NP7v1JI6uLkMT5/WEvJyeeRlAHphGR0tYvlxw/w== X-Received: by 2002:a17:902:59dc:: with SMTP id d28-v6mr19726998plj.116.1539660051699; Mon, 15 Oct 2018 20:20:51 -0700 (PDT) X-Google-Smtp-Source: ACcGV62JLdSP1o6qJ3aUR/8wQHd6Ln2+0mwqWPfQ3EJOkAkI/unkQmumHgyfK5PnpFVzGNS4qB/0 X-Received: by 2002:a17:902:59dc:: with SMTP id d28-v6mr19726948plj.116.1539660050666; Mon, 15 Oct 2018 20:20:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539660050; cv=none; d=google.com; s=arc-20160816; b=dPP1VP8WhTCw0/iJk2m/EutsB2UM+a9Jhc+skNBBG7FdVYi2fnVT1diaiRN3wvzNnO efI4DIjReF81iBz9z51sw76l3EDRldMP6Y/c/Hzub0iFLhuEMwF5okhOf2ermRd6M3yF 5cTk2REcG8KDmFENbpyO4vDvBwq3zKmfQCZUOtNToEobRfydf9l3VwQjm5AaTZh4LXv7 iI4kv38HWJWL1DaiTJNYs7RSSRhPs2fW4oCNy80X2kIaK8mIFo/68DFNYcjuEN1/oEyq gtf4PsmRcNh4bpfY5AHoH4k76A6mmfemCtKkzOP1hsjBY8wN9nEe8Zl32nZFG8/7AoKu cAKw== 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=yAZ/1PPkeVRlAU93kCg6O9O78UCd/8KO5hoqJKQC2Ek=; b=W73aynStUyrywQV52RqDvyYOUCtrGsHAQhm/3ps24plbw5usFGrcGOxFFxcrCfeQJ0 rcCUSzECNo1Uw9cwNiiaAPF2rytQlxVWBXgByDdiY8xc1EADrlVuvq2l1ecnWkbDuBYa kasUxH63q66W7VlbpyPzESeQzYXWosbfY7R9HbKmmgfk59ZaLv1UY0EXN1sgcspD3vR9 fG9HicvUjpjUrBEK6ocJSnO1vKkpu1n9uO9nLrDbtKTFEKtC6S6i37Fqfo0L/QcCaSyu IkJJh2iEpOCKVxZkXNPFuTRyMYJBDQghwhItnMsa2KsbsG3pqGlxTmXZrH15td9wtShD DXeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=WR4l6CaN; 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 j142-v6si14000356pfd.204.2018.10.15.20.20.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 20:20:50 -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=WR4l6CaN; 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 w9G3J8UH051365; Tue, 16 Oct 2018 03:20:50 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=yAZ/1PPkeVRlAU93kCg6O9O78UCd/8KO5hoqJKQC2Ek=; b=WR4l6CaNFvRFJvo0RrOCbkwn6zqWARZ4QM5OsezyfgD2tuyXdAMCLSg7ARjygnhBIQ4B QrixQ6mYXqO/VtlfFN8xctLozdccypgLlh+mNWsZxiZng1AMJvs5dioZLm6FvY4SGL1j BBPUnkI2dWQO2YPfpJLW4G2ewNqx4ZQ5JZ/VqpsHcTyiyCFVkWEgb6btr1ne9sZTxbZ0 LtZ5JrFHTx7K0RYG9ctwVY1IOGQbUPnHk+6k40hUeCvu+cMKpPW4ZRKwb0F/trgIe/VB G1psh2zVthXpKrtpkRvVOgVOWh3TFpjGFNCsZCNEwTskVG4MP/vTQDpiJicvjdBghQcf 0A== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2130.oracle.com with ESMTP id 2n384tx2a9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:20:49 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3KhAR001355 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:20:43 GMT Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3Khqg010937; Tue, 16 Oct 2018 03:20:43 GMT Received: from localhost (/10.159.227.150) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 15 Oct 2018 20:20:43 -0700 Subject: [PATCH 23/26] ocfs2: remove ocfs2_reflink_remap_range 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: Mon, 15 Oct 2018 20:20:41 -0700 Message-ID: <153966004165.3607.1479048685053789222.stgit@magnolia> In-Reply-To: <153965939489.1256.7400115244528045860.stgit@magnolia> References: <153965939489.1256.7400115244528045860.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9047 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=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810160028 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 Since ocfs2_remap_file_range is a thin shell around ocfs2_remap_remap_range, move everything from the latter into the former. Signed-off-by: Darrick J. Wong --- fs/ocfs2/file.c | 68 +++++++++++++++++++++++++++- fs/ocfs2/refcounttree.c | 113 +++++++---------------------------------------- fs/ocfs2/refcounttree.h | 24 +++++++--- 3 files changed, 102 insertions(+), 103 deletions(-) diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c index 8125c5ccf821..fe570824b991 100644 --- a/fs/ocfs2/file.c +++ b/fs/ocfs2/file.c @@ -2531,11 +2531,75 @@ static loff_t ocfs2_remap_file_range(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, loff_t len, unsigned int remap_flags) { + struct inode *inode_in = file_inode(file_in); + struct inode *inode_out = file_inode(file_out); + struct ocfs2_super *osb = OCFS2_SB(inode_in->i_sb); + struct buffer_head *in_bh = NULL, *out_bh = NULL; + bool same_inode = (inode_in == inode_out); + loff_t remapped = 0; + ssize_t ret; + if (remap_flags & ~(REMAP_FILE_DEDUP | REMAP_FILE_ADVISORY)) return -EINVAL; + if (!ocfs2_refcount_tree(osb)) + return -EOPNOTSUPP; + if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb)) + return -EROFS; - return ocfs2_reflink_remap_range(file_in, pos_in, file_out, pos_out, - len, remap_flags); + /* Lock both files against IO */ + ret = ocfs2_reflink_inodes_lock(inode_in, &in_bh, inode_out, &out_bh); + if (ret) + return ret; + + /* Check file eligibility and prepare for block sharing. */ + ret = -EINVAL; + if ((OCFS2_I(inode_in)->ip_flags & OCFS2_INODE_SYSTEM_FILE) || + (OCFS2_I(inode_out)->ip_flags & OCFS2_INODE_SYSTEM_FILE)) + goto out_unlock; + + ret = generic_remap_file_range_prep(file_in, pos_in, file_out, pos_out, + &len, remap_flags); + if (ret < 0 || len == 0) + goto out_unlock; + + /* Lock out changes to the allocation maps and remap. */ + down_write(&OCFS2_I(inode_in)->ip_alloc_sem); + if (!same_inode) + down_write_nested(&OCFS2_I(inode_out)->ip_alloc_sem, + SINGLE_DEPTH_NESTING); + + /* Zap any page cache for the destination file's range. */ + truncate_inode_pages_range(&inode_out->i_data, + round_down(pos_out, PAGE_SIZE), + round_up(pos_out + len, PAGE_SIZE) - 1); + + remapped = ocfs2_reflink_remap_blocks(inode_in, in_bh, pos_in, + inode_out, out_bh, pos_out, len); + up_write(&OCFS2_I(inode_in)->ip_alloc_sem); + if (!same_inode) + up_write(&OCFS2_I(inode_out)->ip_alloc_sem); + if (remapped < 0) { + ret = remapped; + mlog_errno(ret); + goto out_unlock; + } + + /* + * Empty the extent map so that we may get the right extent + * record from the disk. + */ + ocfs2_extent_map_trunc(inode_in, 0); + ocfs2_extent_map_trunc(inode_out, 0); + + ret = ocfs2_reflink_update_dest(inode_out, out_bh, pos_out + len); + if (ret) { + mlog_errno(ret); + goto out_unlock; + } + +out_unlock: + ocfs2_reflink_inodes_unlock(inode_in, in_bh, inode_out, out_bh); + return remapped > 0 ? remapped : ret; } const struct inode_operations ocfs2_file_iops = { diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c index c7409578657b..dc66b80585ec 100644 --- a/fs/ocfs2/refcounttree.c +++ b/fs/ocfs2/refcounttree.c @@ -4468,9 +4468,9 @@ int ocfs2_reflink_ioctl(struct inode *inode, } /* Update destination inode size, if necessary. */ -static int ocfs2_reflink_update_dest(struct inode *dest, - struct buffer_head *d_bh, - loff_t newlen) +int ocfs2_reflink_update_dest(struct inode *dest, + struct buffer_head *d_bh, + loff_t newlen) { handle_t *handle; int ret; @@ -4621,13 +4621,13 @@ static loff_t ocfs2_reflink_remap_extent(struct inode *s_inode, } /* Set up refcount tree and remap s_inode to t_inode. */ -static loff_t ocfs2_reflink_remap_blocks(struct inode *s_inode, - struct buffer_head *s_bh, - loff_t pos_in, - struct inode *t_inode, - struct buffer_head *t_bh, - loff_t pos_out, - loff_t len) +loff_t ocfs2_reflink_remap_blocks(struct inode *s_inode, + struct buffer_head *s_bh, + loff_t pos_in, + struct inode *t_inode, + struct buffer_head *t_bh, + loff_t pos_out, + loff_t len) { struct ocfs2_cached_dealloc_ctxt dealloc; struct ocfs2_super *osb; @@ -4720,10 +4720,10 @@ static loff_t ocfs2_reflink_remap_blocks(struct inode *s_inode, } /* Lock an inode and grab a bh pointing to the inode. */ -static int ocfs2_reflink_inodes_lock(struct inode *s_inode, - struct buffer_head **bh1, - struct inode *t_inode, - struct buffer_head **bh2) +int ocfs2_reflink_inodes_lock(struct inode *s_inode, + struct buffer_head **bh1, + struct inode *t_inode, + struct buffer_head **bh2) { struct inode *inode1; struct inode *inode2; @@ -4808,10 +4808,10 @@ static int ocfs2_reflink_inodes_lock(struct inode *s_inode, } /* Unlock both inodes and release buffers. */ -static void ocfs2_reflink_inodes_unlock(struct inode *s_inode, - struct buffer_head *s_bh, - struct inode *t_inode, - struct buffer_head *t_bh) +void ocfs2_reflink_inodes_unlock(struct inode *s_inode, + struct buffer_head *s_bh, + struct inode *t_inode, + struct buffer_head *t_bh) { ocfs2_inode_unlock(s_inode, 1); ocfs2_rw_unlock(s_inode, 1); @@ -4823,80 +4823,3 @@ static void ocfs2_reflink_inodes_unlock(struct inode *s_inode, } unlock_two_nondirectories(s_inode, t_inode); } - -/* Link a range of blocks from one file to another. */ -loff_t ocfs2_reflink_remap_range(struct file *file_in, - loff_t pos_in, - struct file *file_out, - loff_t pos_out, - loff_t len, - unsigned int remap_flags) -{ - struct inode *inode_in = file_inode(file_in); - struct inode *inode_out = file_inode(file_out); - struct ocfs2_super *osb = OCFS2_SB(inode_in->i_sb); - struct buffer_head *in_bh = NULL, *out_bh = NULL; - bool same_inode = (inode_in == inode_out); - loff_t remapped = 0; - ssize_t ret; - - if (!ocfs2_refcount_tree(osb)) - return -EOPNOTSUPP; - if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb)) - return -EROFS; - - /* Lock both files against IO */ - ret = ocfs2_reflink_inodes_lock(inode_in, &in_bh, inode_out, &out_bh); - if (ret) - return ret; - - /* Check file eligibility and prepare for block sharing. */ - ret = -EINVAL; - if ((OCFS2_I(inode_in)->ip_flags & OCFS2_INODE_SYSTEM_FILE) || - (OCFS2_I(inode_out)->ip_flags & OCFS2_INODE_SYSTEM_FILE)) - goto out_unlock; - - ret = generic_remap_file_range_prep(file_in, pos_in, file_out, pos_out, - &len, remap_flags); - if (ret < 0 || len == 0) - goto out_unlock; - - /* Lock out changes to the allocation maps and remap. */ - down_write(&OCFS2_I(inode_in)->ip_alloc_sem); - if (!same_inode) - down_write_nested(&OCFS2_I(inode_out)->ip_alloc_sem, - SINGLE_DEPTH_NESTING); - - /* Zap any page cache for the destination file's range. */ - truncate_inode_pages_range(&inode_out->i_data, - round_down(pos_out, PAGE_SIZE), - round_up(pos_out + len, PAGE_SIZE) - 1); - - remapped = ocfs2_reflink_remap_blocks(inode_in, in_bh, pos_in, - inode_out, out_bh, pos_out, len); - up_write(&OCFS2_I(inode_in)->ip_alloc_sem); - if (!same_inode) - up_write(&OCFS2_I(inode_out)->ip_alloc_sem); - if (remapped < 0) { - ret = remapped; - mlog_errno(ret); - goto out_unlock; - } - - /* - * Empty the extent map so that we may get the right extent - * record from the disk. - */ - ocfs2_extent_map_trunc(inode_in, 0); - ocfs2_extent_map_trunc(inode_out, 0); - - ret = ocfs2_reflink_update_dest(inode_out, out_bh, pos_out + len); - if (ret) { - mlog_errno(ret); - goto out_unlock; - } - -out_unlock: - ocfs2_reflink_inodes_unlock(inode_in, in_bh, inode_out, out_bh); - return remapped > 0 ? remapped : ret; -} diff --git a/fs/ocfs2/refcounttree.h b/fs/ocfs2/refcounttree.h index 9e64daba395d..e9e862be4a1e 100644 --- a/fs/ocfs2/refcounttree.h +++ b/fs/ocfs2/refcounttree.h @@ -115,11 +115,23 @@ int ocfs2_reflink_ioctl(struct inode *inode, const char __user *oldname, const char __user *newname, bool preserve); -loff_t ocfs2_reflink_remap_range(struct file *file_in, - loff_t pos_in, - struct file *file_out, - loff_t pos_out, - loff_t len, - unsigned int remap_flags); +loff_t ocfs2_reflink_remap_blocks(struct inode *s_inode, + struct buffer_head *s_bh, + loff_t pos_in, + struct inode *t_inode, + struct buffer_head *t_bh, + loff_t pos_out, + loff_t len); +int ocfs2_reflink_inodes_lock(struct inode *s_inode, + struct buffer_head **bh1, + struct inode *t_inode, + struct buffer_head **bh2); +void ocfs2_reflink_inodes_unlock(struct inode *s_inode, + struct buffer_head *s_bh, + struct inode *t_inode, + struct buffer_head *t_bh); +int ocfs2_reflink_update_dest(struct inode *dest, + struct buffer_head *d_bh, + loff_t newlen); #endif /* OCFS2_REFCOUNTTREE_H */ From patchwork Tue Oct 16 03:20:48 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: 10643011 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 49DB43B73 for ; Tue, 16 Oct 2018 03:20:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3576428F69 for ; Tue, 16 Oct 2018 03:20:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2924429AF7; Tue, 16 Oct 2018 03:20:57 +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 B5F9A28F69 for ; Tue, 16 Oct 2018 03:20:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 046FE6B028E; Mon, 15 Oct 2018 23:20:54 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F15BE6B0290; Mon, 15 Oct 2018 23:20:53 -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 DB6AE6B0291; Mon, 15 Oct 2018 23:20:53 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) by kanga.kvack.org (Postfix) with ESMTP id 8E7496B028E for ; Mon, 15 Oct 2018 23:20:53 -0400 (EDT) Received: by mail-pg1-f199.google.com with SMTP id z8-v6so16073834pgp.20 for ; Mon, 15 Oct 2018 20:20:53 -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=XaJCcJb52edg+aC8VnKgwcIySPxyOilGPHSlrKf5LPY=; b=cE7tMTXUGd4Glq3TTjc1jd9/Ead8bsoln2zPBpI4A6aAOgmlvQJOxdVis4tY2sQiKi a5IVoXseRB3VXkddoCn/pvAGUGTMHK4nbCZfaypENw6bOgLlxMvszCYbxQaKcRhdvA6S aZNGIHycvIwJ+N+4bckorW8CcFh5+SIPgaPtKHVjJFy96pMnT6kepXtVJYa+NrsPseVW 0gLPoKqWbUCKdBGamfM+vzBSZo4iFnYnSjbQQ9qyV/rmsGABuD1SZ41yZahKB7Fp7N2z mLz1IAUFj5l1wdSIpetAQrkeHOT4/nTobdlnfklkm2TtkpD192OGfsS1qo7lQ+mof99l zKMw== X-Gm-Message-State: ABuFfohkmZ/urPZhUGSqC2D05xil76h+A0EhW/BwyglJ52dBWfuAeOZQ rpLbs1wsTL4ES2wRsu6qNbQLVbDyaGBpdVKQ3XSGCL1vpEO8ycimqgJpEimHIqEdS6s3uTXwjS6 qCOOXOZSmzAaBuVXgYJoDEBMrNibK/tDSPFxLZBLJeMPS9FkyJBcZwb+XFTvbrYzRkA== X-Received: by 2002:a17:902:2805:: with SMTP id e5-v6mr19777788plb.169.1539660053256; Mon, 15 Oct 2018 20:20:53 -0700 (PDT) X-Google-Smtp-Source: ACcGV60E2fJp7KpW2Tyr1IvaCWnXXMPFSZTk3o5AgYnPcLS8xaTRVaP5oXew/X+iLJAbbpE2H6NO X-Received: by 2002:a17:902:2805:: with SMTP id e5-v6mr19777766plb.169.1539660052650; Mon, 15 Oct 2018 20:20:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539660052; cv=none; d=google.com; s=arc-20160816; b=bXBtd2erF3dpqwWJLzu0UNsU3Ang9kmIv49I86asCABdsclo6TF9gKOOtXnsU9PtZ+ z/I5mNSIa4VtRifcBdQ+++DAwjaGb9lLGRFfSVzUoqrKInt8xD7j105k35RweNwfVEVR UqndTR/l371lO3PayL65sN97iGiOTFiiKaN7OBQaE8W7litYINwTnuiigalOgT75UytE PEWXubCf6+GaZCQNkiccuehWxR4P6s4EqUbn5J2te8Ex+IzRLjMgwrvCDQowu7I3jCAz Vvv6FgFgjU16STQgZ4wVw4mvQS+pbqX2Se4yy/YzTyu7r2TuVBwCenPIsBM5EMkgLGEq do/A== 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=XaJCcJb52edg+aC8VnKgwcIySPxyOilGPHSlrKf5LPY=; b=qrTYUbGKj/HCUAXIlPsgj2xGVzaYOWLAcocSVOiPr/NQnstHQp9CRBI+Dw2ITwC4xG w31q4YYnEzHCOMBP/2btTb9X5uwxmI6cp9qsQjljdVMTmLrpKrF/CV7Q33ctLSXjae4B SpLdIyS3JtaGDtIt3QZrDzuO0YW09ZDFrHSMM7JX2Dm6Y8qcVLX3+1VVSaTu9PKxoosP SownepimGumS4JSHoQoaGhplSDWVzEGYlGePuZCO9YDNXIf7ZvyMJdpiQz19iJrfr8wr WE5Xdv7QbX7RI/fGD4N/I+spLHfTmrg3m/9Mt8KcKlB08jqeJB46oCsokIDaiQGuAZon aDLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=M9aJJC01; 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 p4-v6si12152616plr.364.2018.10.15.20.20.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 20:20:52 -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=M9aJJC01; 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 w9G3Josa051805; Tue, 16 Oct 2018 03:20:51 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=XaJCcJb52edg+aC8VnKgwcIySPxyOilGPHSlrKf5LPY=; b=M9aJJC01Tp0zKMm3aGPrIymayT3/oGG8aOw26Q0M4e4DEK7vxr+C1dNV8a4IIDYGwIIi 73fE7Y5dtB9kyI9S1StHRq4Sjt9fxomsFtCT+0Ht6jO5HY4+DmCLmcASG5llF1uHcySb QBhvyQmOoB7X7DOwuQZHtEZQdpNs9hS9AgyiFiH2bPXpSGQswfy2L80wcwY4MaZTX0gx ZXcvbFa48F2OK+E88GXXZFNlvxv2qm0kDeGtLP6WwShpaMTkCQVJbAadXd34AA/W2Ysl S0YK4gwPZdTV5v7vHD22j3NAhnrdwWsP/QxerdGr+C414ZQRxelypj0KnkeycLv1ebD2 kQ== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2130.oracle.com with ESMTP id 2n384tx2ae-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:20:51 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3KpjV030152 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:20:51 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3KoTr012714; Tue, 16 Oct 2018 03:20:50 GMT Received: from localhost (/10.159.227.150) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 15 Oct 2018 20:20:50 -0700 Subject: [PATCH 24/26] xfs: fix pagecache truncation prior to reflink 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, Dave Chinner , linux-fsdevel@vger.kernel.org, ocfs2-devel@oss.oracle.com Date: Mon, 15 Oct 2018 20:20:48 -0700 Message-ID: <153966004854.3607.15187709452762502392.stgit@magnolia> In-Reply-To: <153965939489.1256.7400115244528045860.stgit@magnolia> References: <153965939489.1256.7400115244528045860.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9047 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=896 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810160028 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 Prior to remapping blocks, it is necessary to remove pages from the destination file's page cache. Unfortunately, the truncation is not aggressive enough -- if page size > block size, we'll end up zeroing subpage blocks instead of removing them. So, round the start offset down and the end offset up to page boundaries. We already wrote all the dirty data so the larger range shouldn't be a problem. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_reflink.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index 9b1ea42c81d1..e8e86646bb4b 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -1369,8 +1369,9 @@ xfs_reflink_remap_prep( goto out_unlock; /* Zap any page cache for the destination file's range. */ - truncate_inode_pages_range(&inode_out->i_data, pos_out, - PAGE_ALIGN(pos_out + *len) - 1); + truncate_inode_pages_range(&inode_out->i_data, + round_down(pos_out, PAGE_SIZE), + round_up(pos_out + *len, PAGE_SIZE) - 1); return 1; out_unlock: From patchwork Tue Oct 16 03:20:55 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: 10643027 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 D27F918BC for ; Tue, 16 Oct 2018 03:21:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE6C028E72 for ; Tue, 16 Oct 2018 03:21:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B25EC29AA8; Tue, 16 Oct 2018 03:21:03 +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 2960328E72 for ; Tue, 16 Oct 2018 03:21:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B6B536B0290; Mon, 15 Oct 2018 23:21:01 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B1A466B0292; Mon, 15 Oct 2018 23:21:01 -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 A095C6B0293; Mon, 15 Oct 2018 23:21:01 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by kanga.kvack.org (Postfix) with ESMTP id 5EAC56B0290 for ; Mon, 15 Oct 2018 23:21:01 -0400 (EDT) Received: by mail-pg1-f198.google.com with SMTP id b7-v6so16156245pgt.10 for ; Mon, 15 Oct 2018 20:21:01 -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=U+c62WV3nwGtgXT08G5op2c6SHTu+zXo82DM+p37XJg=; b=j/7CDxqcqj7PPUKYzG3RHSMzqoeMdddPUgORv47156hfTbBmg23sd8m2dc5zr/vs3j QmF/cZK8OWCgJaXvVXnCUyGLRpy9jWxpJVO3Z1M3DGUCGf/QSuka4Q+NFpaWX2Szxz6r b0IpUXowCRAnmiC3J+58hOEdMDeJfMhP4/D9qrplj8uvKQG3AvEpCxxjO3vyFHhU9PK9 qy5jtUiF/F4GxtouB7VqinPtYm24IBXrlaEgZMlQm9m/Xz9Dz1fhLMrDjDU5rETAingb j8VRQVuOTM+Yi5EjPDokEjvjy/b0YuBhTOHD8tTLP9pcOM+m0XMfaUKtQuiPsakusBzE 6FaA== X-Gm-Message-State: ABuFfohgSO5vD/i2So5WvavqTWCjCnWCmeHOhcl716nS6YSWIo+K6Cri EVO8bfctGtK/4GHbJPrHSEdUaJN+oDYqlY+UR4MLr0fK2IPexByx/7qWoZlU+0Y9mUf5qcc55L0 tUZR/UZBHMQv08mTG651m6yEMxBO4msYxfjSCTyOBFyQWxb0MPMeXIUZVaxj69bc10w== X-Received: by 2002:a65:528b:: with SMTP id y11-v6mr18593085pgp.269.1539660061060; Mon, 15 Oct 2018 20:21:01 -0700 (PDT) X-Google-Smtp-Source: ACcGV63K0St3BttyUpLhkE3JQYStKmdNwJ1qr/1znObaXkg1g8P4r6Qv+ZzPebaQosJ07wG0Wz4v X-Received: by 2002:a65:528b:: with SMTP id y11-v6mr18593051pgp.269.1539660060176; Mon, 15 Oct 2018 20:21:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539660060; cv=none; d=google.com; s=arc-20160816; b=ERMSM+O5Hah5Cpqp8ExTtU5/QDsmoXA+FpFSiK9yOt8y0BPHrFz7O4x10j/PMw7f3X qd9ze9nF72VB2MVtVED4vVxW7qokkXDqBVPXB09AeZVnMjqmPoVd7+GIjqkLcwuuoq83 U7GP3W0TI8+TGpA+QRibZHinZNAPiLVy70FTyxiwavsH9Cq1m95VuScNKVVr30C9LhuU upDSJkqQLIBrsXW+Q+TjuxjSuhiPBfBJfYTdi5n+GRRQ9aJJejnFZMEqRZejJsM97t9m KTNLOhN6DyDmsTTxGzv0eeCoXX81v2NPS9ud8H24dB2F+N14/2/y2+4OLWgZTiAxJqle 5Dsw== 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=U+c62WV3nwGtgXT08G5op2c6SHTu+zXo82DM+p37XJg=; b=UTmWSUqcDcCWSoeHa0qmr6sQmrvenjImoEs6pKJB2R0qEUDzeP+UlD68S66N8yWQOc MsdiF7LUN+uKCYJTKbalB5tQEOjh6O4A8VUM915E1/Fu7dHPUYU/3YRuEnvpw2SQl2wM YgwhQzvGTpYbYMiD2+7z3d8QShsvt1htHTphLOq/qV0ZLxASuFdnJ2EABj9czf0FfVQh nr083qYYzqqlg6d9/r0MFBn0BXdCIjFi1nyf9lCGdgLdis+wkQv4ddub+e3yqZb4Xhb+ N15sLjMrAWUgRqHCExNA2e8TPMNeyczHkgtBRPyKwAHazb8p6d/HrG5eM2UqsOHrUhbl Fctw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=YgIfoOUW; 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 i23-v6si12393090pgl.230.2018.10.15.20.20.59 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 20:21:00 -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=YgIfoOUW; 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 w9G3JFW7005323; Tue, 16 Oct 2018 03:20:59 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=U+c62WV3nwGtgXT08G5op2c6SHTu+zXo82DM+p37XJg=; b=YgIfoOUWUlhTgGdJirDNW4Ro0FidRDRX01vh9lpqC0g7N9nVAq5K5Zon3u9UZ9fpRwv/ vSDubFdyc5C9PQ/uI8IWSRyo7CBIdyHcGmBh6IhJXJwpHrOcCoB50CnCw4w/jyBrO9N/ P6msPg+nB3TgzWCZESZirwrdg9qeA2bvwTLP10m+0RVttPL47Gj9ej7W9Tg3HhMepS1s zFPuOF2j8LkvoESf3ahcrKXOyky0cPdiKp7qozNPxMtpoSYCa7x1QQy+VB4kxUOhUx78 86wuvIzTexXtY4xOd0KMmAy8uVAcP1SFGcWL+v9h+xe8F+O8pNTTlUngt7aoQzHD69tP uA== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2120.oracle.com with ESMTP id 2n39br5s53-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:20:59 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3KvDX021602 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:20:58 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 w9G3Kv6A007693; Tue, 16 Oct 2018 03:20:57 GMT Received: from localhost (/10.159.227.150) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 15 Oct 2018 20:20:56 -0700 Subject: [PATCH 25/26] xfs: support returning partial reflink results 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: Mon, 15 Oct 2018 20:20:55 -0700 Message-ID: <153966005536.3607.787445581785795364.stgit@magnolia> In-Reply-To: <153965939489.1256.7400115244528045860.stgit@magnolia> References: <153965939489.1256.7400115244528045860.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9047 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=812 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810160028 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 Back when the XFS reflink code only supported clone_file_range, we were only able to return zero or negative error codes to userspace. However, now that copy_file_range (which returns bytes copied) can use XFS' clone_file_range, we have the opportunity to return partial results. For example, if userspace sends a 1GB clone request and we run out of space halfway through, we at least can tell userspace that we completed 512M of that request like a regular write. Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_file.c | 5 +---- fs/xfs/xfs_reflink.c | 20 +++++++++++++++----- fs/xfs/xfs_reflink.h | 2 +- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 38fde4e11714..7d42ab8fe6e1 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -928,14 +928,11 @@ xfs_file_remap_range( loff_t len, unsigned int remap_flags) { - int ret; - if (remap_flags & ~(REMAP_FILE_DEDUP | REMAP_FILE_ADVISORY)) return -EINVAL; - ret = xfs_reflink_remap_range(file_in, pos_in, file_out, pos_out, + return xfs_reflink_remap_range(file_in, pos_in, file_out, pos_out, len, remap_flags); - return ret < 0 ? ret : len; } STATIC int diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index e8e86646bb4b..af3368862c56 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -1123,6 +1123,7 @@ xfs_reflink_remap_blocks( struct xfs_inode *dest, xfs_fileoff_t destoff, xfs_filblks_t len, + xfs_filblks_t *remapped_len, xfs_off_t new_isize) { struct xfs_bmbt_irec imap; @@ -1130,6 +1131,7 @@ xfs_reflink_remap_blocks( int error = 0; xfs_filblks_t range_len; + *remapped_len = 0; /* drange = (destoff, destoff + len); srange = (srcoff, srcoff + len) */ while (len) { uint lock_mode; @@ -1168,6 +1170,7 @@ xfs_reflink_remap_blocks( srcoff += range_len; destoff += range_len; len -= range_len; + *remapped_len += range_len; } return 0; @@ -1382,7 +1385,7 @@ xfs_reflink_remap_prep( /* * Link a range of blocks from one file to another. */ -int +loff_t xfs_reflink_remap_range( struct file *file_in, loff_t pos_in, @@ -1397,9 +1400,10 @@ xfs_reflink_remap_range( struct xfs_inode *dest = XFS_I(inode_out); struct xfs_mount *mp = src->i_mount; xfs_fileoff_t sfsbno, dfsbno; - xfs_filblks_t fsblen; + xfs_filblks_t fsblen, remappedfsb = 0; + loff_t remapped_bytes = 0; xfs_extlen_t cowextsize; - ssize_t ret; + int ret; if (!xfs_sb_version_hasreflink(&mp->m_sb)) return -EOPNOTSUPP; @@ -1415,11 +1419,17 @@ xfs_reflink_remap_range( trace_xfs_reflink_remap_range(src, pos_in, len, dest, pos_out); + if (len == 0) { + ret = 0; + goto out_unlock; + } + dfsbno = XFS_B_TO_FSBT(mp, pos_out); sfsbno = XFS_B_TO_FSBT(mp, pos_in); fsblen = XFS_B_TO_FSB(mp, len); ret = xfs_reflink_remap_blocks(src, sfsbno, dest, dfsbno, fsblen, - pos_out + len); + &remappedfsb, pos_out + len); + remapped_bytes = min_t(loff_t, len, XFS_FSB_TO_B(mp, remappedfsb)); if (ret) goto out_unlock; @@ -1442,7 +1452,7 @@ xfs_reflink_remap_range( xfs_reflink_remap_unlock(file_in, file_out); if (ret) trace_xfs_reflink_remap_range_error(dest, ret, _RET_IP_); - return ret; + return remapped_bytes > 0 ? remapped_bytes : ret; } /* diff --git a/fs/xfs/xfs_reflink.h b/fs/xfs/xfs_reflink.h index c3c46c276fe1..cbc26ff79a8f 100644 --- a/fs/xfs/xfs_reflink.h +++ b/fs/xfs/xfs_reflink.h @@ -27,7 +27,7 @@ extern int xfs_reflink_cancel_cow_range(struct xfs_inode *ip, xfs_off_t offset, extern int xfs_reflink_end_cow(struct xfs_inode *ip, xfs_off_t offset, xfs_off_t count); extern int xfs_reflink_recover_cow(struct xfs_mount *mp); -extern int xfs_reflink_remap_range(struct file *file_in, loff_t pos_in, +extern loff_t xfs_reflink_remap_range(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, loff_t len, unsigned int remap_flags); extern int xfs_reflink_inode_has_shared_extents(struct xfs_trans *tp, From patchwork Tue Oct 16 03:21:02 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: 10643041 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 323AA18BC for ; Tue, 16 Oct 2018 03:21:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E4E528E72 for ; Tue, 16 Oct 2018 03:21:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 11A8B29AA8; Tue, 16 Oct 2018 03:21:10 +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 9DFD128E72 for ; Tue, 16 Oct 2018 03:21:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 37B476B0292; Mon, 15 Oct 2018 23:21:08 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 32AA96B0294; Mon, 15 Oct 2018 23:21: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 241816B0295; Mon, 15 Oct 2018 23:21:08 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by kanga.kvack.org (Postfix) with ESMTP id D76616B0292 for ; Mon, 15 Oct 2018 23:21:07 -0400 (EDT) Received: by mail-pl1-f199.google.com with SMTP id 43-v6so17279211ple.19 for ; Mon, 15 Oct 2018 20:21: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=qvAdS5qtNPwhhtvBsCuVRJiAsJYI4Kg7IlMUAqU/umo=; b=c5A7f4TigvzlNPw3LY+NTO0m1P8Vpyc/hfWOjo/ZLLb9ZrXBfEkQI5BA7rgq8ho5ht MUYkFxpmrkPx+Ax5ZYxF4GL+PE6b/0vF+Sr6tBTo/OaSlMZzUWRIwANkczAAw1QPIDxd 7/tMnNsFEAGs4WwyMIqaAElytHvnlhODX7M5MLEEn8lLmgUfWp9nv105E83f3ZYrAtc/ RFQiBi/Jzum+z6d3O+lHSmymUMek1IC7T2ghPN/NupD/UjtYUBKFlZuTE1aDXzKYlg5i 5v0DvQ6eh1zhDeGw7Eyk6w2bnLEwI+xaBXi6RGKz58MTDqeWoD9QEH3axcGoLlFgDeJg 8V4g== X-Gm-Message-State: ABuFfogmVLrlC2hHc2cgZQe23ntM/G7gAm4nZ2aPbD5rB/6/89vnxOg2 KulBqSIfB2ziumRSjY2J+Ztmt8H4AxJ5QYYVMfzp36UkLKrH7ZiLxLrSsL3TkrJFjbVK+Jq/BX4 C+xNRhoVN6GUN9wgxDKvo8+YxQxZuGeq0yXj+8dKZTXUSn+nboMZz8X31LvwdDxbYUA== X-Received: by 2002:a62:5b43:: with SMTP id p64-v6mr20715955pfb.122.1539660067562; Mon, 15 Oct 2018 20:21:07 -0700 (PDT) X-Google-Smtp-Source: ACcGV61Tc5OPGAKR2UM5YE1oalC9HH4L9LETwXJ9qe4qo880OXh1vuJ568Vyt2n964urq4JFniDS X-Received: by 2002:a62:5b43:: with SMTP id p64-v6mr20715914pfb.122.1539660066875; Mon, 15 Oct 2018 20:21:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539660066; cv=none; d=google.com; s=arc-20160816; b=Y0tTyHoXMaqqhloyhQCxcbd4Zkg90wpcSxjUwVpWQreHvWS9YdFSWBYxfs0ZWwHBbr wki38nhsTItGuQAauePC5RInSM+l6DpIRQrGe2bwY1LsVXVH+AAev0Y681Dbhpq8UZLl 7bAM9XrK2BKsG3Q15eDF5WmftYO7PIIlkLnsYoVf9yLVrt5FBbSMXr1wGgr/wGCRan0y zJgxtDNTjc7WCC6Xj5xjidIkRyrqR+As4pnmP748LcEI0NLqKqvKy+pJYngHIxCfujIN sqaUaVbvN3mf+O0cTooXPT/pGyveIACA0CYzNNwHNwH4rc38Qa944x3QN/bQDrA/ECgh VOVQ== 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=qvAdS5qtNPwhhtvBsCuVRJiAsJYI4Kg7IlMUAqU/umo=; b=fLnal18BqMzZ4U9Mixd9GqceVQfMdneWKtGOSI5F8nFV1O7JXkm4DRUnR7ktiJFR4N GlU9UvPwLhuusoktMoY1rrIEbWubBrDs1ASIVHnS46QPbOYysfoKSKeNw3/aYK1zy3DF tEz2dEutlUrguQ1Hq1gUwnX4cZpQsTGKel9Vb+XI69ASkFZdaGwm+lpsjAu91cQzuon/ vJZXo+wC3lPw/de/RvSE3iqv+A+yNAe+T6yHIuY//lmmYE74rLhxOYTW+V2K+PkLrZQ8 RZVFsa7Fx2MzwavoWHYIhpYgM2bkmmK962ZoQ9rS7L9sNkYneqGDyfWPlU3CYJkZk11S d1sQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b="UxxSYl/D"; 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 b10-v6si13298662pla.253.2018.10.15.20.21.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 20:21:06 -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="UxxSYl/D"; 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 w9G3J5OE051357; Tue, 16 Oct 2018 03:21:06 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=qvAdS5qtNPwhhtvBsCuVRJiAsJYI4Kg7IlMUAqU/umo=; b=UxxSYl/DXrxO/IZg8pk5FZRVB9feaAIbDplQfXDrHRWpbXSAh655KSzHfj9HJTq2FRun 5qWpfgKFkoHUVYXWz28OK9xEaPq3F3TsVSy71nU/I2Pq6Nk+kE3QdsDx/6GamStLikvt RLRqV78hcWqEVgCwxlu/u6rkFjibAfqEoeKUA0OFXP0SG5B4EQ+pmtGQnpQPHILGfor6 scK0Oab9mLmCte2BvdlJ/15BEr6ylQ8dUU1JXef0ajmgJ+f89iwIOJ3URUgAv1+6/92X i8zXaPbKSpSMDvsQvpDNOB55jRz3gSBXZk82gUO/HUdUC7VAqWblExDwxgc0BTb+GRJA cg== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2n384tx2bg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:21:06 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3L4vD006101 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:21:04 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3L3G5011041; Tue, 16 Oct 2018 03:21:03 GMT Received: from localhost (/10.159.227.150) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 15 Oct 2018 20:21:03 -0700 Subject: [PATCH 26/26] xfs: remove redundant remap partial EOF block checks 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, Dave Chinner , linux-fsdevel@vger.kernel.org, ocfs2-devel@oss.oracle.com Date: Mon, 15 Oct 2018 20:21:02 -0700 Message-ID: <153966006214.3607.15131077363912605792.stgit@magnolia> In-Reply-To: <153965939489.1256.7400115244528045860.stgit@magnolia> References: <153965939489.1256.7400115244528045860.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9047 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=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810160028 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 Now that we've moved the partial EOF block checks to the VFS helpers, we can remove the redundant functionality from XFS. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_reflink.c | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index af3368862c56..755d4a9446e3 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -1307,7 +1307,6 @@ xfs_reflink_remap_prep( struct inode *inode_out = file_inode(file_out); struct xfs_inode *dest = XFS_I(inode_out); bool same_inode = (inode_in == inode_out); - u64 blkmask = i_blocksize(inode_in) - 1; ssize_t ret; /* Lock both files against IO */ @@ -1335,24 +1334,6 @@ xfs_reflink_remap_prep( if (ret < 0 || *len == 0) goto out_unlock; - /* - * If the dedupe data matches, chop off the partial EOF block - * from the source file so we don't try to dedupe the partial - * EOF block. - */ - if (remap_flags & REMAP_FILE_DEDUP) { - *len &= ~blkmask; - } else if (*len & blkmask) { - /* - * The user is attempting to share a partial EOF block, - * if it's inside the destination EOF then reject it. - */ - if (pos_out + *len < i_size_read(inode_out)) { - ret = -EINVAL; - goto out_unlock; - } - } - /* Attach dquots to dest inode before changing block map */ ret = xfs_qm_dqattach(dest); if (ret)