Received: by 2002:a17:90b:8d0:0:0:0:0 with SMTP id ds16csp4875173pjb; Mon, 27 Jul 2020 07:21:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyEnpnBOQwwOd4WqcFsW5KQzLDs6ERX79NVVyIx5WL+fAlnFiOcFM/0TJLMi+07/KMmnmTv X-Received: by 2002:a05:6402:204e:: with SMTP id bc14mr21954424edb.128.1595859699431; Mon, 27 Jul 2020 07:21:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595859699; cv=none; d=google.com; s=arc-20160816; b=yJjp/KOWIonU89PrxezuW+DLP46EjBkYy/tuuKQUdPl8QJGjk27cY2WojcNFzD+Ijg vS34SIb9m114kNWKM0tmVKJ/hAu4wBgTaleQ7hveAzHxLlufp1oIw/SSJcUSW2is6L51 1uLtuvp7VmGR+cdtGw3yJ0ggwPCxMaJpZfqCxqAeI3hbtBJqjyz8kcP66QrQuAo4bNrc 7DG+2P/LjuTumS6NVxYqbbX2WmipxKXR8D4Z7WNtxOY/dBGBPSTHEHRQWIZ2luVBHBk2 lo36vI3jMGYU60tvt370jVSeSq9byHqkeOMDXA1vRHKGRTgEFFu+dXMdF/TSyCslE8Z7 SM2g== 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=QPS6ZIwitMZMs4JrzsgmdOVL1wMzIqhc+1GjswTbj/w=; b=KN0+IQJadmC9+uWxikFiXvepAidWn/ESk7GUmHxNorCB5FZ06DzqO2Nl5u89eOKxRK loTS9BFbRqlODayj9o+6WN8wOiGr3oCLwJzjgGWH+X4fHFCkjucvE9BSXB24G6jeoK5F r/1EbXAmaaSAi4SC05JP/Jya6Y30to6EqdAQ+Z7n0n30YZUUx4ifVFD7EpEKSiSjWuik ETtomk2eDHGL50eHg3fuVjfs3Du6hmmD2Y/uYFsSnyzq+wmkfJHRHf/Bft4a/7iE4uoj +BCCm2xXA34DN3Nweua0XmtvQpQfyGBBSWq3ZC4QBNIr8Jde1nQAwDKlqq6ElaXCNpio Q2Vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=c6cCWkTV; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g10si6247393edv.457.2020.07.27.07.21.17; Mon, 27 Jul 2020 07:21:39 -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=c6cCWkTV; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731452AbgG0OT5 (ORCPT + 99 others); Mon, 27 Jul 2020 10:19:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:47970 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731455AbgG0OTw (ORCPT ); Mon, 27 Jul 2020 10:19:52 -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 E34902070A; Mon, 27 Jul 2020 14:19:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595859592; bh=W1KFMAIHFlohENhNRehYvsOhP45gjEfT1u4uc4hD2kM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c6cCWkTV0AFsCbjAIRrCq0t0AV0eu3gMZGKWCNiMoXgM5VL/wjIMDFsDi9MEPRZeC L9/isjDEeW0LmyXiOUpOTxNGgo3lRzaiJsKl5HseAXcwGZl679gMCQE4J2GHim7inA xyK94OxLfJJHkKJhz3irL5QctuIQUdMYng7002lc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qu Wenruo , David Sterba Subject: [PATCH 5.7 031/179] btrfs: reloc: clear DEAD_RELOC_TREE bit for orphan roots to prevent runaway balance Date: Mon, 27 Jul 2020 16:03:26 +0200 Message-Id: <20200727134934.182761381@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727134932.659499757@linuxfoundation.org> References: <20200727134932.659499757@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 1dae7e0e58b484eaa43d530f211098fdeeb0f404 upstream. [BUG] There are several reported runaway balance, that balance is flooding the log with "found X extents" where the X never changes. [CAUSE] Commit d2311e698578 ("btrfs: relocation: Delay reloc tree deletion after merge_reloc_roots") introduced BTRFS_ROOT_DEAD_RELOC_TREE bit to indicate that one subvolume has finished its tree blocks swap with its reloc tree. However if balance is canceled or hits ENOSPC halfway, we didn't clear the BTRFS_ROOT_DEAD_RELOC_TREE bit, leaving that bit hanging forever until unmount. Any subvolume root with that bit, would cause backref cache to skip this tree block, as it has finished its tree block swap. This would cause all tree blocks of that root be ignored by balance, leading to runaway balance. [FIX] Fix the problem by also clearing the BTRFS_ROOT_DEAD_RELOC_TREE bit for the original subvolume of orphan reloc root. Add an umount check for the stale bit still set. Fixes: d2311e698578 ("btrfs: relocation: Delay reloc tree deletion after merge_reloc_roots") Signed-off-by: Qu Wenruo Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/disk-io.c | 1 + fs/btrfs/relocation.c | 2 ++ 2 files changed, 3 insertions(+) --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1998,6 +1998,7 @@ void btrfs_put_root(struct btrfs_root *r if (refcount_dec_and_test(&root->refs)) { WARN_ON(!RB_EMPTY_ROOT(&root->inode_tree)); + WARN_ON(test_bit(BTRFS_ROOT_DEAD_RELOC_TREE, &root->state)); if (root->anon_dev) free_anon_bdev(root->anon_dev); btrfs_drew_lock_destroy(&root->snapshot_lock); --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -2642,6 +2642,8 @@ again: root->reloc_root = NULL; btrfs_put_root(reloc_root); } + clear_bit(BTRFS_ROOT_DEAD_RELOC_TREE, + &root->state); btrfs_put_root(root); }