From: "Xing Ma" <maxing.lan@bytedance.com>
To: <linux-ext4@vger.kernel.org>
Cc: "Theodore Ts'o" <tytso@mit.edu>,
"Andreas Dilger" <adilger.kernel@dilger.ca>,
"Jan Kara" <jack@suse.cz>,
"Baokun Li" <libaokun@linux.alibaba.com>,
"Ojaswin Mujoo" <ojaswin@linux.ibm.com>,
"Ritesh Harjani (IBM)" <ritesh.list@gmail.com>,
"Zhang Yi" <yi.zhang@huawei.com>,
"Harshad Shirwadkar" <harshadshirwadkar@gmail.com>,
<stable@vger.kernel.org>
Subject: [PATCH v2 2/2] ext4: track truncated block range in ext4_truncate() for fast commit
Date: Tue, 01 Dec 2026 01:37:44 +0800 [thread overview]
Message-ID: <20261201013742.1563067-3-maxing.lan@bytedance.com> (raw)
In-Reply-To: <20261201013742.1563067-1-maxing.lan@bytedance.com>
Truncation range tracking (ext4_fc_track_range()) is currently only
called in ext4_truncate_down(), which misses three cases where
ext4_truncate() frees extents:
1. Same-size ftruncate(fd, oldsize) dropping FALLOC_FL_KEEP_SIZE
preallocated blocks beyond EOF jumps straight to ext4_truncate()
without calling ext4_fc_track_range().
2. If a commit occurs between ext4_truncate_down() stopping its handle
and ext4_truncate() starting a new handle in transaction T+1,
ext4_fc_track_inode() resets i_fc_lblk_len to 0 and freed extents
are not tracked.
3. If ext4_ext_remove_space() or ext4_ind_truncate() restarts the
journal handle onto a new transaction, earlier tracking belonged to
the previous transaction.
In all three cases, a subsequent fast commit omits EXT4_FC_TAG_DEL_RANGE
and resurrects freed extents (or emits an indirect-mapped inode without
falling back to a full commit) after crash recovery. Case 1 reproduces
deterministically on -O fast_commit:
xfs_io -f -c "pwrite -S 0xaa 0 4k" -c "falloc -k 4k 64k" mnt/foo
sync
xfs_io -c "truncate 4k" -c "fsync" mnt/foo
# crash (dm-flakey drop_writes) and remount:
# stat -c %b mnt/foo returns 136 instead of 8
Call ext4_fc_track_range(handle, inode, start_lblk, EXT_MAX_BLOCKS - 1)
in ext4_truncate() unconditionally (matching ext4_truncate_down()) after
checking err and !ext4_handle_is_aborted(handle), so both extent-based
and indirect-mapped inodes are tracked safely without dereferencing a
NULL handle->h_transaction after a failed journal restart.
Fixes: aa75f4d3daae ("ext4: main fast-commit commit path")
Cc: stable@vger.kernel.org
Signed-off-by: Xing Ma <maxing.lan@bytedance.com>
---
fs/ext4/inode.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 07a62d8569d31..22560318d2348 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -5608,6 +5608,15 @@ int ext4_truncate(struct inode *inode)
if (err)
goto out_stop;
+ if (!ext4_handle_is_aborted(handle)) {
+ ext4_lblk_t start_lblk;
+
+ start_lblk = inode->i_size > 0 ?
+ (inode->i_size - 1) >> inode->i_blkbits : 0;
+ ext4_fc_track_range(handle, inode, start_lblk,
+ EXT_MAX_BLOCKS - 1);
+ }
+
if (IS_SYNC(inode))
ext4_handle_sync(handle);
--
2.39.5
next prev parent reply other threads:[~2026-11-30 17:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 17:37 [PATCH v2 0/2] ext4: fix fast commit orphan inode replay and truncate range tracking Xing Ma
2026-11-30 17:37 ` [PATCH v2 1/2] ext4: fall back to full commit for unlinked or orphan inodes in fast commit Xing Ma
2026-11-30 17:37 ` Xing Ma [this message]
2026-11-30 17:54 ` [PATCH v2 2/2] ext4: track truncated block range in ext4_truncate() for " sashiko-bot
2026-11-30 17:54 ` [PATCH v2 0/2] ext4: fix fast commit orphan inode replay and truncate range tracking 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=20261201013742.1563067-3-maxing.lan@bytedance.com \
--to=maxing.lan@bytedance.com \
--cc=adilger.kernel@dilger.ca \
--cc=harshadshirwadkar@gmail.com \
--cc=jack@suse.cz \
--cc=libaokun@linux.alibaba.com \
--cc=linux-ext4@vger.kernel.org \
--cc=ojaswin@linux.ibm.com \
--cc=ritesh.list@gmail.com \
--cc=stable@vger.kernel.org \
--cc=tytso@mit.edu \
--cc=yi.zhang@huawei.com \
/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