From patchwork Thu Oct 11 04:14:38 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: 10635939 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 15DD7933 for ; Thu, 11 Oct 2018 04:14:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EBFEE2787C for ; Thu, 11 Oct 2018 04:14:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA8692A63D; Thu, 11 Oct 2018 04:14:48 +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 27DDB2787C for ; Thu, 11 Oct 2018 04:14:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DBE136B028D; Thu, 11 Oct 2018 00:14:45 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D95A86B028F; Thu, 11 Oct 2018 00:14: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 C37436B0290; Thu, 11 Oct 2018 00:14:45 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by kanga.kvack.org (Postfix) with ESMTP id 92C806B028D for ; Thu, 11 Oct 2018 00:14:45 -0400 (EDT) Received: by mail-qt1-f197.google.com with SMTP id c33-v6so7507144qta.20 for ; Wed, 10 Oct 2018 21:14: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=CGsruWwZ9+5W3dIHGIHDPROMqGkFLi0bB5XpuLCATew=; b=JXw5Na2/5o+561aHwoQCLgPCVnisekxwIVusqbfjkjUhyApBvSGmb7Th7cZxFB2vVs vKjj/MNt/IXWXDPAxJOqh1ienUO3Mtn/RL8+hMbnu0Nun3MP3fjCesW1+2/jRmfszjsH xzz+7+TxFn5v8eSqk0W4c8br7IbxTt0gzQYC8OxWgesLPK/P76qbVL/TnzEdPgXe2HKs R2l8yMn2b7NOHDQEr92v+s8+aQF1+tB9IDu4fIHiuhTOrL8nRz2zjKDfi4wysPFeTOkh Clt+psbRTfbyl5a0U108irKjIyTyIhHOa/C4tXjVpcoUMCzxu42kJ/0kSL6zkWd2yOAZ sBiA== X-Gm-Message-State: ABuFfohe6JKMgRqZqoKbxf2bwmCQq+2/Ov2d/Cjj5X55daz2HTeYm4qf KucK+z5+9CjgHuu3q2UHPzxPeM+KydiCeNggWzdZ2wuFWQylyNY1UF73dITD3+O1jkvCArWKR0w Qt76uPdwfLnkeu82KmH9tNunY/dwJNY2x9q87LJoCcXMKVlvINf0F7dJr4fyAD3pZHw== X-Received: by 2002:ac8:2d9d:: with SMTP id p29-v6mr30516396qta.238.1539231285368; Wed, 10 Oct 2018 21:14:45 -0700 (PDT) X-Google-Smtp-Source: ACcGV63hEf4RHHlAEl7THIFpWrgsP320JTcK+pTv+LfIs0mwvGC6QixROEwmTBi2otLdg3LMZn8Y X-Received: by 2002:ac8:2d9d:: with SMTP id p29-v6mr30516373qta.238.1539231284720; Wed, 10 Oct 2018 21:14:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539231284; cv=none; d=google.com; s=arc-20160816; b=DbhIycXHYSJf3kITS0ZPpHADMdbAxNgcgAWLvT/14BRQWkfWXePEL3Hr1k3HeXijqj V0gpAQBFkiqrj2r8/4SY7p3zNVqTUnNTNgpIht2W9dsXvPVW+9UfYYTosCul8wtnB/ql EPPcPOc8GEeZx+fK4EyIAfJdIAy1CT7yBJy55aoHhAtPqjc8RjyLtBPc7GND8Xp9b0W+ mYLoyTmwud1+dy9rCao3D9LUpp0y1Lzn5RW33UlWEZC0HEuSTzB9qyEXHlgC76xKk3WW ap2kM+6Wac06sf/81mPLKYvxYab1kPCy0lEzIDR8ee0p52IKmF7+/QS2dlYX/5PeiSJs gGIg== 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=CGsruWwZ9+5W3dIHGIHDPROMqGkFLi0bB5XpuLCATew=; b=Li6kPj+2De5HplM1OBI+jmsNIaJds6OCIdkfwEfw4hyqyU1yPEteHNRU0IBgdUmLUR mFkUydpZVKRiWDzKwj1nZLfQmiv6zbRFKNlh6NpOuYg5TcNyt7lAlLhkwE7I9pfbuzet OQ1c5T/wSmbeydex3UpQogbpDs4tNnpJoW3whn7m4rTjuUcyrHVNKKhKPAZpcNmrIn/o w9aoqMBpLC4auW7ErgYB+3hUx7w0YxXYDfG9furyA2/jl/OoyZ25ghtBeig6tI34jcQn UsAZu+Ed+CpKecYNmD5uCgy0I/k5wz9xINs+JxKl8ln7FFEVo0eZRktUewCLhrjQh/OD H1fA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=ecbc6Tcb; 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 b16-v6si9455188qkg.77.2018.10.10.21.14.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Oct 2018 21:14: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=ecbc6Tcb; 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 w9B4DspG039247; Thu, 11 Oct 2018 04:14:41 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=CGsruWwZ9+5W3dIHGIHDPROMqGkFLi0bB5XpuLCATew=; b=ecbc6Tcb7OPd+hWU3biSHU9mkSLvXPg74eN4LedTOBjCOpHSv6lbejqBn+xGQo2TtszC MZRw0wpLnrqy9M1wZzEpdYSxfqxaVso7ni+77nUdyI0el0cHOUOaULFQmJbA1BefQPbg OqKR6PM1eQbRaOqjKAj0N0mo4iY7EVHWZawrwYoieGOq5YwyUPVfTXiQySI9N+aERS0D TkfhKG0Zra/aXEzXFj87q9kaGpPNzDq/gOdqOZJHICH4kInFs9Te2LwC4z/+8iNfyFiV 3oYddk8m/72IeQlww7jilfSYbxDYs1TQ4sjWZwTUPPzDWcxM5410+DL8hgjEy4KEoZDB ig== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2130.oracle.com with ESMTP id 2mxmfu1g4a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 11 Oct 2018 04:14:41 +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 w9B4EepS024243 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 11 Oct 2018 04:14:40 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 w9B4Eeqr009582; Thu, 11 Oct 2018 04:14:40 GMT Received: from localhost (/10.159.132.249) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 11 Oct 2018 04:14:40 +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: Wed, 10 Oct 2018 21:14:38 -0700 Message-ID: <153923127846.5546.7509528220834177005.stgit@magnolia> In-Reply-To: <153923113649.5546.9840926895953408273.stgit@magnolia> References: <153923113649.5546.9840926895953408273.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9042 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=626 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810110040 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 --- 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 3713893b7e38..c88a443d9eb2 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,