From patchwork Sat Oct 13 00:07: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: 10639641 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 D51B91508 for ; Sat, 13 Oct 2018 00:07:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C20FC2B78F for ; Sat, 13 Oct 2018 00:07:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B5BD92B7FA; Sat, 13 Oct 2018 00:07:59 +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 150782B78F for ; Sat, 13 Oct 2018 00:07:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A26506B0284; Fri, 12 Oct 2018 20:07:57 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9AEA76B0286; Fri, 12 Oct 2018 20:07:57 -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 8C72D6B0287; Fri, 12 Oct 2018 20:07:57 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by kanga.kvack.org (Postfix) with ESMTP id 4A9456B0284 for ; Fri, 12 Oct 2018 20:07:57 -0400 (EDT) Received: by mail-pg1-f200.google.com with SMTP id 11-v6so10506505pgd.1 for ; Fri, 12 Oct 2018 17:07:57 -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=tC47Y7Of1RhDxOgcQAduRR4B2Ct08GgJmbmOlMIirio=; b=i4RO4TKAeyKH69CFwNsU4q7AoGnLBmhac2j22uzFs6cqU+X4F824DxIlLji7xiAFCk MCCRhAF6S9kNF8aByzabRHz3gEK8ZS/lkTwidxGeOLivTB88KQlTXHXkYXIpNx8loet6 VHbgvK46bolWcYXJ6H1bImSKAe3Ta7xw3xRrGAaZGfHj8M+B2a2yrH4m/R/Dt3WcWT/4 UJQ5rx9Pxug03i+w0Uzsz1TbAXpw3gJfT7UG99on10X3jrejN/dfjcU0FAeXb1tkrA8s iTPm5JTAPwHfhzzOYG8zA6NAkrFmTx0mePSzt76Flf0g5xucZv0OBoT41xrtbUE0PXVV rkTQ== X-Gm-Message-State: ABuFfojnVINHznXUxW64Ou/IIv83TLL2eteY/aZoNl/9LlkwX4tZwdpQ XqGlHmZt+LsLsrduO164Uj3HgLJNO9toCicY7DfBEtLL8Tkth+Rz1arpQcyIdeBXMw/OVKC4qT1 ALyoAlQlZJ8FbKlkdTm9Zg6PFJJfQue+epChNQQYr61fFTz+7msTC7Ar5aWv/J6tlFw== X-Received: by 2002:a65:52c1:: with SMTP id z1-v6mr7316448pgp.65.1539389276960; Fri, 12 Oct 2018 17:07:56 -0700 (PDT) X-Google-Smtp-Source: ACcGV6193FN1MVJ05hrzBugmXZLhljqrO40ZZS4h7eVYmnveS5Y6koZn0LL0yC88GWlJpxxKUgZC X-Received: by 2002:a65:52c1:: with SMTP id z1-v6mr7316404pgp.65.1539389276156; Fri, 12 Oct 2018 17:07:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539389276; cv=none; d=google.com; s=arc-20160816; b=OfEi+Jhyga78qbpImp8Z3/fy35agY/MML4yrTlqjBskF9o9gKBDIYm7w4i5b+29NaP D4zTFiCL4I6Lqag9PGibVYJR2Qg2lwN9rKnSxLV3PQFRV8XlL7/gaucwprk2OGWEme2E yClGVNMl9s6rJxiWuo3V6VMDHotCQyZd8ydTC5TXRB22vAdvog495viPdI5ko9EEM1pK uJTjiIgeTABofpvSO2fR5wS1aI/v5gKRrJqXfqp+85aS9mhnYa2B0fQ3KS0090TfnMYj BLcvnbu/bzsFIZ21WZrhp3ZdtSreUBZtuGd2+sW89Bduei/R7pb6fsM62MK25ffkSmds kiYg== 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=tC47Y7Of1RhDxOgcQAduRR4B2Ct08GgJmbmOlMIirio=; b=fSDt9/cZsi5yOxA9NI57oYbXP67TlcYBvTWzYO4bBGbcTZeAZc1W+vWHhXFo5ghQtV QYcclvrplzsoBXVWrPzsI/1RaeTSxnePZ7VOnthY2ULv0TenszuHkDbOoDSFFBlanF0n 3lsx5Exob+0vmO+fp+dOecUnWt8yS3GhA2+8P2bieWLU/XSKZ99GiZ3iXmPTrv12+5Vw vXVIgGPuqWvjEeyb+9KJssknbMICPPKpo/D4GR5VjPGwSS/cX/seYnepy0zOlYxbgz+M KV/vtk+uj1luIrTI0rgYUG2xZ8a3PsMSso6SM0d4EeG2xyXUPhphg4786DfpoSdhUW/z uPXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=Jqig3QDB; 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 j15-v6si2734057pgg.433.2018.10.12.17.07.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Oct 2018 17:07:56 -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=Jqig3QDB; 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 w9D05F0r105290; Sat, 13 Oct 2018 00:07: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=tC47Y7Of1RhDxOgcQAduRR4B2Ct08GgJmbmOlMIirio=; b=Jqig3QDB6zOoCG+A6Y1STR7XzjNGeYtELin8dHfaFqbHYbG2jqWAEI4D1Z7bHRwUfw9M lcI1926hTXRDkAtJhlultBGguKhBonSjCpAtYHIe2mzYgej1TVtqD+ZNXP9HJxn8MvDZ vECNe9L3qk/duWcKv6+XLNKwKZg1L1+gUWr59lmC1u99zvK3e5pXyFD0CX90v2hF1RJf Zq1pWouSZgizfshH942Tt/7RSrsMG853BACAotHLKzlJsngfDrmcXTtC+RWfRkbYOtQq oIy6INwMRFtJQsXX3hZHwFvlcqggMUpKJ97sGzUpkU+L8e50U5eM/JF4gB1mprxYfIvB bg== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2mxnprnfkf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 13 Oct 2018 00:07:54 +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 w9D07rfM025719 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 13 Oct 2018 00:07:53 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w9D07qch031416; Sat, 13 Oct 2018 00:07:53 GMT Received: from localhost (/10.159.251.254) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 13 Oct 2018 00:07:52 +0000 Subject: [PATCH 18/25] 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, ocfs2-devel@oss.oracle.com Date: Fri, 12 Oct 2018 17:07:51 -0700 Message-ID: <153938927103.8361.6327676425188043040.stgit@magnolia> In-Reply-To: <153938912912.8361.13446310416406388958.stgit@magnolia> References: <153938912912.8361.13446310416406388958.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9044 signatures=668706 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=627 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810130000 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Darrick J. Wong 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 | 191 ++++++++++++++++++++++++++-------------------------- include/linux/fs.h | 3 - 2 files changed, 95 insertions(+), 99 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index 86a8c2557d18..ce3d5c4b1d34 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1714,6 +1714,101 @@ static int remap_verify_area(struct file *file, loff_t pos, loff_t len, return security_file_permission(file, write ? MAY_WRITE : MAY_READ); } +/* + * 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. + */ +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 @@ -1912,102 +2007,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 57cb56bbc30a..f0603ed007e9 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1865,9 +1865,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,