Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3434937pxb; Sun, 7 Feb 2021 09:15:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJztEubjPTNigMW3RTkVAIVYquBYMnYrqQhWd477MeSNj7RD2CzJ0GPisbzEvMwce6XKp6Eu X-Received: by 2002:a17:907:1692:: with SMTP id hc18mr1008306ejc.244.1612718158056; Sun, 07 Feb 2021 09:15:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612718158; cv=none; d=google.com; s=arc-20160816; b=BhGR2ZoD7jWm1a3b65Aa79wVogsWsCfNG5ff6g0jD2ni5jClx3+48GccOThuWbTE0r lK7j/4kACnMaMz7pJTGun5PpqOCP5h2+gGMeI0Hk9/hnV+FpZV6wVMn9KKX6Zq9XaJ7G IehTjeXGwC4nM3cmfPI9RhUmqAwb1HdXNr6Z8uFD9g89GlknOfPg2abixhsR40GDwqQp kEcWUhZBGY4+w8AlF2ZqoV6lDsRE4Zh3sFzxgfuI4fQx9LdnANs4ECy9jp29UlJaqSZV a6Er2EVTY+HOK6GN+0Y9w1dHTwJk/op2gokAVQ2K2IxQB2M/zUOQlUAhoQKpqHpazt9i 1V4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Z5aHJiR+hZVdRjCGWyibeWApBLVc3eTD+ViYT5dzgNM=; b=QLJ2pScnSca17ra/J7stV3oVgoMb3OeI9Qib1XJ14p+KFe3WofHbnoZTSETZfqXlAd OBeJayG0cA+P+Ycc7fnsrzYECJOfsAkmwEQhN8xKKnsIi474rvkmvTT29CrHXi6MmX7Z T2/3IKAlHVUxLt/dcfPwGa6stMw95FvM8e+EMAWv83adcrCntqq0XUL2uxVG3RXZhoc8 wviOZ2Hr3wp79OQMCWKu4o5GobB0H7ZIqRgkBQlgEniDk8wyGcST1ofTrfh6ahesr3v7 +RaKfpmp5eCKdaMuT7Km1zmpKp4Z9EcHLfBboNnPzVIIZxAWHohLfT1gTmcf4bjoDC5E 06nw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p11si316505ejo.704.2021.02.07.09.15.33; Sun, 07 Feb 2021 09:15:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229941AbhBGRLk (ORCPT + 99 others); Sun, 7 Feb 2021 12:11:40 -0500 Received: from mail.cn.fujitsu.com ([183.91.158.132]:49728 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229822AbhBGRLD (ORCPT ); Sun, 7 Feb 2021 12:11:03 -0500 X-IronPort-AV: E=Sophos;i="5.81,160,1610380800"; d="scan'208";a="104299378" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 08 Feb 2021 01:09:44 +0800 Received: from G08CNEXMBPEKD05.g08.fujitsu.local (unknown [10.167.33.204]) by cn.fujitsu.com (Postfix) with ESMTP id A63F74CE6F74; Mon, 8 Feb 2021 01:09:38 +0800 (CST) Received: from G08CNEXCHPEKD04.g08.fujitsu.local (10.167.33.200) by G08CNEXMBPEKD05.g08.fujitsu.local (10.167.33.204) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 8 Feb 2021 01:09:38 +0800 Received: from irides.mr.mr.mr (10.167.225.141) by G08CNEXCHPEKD04.g08.fujitsu.local (10.167.33.209) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 8 Feb 2021 01:09:37 +0800 From: Shiyang Ruan To: , , , CC: , , , , , , , , , Subject: [PATCH 7/7] fs/xfs: Add dedupe support for fsdax Date: Mon, 8 Feb 2021 01:09:24 +0800 Message-ID: <20210207170924.2933035-8-ruansy.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210207170924.2933035-1-ruansy.fnst@cn.fujitsu.com> References: <20210207170924.2933035-1-ruansy.fnst@cn.fujitsu.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-yoursite-MailScanner-ID: A63F74CE6F74.AE72D X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: ruansy.fnst@cn.fujitsu.com X-Spam-Status: No Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add xfs_break_two_dax_layouts() to break layout for tow dax files. Then call compare range function only when files are both DAX or not. Signed-off-by: Shiyang Ruan --- fs/xfs/xfs_file.c | 20 ++++++++++++++++++++ fs/xfs/xfs_inode.c | 8 +++++++- fs/xfs/xfs_inode.h | 1 + fs/xfs/xfs_reflink.c | 21 ++++++++++++++++++--- 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index ab738641a3f4..64ded96b43c8 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -791,6 +791,26 @@ xfs_break_dax_layouts( 0, 0, xfs_wait_dax_page(inode)); } +int +xfs_break_two_dax_layouts( + struct inode *src, + struct inode *dest) +{ + int error; + bool retry = false; + +retry: + error = xfs_break_dax_layouts(src, &retry); + if (error || retry) + goto retry; + + error = xfs_break_dax_layouts(dest, &retry); + if (error || retry) + goto retry; + + return error; +} + int xfs_break_layouts( struct inode *inode, diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 2bfbcf28b1bd..6483dbaa4d57 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -3786,8 +3786,10 @@ xfs_ilock2_io_mmap( struct xfs_inode *ip2) { int ret; + struct inode *inode1 = VFS_I(ip1); + struct inode *inode2 = VFS_I(ip2); - ret = xfs_iolock_two_inodes_and_break_layout(VFS_I(ip1), VFS_I(ip2)); + ret = xfs_iolock_two_inodes_and_break_layout(inode1, inode2); if (ret) return ret; if (ip1 == ip2) @@ -3795,6 +3797,10 @@ xfs_ilock2_io_mmap( else xfs_lock_two_inodes(ip1, XFS_MMAPLOCK_EXCL, ip2, XFS_MMAPLOCK_EXCL); + + if (IS_DAX(inode1) && IS_DAX(inode2)) + ret = xfs_break_two_dax_layouts(inode1, inode2); + return 0; } diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h index 751a3d1d7d84..462b61bea691 100644 --- a/fs/xfs/xfs_inode.h +++ b/fs/xfs/xfs_inode.h @@ -431,6 +431,7 @@ enum xfs_prealloc_flags { int xfs_update_prealloc_flags(struct xfs_inode *ip, enum xfs_prealloc_flags flags); +int xfs_break_two_dax_layouts(struct inode *inode1, struct inode *inode2); int xfs_break_layouts(struct inode *inode, uint *iolock, enum layout_break_reason reason); diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index 38bde16cdb39..bdb9a07e703f 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -29,6 +29,7 @@ #include "xfs_iomap.h" #include "xfs_sb.h" #include "xfs_ag_resv.h" +#include /* * Copy on Write of Shared Blocks @@ -1251,6 +1252,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 @@ -1293,6 +1302,7 @@ xfs_reflink_remap_prep( struct xfs_inode *src = XFS_I(inode_in); struct inode *inode_out = file_inode(file_out); struct xfs_inode *dest = XFS_I(inode_out); + compare_range_t compare_range_fn; int ret; /* Lock both files against IO */ @@ -1306,12 +1316,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)) + compare_range_fn = xfs_reflink_dedupe_file_range_compare; + else + compare_range_fn = 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, compare_range_fn); if (ret || *len == 0) goto out_unlock; -- 2.30.0