All of lore.kernel.org
 help / color / mirror / Atom feed
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" <ritesh.list@gmail.com>,
	 "Zhang Yi" <yi.zhang@huawei.com>,
	 "Harshad Shirwadkar" <harshadshirwadkar@gmail.com>,
	 "Xing Ma" <maxing.lan@bytedance.com>, <stable@vger.kernel.org>
Subject: [PATCH 2/2] ext4: track truncated block range in ext4_truncate() for fast commit
Date: Tue,  1 Dec 2026 00:39:29 +0800	[thread overview]
Message-ID: <20261130163929.14058-3-maxing.lan@bytedance.com> (raw)
In-Reply-To: <20261130163929.14058-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() 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 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() right after ext4_ext_truncate() releases i_data_sem
while the active journal handle is still open.

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 | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 07a62d8569d31..9edb29ca2e1b7 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -5605,6 +5605,14 @@ int ext4_truncate(struct inode *inode)
 		ext4_ind_truncate(handle, inode);
 
 	up_write(&ei->i_data_sem);
+	if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) {
+		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 (err)
 		goto out_stop;
 
-- 
2.39.5

  parent reply	other threads:[~2026-11-30 16:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 16:39 [PATCH 0/2] ext4: fix fast commit orphan inode replay and truncate range tracking Xing Ma
2026-11-30 16:39 ` [PATCH 1/2] ext4: fall back to full commit for unlinked or orphan inodes in fast commit Xing Ma
2026-11-30 16:39 ` Xing Ma [this message]
2026-11-30 17:09   ` [PATCH 2/2] ext4: track truncated block range in ext4_truncate() for " sashiko-bot
2026-11-30 17:10 ` [PATCH 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=20261130163929.14058-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.