Commit eecba891 authored by Alex Lyakas's avatar Alex Lyakas Committed by Chris Mason

btrfs: flush_space: treat return value of do_chunk_alloc properly

do_chunk_alloc returns 1 when it succeeds to allocate a new chunk.
But flush_space will not convert this to 0, and will also return 1.
As a result, reserve_metadata_bytes will think that flush_space failed,
and may potentially return this value "1" to the caller (depends how
reserve_metadata_bytes was called). The caller will also treat this as an error.
For example, btrfs_block_rsv_refill does:

int ret = -ENOSPC;
...
ret = reserve_metadata_bytes(root, block_rsv, num_bytes, flush);
if (!ret) {
        block_rsv_add_bytes(block_rsv, num_bytes, 0);
        return 0;
}

return ret;

So it will return -ENOSPC.
Signed-off-by: default avatarAlex Lyakas <alex@zadarastorage.com>
Reviewed-by: default avatarJosef Bacik <jbacik@fb.com>
Reviewed-by: default avatarLiu Bo <bo.li.liu@oracle.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarChris Mason <clm@fb.com>
parent f3bca802
...@@ -4882,7 +4882,7 @@ static int flush_space(struct btrfs_root *root, ...@@ -4882,7 +4882,7 @@ static int flush_space(struct btrfs_root *root,
btrfs_get_alloc_profile(root, 0), btrfs_get_alloc_profile(root, 0),
CHUNK_ALLOC_NO_FORCE); CHUNK_ALLOC_NO_FORCE);
btrfs_end_transaction(trans, root); btrfs_end_transaction(trans, root);
if (ret == -ENOSPC) if (ret > 0 || ret == -ENOSPC)
ret = 0; ret = 0;
break; break;
case COMMIT_TRANS: case COMMIT_TRANS:
......
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