From: hubcap@kernel.org
To: linux-fsdevel@vger.kernel.org
Cc: Mike Marshall <hubcap@omnibond.com>
Subject: [PATCH] orangefs: do not keep a write range for bytes that were not copied
Date: Wed, 25 Nov 2026 13:47:34 -0500 [thread overview]
Message-ID: <20261125184739.430131-1-hubcap@kernel.org> (raw)
From: Mike Marshall <hubcap@omnibond.com>
write_begin records the whole request before the copy.
generic_perform_write copies with page faults disabled, and if that
copy moves nothing it still calls write_end. For an extending write
the private range then starts at i_size. The retry is not an extension
of that range, so write_begin launders it and orangefs_writepage_locked
warns. generic/010 hit this while creating its ndbm database. The
retry wrote the real bytes, so the file stayed coherent.
We'll shrink the range to the bytes that were copied. If nothing was copied
and the range is only this write, drop it and do not mark the folio
dirty. Do not move i_size when nothing was copied. The retry records a
new range and does not launder. A range that still starts at i_size on
a later launder or writeback is unchanged.
Signed-off-by: Mike Marshall <hubcap@omnibond.com>
---
fs/orangefs/inode.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/fs/orangefs/inode.c b/fs/orangefs/inode.c
index b1fed1c81a4d..4ae081330243 100644
--- a/fs/orangefs/inode.c
+++ b/fs/orangefs/inode.c
@@ -384,13 +384,33 @@ static int orangefs_write_end(const struct kiocb *iocb,
struct folio *folio, void *fsdata)
{
struct inode *inode = folio->mapping->host;
+ struct orangefs_write_range *wr = folio_get_private(folio);
loff_t last_pos = pos + copied;
+ /*
+ * write_begin records the whole request before any byte is
+ * copied. Keep only the copied bytes. A copy that moves
+ * nothing on a new range leaves wr starting at i_size, and
+ * the retry launders it and warns.
+ */
+ if (wr && copied < len &&
+ wr->pos <= pos && wr->pos + wr->len == pos + len) {
+ wr->len -= len - copied;
+ if (wr->len == 0) {
+ kfree(folio_detach_private(folio));
+ folio_cancel_dirty(folio);
+ folio_unlock(folio);
+ folio_put(folio);
+ return 0;
+ }
+ }
+
/*
* No need to use i_size_read() here, the i_size
* cannot change under us because we hold the i_mutex.
+ * A copy that moved nothing must not move i_size either.
*/
- if (last_pos > inode->i_size)
+ if (copied > 0 && last_pos > inode->i_size)
i_size_write(inode, last_pos);
/* zero the stale part of the folio if we did a short copy */
--
2.56.1
reply other threads:[~2026-11-25 18:47 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261125184739.430131-1-hubcap@kernel.org \
--to=hubcap@kernel.org \
--cc=hubcap@omnibond.com \
--cc=linux-fsdevel@vger.kernel.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