Commit 2d0d0a8b authored by Liu Bo's avatar Liu Bo Committed by Stefan Bader

Btrfs: check inconsistence between chunk and block group

BugLink: https://bugs.launchpad.net/bugs/1818237

commit 6fb37b75 upstream.

With btrfs-corrupt-block, one can drop one chunk item and mounting
will end up with a panic in btrfs_full_stripe_len().

This doesn't not remove the BUG_ON, but instead checks it a bit
earlier when we find the block group item.
Signed-off-by: default avatarLiu Bo <bo.li.liu@oracle.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarBen Hutchings <ben.hutchings@codethink.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarJuerg Haefliger <juergh@canonical.com>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
parent 43b8b9b9
...@@ -9502,7 +9502,22 @@ static int find_first_block_group(struct btrfs_root *root, ...@@ -9502,7 +9502,22 @@ static int find_first_block_group(struct btrfs_root *root,
if (found_key.objectid >= key->objectid && if (found_key.objectid >= key->objectid &&
found_key.type == BTRFS_BLOCK_GROUP_ITEM_KEY) { found_key.type == BTRFS_BLOCK_GROUP_ITEM_KEY) {
ret = 0; struct extent_map_tree *em_tree;
struct extent_map *em;
em_tree = &root->fs_info->mapping_tree.map_tree;
read_lock(&em_tree->lock);
em = lookup_extent_mapping(em_tree, found_key.objectid,
found_key.offset);
read_unlock(&em_tree->lock);
if (!em) {
btrfs_err(root->fs_info,
"logical %llu len %llu found bg but no related chunk",
found_key.objectid, found_key.offset);
ret = -ENOENT;
} else {
ret = 0;
}
goto out; goto out;
} }
path->slots[0]++; path->slots[0]++;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment