Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1233163pxa; Thu, 20 Aug 2020 06:19:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+Yku0jahE//24pGxdDfBv8aqOQ00ZAWBXqZeds1G8z22QUt0pUQFU/hrAj4+I1otbAwqG X-Received: by 2002:a50:9fe6:: with SMTP id c93mr2765864edf.286.1597929596924; Thu, 20 Aug 2020 06:19:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597929596; cv=none; d=google.com; s=arc-20160816; b=QkKYk2DsapJa9tCuHwophVq7XZumypgLSlne6YeiFHJ/KftEVxxDCpxemBnXSAAaCv 0fQ8ek8zUN4O3pBHTVaFEpD55541ai+4anPqPzEebqD+Vrhx1hy/dHkCtNXxjAipH6B2 MvHmoJj1NUwg2Y0mgbBoEKHm5pkn2nU9kvR4ypuA62O7U5rY7bzQuq3pscm4054IrzCj Y9YFpUNpd78zR6t5oZ5z6dOzqSmGsFwibQFjnm9sPpT7npKEFeBnH25dmTVvmo1zGhlw Zqh2kwaNjYpektJVJbFKHeZa9zLkN0TXmGj9SuNG5oaUcUr+2n9A0YCHpRga2Fq7Uf5k m4iQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=81LS1X7BsqHgqdGkcCb3Apn9CKCpjEZA7iPEmJwr0VE=; b=M24qw/498W6w6s1LG8tZT/1DZYfsWRWP1UhDWBrYA5kkJ/HVSfBOjkMXUnTNNhEXfT 0Xv/+EUF44NzwQ5SxSOMDcjogEsuFaqKF+CPCDXxJuW3NQ8j5kH8u3JFEfL7coSRMbYu WZ7UUqSyXfBNclO9Q0fBfxh+Ssg4KuiuchRBGGVQfe9POHd6tYtdi0DQFQTd229HOjE1 vu45bhBt76MZ10ikIwZlblx/eQm+mrKOUglW7yJbDgzSFe7E9njYMpY7obKlB90ZXzlY JI7P9bR8hOno4Q4wHxkuMbG+bioP3/9/qJzfkVPGqlf4Az8tV+79AJxCvvJ4n5bKANRO /CHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gOGVBuAV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o17si1297093ejg.21.2020.08.20.06.19.31; Thu, 20 Aug 2020 06:19:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gOGVBuAV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728795AbgHTNPp (ORCPT + 99 others); Thu, 20 Aug 2020 09:15:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:49428 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728510AbgHTJfk (ORCPT ); Thu, 20 Aug 2020 05:35:40 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7384520724; Thu, 20 Aug 2020 09:35:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597916140; bh=f7dSuZvjHUqqU4m9HMc+xEo9Fm4qh0voDgmShpezLN8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gOGVBuAVAhx0xdYfDChABlm+HwoVJEPN6TFaLdf0VWBQNAU6vm8rTT8e+xYL4RhEc e8ymD2NvJAo4dNi4dc/bWWP2BOevOgKmRSCcu1sg+eg2/7llNwnBFcY7bKySbeOy4q 5E2SDsyZSvpKDqEAD1saUBtMdRUghJJtoIuYXSik= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Josef Bacik , Qu Wenruo , David Sterba Subject: [PATCH 5.7 024/204] btrfs: avoid possible signal interruption of btrfs_drop_snapshot() on relocation tree Date: Thu, 20 Aug 2020 11:18:41 +0200 Message-Id: <20200820091607.468694190@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091606.194320503@linuxfoundation.org> References: <20200820091606.194320503@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Qu Wenruo commit f3e3d9cc35252a70a2fd698762c9687718268ec6 upstream. [BUG] There is a bug report about bad signal timing could lead to read-only fs during balance: BTRFS info (device xvdb): balance: start -d -m -s BTRFS info (device xvdb): relocating block group 73001861120 flags metadata BTRFS info (device xvdb): found 12236 extents, stage: move data extents BTRFS info (device xvdb): relocating block group 71928119296 flags data BTRFS info (device xvdb): found 3 extents, stage: move data extents BTRFS info (device xvdb): found 3 extents, stage: update data pointers BTRFS info (device xvdb): relocating block group 60922265600 flags metadata BTRFS: error (device xvdb) in btrfs_drop_snapshot:5505: errno=-4 unknown BTRFS info (device xvdb): forced readonly BTRFS info (device xvdb): balance: ended with status: -4 [CAUSE] The direct cause is the -EINTR from the following call chain when a fatal signal is pending: relocate_block_group() |- clean_dirty_subvols() |- btrfs_drop_snapshot() |- btrfs_start_transaction() |- btrfs_delayed_refs_rsv_refill() |- btrfs_reserve_metadata_bytes() |- __reserve_metadata_bytes() |- wait_reserve_ticket() |- prepare_to_wait_event(); |- ticket->error = -EINTR; Normally this behavior is fine for most btrfs_start_transaction() callers, as they need to catch any other error, same for the signal, and exit ASAP. However for balance, especially for the clean_dirty_subvols() case, we're already doing cleanup works, getting -EINTR from btrfs_drop_snapshot() could cause a lot of unexpected problems. >From the mentioned forced read-only report, to later balance error due to half dropped reloc trees. [FIX] Fix this problem by using btrfs_join_transaction() if btrfs_drop_snapshot() is called from relocation context. Since btrfs_join_transaction() won't get interrupted by signal, we can continue the cleanup. CC: stable@vger.kernel.org # 5.4+ Reviewed-by: Josef Bacik Signed-off-by: Qu Wenruo Reviewed-by: David Sterba 3 Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/extent-tree.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5313,7 +5313,14 @@ int btrfs_drop_snapshot(struct btrfs_roo goto out; } - trans = btrfs_start_transaction(tree_root, 0); + /* + * Use join to avoid potential EINTR from transaction start. See + * wait_reserve_ticket and the whole reservation callchain. + */ + if (for_reloc) + trans = btrfs_join_transaction(tree_root); + else + trans = btrfs_start_transaction(tree_root, 0); if (IS_ERR(trans)) { err = PTR_ERR(trans); goto out_free;