From: Showta Ishizaki <zakinko@snowrabbit.org>
To: Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>
Cc: Jan Kara <jack@suse.cz>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Showta Ishizaki <zakinko@snowrabbit.org>
Subject: [PATCH] ufs: write out moved buffers past i_size
Date: Wed, 25 Nov 2026 23:54:14 +0900 [thread overview]
Message-ID: <20261126-ufs-15-v1@snowrabbit.org> (raw)
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
reply other threads:[~2026-11-25 14:54 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=20261126-ufs-15-v1@snowrabbit.org \
--to=zakinko@snowrabbit.org \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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
all inboxes | Powered by JetHome®