Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp399396ybx; Tue, 29 Oct 2019 21:15:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqyDVG5H8GOozgp7FVmEpiruuBNO0hH0JUUs1P0kL2KIYreg2EnOWnGzF0g1jp+WZBPT3sbg X-Received: by 2002:a50:9a46:: with SMTP id o64mr30026620edb.191.1572408953458; Tue, 29 Oct 2019 21:15:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572408953; cv=none; d=google.com; s=arc-20160816; b=rU1dGgoyidTWTUsNcenOg0W6FAe6+l9T6M49GwZuwcXtiVi9Y07o+qOtNND4HHfpDy q+5vhopdRjbYq+l31fjRQTcS0y4KGIL6QNnoEgVRfABBEL+ND8G3R8YE5wHBlDE9wFCP /Ae9zebGyn+c2DMhMKX0+aXbT9XklDo89Z1OPHXS5iiIjnsn/V04Mm/riO8mk3rAyEkL uJPKLbKJldvp7W9bcxI98uS2LuvKvnErGShFGXGH08keGUfB29uEJj+KF2p6t7c8XpSG 4KbbKoG/vFASn4DTfYfc5vvApq9/5NPyfeogxB7G4JH46BKt+2BEg8gKCLqVZcUJ5Lkg AW8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=8cHOora2ZCco70mwJqo50OQmyPiU1JeGS41vWPke9/E=; b=FxuzzQ4gJ06Uq5V1gp16uNVTnSH428fI/4tv/SbZm6/C98iFuJOdLVS4ppzc3Diyru 9tSS8TE7R7pFY0vb89sGTvknM70G5KhDKN7/rvgUB/dLq9vUk1lY2GcNBAuXpYFjjrcT DaNgmL/LZ1+ThBkXB/ln56U18JfSMXdBSwql6l8G5FmJZv2oHfaw0vCvQ5d11xECfSph yBqTNkSVG6l1n+vdR/jO9h9/j6st6juhwwMi70905PEwR9JzRM0UPwa7APBLREdA8Nk0 t8+nYuQk0D3leeghjD4SDtl7W7WrarWwBcTcT4Ee60kyENwZiOk3Qa6eUuHl3+yD5tf3 eEng== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id nr20si432208ejb.387.2019.10.29.21.15.30; Tue, 29 Oct 2019 21:15:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727478AbfJ3EOf (ORCPT + 99 others); Wed, 30 Oct 2019 00:14:35 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:4021 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727344AbfJ3EOe (ORCPT ); Wed, 30 Oct 2019 00:14:34 -0400 X-IronPort-AV: E=Sophos;i="5.68,245,1569254400"; d="scan'208";a="77665127" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 30 Oct 2019 12:14:32 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id B32E34B6AE15; Wed, 30 Oct 2019 12:06:30 +0800 (CST) Received: from localhost.localdomain (10.167.225.140) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 30 Oct 2019 12:14:39 +0800 From: Shiyang Ruan To: , , , , , CC: , , , , Subject: [RFC PATCH v2 7/7] xfs: support dedupe for fsdax. Date: Wed, 30 Oct 2019 12:13:58 +0800 Message-ID: <20191030041358.14450-8-ruansy.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20191030041358.14450-1-ruansy.fnst@cn.fujitsu.com> References: <20191030041358.14450-1-ruansy.fnst@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.167.225.140] X-yoursite-MailScanner-ID: B32E34B6AE15.A5F6D X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: ruansy.fnst@cn.fujitsu.com X-Spam-Status: No Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use xfs_break_layouts() to break files' layouts when locking them. And call dax_file_range_compare() function to compare range for DAX files. Signed-off-by: Shiyang Ruan --- fs/xfs/xfs_reflink.c | 77 ++++++++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 32 deletions(-) diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index e3620bc794a2..3d8d1d2f0ac0 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -1186,47 +1186,41 @@ xfs_reflink_remap_blocks( * back out both locks. */ static int -xfs_iolock_two_inodes_and_break_layout( - struct inode *src, - struct inode *dest) +xfs_reflink_remap_lock_and_break_layouts( + struct file *file_in, + struct file *file_out) { int error; + struct inode *inode_in = file_inode(file_in); + struct xfs_inode *src = XFS_I(inode_in); + struct inode *inode_out = file_inode(file_out); + struct xfs_inode *dest = XFS_I(inode_out); + uint iolock = XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL; - if (src > dest) + if (inode_in > inode_out) { + swap(inode_in, inode_out); swap(src, dest); - -retry: - /* Wait to break both inodes' layouts before we start locking. */ - error = break_layout(src, true); - if (error) - return error; - if (src != dest) { - error = break_layout(dest, true); - if (error) - return error; } - /* Lock one inode and make sure nobody got in and leased it. */ - inode_lock(src); - error = break_layout(src, false); + inode_lock(inode_in); + xfs_ilock(src, XFS_MMAPLOCK_EXCL); + error = xfs_break_layouts(inode_in, &iolock, BREAK_UNMAP); + xfs_iunlock(src, XFS_MMAPLOCK_EXCL); if (error) { - inode_unlock(src); - if (error == -EWOULDBLOCK) - goto retry; + inode_unlock(inode_in); return error; } - if (src == dest) + if (inode_in == inode_out) return 0; - /* Lock the other inode and make sure nobody got in and leased it. */ - inode_lock_nested(dest, I_MUTEX_NONDIR2); - error = break_layout(dest, false); + inode_lock_nested(inode_out, I_MUTEX_NONDIR2); + xfs_ilock(dest, XFS_MMAPLOCK_EXCL); + error = xfs_break_layouts(inode_out, &iolock, BREAK_UNMAP); + xfs_iunlock(dest, XFS_MMAPLOCK_EXCL); if (error) { - inode_unlock(src); - inode_unlock(dest); - if (error == -EWOULDBLOCK) - goto retry; + inode_unlock(inode_in); + inode_unlock(inode_out); return error; } @@ -1245,6 +1239,11 @@ xfs_reflink_remap_unlock( struct xfs_inode *dest = XFS_I(inode_out); bool same_inode = (inode_in == inode_out); + if (inode_in > inode_out) { + swap(inode_in, inode_out); + swap(src, dest); + } + xfs_iunlock(dest, XFS_MMAPLOCK_EXCL); if (!same_inode) xfs_iunlock(src, XFS_MMAPLOCK_EXCL); @@ -1275,6 +1274,14 @@ xfs_reflink_zero_posteof( &xfs_buffered_write_iomap_ops); } +int xfs_reflink_dedupe_file_range_compare(struct inode *src, loff_t srcoff, + struct inode *dest, loff_t destoff, + loff_t len, bool *is_same) +{ + return dax_file_range_compare(src, srcoff, dest, destoff, len, is_same, + &xfs_read_iomap_ops); +} + /* * Prepare two files for range cloning. Upon a successful return both inodes * will have the iolock and mmaplock held, the page cache of the out file will @@ -1319,9 +1326,10 @@ xfs_reflink_remap_prep( struct xfs_inode *dest = XFS_I(inode_out); bool same_inode = (inode_in == inode_out); ssize_t ret; + compare_range_t cmp; /* Lock both files against IO */ - ret = xfs_iolock_two_inodes_and_break_layout(inode_in, inode_out); + ret = xfs_reflink_remap_lock_and_break_layouts(file_in, file_out); if (ret) return ret; if (same_inode) @@ -1336,12 +1344,17 @@ xfs_reflink_remap_prep( if (XFS_IS_REALTIME_INODE(src) || XFS_IS_REALTIME_INODE(dest)) goto out_unlock; - /* Don't share DAX file data for now. */ - if (IS_DAX(inode_in) || IS_DAX(inode_out)) + /* Don't share DAX file data with non-DAX file. */ + if (IS_DAX(inode_in) != IS_DAX(inode_out)) goto out_unlock; + if (IS_DAX(inode_in)) + cmp = xfs_reflink_dedupe_file_range_compare; + else + cmp = vfs_dedupe_file_range_compare; + ret = generic_remap_file_range_prep(file_in, pos_in, file_out, pos_out, - len, remap_flags, vfs_dedupe_file_range_compare); + len, remap_flags, cmp); if (ret < 0 || *len == 0) goto out_unlock; -- 2.23.0