Linux filesystem development
 help / color / mirror / Atom feed
From: hubcap@kernel.org
To: linux-fsdevel@vger.kernel.org
Cc: Mike Marshall <hubcap@omnibond.com>
Subject: [PATCH] orangefs: do not post writeback that starts at or past i_size
Date: Wed, 25 Nov 2026 13:48:44 -0500	[thread overview]
Message-ID: <20261125184854.430614-1-hubcap@kernel.org> (raw)

From: Mike Marshall <hubcap@omnibond.com>

orangefs_write_range can still start at or past i_size when writeback runs,
because of truncation for example. ow->len is a size_t, so a start past
EOF wraps, and a start equal to i_size becomes a 0-byte write. In either
case, don't do the write. The private range still gets detached, writeback
is ended, and the folios are unlocked. A range that starts below i_size
and runs past it is written, but not past EOF.

orangefs_writepage_locked used to put the original length back when
wlen resolved to 0. That writes past EOF and keeps WARN_ON(wlen == 0) from
firing. Leave the length at 0. The missing-private path does the same
when the folio itself starts at or past i_size.

xfstest generic/464 often produces the warning.

Signed-off-by: Mike Marshall <hubcap@omnibond.com>
---
 fs/orangefs/inode.c | 33 +++++++++++++++++++++++++--------
 1 file changed, 25 insertions(+), 8 deletions(-)

diff --git a/fs/orangefs/inode.c b/fs/orangefs/inode.c
index 4ae081330243..04a2c928452e 100644
--- a/fs/orangefs/inode.c
+++ b/fs/orangefs/inode.c
@@ -33,18 +33,24 @@ static int orangefs_writepage_locked(struct folio *folio,
 	if (folio->private) {
 		wr = folio->private;
 		off = wr->pos;
-		if ((off + wr->len > len) && (off <= len))
+		/*
+		 * The private range can start at or past i_size after a
+		 * truncate. Nothing there is written. Restoring wr->len
+		 * would write past EOF.
+		 */
+		if (off >= len)
+			wlen = 0;
+		else if (off + wr->len > len)
 			wlen = len - off;
 		else
 			wlen = wr->len;
-		if (wlen == 0)
-			wlen = wr->len;
 	} else {
 		WARN_ON(1);
 		off = folio_pos(folio);
 		wlen = folio_size(folio);
-
-		if (wlen > len - off)
+		if (off >= len)
+			wlen = 0;
+		else if (wlen > len - off)
 			wlen = len - off;
 	}
 
@@ -97,15 +103,26 @@ static int orangefs_writepages_work(struct orangefs_writepages *ow,
 	}
 	iov_iter_bvec(&iter, ITER_SOURCE, ow->bv, ow->nfolios, ow->len);
 
+	/*
+	 * The packed range can start at or past i_size after a truncate.
+	 * Keep the warning. Do not post: ow->len is a size_t, so a start
+	 * past EOF wraps, and a 0-byte post does not complete on an old
+	 * client. The folios are still cleaned below.
+	 */
 	WARN_ON(ow->off >= len);
-	if (ow->off + ow->len > len)
+	if (ow->off >= len)
+		ow->len = 0;
+	else if (ow->off + ow->len > len)
 		ow->len = len - ow->off;
 
 	off = ow->off;
 	wr.uid = ow->uid;
 	wr.gid = ow->gid;
-	ret = wait_for_direct_io(ORANGEFS_IO_WRITE, inode, &off, &iter, ow->len,
-	    0, &wr, NULL, NULL);
+	if (ow->len)
+		ret = wait_for_direct_io(ORANGEFS_IO_WRITE, inode, &off, &iter,
+		    ow->len, 0, &wr, NULL, NULL);
+	else
+		ret = 0;
 	if (ret < 0)
 		mapping_set_error(ow->mapping, ret);
 	else
-- 
2.56.1


                 reply	other threads:[~2026-11-25 18:49 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=20261125184854.430614-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