btrfs: Go readonly on bad extent refs in update_ref_for_cow()
authorMark Fasheh <mfasheh@suse.com>
Mon, 29 Aug 2011 21:17:04 +0000 (14:17 -0700)
committerDavid Sterba <dsterba@suse.cz>
Thu, 22 Mar 2012 00:45:37 +0000 (01:45 +0100)
update_ref_for_cow() will BUG_ON() after it's call to
btrfs_lookup_extent_info() if no existing references are found.  Since refs
are computed directly from disk, this should be treated as a corruption
instead of a logic error.

Signed-off-by: Mark Fasheh <mfasheh@suse.de>
fs/btrfs/ctree.c

index e2e43c07f6b16e3c43cf9c0ffb3857200c2302e2..3b767d2b68e833275030627341695d911b6960ac 100644 (file)
@@ -333,7 +333,11 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans,
                                               buf->len, &refs, &flags);
                if (ret)
                        return ret;
-               BUG_ON(refs == 0);
+               if (refs == 0) {
+                       ret = -EROFS;
+                       btrfs_std_error(root->fs_info, ret);
+                       return ret;
+               }
        } else {
                refs = 1;
                if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID ||