btrfs: handle error in btrfs_cache_block_group
authorJosef Bacik <josef@toxicpanda.com>
Tue, 19 Nov 2019 18:59:00 +0000 (13:59 -0500)
committerDavid Sterba <dsterba@suse.com>
Fri, 13 Dec 2019 13:09:22 +0000 (14:09 +0100)
commitdb8fe64f9ce61d1d89d3c3c34d111a43afb9f053
tree46fd83f88378084f8ea02572acf8f7cb85c25637
parentf72ff01df9cf5db25c76674cac16605992d15467
btrfs: handle error in btrfs_cache_block_group

We have a BUG_ON(ret < 0) in find_free_extent from
btrfs_cache_block_group.  If we fail to allocate our ctl we'll just
panic, which is not good.  Instead just go on to another block group.
If we fail to find a block group we don't want to return ENOSPC, because
really we got a ENOMEM and that's the root of the problem.  Save our
return from btrfs_cache_block_group(), and then if we still fail to make
our allocation return that ret so we get the right error back.

Tested with inject-error.py from bcc.

Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
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/extent-tree.c