Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp1142192lqt; Tue, 19 Mar 2024 14:08:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVTwgZwYyY09LEpHL9UIODelX6+HmMqmJDSpiwSlwfWauLK0LLF8wrr/XY2BisHEoJZvcAajN54zBb2Uen3sXBC1R2a5IDlaKLYYIkcmA== X-Google-Smtp-Source: AGHT+IHxXJLq75W4/njCKorpdI7HwQTsLyShF0gjFRj812Q1mUXex8GwxaR5fsOorURG8gwUqMjM X-Received: by 2002:a05:622a:148c:b0:430:d745:2a21 with SMTP id t12-20020a05622a148c00b00430d7452a21mr6601706qtx.66.1710882503012; Tue, 19 Mar 2024 14:08:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710882503; cv=pass; d=google.com; s=arc-20160816; b=U/xFEHGL16d4HyuMlDygDwfVlSBKvy2L+4eHWKuVk1v0GBG2krVD2IEp+RBVX8xNy8 7pQ1kYhegH5oO69PHWOvzXs0eHxek2DmGg+KbtGZxQMU6JyNXGvsii5e5IFtspPSMxtL OIhn6Cke7XzOamXjMxcSSqF5X0kQHFIjLgevyveOpYpRPgQiO17qcmEwHdHRWb75xjSe SPmUTXmImdeggan9us7VqBiytpHvsCMEXdZXca04GM37jKwiSyEJJyzH+JZOl7NjJBwB XerDuqvXt89n4g8SDG7lZqGqqK4kx2u7sUCzU8OfX8l5HdU5EsJbTJlgU74agP1kcqRe AJsg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=mqEnPqJgTr4h3ouZvwB/MGsVvIQ9EvfPm9rfuY+yy3Q=; fh=iF7TKcfyCKMcEoyn3ycxUxdPqyR/HBZimjCvuok7M6s=; b=pMjPOobY4aw78FnlofI2fE45HJ+SD4/12Dm2LShTVpWpThH6oe1zQ07oj8CgmO107z 6nZpKGwB+qu/bot6ZsqSBMyNZUsa5YlNqbDY4yUVJQbcGRzkejdsBo68/dZA49Bpyc16 TURWsG4rTtgvYdUNga78/RgVEYolWnp/dVvk+WMcwYxGt64d2c5WSzv16QOw6ugqAswP qBFdHSkE2nQjNxxZeqA8TRF4kVO3PLpPphsZcMD7JYe2gF9F8PbVR/cVIEOG8pVTVKRr SH6CXLLpVhFYnG8XCuIGyTeW2r4UEYKnbYnwz6+ViB0DNZVhOOy2k17r1SppjifzZ4JI MyOA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CXhxMwXK; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-108139-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108139-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d26-20020a05620a167a00b0078a079472adsi3785056qko.680.2024.03.19.14.08.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 14:08:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-108139-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CXhxMwXK; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-108139-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108139-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id AB5A71C2214A for ; Tue, 19 Mar 2024 21:08:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 84CF13FB9F; Tue, 19 Mar 2024 21:08:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CXhxMwXK" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88CBF3C485; Tue, 19 Mar 2024 21:08:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710882486; cv=none; b=qMiF1XCBU0mUW4634RwdYRZnyzfJECftJsPFwU4Q4+nr58ILi9Tc/XMMfyA+xcs2mPXHHzTSYCUNtPs/gdjpcw0muYry0BL9r6od5+AuL4aZDE/fE/FTwEF1ItdsRzpY4ShKUqYlrJphmoe4QKMknyeZSu4++BgRga6aQrp7Z0c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710882486; c=relaxed/simple; bh=4YY28ffhMpVq+c07gRVzOqaSW91JO13rslhjeezFpTY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QF5PGJwANC6KDVi9x3HBBKuEEvvCekUEEKZzE0TSX+nO3CRw5XIazHXwZiI1wZS+gvvkklLRavW4elnCKEA3YKhf++zGjskNAUrxzkV9e+gcqz5SdV1itidoXRlTjifslm8uKWVU0NckiVjqfJ16fKRKhsWsPZflb6sYcyaVZyI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CXhxMwXK; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 14DA0C433C7; Tue, 19 Mar 2024 21:08:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710882486; bh=4YY28ffhMpVq+c07gRVzOqaSW91JO13rslhjeezFpTY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=CXhxMwXK4qIol6IWNrQ+SNhNVdrQMyft4sjfljLQwLpojdDeG1eT+3zQQWbrjgooe H33gInUX5oM3pEPXpe6BzhACEikWjv42le8cLXiVU9neNAq2fnSyEbCc1mmQlPSZdo i/DpMZYD2dU3BF2QM4tmaUwrSwsQENnQvBEQbhlb+pX3GE+WqHIaaSqhnpnu1drQ2j YE9toO6e4g6FXGH1XdEqVBRF9rw0rBdF941EpuV68Jgzb1yH/v8duz6K/ik8Fk0HT9 bB7DxMBDOcEZLmpW2KTQ3185baA/Ge5IjxkKXWHS36/JGpgZ/EJp66o8XXfqCChivr CERfliH/1ixug== Date: Tue, 19 Mar 2024 14:08:05 -0700 From: "Darrick J. Wong" To: Zhang Yi Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, hch@infradead.org, brauner@kernel.org, david@fromorbit.com, tytso@mit.edu, jack@suse.cz, yi.zhang@huawei.com, chengzhihao1@huawei.com, yukuai3@huawei.com Subject: Re: [PATCH v3 8/9] iomap: make iomap_write_end() return a boolean Message-ID: <20240319210805.GM1927156@frogsfrogsfrogs> References: <20240319011102.2929635-1-yi.zhang@huaweicloud.com> <20240319011102.2929635-9-yi.zhang@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240319011102.2929635-9-yi.zhang@huaweicloud.com> On Tue, Mar 19, 2024 at 09:11:01AM +0800, Zhang Yi wrote: > From: Zhang Yi > > For now, we can make sure iomap_write_end() always return 0 or copied > bytes, so instead of return written bytes, convert to return a boolean > to indicate the copied bytes have been written to the pagecache. > > Signed-off-by: Zhang Yi > Reviewed-by: Christoph Hellwig > --- > fs/iomap/buffered-io.c | 50 +++++++++++++++++++++++++++--------------- > 1 file changed, 32 insertions(+), 18 deletions(-) > > diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c > index 291648c61a32..004673ea8bc1 100644 > --- a/fs/iomap/buffered-io.c > +++ b/fs/iomap/buffered-io.c > @@ -790,7 +790,7 @@ static int iomap_write_begin(struct iomap_iter *iter, loff_t pos, > return status; > } > > -static size_t __iomap_write_end(struct inode *inode, loff_t pos, size_t len, > +static bool __iomap_write_end(struct inode *inode, loff_t pos, size_t len, > size_t copied, struct folio *folio) > { > flush_dcache_folio(folio); > @@ -807,14 +807,14 @@ static size_t __iomap_write_end(struct inode *inode, loff_t pos, size_t len, > * redo the whole thing. > */ > if (unlikely(copied < len && !folio_test_uptodate(folio))) > - return 0; > + return false; > iomap_set_range_uptodate(folio, offset_in_folio(folio, pos), len); > iomap_set_range_dirty(folio, offset_in_folio(folio, pos), copied); > filemap_dirty_folio(inode->i_mapping, folio); > - return copied; > + return true; > } > > -static size_t iomap_write_end_inline(const struct iomap_iter *iter, > +static void iomap_write_end_inline(const struct iomap_iter *iter, > struct folio *folio, loff_t pos, size_t copied) > { > const struct iomap *iomap = &iter->iomap; > @@ -829,21 +829,32 @@ static size_t iomap_write_end_inline(const struct iomap_iter *iter, > kunmap_local(addr); > > mark_inode_dirty(iter->inode); > - return copied; > } > > -/* Returns the number of bytes copied. May be 0. Cannot be an errno. */ > -static size_t iomap_write_end(struct iomap_iter *iter, loff_t pos, size_t len, > +/* > + * Returns true if all copied bytes have been written to the pagecache, > + * otherwise return false. > + */ > +static bool iomap_write_end(struct iomap_iter *iter, loff_t pos, size_t len, > size_t copied, struct folio *folio) > { > const struct iomap *srcmap = iomap_iter_srcmap(iter); > + bool ret = true; > > - if (srcmap->type == IOMAP_INLINE) > - return iomap_write_end_inline(iter, folio, pos, copied); > - if (srcmap->flags & IOMAP_F_BUFFER_HEAD) > - return block_write_end(NULL, iter->inode->i_mapping, pos, len, > - copied, &folio->page, NULL); > - return __iomap_write_end(iter->inode, pos, len, copied, folio); > + if (srcmap->type == IOMAP_INLINE) { > + iomap_write_end_inline(iter, folio, pos, copied); > + } else if (srcmap->flags & IOMAP_F_BUFFER_HEAD) { > + size_t bh_written; > + > + bh_written = block_write_end(NULL, iter->inode->i_mapping, pos, > + len, copied, &folio->page, NULL); > + WARN_ON_ONCE(bh_written != copied && bh_written != 0); > + ret = bh_written == copied; > + } else { > + ret = __iomap_write_end(iter->inode, pos, len, copied, folio); > + } > + > + return ret; This could be cleaned up even further: if (srcmap->type == IOMAP_INLINE) { iomap_write_end_inline(iter, folio, pos, copied); return true; } if (srcmap->flags & IOMAP_F_BUFFER_HEAD) { size_t bh_written; bh_written = block_write_end(NULL, iter->inode->i_mapping, pos, len, copied, &folio->page, NULL); WARN_ON_ONCE(bh_written != copied && bh_written != 0); return bh_written == copied; } return __iomap_write_end(iter->inode, pos, len, copied, folio); > } > > static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) > @@ -907,7 +918,8 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) > flush_dcache_folio(folio); > > copied = copy_folio_from_iter_atomic(folio, offset, bytes, i); > - written = iomap_write_end(iter, pos, bytes, copied, folio); > + written = iomap_write_end(iter, pos, bytes, copied, folio) ? > + copied : 0; > > /* > * Update the in-memory inode size after copying the data into > @@ -1285,6 +1297,7 @@ static loff_t iomap_unshare_iter(struct iomap_iter *iter) > int status; > size_t offset; > size_t bytes = min_t(u64, SIZE_MAX, length); > + bool ret; > > status = iomap_write_begin(iter, pos, bytes, &folio); > if (unlikely(status)) > @@ -1296,9 +1309,9 @@ static loff_t iomap_unshare_iter(struct iomap_iter *iter) > if (bytes > folio_size(folio) - offset) > bytes = folio_size(folio) - offset; > > - bytes = iomap_write_end(iter, pos, bytes, bytes, folio); > + ret = iomap_write_end(iter, pos, bytes, bytes, folio); > __iomap_put_folio(iter, pos, bytes, folio); > - if (WARN_ON_ONCE(bytes == 0)) > + if (WARN_ON_ONCE(!ret)) If you named this variable "write_end_ok" then the diagnostic output from the WARN_ONs would say that. That said, it also encodes the line number so it's not a big deal to leave this as it is. With at least the first cleanup applied, Reviewed-by: Darrick J. Wong --D > return -EIO; > > cond_resched(); > @@ -1347,6 +1360,7 @@ static loff_t iomap_zero_iter(struct iomap_iter *iter, bool *did_zero) > int status; > size_t offset; > size_t bytes = min_t(u64, SIZE_MAX, length); > + bool ret; > > status = iomap_write_begin(iter, pos, bytes, &folio); > if (status) > @@ -1361,9 +1375,9 @@ static loff_t iomap_zero_iter(struct iomap_iter *iter, bool *did_zero) > folio_zero_range(folio, offset, bytes); > folio_mark_accessed(folio); > > - bytes = iomap_write_end(iter, pos, bytes, bytes, folio); > + ret = iomap_write_end(iter, pos, bytes, bytes, folio); > __iomap_put_folio(iter, pos, bytes, folio); > - if (WARN_ON_ONCE(bytes == 0)) > + if (WARN_ON_ONCE(!ret)) > return -EIO; > > pos += bytes; > -- > 2.39.2 > >