From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.127.231.112 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796056808; b=oz2GcP+JH6xcLPtFNKh2lFIRVTcuIt09inFCU1Za7ymXsl86bf/SzINaFGqKZE+JI4c3 ItI9oRE8YqnDQKc4BfnnWgxsxn2YHk8izCNWo25gIMofnZIK2raFOjrIEbpW0h3jFXJd3 sqPOzXpI04BFg6IDdVIT48O7f08UkGuwRO1f2nQPYMEFyv8G8hhf/tLTKHTYbZedrzYj3 xaGSMNDTn+EZwivVPLlP6nj8evWB0H1Z35d6WfRhN4E75ypxk5S8DSFbEeHWxts5p9rgE ENslysKETI8WNnXIwjF7H34LQNObjmofuzufY+aYCdCxKs9MhospumLni34zD1fZDxA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796056808; h=DMARC-Filter:DKIM-Signature:Date:Content-Transfer-Encoding: Mime-Version:Content-Type:Subject:Message-Id:X-Mailer: X-Lms-Return-Path:To:Cc:From:In-Reply-To:References:X-Original-From; bh=kFE6sWTMTI7CdSE7DSQ/UFZiM1Nws/Iu6G+2b1QZdag=; b=fM30ZzCkATQt98se4sj0X3OBH6hVXYp+yOtD5k6pEYYfIg7TH3/OZia3t5KSUvW8OPYU QXp/3ubNJZmU+LU45ElogKEDFkU7pthZ+uk53Qf18f4d0RdRS6cblHYKmSmtYHEOtIA8m Nvcu5tRPEWGQ8C/mOh1fpP99ya8Ajmv0Yt9vSKQkl68A2Jr+yMgYEeau2QpfYFOhP/7Iq fJPeruGwxrqGW3Srs1y5OlsYGKtQtHBpBKJDXwWa/ug6YQVlb9uqv7ZmSExyxbr0QVatS tUCeM5CYPej9dfzWWUOuscFEBYjSdd0/pMPfjm8srLNS7+cyBjW9B/Trl0VWUWekOWw== 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=oJ3pO25b; arc=none smtp.remote-ip=209.127.231.112 Received: from va-2-112.ptr.blmpb.com (va-2-112.ptr.blmpb.com [209.127.231.112]) (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 F31F1606A31C for ; Mon, 30 Nov 2026 16:40:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F31F1606A31C 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=oJ3pO25b DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1796056804; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=kFE6sWTMTI7CdSE7DSQ/UFZiM1Nws/Iu6G+2b1QZdag=; b=oJ3pO25bDGKVoM9wUbuWiGGEqd0t6O9PCWGcUtoTze2yooor07mkK5bfvi8K1dJ9ZkbbG8 OzdQsL7TFCSnaoItgZkLnrOmHO7IlWfHg1gVb3dcf7P3OlacOeaz6OSCGtkNyVNaKDMR5U HYULCXilP69NrlHKUFClmKvgG+IVAkIi1NN0RK2VMRsurZUSbwjgu9xZYDuN9yF30yRKtL DHpgMghL7M24RLc8VxpQqaeh5khsxNpMrdTb5S85CafYRZr9cBBq8Ev4k4bF91BL+Ml7VV t3thEpe067d0eJSzrWkAyKNj2/dnnpccVfah6ssDx37KWEVMlv1zKDN9M0x2WA== Date: Tue, 1 Dec 2026 00:39:28 +0800 Content-Transfer-Encoding: 7bit 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 Content-Type: text/plain; charset=UTF-8 Subject: [PATCH 1/2] ext4: fall back to full commit for unlinked or orphan inodes in fast commit Message-Id: <20261130163929.14058-2-maxing.lan@bytedance.com> X-Mailer: git-send-email 2.54.0 X-Lms-Return-Path: To: Cc: "Theodore Ts'o" , "Andreas Dilger" , "Jan Kara" , "Baokun Li" , "Ojaswin Mujoo" , "Ritesh Harjani" , "Zhang Yi" , "Harshad Shirwadkar" , "Xing Ma" , From: "Xing Ma" In-Reply-To: <20261130163929.14058-1-maxing.lan@bytedance.com> References: <20261130163929.14058-1-maxing.lan@bytedance.com> X-Original-From: Xing Ma Fast commit does not log orphan list updates (s_last_orphan or orphan file). When a fast commit snapshots a tracked inode that is unlinked or on the orphan list, crash recovery fails in two ways: 1. Unlinked open inode (open+unlink, overwrite rename over an open file, or O_TMPFILE): the inode has i_nlink == 0 and stays on s_fc_q until closed. Emitting EXT4_FC_TAG_INODE with i_links_count == 0 causes ext4_fc_replay_inode() to reload it via ext4_iget() without EXT4_ORPHAN_FS, turning -ESTALE into -EFSCORRUPTED and aborting journal recovery ("JBD2: journal recovery failed"). This is deterministically reproduced by xfstests generic/764 with -O fast_commit. 2. Mid-truncate orphan inode: ext4_truncate_down() adds the inode to the orphan list, shrinks i_size/i_disksize, and stops its handle before ext4_truncate() frees blocks. Snapshotting the inode in this window logs the shrunk i_size with unfreed extents and no orphan entry, causing e2fsck to report "end of extent exceeds allowed value". Return -ECANCELED from ext4_fc_snapshot_inode() when i_nlink == 0, ext4_inode_orphan_tracked(inode) is true, or raw i_links_count == 0 so ext4_fc_commit() falls back to a full JBD2 commit. Normal unlinks of closed files and completed truncates remain fast-commit eligible. Also add KUnit coverage in test_fc_snapshot_inode_and_ranges() for i_nlink == 0 and EXT4_STATE_ORPHAN_FILE fallback. Fixes: 8016e29f4362 ("ext4: fast commit recovery path") Cc: stable@vger.kernel.org Signed-off-by: Xing Ma --- fs/ext4/fast_commit-test.c | 18 ++++++++++++++++++ fs/ext4/fast_commit.c | 17 +++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/fs/ext4/fast_commit-test.c b/fs/ext4/fast_commit-test.c index 07cb9c043cd2c..2d342cabb4cf7 100644 --- a/fs/ext4/fast_commit-test.c +++ b/fs/ext4/fast_commit-test.c @@ -1752,6 +1752,24 @@ static void test_fc_snapshot_inode_and_ranges(struct kunit *test) ext4_test_inode_state(file2, EXT4_STATE_FC_COMMITTING)); KUNIT_EXPECT_NOT_NULL(test, EXT4_I(file2)->i_fc_snap); kvfree(inodes); + + /* + * 8) Unlinked (i_nlink == 0) or orphan-tracked inodes force fallback + * via -ECANCELED. + */ + clear_nlink(file1); + KUNIT_EXPECT_EQ(test, + ext4_fc_snapshot_inode_test(file1, 0, &nr_ranges, + &snap_err), + -ECANCELED); + set_nlink(file1, 1); + + ext4_set_inode_state(file1, EXT4_STATE_ORPHAN_FILE); + KUNIT_EXPECT_EQ(test, + ext4_fc_snapshot_inode_test(file1, 0, &nr_ranges, + &snap_err), + -ECANCELED); + ext4_clear_inode_state(file1, EXT4_STATE_ORPHAN_FILE); } /* ========================================================================= diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index 9beb423b208f8..fd98f7b54fc0f 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -1119,6 +1119,18 @@ static int ext4_fc_snapshot_inode(struct inode *inode, int ret; int alloc_ctx; + /* + * Fast commit does not log orphan list updates, and + * ext4_fc_replay_inode() reloads replayed inodes with + * EXT4_IGET_NORMAL, which rejects i_nlink == 0 inodes with + * -ESTALE (causing journal recovery to abort with -EFSCORRUPTED). + * Fall back to a full commit whenever a tracked inode is + * currently unlinked or on the orphan list (e.g., open-unlinked, + * rename-overwritten while open, O_TMPFILE, or mid-truncate). + */ + if (inode->i_nlink == 0 || ext4_inode_orphan_tracked(inode)) + return -ECANCELED; + ret = ext4_get_inode_loc_noio(inode, &iloc); if (ret) { atomic64_inc(&stats->snap_fail_inode_loc); @@ -1126,6 +1138,11 @@ static int ext4_fc_snapshot_inode(struct inode *inode, return ret; } + if (le16_to_cpu(ext4_raw_inode(&iloc)->i_links_count) == 0) { + brelse(iloc.bh); + return -ECANCELED; + } + if (ext4_test_inode_flag(inode, EXT4_INODE_INLINE_DATA)) inode_len = EXT4_INODE_SIZE(inode->i_sb); else if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE) -- 2.39.5