[PATCH 0/3] ext4: fix counts left by fast commit replay of a mkdir
From: Mani Tofigh via B4 Relay
Date: Wed Nov 11 2026 - 18:10:03 EST
On ext4 with fast_commit, a crash after an fsync of a file in a new
directory leaves counts that e2fsck has to fix. The mount works, but
e2fsck -fn reports:
Inode 14, i_blocks is 0, should be 8. Fix? no
Inode 2 ref count is 3, should be 4. Fix? no
Inode 14 ref count is 1, should be 2. Fix? no
Directories count wrong for group #0 (2, counted=3).
All it takes is
mkdir a
fd = creat a/f0
fsync(fd)
<crash>
Fast commits don't track directories, so the replay of a CREAT tag has
to redo what ext4_mkdir() does and misses each of these counts. The
replay of an rmdir has the opposite problem with the link counts.
There's one patch per count. Patch 1 has to go before patch 3, since
with patch 3 the replay of an rmdir frees the directory and lowers the
directory count.
Baokun has the same fix as patch 1 in his LBS RFC [1], plus a flex_bg
update that never runs during replay since s_log_groups_per_flex is
still 0 then. Baokun, happy to drop patch 1 if you'd rather send yours.
This bug was identified and confirmed with the help of a deterministic
hypervisor currently under development. The C reproducer below however
hits it every time.
Reproducer: https://github.com/manitofigh/files/blob/main/linux-repros/ext4fcmkdir.c
[1] https://lore.kernel.org/linux-ext4/20260508121539.4174601-12-libaokun@xxxxxxxxxxxxxxxxx/
---
Mani Tofigh (3):
ext4: fix directory count after fast commit replay
ext4: fix directory i_blocks after fast commit replay
ext4: fix directory link counts after fast commit replay
fs/ext4/ext4.h | 4 +++-
fs/ext4/fast_commit.c | 34 ++++++++++++++++++++++++++--------
fs/ext4/ialloc.c | 4 +++-
fs/ext4/namei.c | 4 ++--
4 files changed, 34 insertions(+), 12 deletions(-)
---
base-commit: 067c5c24cef23d913b67eaaf71ae67e7169a6620
change-id: 20261111-ext4-fc-replay-mkdir-3c0adf845a19
Best regards,
--
Mani Tofigh <mt4022@xxxxxxxxxxxx>