btrfs: fix ref-verify to catch operations on 0 ref extents
authorJosef Bacik <josef@toxicpanda.com>
Wed, 11 Mar 2020 15:21:44 +0000 (11:21 -0400)
committerDavid Sterba <dsterba@suse.com>
Mon, 23 Mar 2020 16:01:56 +0000 (17:01 +0100)
While debugging I noticed I wasn't getting ref verify errors before
everything blew up.  Turns out it's because we don't warn when we try to
add a normal ref via btrfs_inc_ref() if the block entry exists but has 0
references.  This is incorrect, we should never be doing anything other
than adding a new extent once a block entry drops to 0 references.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ref-verify.c

index 454a1015d026b741ec1a1b168375755d6df5971a..7887317033c98218a45bf710157fa37459d09b91 100644 (file)
@@ -803,6 +803,15 @@ int btrfs_ref_tree_mod(struct btrfs_fs_info *fs_info,
                        kfree(ref);
                        kfree(ra);
                        goto out_unlock;
+               } else if (be->num_refs == 0) {
+                       btrfs_err(fs_info,
+               "trying to do action %d for a bytenr that has 0 total references",
+                               action);
+                       dump_block_entry(fs_info, be);
+                       dump_ref_action(fs_info, ra);
+                       kfree(ref);
+                       kfree(ra);
+                       goto out_unlock;
                }
 
                if (!parent) {