From: Jan Kara <jack@suse.cz>
To: <linux-fsdevel@vger.kernel.org>
Cc: Christian Brauner <brauner@kernel.org>,
aivazian.tigran@gmail.com, Ted Tso <tytso@mit.edu>,
<linux-ext4@vger.kernel.org>,
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>,
Jan Kara <jack@suse.cz>
Subject: [PATCH v4 0/21] fs: Fix missed inode write during fsync
Date: Thu, 16 Jul 2026 16:55:22 +0200 [thread overview]
Message-ID: <20260716145359.28639-1-jack@suse.cz> (raw)
Hello,
here is v4 of the patch series which fixes the possibly missing inode write
during fsync(2) for filesystems using generic metadata bh tracking. This
revision contains mostly small fixes and improvements since v3, neither
Sashiko nor Christian found fundamental issues with this approach.
Patches have survived some testing with fstests so they should be reasonably
sound. I'd just like Ogawa to have a look at FAT changes. Similarly as for
other filesystems I've included some cleanups and simplifications these changes
enabled but it would be good to get a confirmation from the maintainer this is
what they want. I could also limit FAT changes to a bare minimum fixing the
data integrity issues.
Changes since v3:
* Add a fix for ext2 lost inode updates for IS_SYNC inodes (independent issue
found during testing)
* Check I_METADATA_WRITEBACK in simple_fsync_noflush() to avoid skipping inodes
with pending bh writeout
* Reorder buffer writeback in to first write out metadata blocks and only then
inodes. It should lead to a more consistent filesystem in case of a crash.
* Added handling of IO errors from metadata writeback for IS_SYNC inodes for
FAT
* Fix inode writeout during eviction for ext2
* Fix conversion of ext4_nfs_commit_metadata() to work for filesystems with
a journal
* Fix races when handling of IS_SYNC inodes for UDF by using
sync_inode_metadata()
* Add ext4 helper for accessing i_metadata_bhs
* Fix some bisectability hazards
* Removed some dead branches after FAT conversion
Changes since v2:
* redesigned the patch set to use new superblock operation
* fixed race of inode freeing with IO error processing in
mark_buffer_write_io_error()
Changes since v1:
* Fixed freeing for ext4 dynamically allocated mmb struct
* Optimized tracking of block carrying the inode so that we don't flush it
unnecessarily on fsync
* Add forgotten check for reclaimed bh to mmb_sync() to avoid NULL ptr deref
* Couple other smaller fixups pointed out by Sashiko
Honza
Original design explanation:
The series strives to make sure sync_inode_metadata() ->
writeback_single_inode() will end up to properly persisting not only the inode
but also all metadata associated with the inode. This is beneficial for
several reasons:
1) This removes the need for separate mmb_fsync() implementations. Filesystems
can just use simple_fsync().
2) This makes sure all metadata is written for IS_SYNC / IS_DIRSYNC inodes.
Currently most filesystems just write inode itself.
3) This fixes races when multiple fsyncs race for a while where mmb_sync()
could return before all buffers were really persisted (now I_SYNC state flag
properly serializes everything).
To be able to achieve this we add new .sync_inode_metadata superblock operation
which gets called from __writeback_single_inode() and new I_METADATA_WRITEBACK
state flag (putting everything into .write_inode is possible but it looked too
ugly so I've decided for the new operation).
This scheme with I_METADATA_WRITEBACK state flag also fixes the problem that
when WB_SYNC_NONE writeback happened between write(2) and fsync(2), fsync(2)
would fail to properly persist the inode. Note that this problem isn't specific
to filesystems using the generic metadata bh tracking. This patch set doesn't
fix such filesystems as it is already big enough but the universality of this
problem among simple filesystems is another reason why I've chosen the new
superblock operation instead of trying to somehow hack up metadata bh tracking
infrastructure.
Previous versions:
Link: http://lore.kernel.org/r/20260511115725.28441-1-jack@suse.cz # v1
Link: http://lore.kernel.org/r/20260525085035.12891-1-jack@suse.cz # v2
Link: http://lore.kernel.org/r/20260702175436.12226-1-jack@suse.cz # v3
next reply other threads:[~2026-07-16 14:55 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-16 14:55 Jan Kara [this message]
2026-07-16 14:55 ` [PATCH v4 01/21] affs: Drop support for metadata bh tracking Jan Kara
2026-07-16 14:55 ` [PATCH v4 02/21] fs: Fix possible UAF in mark_buffer_write_io_error() Jan Kara
2026-07-16 14:55 ` [PATCH v4 03/21] fs: Fix missed inode writeback when racing with __writeback_single_inode Jan Kara
2026-07-16 14:55 ` [PATCH v4 04/21] ext4: Allocate mapping_metadata_bhs struct on demand Jan Kara
2026-07-16 14:55 ` [PATCH v4 05/21] fs: Provide way for filesystem to wait for metadata writeback Jan Kara
2026-07-16 14:55 ` [PATCH v4 06/21] ext2: Fix lost inode updates for IS_SYNC inodes Jan Kara
2026-07-16 14:55 ` [PATCH v4 07/21] ext2: Drop __ext2_write_inode() Jan Kara
2026-07-16 14:55 ` [PATCH v4 08/21] ext2: Avoid unnecessary inode buffer writeback for sync(2) Jan Kara
2026-07-16 14:55 ` [PATCH v4 09/21] ext2: Fix data integrity writeout issues Jan Kara
2026-07-16 14:55 ` [PATCH v4 10/21] udf: " Jan Kara
2026-07-16 14:55 ` [PATCH v4 11/21] udf: Use sync_inode_metadata() to writeout IS_SYNC inode Jan Kara
2026-07-16 14:55 ` [PATCH v4 12/21] udf: Drop udf_sync_inode() Jan Kara
2026-07-16 14:55 ` [PATCH v4 13/21] udf: Use sync_inode_metadata() in udf_evict_inode() Jan Kara
2026-07-16 14:55 ` [PATCH v4 14/21] udf: Fold udf_update_inode() into udf_write_inode() Jan Kara
2026-07-16 14:55 ` [PATCH v4 15/21] bfs: Fix data integrity writeout issues Jan Kara
2026-07-16 14:55 ` [PATCH v4 16/21] minix: " Jan Kara
2026-07-16 14:55 ` [PATCH v4 17/21] ext4: Fix data integrity writeout issues in nojournal mode Jan Kara
2026-07-16 14:55 ` [PATCH v4 18/21] fat: Fix missed inode writeback during fsync(2) Jan Kara
2026-07-16 14:55 ` [PATCH v4 19/21] fat: Remove some superfluous sync_dirty_buffer() calls Jan Kara
2026-07-16 14:55 ` [PATCH v4 20/21] fat: Replace fat_sync_inode() with sync_inode_metadata() Jan Kara
2026-07-16 14:55 ` [PATCH v4 21/21] vfs: Remove mmb_fsync() Jan Kara
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=20260716145359.28639-1-jack@suse.cz \
--to=jack@suse.cz \
--cc=aivazian.tigran@gmail.com \
--cc=brauner@kernel.org \
--cc=hirofumi@mail.parknet.co.jp \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=tytso@mit.edu \
/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