Linux EXT4 FS development
 help / color / mirror / Atom feed
From: Wesley Atwell <atwellwea@gmail.com>
To: Jan Kara <jack@suse.cz>
Cc: linux-ext4@vger.kernel.org, Wesley Atwell <atwellwea@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH] ext2: report failed synchronous inode writes during truncate
Date: Sat, 28 Nov 2026 14:19:22 -0700	[thread overview]
Message-ID: <kernel-5e344791e4b04a67-v1.atwellwea@gmail.com> (raw)

For a file marked synchronous with chattr +S, ext2_setsize() writes the
changed inode metadata before returning from truncate. It currently
ignores the result of sync_inode_metadata(). If the inode-table write
fails, a caller can receive success even though the new size was not
persisted.

On an unmodified kernel from the ext2 for_next tree, a QEMU guest used
GNU truncate to clear an 8 KiB ext2 file marked +S. A targeted write
error on that file's inode-table block was reported by ext2, but
ftruncate() returned 0. After an abrupt guest stop and a fault-free
read-only mount, the original file and its hash remained. Two separate
fault runs reproduced this result; the healthy control truncated the
file durably.

Return the synchronous metadata-write result through ext2_setsize() and
its existing ext2_setattr() caller. With the same fault, GNU truncate
now receives EIO in two runs; the healthy control still succeeds. This
reports failed persistence to userspace. It does not roll back changes
already made in memory or repair the filesystem after a device error.

OpenAI Codex identified the ignored write result, drafted the fix and
changelog, and prepared the QEMU truncate tests. Both fault runs on the
changed kernel returned EIO. The healthy controls persisted the new
file size on both kernels.

Signed-off-by: Wesley Atwell <atwellwea@gmail.com>
---
 fs/ext2/inode.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c
index 1989258aef8a..43d155bb09b6 100644
--- a/fs/ext2/inode.c
+++ b/fs/ext2/inode.c
@@ -1266,9 +1266,9 @@ static int ext2_setsize(struct inode *inode, loff_t newsize)
 	inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
 	mark_inode_dirty(inode);
 	if (inode_needs_sync(inode))
-		sync_inode_metadata(inode, 1);
+		error = sync_inode_metadata(inode, 1);
 
-	return 0;
+	return error;
 }
 
 static struct ext2_inode *ext2_get_inode(struct super_block *sb, ino_t ino,

base-commit: cc226183b2c07b301f21af709b2f95c8c7050393

             reply	other threads:[~2026-11-28 21:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28 21:19 Wesley Atwell [this message]
2026-11-28 21:23 ` [PATCH] ext2: report failed synchronous inode writes during truncate sashiko-bot

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=kernel-5e344791e4b04a67-v1.atwellwea@gmail.com \
    --to=atwellwea@gmail.com \
    --cc=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@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