Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp727027rwb; Thu, 1 Dec 2022 07:40:53 -0800 (PST) X-Google-Smtp-Source: AA0mqf54hH9F9MItve35PtAZC9pHSxTRiJhRwMh1OcN/KU+oON049ROX2PLNIKxv2HI3Yuf5bita X-Received: by 2002:a05:6a00:1a4c:b0:574:97d4:c10f with SMTP id h12-20020a056a001a4c00b0057497d4c10fmr36089042pfv.81.1669909252681; Thu, 01 Dec 2022 07:40:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669909252; cv=none; d=google.com; s=arc-20160816; b=vcmoO3zQ3YtA/GRNb1t5tfjtTIgySuQsOrg5xN6OM0x3XndFsZaCOmkNpOPJ2rZ1rk TOkYXHNAfB78aMspPV3hF4q6Skcr8/TQkqT+0TOQpqH45SsDnROnqWRgBxCopDDtsrfl uoi7+ue1WcntTA4Q0OBD8Q5EQDeWFkXusSJ9ac/HjsRFVbz1agSt+oR9bJyc7NDdYiZu ZvReX9BbIYF64zxc/8xs1yiR8mVSIAiPu9GKuoQoSznB3A6lXiY9+Mo+xyRfLQTXBcU0 F9mWVBbCQry/Zzmv3+EcQr7TlgP2UpouctAkm8eVYoykdKWozz12hKQaDOZDFLGIQfzS lsAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=9IQSXH/mBJ0Rz36RhWdtV/CNJuRmPioRHTD0RIk1xlI=; b=U9deN9L8HeioXuUMHfjF4NXeDxyAvkNZ2N/dxqriy4poq6SDxqRieEPpPDUtYscAT2 C38FsI4AxcIAtEuC83BM2pnGiTpmz/WOKOOC67r8I17gyDq9yVy2XCz01BmnGbg+jCQT epot5dqZNMxS1dlg7gc7qe2Aw1DX2pbBzileRkmxCZSW/sX2qUPqxzKuq7Mq1JSJ7i3K 0w4aD2qaFlLDU5Gof9m89MekyEFTA2esXRU1H95pIrwpUN4AYff4O6/LQfGIDU1f6ohr PZXGkXSKJ02V+rOMCVTlRbv4lTuMfrRP9ZagCS+oXoBMtD07V5jP0HC/SdRhq0pDddJb n2XA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fujitsu.com header.s=170520fj header.b=R8uXsH9y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fujitsu.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z1-20020a056a00240100b0057593ed4874si5349103pfh.315.2022.12.01.07.40.41; Thu, 01 Dec 2022 07:40:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@fujitsu.com header.s=170520fj header.b=R8uXsH9y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fujitsu.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232011AbiLAPdr (ORCPT + 83 others); Thu, 1 Dec 2022 10:33:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231984AbiLAPdU (ORCPT ); Thu, 1 Dec 2022 10:33:20 -0500 Received: from mail1.bemta32.messagelabs.com (mail1.bemta32.messagelabs.com [195.245.230.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88046ABA3F; Thu, 1 Dec 2022 07:32:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fujitsu.com; s=170520fj; t=1669908767; i=@fujitsu.com; bh=9IQSXH/mBJ0Rz36RhWdtV/CNJuRmPioRHTD0RIk1xlI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=R8uXsH9yOqUsRPaoxjUGuV1g3UHH/LUIaiR0k/bP5MjwbiaqqRWA7fljFcQ2YAdQj Mq3EHaOLmR3DXasTotl3VZEs08QCdzpAhMPitHVel+EABJeMD8PJYJv39OJMJyKcjM kTCFX2YchTMSxYQwO59WfbI4KgfeDUIhXC/H2NaDc3KvIx5LymlVRB0M0La1d3X//w NbICES275v2veOWEyySMOXwTyhMn+dfq/wSHUmiUZ7MiW9rEPWXlAEGbRE5LN+5RJ9 AjhVBR8w5xlNySX0B7ZRK/dVnqXaPJTsdamYbAnTJtGIf7HJIXhKX/87TIS2z9eSc4 IxL0IzbvIPo3A== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupjleJIrShJLcpLzFFi42Kxs+GYpCt3siP Z4HqbkcWc9WvYLKZPvcBoseXYPUaLy0/4LPbsPclicXnXHDaLXX92sFus/PGH1YHD49QiCY/F e14yeWxa1cnmcWLGbxaPF5tnMnp83iQXwBbFmpmXlF+RwJrxZtcxpoIdEhXnb3xiaWA8J9LFy MUhJLCFUeL22gb2LkZOIGc5k8SkD84QiT2MElte3WEDSbAJ6EhcWPCXtYuRg0NEoFri1lKwML NAhsTxK3+YQWxhAQuJtl2bweawCKhI/JixlxXE5hVwlXg86SoTiC0hoCAx5eF7sHpOoPjLvxu h9rpIXG8+yAxRLyhxcuYTFoj5EhIHX7xgBlkrIaAkMbM7HmJMhcSsWW1QI9Ukrp7bxDyBUXAW ku5ZSLoXMDKtYjQtTi0qSy3SNdFLKspMzyjJTczM0Uus0k3USy3VLU8tLtE11EssL9ZLLS7WK 67MTc5J0ctLLdnECIyUlGI2nx2M/5b+0TvEKMnBpCTKq72vI1mILyk/pTIjsTgjvqg0J7X4EK MMB4eSBG/KHqCcYFFqempFWmYOMGph0hIcPEoivHzHgNK8xQWJucWZ6RCpU4zGHGsbDuxl5pg 6+99+ZiGWvPy8VClx3sDjQKUCIKUZpXlwg2DJ5BKjrJQwLyMDA4MQT0FqUW5mCar8K0ZxDkYl Yd5t24Cm8GTmlcDtewV0ChPQKZFibSCnlCQipKQamIzLMj/o6NwuimRbyrtgc0zLJy5zBaZf+ tNPyJy1s7CyWPX4ZXFU48mJe2ptS2L5GD+6vJY02RC3J9+KeU0Gd479HR2NP53nJZiFmNg8Lb +tfmVvaexgf0JD7YBHv4nvdanFk+bVxP/atu7oRfeupr0/ymcWu8VL3vo9q+Tn5bLQmvOeZ1/ NVyx+ncPZrc5l0GbRLay/wvOLl6na0x8bJ7FbMJyTsj2ZOK3IzWm5U5fxkZq9Rp+e37P2/J5X Gi91Y+u58y+4S9fe7HvyzN7w0yaX6YbuSccuzjqw9+7JpHtCE8Nmn9x69qPAuXXz1yyUZT0S3 dyo8vuT9Jp3By22O8178iam5SmXJh9ru8Ceg0osxRmJhlrMRcWJAFpNk5yhAwAA X-Env-Sender: ruansy.fnst@fujitsu.com X-Msg-Ref: server-22.tower-587.messagelabs.com!1669908766!107085!1 X-Originating-IP: [62.60.8.146] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.101.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 27136 invoked from network); 1 Dec 2022 15:32:46 -0000 Received: from unknown (HELO n03ukasimr02.n03.fujitsu.local) (62.60.8.146) by server-22.tower-587.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 1 Dec 2022 15:32:46 -0000 Received: from n03ukasimr02.n03.fujitsu.local (localhost [127.0.0.1]) by n03ukasimr02.n03.fujitsu.local (Postfix) with ESMTP id 5C5231000D5; Thu, 1 Dec 2022 15:32:46 +0000 (GMT) Received: from R01UKEXCASM126.r01.fujitsu.local (R01UKEXCASM126 [10.183.43.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by n03ukasimr02.n03.fujitsu.local (Postfix) with ESMTPS id 4F77B1000C1; Thu, 1 Dec 2022 15:32:46 +0000 (GMT) Received: from localhost.localdomain (10.167.225.141) by R01UKEXCASM126.r01.fujitsu.local (10.183.43.178) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Thu, 1 Dec 2022 15:32:42 +0000 From: Shiyang Ruan To: , , , CC: , , , Subject: [PATCH v2 7/8] fsdax,xfs: port unshare to fsdax Date: Thu, 1 Dec 2022 15:32:33 +0000 Message-ID: <1669908753-169-1-git-send-email-ruansy.fnst@fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1669908538-55-1-git-send-email-ruansy.fnst@fujitsu.com> References: <1669908538-55-1-git-send-email-ruansy.fnst@fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.167.225.141] X-ClientProxiedBy: G08CNEXCHPEKD07.g08.fujitsu.local (10.167.33.80) To R01UKEXCASM126.r01.fujitsu.local (10.183.43.178) X-Virus-Scanned: ClamAV using ClamSMTP X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Implement unshare in fsdax mode: copy data from srcmap to iomap. Signed-off-by: Shiyang Ruan Reviewed-by: Darrick J. Wong --- fs/dax.c | 52 ++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_reflink.c | 8 +++++-- include/linux/dax.h | 2 ++ 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/fs/dax.c b/fs/dax.c index 354be56750c2..a57e320e7971 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -1244,6 +1244,58 @@ static vm_fault_t dax_pmd_load_hole(struct xa_state *xas, struct vm_fault *vmf, } #endif /* CONFIG_FS_DAX_PMD */ +static s64 dax_unshare_iter(struct iomap_iter *iter) +{ + struct iomap *iomap = &iter->iomap; + const struct iomap *srcmap = iomap_iter_srcmap(iter); + loff_t pos = iter->pos; + loff_t length = iomap_length(iter); + int id = 0; + s64 ret = 0; + void *daddr = NULL, *saddr = NULL; + + /* don't bother with blocks that are not shared to start with */ + if (!(iomap->flags & IOMAP_F_SHARED)) + return length; + /* don't bother with holes or unwritten extents */ + if (srcmap->type == IOMAP_HOLE || srcmap->type == IOMAP_UNWRITTEN) + return length; + + id = dax_read_lock(); + ret = dax_iomap_direct_access(iomap, pos, length, &daddr, NULL); + if (ret < 0) + goto out_unlock; + + ret = dax_iomap_direct_access(srcmap, pos, length, &saddr, NULL); + if (ret < 0) + goto out_unlock; + + ret = copy_mc_to_kernel(daddr, saddr, length); + if (ret) + ret = -EIO; + +out_unlock: + dax_read_unlock(id); + return ret; +} + +int dax_file_unshare(struct inode *inode, loff_t pos, loff_t len, + const struct iomap_ops *ops) +{ + struct iomap_iter iter = { + .inode = inode, + .pos = pos, + .len = len, + .flags = IOMAP_WRITE | IOMAP_UNSHARE | IOMAP_DAX, + }; + int ret; + + while ((ret = iomap_iter(&iter, ops)) > 0) + iter.processed = dax_unshare_iter(&iter); + return ret; +} +EXPORT_SYMBOL_GPL(dax_file_unshare); + static int dax_memzero(struct iomap_iter *iter, loff_t pos, size_t size) { const struct iomap *iomap = &iter->iomap; diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index 93bdd25680bc..fe46bce8cae6 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -1693,8 +1693,12 @@ xfs_reflink_unshare( inode_dio_wait(inode); - error = iomap_file_unshare(inode, offset, len, - &xfs_buffered_write_iomap_ops); + if (IS_DAX(inode)) + error = dax_file_unshare(inode, offset, len, + &xfs_dax_write_iomap_ops); + else + error = iomap_file_unshare(inode, offset, len, + &xfs_buffered_write_iomap_ops); if (error) goto out; diff --git a/include/linux/dax.h b/include/linux/dax.h index ba985333e26b..2b5ecb591059 100644 --- a/include/linux/dax.h +++ b/include/linux/dax.h @@ -205,6 +205,8 @@ static inline void dax_unlock_mapping_entry(struct address_space *mapping, } #endif +int dax_file_unshare(struct inode *inode, loff_t pos, loff_t len, + const struct iomap_ops *ops); int dax_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero, const struct iomap_ops *ops); int dax_truncate_page(struct inode *inode, loff_t pos, bool *did_zero, -- 2.38.1