Linux EXT4 FS development
 help / color / mirror / Atom feed
* [PATCH] ext2: report failed synchronous inode writes during truncate
@ 2026-11-28 21:19 Wesley Atwell
  2026-11-28 21:23 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Wesley Atwell @ 2026-11-28 21:19 UTC (permalink / raw)
  To: Jan Kara; +Cc: linux-ext4, Wesley Atwell, linux-kernel

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-28 21:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-28 21:19 [PATCH] ext2: report failed synchronous inode writes during truncate Wesley Atwell
2026-11-28 21:23 ` sashiko-bot

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