Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1010501pxb; Thu, 26 Aug 2021 22:08:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFgsXNd9i8FpLIWxP4YZwaeYYIgwfn93lh2wrbDMUYdhUg21Ta9MMvgklJyblV1ggSXax+ X-Received: by 2002:a17:906:2acc:: with SMTP id m12mr8303331eje.231.1630040926405; Thu, 26 Aug 2021 22:08:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630040926; cv=none; d=google.com; s=arc-20160816; b=TERe+2h14otlwJDStJPdwIjxdp9pb4DI0NNrgOngnTO6AJjVzSPHqicyraQ4mRGL4M SbltNpGTPMteS/vAs8cBdgZi+nxKVOQj1LnsFFLagV6GT707XyTRSqRbgbGUp7IG4+Wq +9cXzg5e872vbjsP/jk7H4B2sKi6bm/tRfaVIafBI9uP2mdiZlncldPWpkCn9ri4PJMm BUQUzSmg6Tc91TOUli8kjMyoiHTeh7qJDvv6Rg5cwzanDirbhgYjn5rkwfAOo4g/1cS2 ODbubfgAA5vZXpzO3qYuzRNla3SB02A7vYPkSFcHqHN7HsZcOBfXw8QeoDo/OcPZOlmN l5yQ== 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=nFc3sdoCByIwYxggk+AQ1a3lDorwtem5TNHN34NU5Jc=; b=NCMtPjTWrxyol0KSsDrQDjeD2ZGJG3h19XsOwN+IYuP0Qi0saNZMgUcCAvAejHwhNT TTq3pKSkKbkOmNYuEOxGTa5//3rFOfwIJB7tzVTK1cLnXoB/bTYp+FXlNO7ENx8nO747 XhBgXPUSslaYUqPtElqwIbEFO2vn9jAvqB5aPs/5jMj5XfTJ6u1FizRG28ODQSSdi12R SNogua0JdFMNezmp6uzK/eXCcJjIcfS81XIkEVViDbbIvsJk/wml4O94e89UsrpmT8ob U7yXaPjqabGTeeUp4mKr68wqjFhZDGH9Yu8dmR8sjd3lRU8R3yKCwNrJaOLvBBSxpATy 0nig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=LgiKD4Zo; 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 s10si5306404edw.319.2021.08.26.22.08.23; Thu, 26 Aug 2021 22:08:46 -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=LgiKD4Zo; 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 S244242AbhH0FFT (ORCPT + 99 others); Fri, 27 Aug 2021 01:05:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229645AbhH0FFP (ORCPT ); Fri, 27 Aug 2021 01:05:15 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DB03C0613CF for ; Thu, 26 Aug 2021 22:04:27 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id d17so3185205plr.12 for ; Thu, 26 Aug 2021 22:04:27 -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=nFc3sdoCByIwYxggk+AQ1a3lDorwtem5TNHN34NU5Jc=; b=LgiKD4Zo3v0mLVNslAx3ru3XtLkSlizC6BQHy54CHr1TxM3DHOu8L6d9ohwdHl5jFZ LkcpZVu3aeWV1BX8/WFgZg1yawyzpq8FRD5EBw7PgkylUIhyTGYix6wr2qwhNnngONqR 0KEMJ1c1HG4X4r9v8ML+NuRn40w61WyyPUGqLvzFkC62+nmMKhUUfuMWrU18/421ViQw qFNP/c7LIRCkO8UxTd8/rAJ/bKWN642/FNsp6dFY0IbLVvkYKT9H1q/Fr2eYwf6Wktjf Nu3mNKm9t+SZYpDwmalLqn/R31CQX0b42gZapFrwVOZEwfLcUvhSXcOfnpyRdxw2a61t npiQ== 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=nFc3sdoCByIwYxggk+AQ1a3lDorwtem5TNHN34NU5Jc=; b=rvQ4kPmeWFK60gcj7Mfph98xiKjFW84McLi/isc+0kW1sOsPgV2NbQNAW9FEaFQ7E4 nt/QTQ6ZNN4pN7ub4+H+JKBdGvGSdAT+sHZ5TyL1jZlrEAClD6BltKC1QuAMQzKReG9d YGYJhLOjtphrGLMQHPr4HllEuyKjDirI35l8wN/N2DGcDIiOO7EXneyhoYhb8VCoGCet C2CkT/OvIoRrROpw4zLnBHUPwQyxI5wtS5DcW2iAaoiPJyLLeY5JnqyTIBJSmIis5bUh vlunqJOD//619DFpgZn1GYLlNqWC2H3KfFFUpIoGNnuTCCIzP3JQqwEwncq3ka2YICx0 AJhw== X-Gm-Message-State: AOAM532zzzAMov8Y+W93n8O18Isthpcty/omXvLKEqbHfz1glzElkepm QjMMt9Gjk4H2RolmVUn6/8GMqRAswPP3YrlH4nBm7Q== X-Received: by 2002:a17:902:e550:b0:137:734f:1d84 with SMTP id n16-20020a170902e55000b00137734f1d84mr6796413plf.27.1630040666934; Thu, 26 Aug 2021 22:04:26 -0700 (PDT) MIME-Version: 1.0 References: <20210816060359.1442450-1-ruansy.fnst@fujitsu.com> <20210816060359.1442450-8-ruansy.fnst@fujitsu.com> <32fa5333-b14e-2060-d659-d77f6c75ff16@fujitsu.com> In-Reply-To: <32fa5333-b14e-2060-d659-d77f6c75ff16@fujitsu.com> From: Dan Williams Date: Thu, 26 Aug 2021 22:04:16 -0700 Message-ID: Subject: Re: [PATCH v7 7/8] fsdax: Introduce dax_iomap_ops for end of reflink To: Shiyang Ruan 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 26, 2021 at 8:30 PM Shiyang Ruan wrot= e: > > > > On 2021/8/20 23:18, Dan Williams wrote: > > On Thu, Aug 19, 2021 at 11:13 PM ruansy.fnst = wrote: > >> > >> > >> > >> 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 n= ew > >>>> allocated extents. The current ->iomap_end() ignores the error code > >>>> returned from ->actor(), so we introduce this dax_iomap_ops and chan= ge > >>>> 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 ref= link > >>>> - 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 io= map_iter *iomi, > >>>> return done ? done : ret; > >>>> } > >>>> > >>>> +static inline int > >>>> +__dax_iomap_iter(struct iomap_iter *iter, const struct dax_iomap_op= s *ops) > >>>> +{ > >>>> + int ret; > >>>> + > >>>> + /* > >>>> + * Call dax_iomap_ops->actor_end() before iomap_ops->iomap_e= nd() in > >>>> + * each iteration. > >>>> + */ > >>>> + if (iter->iomap.length && ops->actor_end) { > >>>> + ret =3D ops->actor_end(iter->inode, iter->pos, iter-= >len, > >>>> + 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/= #m79a66a928da2d089e2458c1a97c0516dbfde2f7f > >> > >> 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_l= ength(iter), > > iter->processed > 0 ? iter->processed = : 0, > > As you can see, here is the same logic as the old iomap_apply(): the > negative iter->processed won't be passed into ->iomap_end(). > > > 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),= iomap); > > struct xfs_inode *ip =3D XFS_I(inode); > > ssize_t written =3D iter->processed; > > The written will be 0 or positive. The original error code is ingnored. Correct, but you can use container_of() to get back to the iter and consider the raw untranslated value of iter->processed. As Christoph mentioned this needs a comment explaining the layering violation, but that's a cleaner change than the dax_iomap_ops approach.