Btrfs: handle errors when doing slow caching
Alex Lyakas reported a bug where wait_block_group_cache_progress() would wait forever if a drive failed. This is because we just bail out if there is an error while trying to cache a block group, we don't update anybody who may be waiting. So this introduces a new enum for the cache state in case of error and makes everybody bail out if we have an error. Alex tested and verified this patch fixed his problem. This fixes bz 59431. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
This commit is contained in:
parent
0f0fe8f710
commit
36cce92287
|
@ -1188,6 +1188,7 @@ enum btrfs_caching_type {
|
||||||
BTRFS_CACHE_STARTED = 1,
|
BTRFS_CACHE_STARTED = 1,
|
||||||
BTRFS_CACHE_FAST = 2,
|
BTRFS_CACHE_FAST = 2,
|
||||||
BTRFS_CACHE_FINISHED = 3,
|
BTRFS_CACHE_FINISHED = 3,
|
||||||
|
BTRFS_CACHE_ERROR = 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum btrfs_disk_cache_state {
|
enum btrfs_disk_cache_state {
|
||||||
|
|
|
@ -113,7 +113,8 @@ static noinline int
|
||||||
block_group_cache_done(struct btrfs_block_group_cache *cache)
|
block_group_cache_done(struct btrfs_block_group_cache *cache)
|
||||||
{
|
{
|
||||||
smp_mb();
|
smp_mb();
|
||||||
return cache->cached == BTRFS_CACHE_FINISHED;
|
return cache->cached == BTRFS_CACHE_FINISHED ||
|
||||||
|
cache->cached == BTRFS_CACHE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int block_group_bits(struct btrfs_block_group_cache *cache, u64 bits)
|
static int block_group_bits(struct btrfs_block_group_cache *cache, u64 bits)
|
||||||
|
@ -389,7 +390,7 @@ static noinline void caching_thread(struct btrfs_work *work)
|
||||||
u64 total_found = 0;
|
u64 total_found = 0;
|
||||||
u64 last = 0;
|
u64 last = 0;
|
||||||
u32 nritems;
|
u32 nritems;
|
||||||
int ret = 0;
|
int ret = -ENOMEM;
|
||||||
|
|
||||||
caching_ctl = container_of(work, struct btrfs_caching_control, work);
|
caching_ctl = container_of(work, struct btrfs_caching_control, work);
|
||||||
block_group = caching_ctl->block_group;
|
block_group = caching_ctl->block_group;
|
||||||
|
@ -517,6 +518,12 @@ err:
|
||||||
|
|
||||||
mutex_unlock(&caching_ctl->mutex);
|
mutex_unlock(&caching_ctl->mutex);
|
||||||
out:
|
out:
|
||||||
|
if (ret) {
|
||||||
|
spin_lock(&block_group->lock);
|
||||||
|
block_group->caching_ctl = NULL;
|
||||||
|
block_group->cached = BTRFS_CACHE_ERROR;
|
||||||
|
spin_unlock(&block_group->lock);
|
||||||
|
}
|
||||||
wake_up(&caching_ctl->wait);
|
wake_up(&caching_ctl->wait);
|
||||||
|
|
||||||
put_caching_control(caching_ctl);
|
put_caching_control(caching_ctl);
|
||||||
|
@ -6035,8 +6042,11 @@ static u64 stripe_align(struct btrfs_root *root,
|
||||||
* for our min num_bytes. Another option is to have it go ahead
|
* for our min num_bytes. Another option is to have it go ahead
|
||||||
* and look in the rbtree for a free extent of a given size, but this
|
* and look in the rbtree for a free extent of a given size, but this
|
||||||
* is a good start.
|
* is a good start.
|
||||||
|
*
|
||||||
|
* Callers of this must check if cache->cached == BTRFS_CACHE_ERROR before using
|
||||||
|
* any of the information in this block group.
|
||||||
*/
|
*/
|
||||||
static noinline int
|
static noinline void
|
||||||
wait_block_group_cache_progress(struct btrfs_block_group_cache *cache,
|
wait_block_group_cache_progress(struct btrfs_block_group_cache *cache,
|
||||||
u64 num_bytes)
|
u64 num_bytes)
|
||||||
{
|
{
|
||||||
|
@ -6044,28 +6054,29 @@ wait_block_group_cache_progress(struct btrfs_block_group_cache *cache,
|
||||||
|
|
||||||
caching_ctl = get_caching_control(cache);
|
caching_ctl = get_caching_control(cache);
|
||||||
if (!caching_ctl)
|
if (!caching_ctl)
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
wait_event(caching_ctl->wait, block_group_cache_done(cache) ||
|
wait_event(caching_ctl->wait, block_group_cache_done(cache) ||
|
||||||
(cache->free_space_ctl->free_space >= num_bytes));
|
(cache->free_space_ctl->free_space >= num_bytes));
|
||||||
|
|
||||||
put_caching_control(caching_ctl);
|
put_caching_control(caching_ctl);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static noinline int
|
static noinline int
|
||||||
wait_block_group_cache_done(struct btrfs_block_group_cache *cache)
|
wait_block_group_cache_done(struct btrfs_block_group_cache *cache)
|
||||||
{
|
{
|
||||||
struct btrfs_caching_control *caching_ctl;
|
struct btrfs_caching_control *caching_ctl;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
caching_ctl = get_caching_control(cache);
|
caching_ctl = get_caching_control(cache);
|
||||||
if (!caching_ctl)
|
if (!caching_ctl)
|
||||||
return 0;
|
return (cache->cached == BTRFS_CACHE_ERROR) ? -EIO : 0;
|
||||||
|
|
||||||
wait_event(caching_ctl->wait, block_group_cache_done(cache));
|
wait_event(caching_ctl->wait, block_group_cache_done(cache));
|
||||||
|
if (cache->cached == BTRFS_CACHE_ERROR)
|
||||||
|
ret = -EIO;
|
||||||
put_caching_control(caching_ctl);
|
put_caching_control(caching_ctl);
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int __get_raid_index(u64 flags)
|
int __get_raid_index(u64 flags)
|
||||||
|
@ -6248,6 +6259,8 @@ have_block_group:
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (unlikely(block_group->cached == BTRFS_CACHE_ERROR))
|
||||||
|
goto loop;
|
||||||
if (unlikely(block_group->ro))
|
if (unlikely(block_group->ro))
|
||||||
goto loop;
|
goto loop;
|
||||||
|
|
||||||
|
@ -8230,7 +8243,8 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info)
|
||||||
* We haven't cached this block group, which means we could
|
* We haven't cached this block group, which means we could
|
||||||
* possibly have excluded extents on this block group.
|
* possibly have excluded extents on this block group.
|
||||||
*/
|
*/
|
||||||
if (block_group->cached == BTRFS_CACHE_NO)
|
if (block_group->cached == BTRFS_CACHE_NO ||
|
||||||
|
block_group->cached == BTRFS_CACHE_ERROR)
|
||||||
free_excluded_extents(info->extent_root, block_group);
|
free_excluded_extents(info->extent_root, block_group);
|
||||||
|
|
||||||
btrfs_remove_free_space_cache(block_group);
|
btrfs_remove_free_space_cache(block_group);
|
||||||
|
|
Loading…
Reference in a new issue