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,