Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2219071pxa; Fri, 7 Aug 2020 06:15:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwPI80/HBSlA2Mzpopz8J7pGUgigpUpMMWrUNczhfc7LYcVwtfLZgvNs+J1ZgAz7Dj/5Tiv X-Received: by 2002:a17:906:4a07:: with SMTP id w7mr8982527eju.269.1596806119386; Fri, 07 Aug 2020 06:15:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596806119; cv=none; d=google.com; s=arc-20160816; b=0iSUew7C48VECjnKEyVVO486LdhSJ6/1czFdWxgcOvV+dG9nUoEnqkR2CMztVN7sZe SPMRTyBnGBCfwL+XPJ8UMWPS5E7o0kqHiHNBiuKuJxa67iMN6O2YWzVBsPljaiM7uaNL nEYHlsgPCgUn0TsIfkekkqziopNMTv3zq4hyF3mwafnTlUi7S0dmDKem2oMRVuBAwVkR DpQAy5W5iQfjzldAWlmTrs24n1aUYEdS3/005fh1Pl+Mivz3fSo2SZohcVplAw0bJOTj F3XTbkmtyeJSldodRycF1cStQS8K3njGpZaCFcaGk5WZXXdctGfWbmO/LiBZ6jyyjWKn UFHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=uU/0mtJvc4K+jyLYZQ4alAXvv+AQUMARWFt/XU0VeQQ=; b=DUeDzUPlMdwoYFaN2SsrVw//Xq1Si5wG7qr//Mz2UVJ3KwkdTmaNnT4ryB8QUSNnJv iUPiudOInzxdK31G9ls14R2GreAqmTwpGrclqliydLUcH3ShpGvXHSUg/8QRZ2pqZx7R QG9gOwOYR0L2M6RW2Y+l94I8TyEjyQwI86XEqRM/JbkNszxGkjq6btQ4coSSVbnXl776 sYa1vGXJMcTqWPvOPPTK7HEFCaPX5gO2ysaILb1PvQh1bQxATHpqAkSbjR30PuUMbV4c eHO794ar64eA1Fz2H1/G7aooHXtqTuRtWe7lix2zZILfsF2gahKyv2Ptzw35ZXZTJ7JE QvhA== 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 g8si5493880edj.508.2020.08.07.06.14.56; Fri, 07 Aug 2020 06:15:19 -0700 (PDT) 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 S1726533AbgHGNOF (ORCPT + 99 others); Fri, 7 Aug 2020 09:14:05 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:4473 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726198AbgHGNOE (ORCPT ); Fri, 7 Aug 2020 09:14:04 -0400 X-IronPort-AV: E=Sophos;i="5.75,445,1589212800"; d="scan'208";a="97774923" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 07 Aug 2020 21:13:48 +0800 Received: from G08CNEXMBPEKD05.g08.fujitsu.local (unknown [10.167.33.204]) by cn.fujitsu.com (Postfix) with ESMTP id 7467E4CE34F3; Fri, 7 Aug 2020 21:13:44 +0800 (CST) Received: from G08CNEXJMPEKD02.g08.fujitsu.local (10.167.33.202) by G08CNEXMBPEKD05.g08.fujitsu.local (10.167.33.204) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 7 Aug 2020 21:13:44 +0800 Received: from G08CNEXCHPEKD06.g08.fujitsu.local (10.167.33.205) by G08CNEXJMPEKD02.g08.fujitsu.local (10.167.33.202) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 7 Aug 2020 21:13:44 +0800 Received: from localhost.localdomain (10.167.225.141) by G08CNEXCHPEKD06.g08.fujitsu.local (10.167.33.209) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 7 Aug 2020 21:13:42 +0800 From: Shiyang Ruan To: , , CC: , , , , , , , , Subject: [RFC PATCH 8/8] fs/xfs: support dedupe for fsdax Date: Fri, 7 Aug 2020 21:13:36 +0800 Message-ID: <20200807131336.318774-9-ruansy.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200807131336.318774-1-ruansy.fnst@cn.fujitsu.com> References: <20200807131336.318774-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: 7467E4CE34F3.AD342 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 files both have DAX flag. Signed-off-by: Shiyang Ruan --- fs/xfs/xfs_reflink.c | 78 ++++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 32 deletions(-) diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index f87ab78dd421..b2901ad1a269 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 @@ -1185,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; } @@ -1244,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); @@ -1274,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 @@ -1318,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) @@ -1335,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.27.0