Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1777698pxp; Mon, 7 Mar 2022 02:05:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJwLvc2qZdVwvzc/L21v0a1jFalCd2AMU7TQ5xcBYbpDqnLwFcihVFiZFGyWp4nGXnvNKtw6 X-Received: by 2002:a17:906:4fd0:b0:6db:2639:6640 with SMTP id i16-20020a1709064fd000b006db26396640mr4040546ejw.313.1646647518831; Mon, 07 Mar 2022 02:05:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646647518; cv=none; d=google.com; s=arc-20160816; b=XL+UPmJgTdHcjGq4Z0EGCiFfYCZCuvxHfQegZP1nSHPgq9z2yeZ2dvaAHmnlXGQnBa T0tU5DNnU0Qcv3rop8sQVq/9Sy32BPBjH+znW5/kpNSSF/I6g3AGHdNxzEBMePjqq2Qh zEAQA5+ayvyxZaOtJ0za4TRCNcGDgl33aWRDsD9A8DmqloG3oAxgWWHatOGY6zQOiNYT JV/uBxCo4ZnAZL5HyTN/O+tJgqrO1sRGzjfRfFF8Nv0Xx/l1MWzsqKdW60douXcTQ2Jc sVv+gm1ANvLFrdG0RK64Lc5H49pS3/U4ifUcIUGRXZ/7opTKdti8l95GnHsoKyxelGlG ioUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FfelJCalDXdYUWXgXqNPR+JB9o7vcdQvhRVrc9tvS40=; b=QTLyB3GwbA7LQrEasuqT2xaga/ICuwQuZc7oOBq0Xs0tN3tX+eEz8HUaPwnVLIQQa0 ogT2bqRnUuTdAQwmIKAeHKLT42ZsaNmr1HZhjFaOtyaks0SVolGsBfsCYnZ8VX2clmVD 3+rQFzfbNf8YdzjXq13l0vpyYc1CGlKvplv5jSAVmaSd1xk5pvs/JcBk5OHZ5EjavQQy FFAi02p9vuc123YyPgxIfomsujwnxGqrZK9a0JPUDD05iStuVrmYFBu0X6/1yzJxarqB n/Ysvi/LqRivOGlM7DRTdpWN7GqdDHgjxiXxLDsvOWMK3klNu74iqlO0ZBzzZH4DTwi5 3J8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kdgKUt3C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g7-20020aa7dd87000000b00415a29c1ecfsi7608901edv.170.2022.03.07.02.04.56; Mon, 07 Mar 2022 02:05:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kdgKUt3C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230349AbiCGJb0 (ORCPT + 99 others); Mon, 7 Mar 2022 04:31:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237712AbiCGJ2W (ORCPT ); Mon, 7 Mar 2022 04:28:22 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F01B5C84E; Mon, 7 Mar 2022 01:25:55 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id ECBE46114D; Mon, 7 Mar 2022 09:25:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E63F1C340F4; Mon, 7 Mar 2022 09:25:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646645139; bh=yTOllWjCgOoc5lILcUbRa5RKg2Cr4i89zGrd/HAZhkc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kdgKUt3CnmmXhiJU68xc1D2l/zeRPWfqsdo1sxbm21JVt4EHKkGmE0jhVvXnL2llw 2wX3wpSX78pjIbDPforXeEMKIcTeIvhybZ7oKsnGsJHznxf95r0l1Ol6MYtw1wzfv2 WX2oILQqjyun/DrpO4rmXRqTMrOSW3PkHSB2SZTg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Filipe Manana , David Sterba Subject: [PATCH 4.19 50/51] btrfs: add missing run of delayed items after unlink during log replay Date: Mon, 7 Mar 2022 10:19:25 +0100 Message-Id: <20220307091638.412482256@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220307091636.988950823@linuxfoundation.org> References: <20220307091636.988950823@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Filipe Manana commit 4751dc99627e4d1465c5bfa8cb7ab31ed418eff5 upstream. During log replay, whenever we need to check if a name (dentry) exists in a directory we do searches on the subvolume tree for inode references or or directory entries (BTRFS_DIR_INDEX_KEY keys, and BTRFS_DIR_ITEM_KEY keys as well, before kernel 5.17). However when during log replay we unlink a name, through btrfs_unlink_inode(), we may not delete inode references and dir index keys from a subvolume tree and instead just add the deletions to the delayed inode's delayed items, which will only be run when we commit the transaction used for log replay. This means that after an unlink operation during log replay, if we attempt to search for the same name during log replay, we will not see that the name was already deleted, since the deletion is recorded only on the delayed items. We run delayed items after every unlink operation during log replay, except at unlink_old_inode_refs() and at add_inode_ref(). This was due to an overlook, as delayed items should be run after evert unlink, for the reasons stated above. So fix those two cases. Fixes: 0d836392cadd5 ("Btrfs: fix mount failure after fsync due to hard link recreation") Fixes: 1f250e929a9c9 ("Btrfs: fix log replay failure after unlink and link combination") CC: stable@vger.kernel.org # 4.19+ Signed-off-by: Filipe Manana Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/tree-log.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -1289,6 +1289,15 @@ again: inode, name, namelen); kfree(name); iput(dir); + /* + * Whenever we need to check if a name exists or not, we + * check the subvolume tree. So after an unlink we must + * run delayed items, so that future checks for a name + * during log replay see that the name does not exists + * anymore. + */ + if (!ret) + ret = btrfs_run_delayed_items(trans); if (ret) goto out; goto again; @@ -1480,6 +1489,15 @@ static noinline int add_inode_ref(struct */ if (!ret && inode->i_nlink == 0) inc_nlink(inode); + /* + * Whenever we need to check if a name exists or + * not, we check the subvolume tree. So after an + * unlink we must run delayed items, so that future + * checks for a name during log replay see that the + * name does not exists anymore. + */ + if (!ret) + ret = btrfs_run_delayed_items(trans); } if (ret < 0) goto out;