Skip to content

Commit

Permalink
Btrfs: drop spin lock when memory alloc fails
Browse files Browse the repository at this point in the history
Drop spin lock in convert_extent_bit() when memory alloc fails,
otherwise, it will be a deadlock.

Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
  • Loading branch information
Liu Bo authored and Chris Mason committed Dec 8, 2011
1 parent a5d1633 commit 1cf4ffd
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions fs/btrfs/extent_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -935,8 +935,10 @@ int convert_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
node = tree_search(tree, start);
if (!node) {
prealloc = alloc_extent_state_atomic(prealloc);
if (!prealloc)
return -ENOMEM;
if (!prealloc) {
err = -ENOMEM;
goto out;
}
err = insert_state(tree, prealloc, start, end, &bits);
prealloc = NULL;
BUG_ON(err == -EEXIST);
Expand Down Expand Up @@ -992,8 +994,10 @@ int convert_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
*/
if (state->start < start) {
prealloc = alloc_extent_state_atomic(prealloc);
if (!prealloc)
return -ENOMEM;
if (!prealloc) {
err = -ENOMEM;
goto out;
}
err = split_state(tree, state, prealloc, start);
BUG_ON(err == -EEXIST);
prealloc = NULL;
Expand Down Expand Up @@ -1024,8 +1028,10 @@ int convert_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
this_end = last_start - 1;

prealloc = alloc_extent_state_atomic(prealloc);
if (!prealloc)
return -ENOMEM;
if (!prealloc) {
err = -ENOMEM;
goto out;
}

/*
* Avoid to free 'prealloc' if it can be merged with
Expand All @@ -1051,8 +1057,10 @@ int convert_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
*/
if (state->start <= end && state->end > end) {
prealloc = alloc_extent_state_atomic(prealloc);
if (!prealloc)
return -ENOMEM;
if (!prealloc) {
err = -ENOMEM;
goto out;
}

err = split_state(tree, state, prealloc, end + 1);
BUG_ON(err == -EEXIST);
Expand Down

0 comments on commit 1cf4ffd

Please sign in to comment.