From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.127.230.115 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796060384; b=1RH3XRXEVNo78xetb3rcNvgZUvjLUSC4r3DnpVfRz1GLQK8r7pRpVM7v9V8HrIE/wz7S qL0Yuncpcujh5Pt6OtDLpo8WtP4ShCsO3RVDxLK1n+sSCneuvloY+tN7YQ8sHzRvl8+F2 Ii/ls1e0DBZTBTx0KdcqYkhPYie9ajBfRKGnYKFIsX3IQNNIp19OefI3hSmph/e/NbbEx bLoTQZCdJnG1c8jbw8JIj+ytHjd+II5a4ERs3tFKZuMmpbVS2ZX8sqyUS07Wsejzzk/kQ nFMl59RTVCzxDkNqSqrVfIjItkbJ5UuK9DkDZkvEkW+Ojxrby0TQAIWJgHqIY/yuHcA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796060384; h=DMARC-Filter:DKIM-Signature:Content-Type:X-Original-From:In-Reply-To: References:From:Message-Id:To:Date:Mime-Version:X-Lms-Return-Path: Content-Transfer-Encoding:Cc:Subject; bh=E0nSkfmJVqVyB7xbGONgRIBlZGitAr3qi4jBAVJU0dM=; b=MY1Cjrg+6HtHfjAug8xztKQBYXcXoLMPt0PYFhFKOjWSMdYralyzdWiKXdXPjLC6kEun jgM19DhS0veg7vfYLd0SQWaAPoAzM8oLC9xP7KdRMv2bur1+hBViztGcOJ2gAsLtlsI6F leFwPk9URIttHSMcEyR1s8jKPh+YUyIzu132hqSv8MbePKL1bxjVh3T2MAmxu/ebW0C6q gqstiEWLTW4DsSpbw8MRA0hp+FkZWaCP+nhOuvIkKNUlNhyb65tJgJ16l94xUtnMe2Zeo x9BoOSnm8R0KLjCwMKuFhiMPMHEPKXjwXPPOIvAAvp1KE4O2s9Jdrlf4Gd/8dI5GnCg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass header.d=bytedance.com header.i=@bytedance.com header.a=rsa-sha256 header.s=2212171451 header.b=OKICJRmB; arc=none smtp.remote-ip=209.127.230.115 Received: from va-1-115.ptr.blmpb.com (va-1-115.ptr.blmpb.com [209.127.230.115]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6CC97606A327 for ; Mon, 30 Nov 2026 17:39:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6CC97606A327 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.a=rsa-sha256 header.s=2212171451 header.b=OKICJRmB DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1796060380; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=E0nSkfmJVqVyB7xbGONgRIBlZGitAr3qi4jBAVJU0dM=; b=OKICJRmBfmxV2Ldn4a+ySXVuS1Q1iTg3/97ROcaV4mC90eK1FYg8DsnEtyyGaA180BqB6E PPerK2Ik7c7bEUhSv6NoXkKOgAD8HbPPZvO0xw4TgQfqMwAkQSCMDWjaVetA7wZbcEIVCU YgABLz4uoTZogXEZbZqc4m7B0JQzWLl5Gbi/x5We7dJY/0asXBAt3s2beAwTWJwmHFTFCR 9f+nXtjb1tH3nP4PEUhn2T2s2QzGxZycbtfeguGUIuz8j5VWwOXejzrjnL9oQWht6Cc0q+ 0F1n9kNnkfuHing43yijTe67oiG8HLecm2BgwCLRf69BzvS3TDpkT2Di4BPRaQ== Content-Type: text/plain; charset=UTF-8 X-Original-From: Xing Ma In-Reply-To: <20261201013742.1563067-1-maxing.lan@bytedance.com> References: <20261201013742.1563067-1-maxing.lan@bytedance.com> From: "Xing Ma" Message-Id: <20261201013742.1563067-3-maxing.lan@bytedance.com> To: Date: Tue, 01 Dec 2026 01:37:44 +0800 X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 X-Lms-Return-Path: Content-Transfer-Encoding: 7bit Cc: "Theodore Ts'o" , "Andreas Dilger" , "Jan Kara" , "Baokun Li" , "Ojaswin Mujoo" , "Ritesh Harjani (IBM)" , "Zhang Yi" , "Harshad Shirwadkar" , Subject: [PATCH v2 2/2] ext4: track truncated block range in ext4_truncate() for fast commit 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 --- 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