btrfs:Change BUG_ON to new error path in __clear_extent_bit
PATCH 1/1 btrfs:Change BUG_ON to new error path in __clear_extent_bit
This remove the unnessary BUG_ON if the allocation with alloc_extent_state_atomic fails due to this function failure not being unrecoverable. Instead we now change this BUG_ON into a new error path that jumps to the goto label, out from freeing previously allocated resources before returning the error code -ENOMEM to signal callers that the call to __clear_extent_bit failed due to a memory allocation failure.
--- fs/btrfs/extent_io.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/btrfs/extent_io.c +4 -1
@@ -682,7 +682,10 @@ hit_next:if (state->start < start) { prealloc =alloc_extent_state_atomic (prealloc); -BUG_ON (!prealloc); +if (!prealloc) { + err = -ENOMEM ; + goto out; + } err =split_state (tree, state, prealloc, start);if (err)extent_io_tree_panic (tree, err);
Signature · 1 line
2.5.0
Quoted 19 lines · Bastien Philbert
This remove the unnessary
BUG_ONif the allocation withalloc_extent_state_atomicfails due to this function failure not being unrecoverable. Instead we now change thisBUG_ONinto a new error path that jumps to the goto label, out from freeing previously allocated resources before returning the error code-ENOMEMto signal callers that the call to__clear_extent_bitfailed due to a memory allocation failure.Signed-off-by Bastien Philbert <[email protected]>--- fs/btrfs/extent_io.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)fs/btrfs/extent_io.c +0
-0
fs/btrfs/extent_io.c hit_next: · line 688
Quoted 8 lines
fs/btrfs/extent_io.c +4
-1@@ -682,7 +682,10 @@ hit_next:if (state->start < start) { prealloc =alloc_extent_state_atomic (prealloc); -BUG_ON (!prealloc); +if (!prealloc) { + err = -ENOMEM ; + goto out; + }
Why only in this particular place? We do this in other places in this function.
Second, setting err to -ENOMEM is not enough. Under the out label we always return 0, so you're not propagating the error to callers.
Now, most importantly, you didn't check if callers handle errors from this function (__clear_extent_bit()) at all. A failure in this function is critical.
For example, it can cause a range in an inode's io tree to become locked forever, blocking any other tasks that want to operate on the range, and we won't ever know what happened.
So it's far from trivial to handle errors from this function and that's why the BUG_ON is there.
If you really want to get rid of the BUG_ON() calls you need to make sure all callers don't ignore the errors and that they deal with them properly.
Quoted 10 lines
fs/btrfs/extent_io.c +0
-1err =split_state (tree, state, prealloc, start);if (err)extent_io_tree_panic (tree, err); --2.5.0
--
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
Signature · 5 lines
Filipe David Manana, "Reasonable men adapt themselves to the world. Unreasonable men adapt the world to themselves. That's why all progress depends on unreasonable men."
Quoted 44 lines · Filipe Manana
Quoted 19 lines · Bastien Philbert
This remove the unnessary
BUG_ONif the allocation withalloc_extent_state_atomicfails due to this function failure not being unrecoverable. Instead we now change thisBUG_ONinto a new error path that jumps to the goto label, out from freeing previously allocated resources before returning the error code-ENOMEMto signal callers that the call to__clear_extent_bitfailed due to a memory allocation failure.Signed-off-by Bastien Philbert <[email protected]>--- fs/btrfs/extent_io.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)fs/btrfs/extent_io.c +0
-0fs/btrfs/extent_io.c hit_next: · line 688
Quoted 8 lines
fs/btrfs/extent_io.c +4
-1@@ -682,7 +682,10 @@ hit_next:if (state->start < start) { prealloc =alloc_extent_state_atomic (prealloc); -BUG_ON (!prealloc); +if (!prealloc) { + err = -ENOMEM ; + goto out; + }Why only in this particular place? We do this in other places in this function.
Second, setting err to
-ENOMEMis not enough. Under the out label we always return 0, so you're not propagating the error to callers.Now, most importantly, you didn't check if callers handle errors from this function (
__clear_extent_bit()) at all. A failure in this function is critical.
For example, it can cause a range in an inode's io tree to become locked forever, blocking any other tasks that want to operate on the range, and we won't ever know what happened.
So it's far from trivial to handle errors from this function and that's why theBUG_ONis there.
Quoted 3 lines
If you really want to get rid of the
BUG_ON()calls you need to make sure all callers don't ignore the errors and that they deal with them properly.
Sorry, I feel really stupid about missing those other callers. :( Bastien
Quoted 15 lines
Quoted 12 lines
fs/btrfs/extent_io.c +0
-1err =split_state (tree, state, prealloc, start);if (err)extent_io_tree_panic (tree, err); --2.5.0
--
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