linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andreas Gruenbacher <agruenba@redhat.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: Andreas Gruenbacher <agruenba@redhat.com>,
	"Darrick J. Wong" <djwong@kernel.org>,
	Christoph Hellwig <hch@infradead.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	linux-xfs@vger.kernel.org,
	linux-fsdevel <linux-fsdevel@vger.kernel.org>
Subject: Re: [PATCH] iomap: iomap_write_end cleanup
Date: Wed,  4 May 2022 10:02:52 +0200	[thread overview]
Message-ID: <20220504080252.3299512-1-agruenba@redhat.com> (raw)
In-Reply-To: <YnHIeHuAXr6WCk7M@casper.infradead.org>

On Wed, May 4, 2022 at 2:27 AM Matthew Wilcox <willy@infradead.org> wrote:
> On Tue, May 03, 2022 at 04:02:26PM -0700, Darrick J. Wong wrote:
> > On Wed, May 04, 2022 at 12:15:45AM +0200, Andreas Gruenbacher wrote:
> > > On Tue, May 3, 2022 at 11:53 PM Matthew Wilcox <willy@infradead.org> wrote:
> > > > On Tue, May 03, 2022 at 11:37:27PM +0200, Andreas Gruenbacher wrote:
> > > > > In iomap_write_end(), only call iomap_write_failed() on the byte range
> > > > > that has failed.  This should improve code readability, but doesn't fix
> > > > > an actual bug because iomap_write_failed() is called after updating the
> > > > > file size here and it only affects the memory beyond the end of the
> > > > > file.
> > > >
> > > > I can't find a way to set 'ret' to anything other than 0 or len.  I know
> > > > the code is written to make it look like we can return a short write,
> > > > but I can't see a way to do it.
> > >
> > > Good point, but that doesn't make the code any less confusing in my eyes.
> >
> > Not to mention it leaves a logic bomb if we ever /do/ start returning
> > 0 < ret < len.
>
> This is one of the things I noticed when folioising iomap and didn't
> get round to cleaning up, but I feel like we should change the calling
> convention here to bool (true = success, false = fail).  Changing
> block_write_end() might not be on the cards, unless someone's really
> motivated, but we can at least change iomap_write_end() to not have this
> stupid calling convention.
>
> I mean, I won't NAK this patch, it is somewhat better with it than without
> it, but it perpetuates the myth that this is in some way ever going to
> happen, and the code could be a lot simpler if we stopped pretending.

Hmm, I don't really see how this would make things significantly
simpler.  Trying it out made me notice the following problem, though.
Any thoughts?

Of course this was copied from generic_write_end(), and so we have the same
issue there as well as in nobh_write_end().

Thanks,
Andreas

diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index 8fb9b2797fc5..1938dbbda1c0 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -721,13 +721,13 @@ static size_t iomap_write_end(struct iomap_iter *iter, loff_t pos, size_t len,
 	 * cache.  It's up to the file system to write the updated size to disk,
 	 * preferably after I/O completion so that no stale data is exposed.
 	 */
-	if (pos + ret > old_size) {
+	if (ret && pos + ret > old_size) {
 		i_size_write(iter->inode, pos + ret);
 		iter->iomap.flags |= IOMAP_F_SIZE_CHANGED;
 	}
 	folio_unlock(folio);

-	if (old_size < pos)
+	if (ret && old_size < pos)
 		pagecache_isize_extended(iter->inode, old_size, pos);
 	if (page_ops && page_ops->page_done)
 		page_ops->page_done(iter->inode, pos, ret, &folio->page);


  parent reply	other threads:[~2022-05-04  8:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-03 21:37 [PATCH] iomap: iomap_write_end cleanup Andreas Gruenbacher
2022-05-03 21:52 ` Matthew Wilcox
2022-05-03 22:15   ` Andreas Gruenbacher
2022-05-03 23:02     ` Darrick J. Wong
2022-05-04  0:27       ` Matthew Wilcox
2022-05-04 14:22         ` Christoph Hellwig
2022-05-04 17:21           ` Andreas Gruenbacher
2022-05-04  8:02       ` Andreas Gruenbacher [this message]
2022-05-04 14:13 ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220504080252.3299512-1-agruenba@redhat.com \
    --to=agruenba@redhat.com \
    --cc=djwong@kernel.org \
    --cc=hch@infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).