From patchwork Wed Oct 17 22:46: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: 10646393 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 6A72515E2 for ; Wed, 17 Oct 2018 22:46:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 59D64288C7 for ; Wed, 17 Oct 2018 22:46:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D92C288E4; Wed, 17 Oct 2018 22:46: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 A1047288C7 for ; Wed, 17 Oct 2018 22:46:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6D5126B0287; Wed, 17 Oct 2018 18:46:25 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6854A6B0289; Wed, 17 Oct 2018 18:46: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 575B06B028A; Wed, 17 Oct 2018 18:46:25 -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 13F1D6B0287 for ; Wed, 17 Oct 2018 18:46:25 -0400 (EDT) Received: by mail-pg1-f197.google.com with SMTP id z8-v6so21138282pgp.20 for ; Wed, 17 Oct 2018 15:46: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=KzS1YpGdWiJRTm/Yeg6QnEh5g6eeuSdILXoQJhMO7DM=; b=W0ayM2Lc8M9cRw1t+s796h1jPudttrM2sOIy3kAEIlejWcJN0ZLZPPGJXsRDZraFK6 Uo9HcdRjaqLhigd5lpZyhU8LGftk8igza1k77nrJsy7Ii4MbDdqMWXIpy++2AWPP1xap 3zyTxkOChybeq9wnxKJzI+IeVbsaJHaEklHnPfCkI4aLNMUfYxiqGVEK8S4B6I/RvVQi avA0hrGSYReSdkXuBjvoBV9NietufByGqrOa/kc88Asd+R/SbwQCDl3zOPyV7/s5Avgb DmBEK0ADBNZKJhBD4qhuZv7EwROiuCB4k5ZpLdiBldwtkMWjWkVzaIAlT0oS7j987CJA YnBQ== X-Gm-Message-State: ABuFfohCiLSYRV61s+dpnrVGsHRRWkP5ZGxXmCEHFhaD8wC7r/fpTriA a4Dsb/w4KJtp69/iFllW5DjlCA5uleeWHT3eo6tm8T9nmdffJdun6MUolg2OARyhdlR6y6rd9zW Jx7efztstnYk9cGOxBjBTvRqKBfZG6UhpqPpvpfV++ZLkS1n5Z3UqTYKeSknX1H7oXw== X-Received: by 2002:a63:c5a:: with SMTP id 26-v6mr26136498pgm.372.1539816384741; Wed, 17 Oct 2018 15:46:24 -0700 (PDT) X-Google-Smtp-Source: ACcGV63bDs2uPByPeXFll6KVXLS7YwV7KLB0J6/alFlkz06rPmROa6oXEIGuIz/nDor+2hmM+3PJ X-Received: by 2002:a63:c5a:: with SMTP id 26-v6mr26136471pgm.372.1539816383859; Wed, 17 Oct 2018 15:46:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539816383; cv=none; d=google.com; s=arc-20160816; b=g9ZRHlFy37Z6VjwFwhXGgyc91pF8kGmeH/x99lxwvkye7AErkGb9x+uHYbY4gZMdKm Ps9KAlF7fY5AfgLhRzgRuT37XhKhuHPpimgeHO78FIOb4V04SGsA28LUN2LVIlij0drd Uh9y+knR9WdogEv6AenkB4ZqPmxIfOfQIyugWH3q1JNiQk2DK3p6F/WX0o47DJtLFbEh JrnXWXXns11wus3wUepVXoEGd8aVdWH9yfkkMyNX9MtVlmeGcYBIFrY48crY0Ti8qnQ5 Hw5qovxVPWfs1tmfsULum1OazDdIDBOpuG0rFBZCLqQmecDuPDRax5FiD+o7U/qneT2x vFUQ== 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=KzS1YpGdWiJRTm/Yeg6QnEh5g6eeuSdILXoQJhMO7DM=; b=ZFrrbB2zuWrGx8z3ER9Cb4/+1divAdhoL/5st4MMU3oZ7Xzhsfz4KHDrdoaL4VyPuD qLgxGdvYT9IfVLVZPtKRZhfR9wag7jaCe0MEgJj4w/uhfApMKjzbt4JccE0VFJZgdH+N 6SN9KLvt7l7bb3USlQgwASWXtEo953INGQKipmUbQ19vxw6XLYWnE1oLxS1X8mPyZTje xNqZlWtAYATVup8b+UpM8k63Xt29djZHeOM5JTS91rVLAbxnWpSZkHCabxMnjRXghET5 TcmVKs+n+0hiTX82hzacWF+9MXkm9W9vJK46i+F7IEtSc+RlRtt4N6dR3ONKOAh++Kzk /4pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=lVtnE4It; 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 c21-v6si18496455pgg.407.2018.10.17.15.46.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Oct 2018 15:46:23 -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=lVtnE4It; 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 w9HMiZQA040586; Wed, 17 Oct 2018 22:46:22 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=KzS1YpGdWiJRTm/Yeg6QnEh5g6eeuSdILXoQJhMO7DM=; b=lVtnE4It0+qQyj8BXkhNWaG0Xp5U867+NBJr7ZE5Po5ANUyHDC1U2SIMXlPpa+Pybwvb +kcNZ6l95Kk75J4l3OGR50Y6v0OFuIpCgFVQdTVeR3J5acjGxsj2YpJYI4HpLpRnodUD oMGCTgDRV56pNni+LUaYHWqwHZ+XQykCTS/sKkE3NbHDpRlOXaGFySJoNC9pZVfP0pm1 Wds0+jJTZGA1DgMu4E23+OfhPa09jdgFYYNC2cnwO39emNVFK6b6ZsovtTbdPWnkQJJ8 iZsUVGuinun6jYa40ZVrfK98mOeeeGmG30EuKtB3BHBm3dU3eunIzvb1YSx81Lk7uT76 tA== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2130.oracle.com with ESMTP id 2n384ua02q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Oct 2018 22:46:21 +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 w9HMkKnp006053 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Oct 2018 22:46:21 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w9HMkKB5015316; Wed, 17 Oct 2018 22:46:20 GMT Received: from localhost (/10.159.132.177) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 17 Oct 2018 15:46:20 -0700 Subject: [PATCH 17/29] 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: Wed, 17 Oct 2018 15:46:19 -0700 Message-ID: <153981637899.5568.11427312080035617896.stgit@magnolia> In-Reply-To: <153981625504.5568.2708520119290577378.stgit@magnolia> References: <153981625504.5568.2708520119290577378.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9049 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=638 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810170188 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 c0bcc1a20650..e4d295d0d236 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1752,6 +1752,97 @@ static int generic_remap_check_len(struct inode *inode_in, return (remap_flags & REMAP_FILE_DEDUP) ? -EBADE : -EINVAL; } +/* + * 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 @@ -1923,102 +2014,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 0b750e3f8f20..403860b25725 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1849,9 +1849,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,