Skip to contentSkip to conversation

Btrfs: return ENOSPC when target space is full

PATCH In review Filipe David Borba Manana 2 participants 2 messages Aug 5, 2013 – Jan 19, 2014 Btrfs file system

lore
Share & tools
lore
#0 lore raw

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
index e868c35..ef89a66 100644
@@ -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
#1 lore raw

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 -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 -2
index e868c35..ef89a66 100644
@@ -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