mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ufs: write out moved buffers past i_size
@ 2026-11-25 14:54 Showta Ishizaki
  0 siblings, 0 replies; only message in thread
From: Showta Ishizaki @ 2026-11-25 14:54 UTC (permalink / raw)
  To: Alexander Viro, Christian Brauner
  Cc: Jan Kara, linux-fsdevel, linux-kernel, Showta Ishizaki

When ufs_new_fragments() has to move a file's tail, ufs_change_blocknr()
gives the buffers in the page cache their new block numbers and marks
them dirty, and leaves them to writeback.  This happens inside a write
that has not moved i_size yet.  If writeback gets to a folio which is
wholly past i_size first, block_write_full_folio() drops it and nothing
is written at the new place.  The folio is clean afterwards with its
buffers still dirty, so later writes to it do not reach the device
either, and the file shows what the device held there before.  In a
folio which straddles i_size the buffers past it can be skipped too.

Write such buffers out when they are moved.  The folio being written
stays locked until i_size has moved, so it does not need it.

I ran fsstress with eight processes on UFS2 images made on NetBSD and
on FreeBSD, 16 seeds each, and compared the files before umount and
after mounting again.  In 5 of the 32 runs a file had changed, all
of them on the image from NetBSD, with 1K fragments.  With this patch
none did.

Signed-off-by: Showta Ishizaki <zakinko@snowrabbit.org>
---

diff --git a/fs/ufs/balloc.c b/fs/ufs/balloc.c
index 628edfde3..b18a512c9 100644
--- a/fs/ufs/balloc.c
+++ b/fs/ufs/balloc.c
@@ -301,6 +301,24 @@ static void ufs_change_blocknr(struct inode *inode, sector_t beg,
 			bh->b_blocknr = newb + pos;
 			clean_bdev_bh_alias(bh);
 			mark_buffer_dirty(bh);
+			/*
+			 * We are inside a write that has not moved i_size
+			 * yet.  Writeback drops a folio wholly past i_size
+			 * without writing it and leaves it clean with its
+			 * buffers dirty, so that later writes do not reach
+			 * the device either.  It may skip the buffers past
+			 * i_size of one that straddles it, too.  The folio
+			 * being written stays locked until the write has
+			 * moved i_size, so only the others need this.
+			 */
+			if (folio != locked_folio &&
+			    (loff_t)(beg + pos) << inode->i_blkbits >=
+			    i_size_read(inode)) {
+				/* A folio's buffers carry no reference. */
+				get_bh(bh);
+				sync_dirty_buffer(bh);
+				put_bh(bh);
+			}
 			++j;
 			bh = bh->b_this_page;
 		} while (bh != head);

base-commit: 4dce97c6c265544342e716e62fd24bbb232590c5

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-25 14:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 14:54 [PATCH] ufs: write out moved buffers past i_size Showta Ishizaki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®