Btrfs-progs: return an error if we can't find an fs root
authorJosef Bacik <jbacik@fusionio.com>
Fri, 1 Feb 2013 20:21:04 +0000 (15:21 -0500)
committerDavid Sterba <dsterba@suse.cz>
Thu, 7 Feb 2013 00:19:50 +0000 (01:19 +0100)
Instead of doing a BUG_ON() if we fail to find the last fs root just return
an error so the callers can deal with it how they like.  Also we need to
actually return an error if we can't find the latest root so that the error
handling works.  With this btrfsck was able to deal with a file system that
was missing a root item but still had extents that referred back to the
root.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
disk-io.c
root-tree.c

index 27befca..5aa9aa3 100644 (file)
--- a/disk-io.c
+++ b/disk-io.c
@@ -613,7 +613,8 @@ static int find_and_setup_root(struct btrfs_root *tree_root,
                     root, fs_info, objectid);
        ret = btrfs_find_last_root(tree_root, objectid,
                                   &root->root_item, &root->root_key);
-       BUG_ON(ret);
+       if (ret)
+               return ret;
 
        blocksize = btrfs_level_size(root, btrfs_root_level(&root->root_item));
        generation = btrfs_root_generation(&root->root_item);
index 782472c..ecb7599 100644 (file)
@@ -47,7 +47,7 @@ int btrfs_find_last_root(struct btrfs_root *root, u64 objectid,
        slot = path->slots[0] - 1;
        btrfs_item_key_to_cpu(l, &found_key, slot);
        if (found_key.objectid != objectid) {
-               ret = 1;
+               ret = -ENOENT;
                goto out;
        }
        read_extent_buffer(l, item, btrfs_item_ptr_offset(l, slot),