Btrfs: return ENOSPC when target space is full
PATCH 1/1 Btrfs: return ENOSPC when target space is full
In extent-tree.c:do_chunk_alloc(), early on we returned 0 (success) when the target space was full and when chunk allocation is needed. However, later on in that same function we return ENOSPC if btrfs_alloc_chunk() fails (and chunk allocation was needed) and set the space's full flag.
This was inconsistent, as -ENOSPC should be returned if the space is full and a chunk allocation needs to performed. If the space is full but no chunk allocation is needed, just return 0 (success).
--- fs/btrfs/extent-tree.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/btrfs/extent-tree.c +5 -1
@@ -3829,8 +3829,12 @@ again:if (force < space_info->force_alloc) force = space_info->force_alloc;if (space_info->full) { +if (should_alloc_chunk (extent_root, space_info, force)) + ret = -ENOSPC ; +else + ret =0 ;spin_unlock (&space_info->lock); -return 0 ; +return ret; }if (!should_alloc_chunk (extent_root, space_info, force)) {
Signature · 1 line
1.7.9.5
Hi Filipe,
I think in the context of do_chunk_alloc(), 0 doesn't mean "success". 0 means "allocation was not attempted". While 1 means "allocation was attempted and succeeded". -ENOSPC means "allocation was attempted but failed". Any other errno deserves transaction abort. Anyways, the callers are ok with "0" and -ENOSPC and re-search for a free extent in these cases.
Alex.
Quoted 40 lines · Filipe David Borba Manana
In extent-tree.c:do_chunk_alloc(), early on we returned 0 (success) when the target space was full and when chunk allocation is needed. However, later on in that same function we return ENOSPC if
btrfs_alloc_chunk()fails (and chunk allocation was needed) and set the space's full flag.This was inconsistent, as
-ENOSPCshould be returned if the space is full and a chunk allocation needs to performed. If the space is full but no chunk allocation is needed, just return 0 (success).Signed-off-by Filipe David Borba Manana <[email protected]>--- fs/btrfs/extent-tree.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)fs/btrfs/extent-tree.c +5
-2@@ -3829,8 +3829,12 @@ again:if (force < space_info->force_alloc) force = space_info->force_alloc;if (space_info->full) { +if (should_alloc_chunk (extent_root, space_info, force)) + ret = -ENOSPC ; +else + ret =0 ;spin_unlock (&space_info->lock); -return 0 ; +return ret; }if (!should_alloc_chunk (extent_root, space_info, force)) { --1.7.9.5
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html