]> git.itanic.dy.fi Git - linux-stable/commit
btrfs: track reloc roots based on their commit root bytenr
authorJosef Bacik <josef@toxicpanda.com>
Fri, 13 Mar 2020 21:17:08 +0000 (17:17 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 24 Apr 2020 05:57:08 +0000 (07:57 +0200)
commit5a22f88ca38b1c8080a5e496d47f59c4f3cc8ffa
tree5a668aeb22a541d2d4ccf50f10ca291ef3d7aab5
parent753baee612d3040775a7c32e9bd093c72f8f5f44
btrfs: track reloc roots based on their commit root bytenr

[ 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 <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/btrfs/relocation.c