From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E55A335BDA; Mon, 18 Aug 2025 13:41:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755524478; cv=none; b=mJhIh5uQkRw6Af8/imnFFAMfV+5cAh8inK1suNUhJe9iGNsqcGQUPsQ1WpodCrsC7ihQ+7dIjjcEuMGkdMLByKJFzK6fBsoo4K3zqa6VWdNFdb168AcYX/C6/6v+z7Wj/VW+e5ikRbNpceTiMSDIHVZebABJjbNVBDMTKh+tgKc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755524478; c=relaxed/simple; bh=S/1JmARk4ry9lv49C6U1/HDRgh/iXHc+RoS2pTYVuf4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pvffJBB3na08Fpg5tVrrTE5dIth5ZvETwAr6jp83yurQ28Y4i/gA5xshgHiVxUNJt/7h8eN6XSyaKFvHomXoOrEmHC7yRaKVFN4Um3HFmYlEOI2t3xTixcF7kZuSJUiTgY7qjBvXAhMAb64gMVTthrZvHRY0TLQ3tRpyscHSyjg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=cSG77IA2; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="cSG77IA2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 892B7C4CEEB; Mon, 18 Aug 2025 13:41:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1755524477; bh=S/1JmARk4ry9lv49C6U1/HDRgh/iXHc+RoS2pTYVuf4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cSG77IA2FR1q8TPbRtgkfD+v4ptqg0vSd6dgIW/ZWWoVulJm4GXWm7iZYoXWRTlHM OuMqonWxRZc4kqwUmIR+WCKMscLbvjvdOYmIW9+cpCY7XhdaH6ffOJF4xjYitJM02h ZcbywRgA55DvkzmvK7m40Yr8On6eQuh37b0QjZlQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Boris Burkov , Filipe Manana , David Sterba Subject: [PATCH 6.15 467/515] btrfs: dont ignore inode missing when replaying log tree Date: Mon, 18 Aug 2025 14:47:33 +0200 Message-ID: <20250818124516.398913241@linuxfoundation.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250818124458.334548733@linuxfoundation.org> References: <20250818124458.334548733@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Filipe Manana commit 7ebf381a69421a88265d3c49cd0f007ba7336c9d upstream. During log replay, at add_inode_ref(), we return -ENOENT if our current inode isn't found on the subvolume tree or if a parent directory isn't found. The error comes from btrfs_iget_logging() <- btrfs_iget() <- btrfs_read_locked_inode(). The single caller of add_inode_ref(), replay_one_buffer(), ignores an -ENOENT error because it expects that error to mean only that a parent directory wasn't found and that is ok. Before commit 5f61b961599a ("btrfs: fix inode lookup error handling during log replay") we were converting any error when getting a parent directory to -ENOENT and any error when getting the current inode to -EIO, so our caller would fail log replay in case we can't find the current inode. After that commit however in case the current inode is not found we return -ENOENT to the caller and therefore it ignores the critical fact that the current inode was not found in the subvolume tree. Fix this by converting -ENOENT to 0 when we don't find a parent directory, returning -ENOENT when we don't find the current inode and making the caller, replay_one_buffer(), not ignore -ENOENT anymore. Fixes: 5f61b961599a ("btrfs: fix inode lookup error handling during log replay") CC: stable@vger.kernel.org # 6.16 Reviewed-by: Boris Burkov Signed-off-by: Filipe Manana Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/tree-log.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -1380,6 +1380,8 @@ static noinline int add_inode_ref(struct dir = btrfs_iget_logging(parent_objectid, root); if (IS_ERR(dir)) { ret = PTR_ERR(dir); + if (ret == -ENOENT) + ret = 0; dir = NULL; goto out; } @@ -1404,6 +1406,15 @@ static noinline int add_inode_ref(struct if (IS_ERR(dir)) { ret = PTR_ERR(dir); dir = NULL; + /* + * A new parent dir may have not been + * logged and not exist in the subvolume + * tree, see the comment above before + * the loop when getting the first + * parent dir. + */ + if (ret == -ENOENT) + ret = 0; goto out; } } @@ -2516,9 +2527,8 @@ static int replay_one_buffer(struct btrf key.type == BTRFS_INODE_EXTREF_KEY) { ret = add_inode_ref(wc->trans, root, log, path, eb, i, &key); - if (ret && ret != -ENOENT) + if (ret) break; - ret = 0; } else if (key.type == BTRFS_EXTENT_DATA_KEY) { ret = replay_one_extent(wc->trans, root, path, eb, i, &key);