Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp570665ybz; Wed, 22 Apr 2020 03:57:57 -0700 (PDT) X-Google-Smtp-Source: APiQypJ16RVPQwnfqoNiZfOp8VwGpOWoPGp6SRLVQWNlHMysWy1dfn1+1LpooOO4RVTCOU4vwFRj X-Received: by 2002:a05:6402:16da:: with SMTP id r26mr21568590edx.375.1587553077398; Wed, 22 Apr 2020 03:57:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587553077; cv=none; d=google.com; s=arc-20160816; b=ibXsf8chCAPAqvUXzaI3QYgzoj6Fvot/hDRsn82k87Z4PY+0v9V6GOAf/JRhFljlxG 7KHmiJhqhVEz7+BfGaw9L6fHNS5wvnQbmxzWHJcV2bHWWhNdudZp/QPlKgZJJTvzNGND o06/ehXm9cyXJAWCoO4Z/DqwEpQFbGJM4oXOCBWlU397/jb89mUhN4HgQQ6nOPIi2dWy 1TuC7Z0l7hz9TvajlPfKVEEiiCAeicPzEw7qjAXpPy2wDj48Z1mZclwJF3uqo20W3U9F qPQ/ugq9GIN2f99NV096hZrf62qUgBCsxxi1ZD72Srq364Qrnw9Omx12lPWRSamCMnMB /3sQ== 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=k7DzSqFOVC8e+oOm/e4DMzZpe6duKogs/C8ZJ/1LoiQ=; b=axYQR9Ys/NODcNq79vMruK3s3E+5vD4vtWsSPhIC5Bsh/5R6PUTEZMn+hs6NXa2ppF eDK0lC8tHtauGDUk20Xk6JFpN666YK/3jHrdiFLRhonTwRDUDsS2iKs1BAywF0NheA4k IaGxNW5aeFeg1VDSmWrPUy++3QMbaA9PgR4ip3FqZKpCF7cPvpFUIG/5k26WLIYv0/ct xyuoy5WzjsEIcOg0uuii+14zDyTafm9KCj9qu1S4E/Xu0+SX5AYok6iKYdPQ82Up1KKa trUD5GPt/XfBhr7GlTvlulqMYctLPY63GVqf74f3HSRBfwYoVKT7fyohZZh5KSKqaOey GyfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=U6s0zMWN; 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 s18si3326696edg.380.2020.04.22.03.57.34; Wed, 22 Apr 2020 03:57:57 -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=U6s0zMWN; 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 S1732100AbgDVKxQ (ORCPT + 99 others); Wed, 22 Apr 2020 06:53:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:35418 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728801AbgDVKJG (ORCPT ); Wed, 22 Apr 2020 06:09:06 -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 2FFE32077D; Wed, 22 Apr 2020 10:09:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587550145; bh=n3hQeJ8At695vTAd/LFPvlrNob3UHrP0u/aOixvMnt4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U6s0zMWN9IVJWkow+Pwd+MbI0/ZaGt/lVmLBTy6RqhDlWioeKFkqJ8jfIqBjD6Ynf j21HFQf3i0P6tflfqNj3retENXLKNkcT6ZGDEpLYiwhIxTv6Y1vOtAZI5B+ABihxvF On67s2HuBSj0lJrEc8SVTmwYBPQPotDwnIFVLQtk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Josef Bacik , David Sterba , Sasha Levin Subject: [PATCH 4.14 028/199] btrfs: track reloc roots based on their commit root bytenr Date: Wed, 22 Apr 2020 11:55:54 +0200 Message-Id: <20200422095100.907972648@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200422095057.806111593@linuxfoundation.org> References: <20200422095057.806111593@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: Josef Bacik [ Upstream commit ea287ab157c2816bf12aad4cece41372f9d146b4 ] We always search the commit root of the extent tree for looking up back references, however we track the reloc roots based on their current bytenr. This is wrong, if we commit the transaction between relocating tree blocks we could end up in this code in build_backref_tree if (key.objectid == key.offset) { /* * Only root blocks of reloc trees use backref * pointing to itself. */ root = find_reloc_root(rc, cur->bytenr); ASSERT(root); cur->root = root; break; } find_reloc_root() is looking based on the bytenr we had in the commit root, but if we've COWed this reloc root we will not find that bytenr, and we will trip over the ASSERT(root). Fix this by using the commit_root->start bytenr for indexing the commit root. Then we change the __update_reloc_root() caller to be used when we switch the commit root for the reloc root during commit. This fixes the panic I was seeing when we started throttling relocation for delayed refs. Signed-off-by: Josef Bacik Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/relocation.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 42f388ed0796b..04db7c5f5ca4e 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1306,7 +1306,7 @@ static int __must_check __add_reloc_root(struct btrfs_root *root) if (!node) return -ENOMEM; - node->bytenr = root->node->start; + node->bytenr = root->commit_root->start; node->data = root; spin_lock(&rc->reloc_root_tree.lock); @@ -1337,10 +1337,11 @@ static void __del_reloc_root(struct btrfs_root *root) if (rc && root->node) { spin_lock(&rc->reloc_root_tree.lock); rb_node = tree_search(&rc->reloc_root_tree.rb_root, - root->node->start); + root->commit_root->start); if (rb_node) { node = rb_entry(rb_node, struct mapping_node, rb_node); rb_erase(&node->rb_node, &rc->reloc_root_tree.rb_root); + RB_CLEAR_NODE(&node->rb_node); } spin_unlock(&rc->reloc_root_tree.lock); if (!node) @@ -1358,7 +1359,7 @@ static void __del_reloc_root(struct btrfs_root *root) * helper to update the 'address of tree root -> reloc tree' * mapping */ -static int __update_reloc_root(struct btrfs_root *root, u64 new_bytenr) +static int __update_reloc_root(struct btrfs_root *root) { struct btrfs_fs_info *fs_info = root->fs_info; struct rb_node *rb_node; @@ -1367,7 +1368,7 @@ static int __update_reloc_root(struct btrfs_root *root, u64 new_bytenr) spin_lock(&rc->reloc_root_tree.lock); rb_node = tree_search(&rc->reloc_root_tree.rb_root, - root->node->start); + root->commit_root->start); if (rb_node) { node = rb_entry(rb_node, struct mapping_node, rb_node); rb_erase(&node->rb_node, &rc->reloc_root_tree.rb_root); @@ -1379,7 +1380,7 @@ static int __update_reloc_root(struct btrfs_root *root, u64 new_bytenr) BUG_ON((struct btrfs_root *)node->data != root); spin_lock(&rc->reloc_root_tree.lock); - node->bytenr = new_bytenr; + node->bytenr = root->node->start; rb_node = tree_insert(&rc->reloc_root_tree.rb_root, node->bytenr, &node->rb_node); spin_unlock(&rc->reloc_root_tree.lock); @@ -1524,6 +1525,7 @@ int btrfs_update_reloc_root(struct btrfs_trans_handle *trans, } if (reloc_root->commit_root != reloc_root->node) { + __update_reloc_root(reloc_root); btrfs_set_root_node(root_item, reloc_root->node); free_extent_buffer(reloc_root->commit_root); reloc_root->commit_root = btrfs_root_node(reloc_root); @@ -4712,11 +4714,6 @@ int btrfs_reloc_cow_block(struct btrfs_trans_handle *trans, BUG_ON(rc->stage == UPDATE_DATA_PTRS && root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID); - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) { - if (buf == root->node) - __update_reloc_root(root, cow->start); - } - level = btrfs_header_level(buf); if (btrfs_header_generation(buf) <= btrfs_root_last_snapshot(&root->root_item)) -- 2.20.1