btrfs: backref: distinguish reloc and non-reloc use of indirect resolution
authorQu Wenruo <wqu@suse.com>
Mon, 16 Mar 2020 06:10:01 +0000 (14:10 +0800)
committerDavid Sterba <dsterba@suse.com>
Mon, 25 May 2020 09:25:22 +0000 (11:25 +0200)
For relocation tree detection, relocation backref cache uses
btrfs_should_ignore_reloc_root() which uses relocation-specific checks
like checking the DEAD_RELOC_ROOT bit.

However for general purpose backref cache, we can rely on that check, as
it's possible that relocation is also running.

For generic purposed backref cache, we detect reloc root by
SHARED_BLOCK_REF item.  Only reloc root node has its parent bytenr
pointing back to itself.

And in that case, backref cache will mark the reloc root node useless,
dropping any child orphan nodes.

So only call btrfs_should_ignore_reloc_root() if the backref cache is
for relocation.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/backref.c

index b38a680e6678b8ca3c32e5d9577e34570f399beb..ac3c34f47b5624933c54233629f73eebc28e2a01 100644 (file)
@@ -2708,7 +2708,17 @@ static int handle_indirect_tree_backref(struct btrfs_backref_cache *cache,
        if (btrfs_root_level(&root->root_item) == cur->level) {
                /* Tree root */
                ASSERT(btrfs_root_bytenr(&root->root_item) == cur->bytenr);
-               if (btrfs_should_ignore_reloc_root(root)) {
+               /*
+                * For reloc backref cache, we may ignore reloc root.  But for
+                * general purpose backref cache, we can't rely on
+                * btrfs_should_ignore_reloc_root() as it may conflict with
+                * current running relocation and lead to missing root.
+                *
+                * For general purpose backref cache, reloc root detection is
+                * completely relying on direct backref (key->offset is parent
+                * bytenr), thus only do such check for reloc cache.
+                */
+               if (btrfs_should_ignore_reloc_root(root) && cache->is_reloc) {
                        btrfs_put_root(root);
                        list_add(&cur->list, &cache->useless_node);
                } else {
@@ -2749,7 +2759,9 @@ static int handle_indirect_tree_backref(struct btrfs_backref_cache *cache,
                if (!path->nodes[level]) {
                        ASSERT(btrfs_root_bytenr(&root->root_item) ==
                               lower->bytenr);
-                       if (btrfs_should_ignore_reloc_root(root)) {
+                       /* Same as previous should_ignore_reloc_root() call */
+                       if (btrfs_should_ignore_reloc_root(root) &&
+                           cache->is_reloc) {
                                btrfs_put_root(root);
                                list_add(&lower->list, &cache->useless_node);
                        } else {