Commit 92fb94b6 authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba

btrfs: set cache_block_group_error if we find an error

We set cache_block_group_error if btrfs_cache_block_group() returns an
error, this is because we could end up not finding space to allocate and
mistakenly return -ENOSPC, and which could then abort the transaction
with the incorrect errno, and in the case of ENOSPC result in a
WARN_ON() that will trip up tests like generic/475.

However there's the case where multiple threads can be racing, one
thread gets the proper error, and the other thread doesn't actually call
btrfs_cache_block_group(), it instead sees ->cached ==
BTRFS_CACHE_ERROR.  Again the result is the same, we fail to allocate
our space and return -ENOSPC.  Instead we need to set
cache_block_group_error to -EIO in this case to make sure that if we do
not make our allocation we get the appropriate error returned back to
the caller.

CC: stable@vger.kernel.org # 4.14+
Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 6ebcd021
...@@ -4310,8 +4310,11 @@ static noinline int find_free_extent(struct btrfs_root *root, ...@@ -4310,8 +4310,11 @@ static noinline int find_free_extent(struct btrfs_root *root,
ret = 0; ret = 0;
} }
if (unlikely(block_group->cached == BTRFS_CACHE_ERROR)) if (unlikely(block_group->cached == BTRFS_CACHE_ERROR)) {
if (!cache_block_group_error)
cache_block_group_error = -EIO;
goto loop; goto loop;
}
if (!find_free_extent_check_size_class(ffe_ctl, block_group)) if (!find_free_extent_check_size_class(ffe_ctl, block_group))
goto loop; goto loop;
......
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