From patchwork Wed Oct 10 00:14:11 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: 10633669 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 E949616B1 for ; Wed, 10 Oct 2018 00:14:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB28C284C9 for ; Wed, 10 Oct 2018 00:14:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CF63F28FE7; Wed, 10 Oct 2018 00:14:21 +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=unavailable 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 1D3DA284C9 for ; Wed, 10 Oct 2018 00:14:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 068666B0289; Tue, 9 Oct 2018 20:14:18 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E3A1C6B028B; Tue, 9 Oct 2018 20:14:17 -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 C67276B028A; Tue, 9 Oct 2018 20:14:17 -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 747EF6B0288 for ; Tue, 9 Oct 2018 20:14:17 -0400 (EDT) Received: by mail-pl1-f200.google.com with SMTP id 43-v6so2667546ple.19 for ; Tue, 09 Oct 2018 17:14:17 -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=qfspqRNHCaOaTIBE4rkWnm0h3QBJGde2tP1fYMCNyPE=; b=c5B2DahSP3n4rTy9rs80SY6Yrv5tkTWwMVZKbEUQQpmNtmrmFoyU6cDIPTw2AeS8YM XAgJgOBcQ4PvpY8AQ0JJCfNvGOmSkAYnEvjnKTTckKE3HcY34WHqDBMcH0mCH2mAFn0O rQG9QdUEHgio1BwYhG5og9DliI9AdtTTBtZUg6xqqZE82bkIAC4C9IbcRG6B0s+77eLw eVrFdA1UPiFHeC+7+AhCTHxZEz9JB7aBlVixK7650ft64CiBsNKjYhJ3n0uODaEFCL3B /69WpPKctZk8FSdpxxKbCUALZvahyG5pFkLMWtPWYMBCMQniLukE1o1VV2m4R3Cc6Tgr jGxA== X-Gm-Message-State: ABuFfoiWfMo5jc11D3tRew7khT21/sAePF2kjFwlXG9kpVzTsrm3XcF9 62icMPWRcWFvbLfYhhwhkx6xHNkn2T878Kl2mBHYNsf3UyO7Ohm4qb+TBRrEvYxlvBe9ErbOJlb OxlulNZmyDgX9bWPzTzkQIky+Uf3Ugoq6q8rBda/1S4JwwmqFpItHDiU7oFzgvFaWZQ== X-Received: by 2002:a63:214d:: with SMTP id s13-v6mr27708128pgm.148.1539130456674; Tue, 09 Oct 2018 17:14:16 -0700 (PDT) X-Google-Smtp-Source: ACcGV61zMHvCxrqJ5IbE9VICfsVL/R5TagCxWiitXBoEwFMOgP+oIvh+NBhNMb2tvSTnlKyJXJL5 X-Received: by 2002:a63:214d:: with SMTP id s13-v6mr27708089pgm.148.1539130455867; Tue, 09 Oct 2018 17:14:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539130455; cv=none; d=google.com; s=arc-20160816; b=ShoQ5lllfsI6TFLTsBc+qB1yc4InmNBiFq7OD48BN+QvXX80900wwroGpEfEXDL9nO xBQlBkj4MxUNFxeNvZwbL2fbVpgiKGd5yeSQ0McZd7aimQPMFgf1+96u7SXT67MnrCDb Y3PbNBpBJ8bdOyXqz3Z7HoqbuwByD/ARB0K6PQji1xuG2z8IgCswr4DgJVqh/0oedZwj m3dQcINdBEDCHFVrdAynxhNmqVV4XtpAnk5Qogcy4KWyehWfhQ6obwHaZd0DkqJUuo4e Vt6ovW0P+DpiXAjvITnx/EYBbFV5CL+jZeVKXOogXiyYUaaaY22Cbx5wSeQiaDN4lC/W 50kQ== 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=qfspqRNHCaOaTIBE4rkWnm0h3QBJGde2tP1fYMCNyPE=; b=PoMXR5ZrZNQS1E6qkqE+rpfpEUt0PZeqatVRSNhsTCmQWddKZOUef8+X7f+liDL3g7 YXjYOFJXB1g65XalefKHv6WBtZgE2yu2NGZA6KzP9n51MvEkRgGA68pHr3I3eGmekfYV jwwr8prilFEBSwXLjGZ13t5zFpZ6e5Lg/rYuNuQfLvWR8pzguGkrwOorvCqT2TgefV9X XevWXnVL6Bw9Uz5spoB7ehe3JS2DbYyWePAkYsRuhx2z8ho2ReWdr7wr8IDoLaBgR8Y7 QC7zbqN4LtoEsD14KDqPZTwZzp6GlS/IdjiV1LpuSU0uvGeOKIjOjCU7NCY/Wh04zVW8 PZ/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=t2ITIMkC; 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 u192-v6si21419299pgu.449.2018.10.09.17.14.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Oct 2018 17:14:15 -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=t2ITIMkC; 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 w9A0Df3O123119; Wed, 10 Oct 2018 00:14: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=qfspqRNHCaOaTIBE4rkWnm0h3QBJGde2tP1fYMCNyPE=; b=t2ITIMkCFMzrTPnnp6mVgDbqDBECcdE15lUZHVgSxYMxZuVCnMS0tTj4i26V5YHsfD0J L2IOj8cYrJs2mrH2hiCSs3nojXUDRPJCaobzsU4pJjn7d4vYLyLtDb9Je2Wz82LLdEDO HoWIKh6vAmJLHXK2TGYg4NGS5FXO+Cb/CJy0Ln4yk+c9GZacRMC0Fg4DxFYVICJvH9nH qr9tYkFB8sb1WXU/uGiuolQ39GxMXVc1pmOsD906fm9949OrEV4FOByrM0/hTBnPOKea 1iCjg7izNpFtdg3iQTRVz6MyxHHVPGI9icaQpKZ52LwRotKt15sD28WUl890/dmIO0uT kA== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2mxmftrvs0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Oct 2018 00:14:14 +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 w9A0EDdB032636 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Oct 2018 00:14:14 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w9A0ECSo021892; Wed, 10 Oct 2018 00:14:13 GMT Received: from localhost (/10.159.249.114) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 10 Oct 2018 00:14:12 +0000 Subject: [PATCH 19/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, linux-unionfs@vger.kernel.org, linux-xfs@vger.kernel.org, linux-mm@kvack.org, linux-btrfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, ocfs2-devel@oss.oracle.com Date: Tue, 09 Oct 2018 17:14:11 -0700 Message-ID: <153913045111.32295.15783645423071362029.stgit@magnolia> In-Reply-To: <153913023835.32295.13962696655740190941.stgit@magnolia> References: <153913023835.32295.13962696655740190941.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9041 signatures=668706 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=632 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810100001 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Darrick J. Wong 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 --- 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 8ed0aed81649..57627202bd50 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 @@ -1887,102 +1982,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 e0494d719ebc..9c53276979bb 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1846,9 +1846,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,