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=1796089667; b=qFxsG5PHrg7IlgnxO6s6XkjQVBpw1Q6C6igH3ykPKVR4rIJh4HWnabgdz+MjJCJ8MgPj aj6ptgCisvR3oh6Vya5UR4dVJIJhweoaZHWQjf92CWtWbFfB34VO5aba8TmLr7Ia8R5AW OK3lXkkZmpwcM00hcOOFv364TBOmHuYXdccBSpCqf6b+s/LWUSmgPeTAgjIHmXWiEVWrE l6caeCnD3oB484tUHMHwfI6pjipoOYpQmUaUyvhxbwhHVcO5DAUr9h9p4ylXs9J25oyuQ j72i7Y3C6uRmtWB0I/6TAWNM62qA5SVbbXrSgi55FIKFLcakks1tRMBEeESjfT2hJuQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796089667; h=DMARC-Filter:DKIM-Signature:Date:Cc:X-Lms-Return-Path:Content-Type: From:Message-Id:Content-Transfer-Encoding:To:Subject:Mime-Version: X-Original-From; bh=czEAj1afdO9oQxpjWooDc0deQaF882Bof7AVZ4XeqBY=; b=5V9ZIY6kzYg++Su+aSZDRepBqYrbX5LpgcWDkHj/Gy6GMmKexRLxVhOyLtjSEWcDgvMv rMj/+lBCz1g8bCyXeFNTcWKo6CzeIfMyBdKjwtMiSGKu/eHWUQ2B8Wh/jfbe51SwHicuv C6JGGgcsmststLtmJLjJftS6+KcPa2h9oVcsPkWpMkQpWT6v0TS6ZHB6XGHOz/8aPCjhl kMgLD/BFeq6M2sRGEl8VCNLWZF8LRD0ku5r3QPtFjKrtos49lzL46bQuyF88I9VryFhkw SQtkQ1K+XdeVv4Usrtv4ILfIXxk5YBs7dBHjisCNldrEQVxs62V2rhyDcgtLea2bxYw== 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=YsfLeXSF; 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 AEEBE606A31A for ; Tue, 1 Dec 2026 01:47:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AEEBE606A31A 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, unprotected) header.d=bytedance.com header.i=@bytedance.com header.a=rsa-sha256 header.s=2212171451 header.b=YsfLeXSF DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1796089660; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=czEAj1afdO9oQxpjWooDc0deQaF882Bof7AVZ4XeqBY=; b=YsfLeXSFxytNA6fhByaqTCgBYiIE/NkO5wmW5ZTPEJJ/RtqvLEOMKoLw0EcNyYcHu0Qc95 czJx/A0FJKzN2beJzLMXZSELtr+YuLA2siDK+TClucmHDABMZkLUv3wDkhSiZT170FNh3s eCVEf6uPb1WCcIFRXYAjqSYi4/xnBG+C1Iu1bhRrQ7MpZr/V6hp9kM25LB/Tvfm7xUS7Hw FoPf2iTI/Skm/w5zIL25tE6QWfP4WSyBORnR2SCPQoq5aBCY3o47uupTixRNv6pU4y5g6b 3lcVWCYO75FX6mNQRHq8WWuhgKy9EdxcCbuRLc9ddF6kslcKZgVllqk2fgFKkQ== Date: Tue, 01 Dec 2026 09:47:25 +0800 Cc: "Theodore Ts'o" , "Andreas Dilger" , "Jan Kara" , "Baokun Li" , "Ojaswin Mujoo" , "Ritesh Harjani (IBM)" , "Zhang Yi" , "Harshad Shirwadkar" X-Lms-Return-Path: Content-Type: text/plain; charset=UTF-8 From: "Xing Ma" Message-Id: <20261201094725.1223999-1-maxing.lan@bytedance.com> Content-Transfer-Encoding: 7bit To: Subject: [PATCH v4 0/2] ext4: fix fast commit orphan inode replay and truncate range tracking 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-Original-From: Xing Ma This 2-patch series fixes two crash-recovery bugs in ext4 fast commit on tytso/ext4.git dev (aceadbccd428f): 1. Patch 1 ("ext4: fall back to full commit for unlinked or orphan inodes in fast commit"): Fast commit does not log orphan list updates. Snapshotting an unlinked open inode (i_nlink == 0) emits EXT4_FC_TAG_INODE with i_links_count == 0, which causes ext4_fc_replay_inode() to fail ext4_iget() with -ESTALE -> -EFSCORRUPTED and abort journal recovery. Snapshotting a mid-truncate orphan inode logs shrunk i_size with unfreed extents. Fall back cleanly to a full JBD2 commit via -ECANCELED, and add KUnit coverage in fast_commit-test.c. 2. Patch 2 ("ext4: track truncated block range in ext4_truncate() for fast commit"): ext4_fc_track_range() for truncation is only called in ext4_truncate_down(), missing same-size ftruncate(fd, oldsize) dropping FALLOC_FL_KEEP_SIZE post-EOF blocks, cross-transaction ext4_truncate() handles, and handle restarts in ext4_ext_remove_space() / ext4_ind_truncate(). Insert an EXTENT_STATUS_HOLE entry for [last_block, EXT_MAX_BLOCKS - 1] in ext4_ext_truncate() (when fast commit is enabled and the inode is still linked) and align both ext4_truncate() and ext4_truncate_down() to track [last_block, EXT_MAX_BLOCKS - 1]. Changes since v3 (addressing Sashiko AI review): - Patch 1: unchanged (no issues found). - Patch 2: * Align ext4_truncate_down() to compute last_block = (newsize + s_blocksize - 1) >> i_blkbits (matching ext4_ext_truncate() and ext4_truncate()) instead of (newsize - 1) >> i_blkbits (last_block - 1). Previously, merging ext4_truncate_down() and ext4_truncate() in the same transaction kept i_fc_lblk_start at last_block - 1, causing cold-cache block-aligned shrinking truncate to hit EXT4_FC_SNAP_ERR_ES_MISS and fall back to a full commit. Changes since v2 (addressing Sashiko AI review): - Patch 1: unchanged (no issues found). - Patch 2: * In ext4_ext_truncate(), insert EXTENT_STATUS_HOLE covering [last_block, EXT_MAX_BLOCKS - 1] after ext4_ext_remove_space() succeeds (when JOURNAL_FAST_COMMIT is enabled and i_nlink != 0), matching ext4_punch_hole(). * Track [last_block, EXT_MAX_BLOCKS - 1] in ext4_truncate() guarded by last_block < EXT_MAX_BLOCKS. Changes since v1 (addressing Sashiko AI review): - Patch 1: unchanged (no issues found). - Patch 2: * Move ext4_fc_track_range() after `if (err) goto out_stop;` and guard it with `!ext4_handle_is_aborted(handle)`. * Call ext4_fc_track_range() for both extent-based and indirect-mapped inodes; indirect-mapped inodes have no hole entry inserted and continue to fall back safely to a full commit. Testing on tytso/ext4.git dev (aceadbccd428f, -O fast_commit): - Patch 1: xfstests generic/764 fails 100% before ("Structure needs cleaning" / "JBD2: journal recovery failed") and passes after; KUnit ext4_fast_commit_test 11/11 PASS. - Patch 2: verified via /proc/fs/ext4//fc_info that same-size ftruncate() (post-EOF falloc -k drop and no-op), cold-cache block-aligned shrinking truncate (64K -> 4K after drop_caches=3), cold-cache unaligned shrinking truncate (64K -> 2048), and truncate-to-0 all commit via fast commit (commits++, ineligible unchanged, es_miss == 0) and survive dm-flakey crash recovery with expected block counts and clean e2fsck -fn. Xing Ma (2): ext4: fall back to full commit for unlinked or orphan inodes in fast commit ext4: track truncated block range in ext4_truncate() for fast commit fs/ext4/extents.c | 5 +++++ fs/ext4/fast_commit-test.c | 18 ++++++++++++++++++ fs/ext4/fast_commit.c | 17 +++++++++++++++++ fs/ext4/inode.c | 19 ++++++++++++++++--- 4 files changed, 56 insertions(+), 3 deletions(-) base-commit: aceadbccd428fb8e6593b27a3091d961f80225d1 -- 2.39.5