From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 59756C7C867 for ; Mon, 27 Apr 2020 08:48:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1D668206D4 for ; Mon, 27 Apr 2020 08:48:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1D668206D4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=cn.fujitsu.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D9FB58E0009; Mon, 27 Apr 2020 04:48:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D76A08E0001; Mon, 27 Apr 2020 04:48:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C8EF18E0009; Mon, 27 Apr 2020 04:48:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id AE6998E0001 for ; Mon, 27 Apr 2020 04:48:40 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 6F0E4180AD804 for ; Mon, 27 Apr 2020 08:48:40 +0000 (UTC) X-FDA: 76753009200.19.feast49_2e8344f49794f X-HE-Tag: feast49_2e8344f49794f X-Filterd-Recvd-Size: 6372 Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by imf49.hostedemail.com (Postfix) with ESMTP for ; Mon, 27 Apr 2020 08:48:39 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.73,323,1583164800"; d="scan'208";a="90547660" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 27 Apr 2020 16:48:37 +0800 Received: from G08CNEXMBPEKD04.g08.fujitsu.local (unknown [10.167.33.201]) by cn.fujitsu.com (Postfix) with ESMTP id C716A4BCC89B; Mon, 27 Apr 2020 16:37:57 +0800 (CST) Received: from G08CNEXCHPEKD05.g08.fujitsu.local (10.167.33.203) by G08CNEXMBPEKD04.g08.fujitsu.local (10.167.33.201) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 27 Apr 2020 16:48:40 +0800 Received: from localhost.localdomain (10.167.225.141) by G08CNEXCHPEKD05.g08.fujitsu.local (10.167.33.209) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 27 Apr 2020 16:48:39 +0800 From: Shiyang Ruan To: , , CC: , , , , , , , , Subject: [RFC PATCH 8/8] fs/xfs: support dedupe for fsdax Date: Mon, 27 Apr 2020 16:47:50 +0800 Message-ID: <20200427084750.136031-9-ruansy.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200427084750.136031-1-ruansy.fnst@cn.fujitsu.com> References: <20200427084750.136031-1-ruansy.fnst@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain X-yoursite-MailScanner-ID: C716A4BCC89B.A09FE X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: ruansy.fnst@cn.fujitsu.com Content-Transfer-Encoding: quoted-printable 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: Use xfs_break_layouts() to break files' layouts when locking them. And call dax_file_range_compare() function to compare range for files both DAX. 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 f87ab78dd421..efbe3464ae85 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -1185,47 +1185,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 =3D file_inode(file_in); + struct xfs_inode *src =3D XFS_I(inode_in); + struct inode *inode_out =3D file_inode(file_out); + struct xfs_inode *dest =3D XFS_I(inode_out); + uint iolock =3D XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL; =20 - 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 =3D break_layout(src, true); - if (error) - return error; - if (src !=3D dest) { - error =3D break_layout(dest, true); - if (error) - return error; } =20 - /* Lock one inode and make sure nobody got in and leased it. */ - inode_lock(src); - error =3D break_layout(src, false); + inode_lock(inode_in); + xfs_ilock(src, XFS_MMAPLOCK_EXCL); + error =3D xfs_break_layouts(inode_in, &iolock, BREAK_UNMAP); + xfs_iunlock(src, XFS_MMAPLOCK_EXCL); if (error) { - inode_unlock(src); - if (error =3D=3D -EWOULDBLOCK) - goto retry; + inode_unlock(inode_in); return error; } =20 - if (src =3D=3D dest) + if (inode_in =3D=3D inode_out) return 0; =20 - /* Lock the other inode and make sure nobody got in and leased it. */ - inode_lock_nested(dest, I_MUTEX_NONDIR2); - error =3D break_layout(dest, false); + inode_lock_nested(inode_out, I_MUTEX_NONDIR2); + xfs_ilock(dest, XFS_MMAPLOCK_EXCL); + error =3D xfs_break_layouts(inode_out, &iolock, BREAK_UNMAP); + xfs_iunlock(dest, XFS_MMAPLOCK_EXCL); if (error) { - inode_unlock(src); - inode_unlock(dest); - if (error =3D=3D -EWOULDBLOCK) - goto retry; + inode_unlock(inode_in); + inode_unlock(inode_out); return error; } =20 @@ -1244,6 +1238,11 @@ xfs_reflink_remap_unlock( struct xfs_inode *dest =3D XFS_I(inode_out); bool same_inode =3D (inode_in =3D=3D inode_out); =20 + 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 +1273,14 @@ xfs_reflink_zero_posteof( &xfs_buffered_write_iomap_ops); } =20 +int xfs_reflink_dedupe_file_range_compare(struct inode *src, loff_t srco= ff, + 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 i= nodes * will have the iolock and mmaplock held, the page cache of the out fil= e will @@ -1318,9 +1325,10 @@ xfs_reflink_remap_prep( struct xfs_inode *dest =3D XFS_I(inode_out); bool same_inode =3D (inode_in =3D=3D inode_out); ssize_t ret; + compare_range_t cmp; =20 /* Lock both files against IO */ - ret =3D xfs_iolock_two_inodes_and_break_layout(inode_in, inode_out); + ret =3D xfs_reflink_remap_lock_and_break_layouts(file_in, file_out); if (ret) return ret; if (same_inode) @@ -1335,12 +1343,17 @@ xfs_reflink_remap_prep( if (XFS_IS_REALTIME_INODE(src) || XFS_IS_REALTIME_INODE(dest)) goto out_unlock; =20 - /* 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) !=3D IS_DAX(inode_out)) goto out_unlock; =20 + if (IS_DAX(inode_in)) + cmp =3D xfs_reflink_dedupe_file_range_compare; + else + cmp =3D vfs_dedupe_file_range_compare; + ret =3D generic_remap_file_range_prep(file_in, pos_in, file_out, pos_ou= t, - len, remap_flags, vfs_dedupe_file_range_compare); + len, remap_flags, cmp); if (ret < 0 || *len =3D=3D 0) goto out_unlock; =20 --=20 2.26.2