Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1559843pxb; Fri, 20 Aug 2021 08:20:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPol9FgXhEai1U3Ah/sh50b0ZJ00yNCAdKHMWgOjJ9P8FT17cnMYcltChm/HpQWUnuuFVQ X-Received: by 2002:a5d:990f:: with SMTP id x15mr16598619iol.200.1629472837761; Fri, 20 Aug 2021 08:20:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629472837; cv=none; d=google.com; s=arc-20160816; b=rfyZOGGZRRKCmaCSTqBQLDh4UgI8fy3/TY9BeptVISRGkU0vdXXmYWI4SU0MrXcdQE IiQGKtJAsf9YBk1ZCX/v3ta1i4xWYXwMG9QhdAQJS6LXt7JnFCiqKZt2uUY0WSPU0fPA p6jgzcqPmcTRZKO4KZkTga8hz+gTq+s6ONWox0m5fzEywiAHM+hY7OqV5jhC+x8HaUXI Dhsxhim7LW48fYJWRH9UyDAAFhL9ba3fbrcxwkjbP5v2rkTqrcTj52cG/dyfqtM5wKZI 5TJlPFhj/hWRu0VAqFzxeCM3wiwv4JeZI3ZGWGp+jSlEL4gbfV1lpTuyQ8a4/1Wm6I+a VpHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=e7Os9VAnizBXv51HC/2jWtdqVC6IT3MX2PEly7Hzllc=; b=BTjAvAvUzwe/qSEagwzqfTSKV+SVc/ovbGDmVUAkz+CAbAteRm1NjbsdKfCoBuk7R4 4t5w/2WpFQfB4B6Ssjx/nW/SphKVEjg+2qUs+MgjxG6ONqlHb+KlBgXyPaoqtzLAzecf iRuRdYCcXG2npKnhF0MEt9UWYwdFjDnEWnXaZC7T39xWBo/IERxqy1KamZYx4tlofoNO EuVR51/HpCLjMjWCb0z3yeLb1DfyplcUC2RL6T6vAKwubssUohJcWWl1PsxTdeEst0Xq lG8zyx0UGAOT4Ho3rPv/DNKanJWLCr0Ar/KNLYdt8onCXYCrNtU+h16tkqnjsLY18VBR SsPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=M+ibRtOT; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c6si3367134iow.84.2021.08.20.08.20.24; Fri, 20 Aug 2021 08:20:37 -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; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=M+ibRtOT; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240956AbhHTPTp (ORCPT + 99 others); Fri, 20 Aug 2021 11:19:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240992AbhHTPTk (ORCPT ); Fri, 20 Aug 2021 11:19:40 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35D19C061575 for ; Fri, 20 Aug 2021 08:18:56 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id u13-20020a17090abb0db0290177e1d9b3f7so14040226pjr.1 for ; Fri, 20 Aug 2021 08:18:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=e7Os9VAnizBXv51HC/2jWtdqVC6IT3MX2PEly7Hzllc=; b=M+ibRtOTQAZRmC0FnL3AMilGRh2mUgMJmWUfg9JNOtAKXFs9lFLPXucpaO7ELUpNDb EGbzGydfkHCtIjzQLeNz+1/fIOA2rFhRJv3yC4ZhYvpISJH4iNfkhazi5Hz/Nq0fpYXO QpGdn8L+8PdTFb0E+p78qZDHRXkUnXo7JNSYlGQecnF0IhE5VtdC/Y+7Y9yUsL+y7PV3 5x4ObvPPy0AxrVohJG1gL8vPnbME69k1gCKAA1GyMrEqgR+PWW/PMthly7voCniXVW59 FcwvvH0AWzl2X+1XFpdijT2XoPDvNcAXBc2pyggbrImBdT+vil40sbH7g0dNEEtf0bPA hjMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=e7Os9VAnizBXv51HC/2jWtdqVC6IT3MX2PEly7Hzllc=; b=ewiD5ihzOk2DZO4QIlV1cjHYfK7N9sjRZjXQn8Fy9wTNogDKMPW25mVSB5FHGGYgnj uR3Zc8EYJZ+sfIrJWsnhuRAbG5Ip6YUeMVcWg0bpaNW2YrpfSul8lCDUvZn7FhXGQ8Bf asOKAaC9Z7vZloMr94MMFdTsW4lMDZ5ZT92152sTq7oHehuWhgn+FrXepRuCCY2Dv9T8 QvERu7bTnLurfqUOojtsMhDKEi/rwT3j0e2bPEe2xZRGHsfPK0D6ptuhQELqGe0MHVoh F4nP9GMfF/zq0yI3ODLdUcxq367kdXEwHcUEpL7JhdXLKGXR0a8h1tqDNM58t/PD/ap1 LLHw== X-Gm-Message-State: AOAM531qal42p9BGOaM/RJ+EQSDQP4pg9OfPmFSpt2ec0stSfDZ4oEwU 6E9e2stx7hjUtxTKe+xfb6s40OfKDNRL4Iy5lgFWbQ== X-Received: by 2002:a17:90a:708c:: with SMTP id g12mr5224172pjk.13.1629472735668; Fri, 20 Aug 2021 08:18:55 -0700 (PDT) MIME-Version: 1.0 References: <20210816060359.1442450-1-ruansy.fnst@fujitsu.com> <20210816060359.1442450-8-ruansy.fnst@fujitsu.com> In-Reply-To: From: Dan Williams Date: Fri, 20 Aug 2021 08:18:44 -0700 Message-ID: Subject: Re: [PATCH v7 7/8] fsdax: Introduce dax_iomap_ops for end of reflink To: "ruansy.fnst" Cc: "Darrick J. Wong" , Christoph Hellwig , linux-xfs , david , linux-fsdevel , Linux Kernel Mailing List , Linux NVDIMM , Goldwyn Rodrigues , Al Viro , Matthew Wilcox Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 19, 2021 at 11:13 PM ruansy.fnst wrot= e: > > > > On 2021/8/20 =E4=B8=8A=E5=8D=8811:01, Dan Williams wrote: > > On Sun, Aug 15, 2021 at 11:05 PM Shiyang Ruan = wrote: > >> > >> After writing data, reflink requires end operations to remap those new > >> allocated extents. The current ->iomap_end() ignores the error code > >> returned from ->actor(), so we introduce this dax_iomap_ops and change > >> the dax_iomap_*() interfaces to do this job. > >> > >> - the dax_iomap_ops contains the original struct iomap_ops and fsdax > >> specific ->actor_end(), which is for the end operations of reflin= k > >> - also introduce dax specific zero_range, truncate_page > >> - create new dax_iomap_ops for ext2 and ext4 > >> > >> Signed-off-by: Shiyang Ruan > >> --- > >> fs/dax.c | 68 +++++++++++++++++++++++++++++++++++++---= -- > >> fs/ext2/ext2.h | 3 ++ > >> fs/ext2/file.c | 6 ++-- > >> fs/ext2/inode.c | 11 +++++-- > >> fs/ext4/ext4.h | 3 ++ > >> fs/ext4/file.c | 6 ++-- > >> fs/ext4/inode.c | 13 ++++++-- > >> fs/iomap/buffered-io.c | 3 +- > >> fs/xfs/xfs_bmap_util.c | 3 +- > >> fs/xfs/xfs_file.c | 8 ++--- > >> fs/xfs/xfs_iomap.c | 36 +++++++++++++++++++++- > >> fs/xfs/xfs_iomap.h | 33 ++++++++++++++++++++ > >> fs/xfs/xfs_iops.c | 7 ++--- > >> fs/xfs/xfs_reflink.c | 3 +- > >> include/linux/dax.h | 21 ++++++++++--- > >> include/linux/iomap.h | 1 + > >> 16 files changed, 189 insertions(+), 36 deletions(-) > >> > >> diff --git a/fs/dax.c b/fs/dax.c > >> index 74dd918cff1f..0e0536765a7e 100644 > >> --- a/fs/dax.c > >> +++ b/fs/dax.c > >> @@ -1348,11 +1348,30 @@ static loff_t dax_iomap_iter(const struct ioma= p_iter *iomi, > >> return done ? done : ret; > >> } > >> > >> +static inline int > >> +__dax_iomap_iter(struct iomap_iter *iter, const struct dax_iomap_ops = *ops) > >> +{ > >> + int ret; > >> + > >> + /* > >> + * Call dax_iomap_ops->actor_end() before iomap_ops->iomap_end= () in > >> + * each iteration. > >> + */ > >> + if (iter->iomap.length && ops->actor_end) { > >> + ret =3D ops->actor_end(iter->inode, iter->pos, iter->l= en, > >> + iter->processed); > >> + if (ret < 0) > >> + return ret; > >> + } > >> + > >> + return iomap_iter(iter, &ops->iomap_ops); > > > > This reorganization looks needlessly noisy. Why not require the > > iomap_end operation to perform the actor_end work. I.e. why can't > > xfs_dax_write_iomap_actor_end() just be the passed in iomap_end? I am > > not seeing where the ->iomap_end() result is ignored? > > > > The V6 patch[1] was did in this way. > [1]https://lore.kernel.org/linux-xfs/20210526005159.GF202144@locust/T/#m7= 9a66a928da2d089e2458c1a97c0516dbfde2f7f > > But Darrick reminded me that ->iomap_end() will always take zero or > positive 'written' because iomap_apply() handles this argument. > > ``` > if (ops->iomap_end) { > ret =3D ops->iomap_end(inode, pos, length, > written > 0 ? written : 0, > flags, &iomap); > } > ``` > > So, we cannot get actual return code from CoW in ->actor(), and as a > result, we cannot handle the xfs end_cow correctly in ->iomap_end(). > That's where the result of CoW was ignored. Ah, thank you for the explanation. However, this still seems like too much code thrash just to get back to the original value of iter->processed. I notice you are talking about iomap_apply(), but that routine is now gone in Darrick's latest iomap-for-next branch. Instead iomap_iter() does this: if (iter->iomap.length && ops->iomap_end) { ret =3D ops->iomap_end(iter->inode, iter->pos, iomap_length= (iter), iter->processed > 0 ? iter->processed : 0, iter->flags, &iter->iomap); if (ret < 0 && !iter->processed) return ret; } I notice that the @iomap argument to ->iomap_end() is reliably coming from @iter. So you could do the following in your iomap_end() callback: struct iomap_iter *iter =3D container_of(iomap, typeof(*iter), ioma= p); struct xfs_inode *ip =3D XFS_I(inode); ssize_t written =3D iter->processed; bool cow =3D xfs_is_cow_inode(ip); if (cow) { if (written <=3D 0) xfs_reflink_cancel_cow_range(ip, pos, length, true) }