From d5ecd0bd9003dd23cc502563282e99eff7c8a895 Mon Sep 17 00:00:00 2001 From: Xiao Guangrong Date: Wed, 20 Apr 2011 06:44:57 +0000 Subject: [PATCH] --- yaml --- r: 252335 b: refs/heads/master c: 8233767a227ac5843f1023b88c7272a7b5058f5f h: refs/heads/master i: 252333: dbddc4bb1b044de85c56ff67dad04fc7e0d1a3a1 252331: 788bb0ab12caac5931150ca6152f4a4e22877058 252327: 68cda59ad7451925f13254ee79adafe7556fa445 252319: 8ec786dd04d8e618d2fb1a635a9068078e4f3018 v: v3 --- [refs] | 2 +- trunk/fs/btrfs/extent_io.c | 34 ++++++++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/[refs] b/[refs] index e3c87c3fcb8f..dc0861f549ba 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: b083916638eee513be501f53b42a4be0b9851db0 +refs/heads/master: 8233767a227ac5843f1023b88c7272a7b5058f5f diff --git a/trunk/fs/btrfs/extent_io.c b/trunk/fs/btrfs/extent_io.c index ba41da59e31b..9ccea86dd015 100644 --- a/trunk/fs/btrfs/extent_io.c +++ b/trunk/fs/btrfs/extent_io.c @@ -439,6 +439,15 @@ static int clear_state_bit(struct extent_io_tree *tree, return ret; } +static struct extent_state * +alloc_extent_state_atomic(struct extent_state *prealloc) +{ + if (!prealloc) + prealloc = alloc_extent_state(GFP_ATOMIC); + + return prealloc; +} + /* * clear some bits on a range in the tree. This may require splitting * or inserting elements in the tree, so the gfp mask is used to @@ -476,8 +485,7 @@ int clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, again: if (!prealloc && (mask & __GFP_WAIT)) { prealloc = alloc_extent_state(mask); - if (!prealloc) - return -ENOMEM; + BUG_ON(!prealloc); } spin_lock(&tree->lock); @@ -529,8 +537,8 @@ int clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, */ if (state->start < start) { - if (!prealloc) - prealloc = alloc_extent_state(GFP_ATOMIC); + prealloc = alloc_extent_state_atomic(prealloc); + BUG_ON(!prealloc); err = split_state(tree, state, prealloc, start); BUG_ON(err == -EEXIST); prealloc = NULL; @@ -551,8 +559,8 @@ int clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, * on the first half */ if (state->start <= end && state->end > end) { - if (!prealloc) - prealloc = alloc_extent_state(GFP_ATOMIC); + prealloc = alloc_extent_state_atomic(prealloc); + BUG_ON(!prealloc); err = split_state(tree, state, prealloc, end + 1); BUG_ON(err == -EEXIST); if (wake) @@ -725,8 +733,7 @@ int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, again: if (!prealloc && (mask & __GFP_WAIT)) { prealloc = alloc_extent_state(mask); - if (!prealloc) - return -ENOMEM; + BUG_ON(!prealloc); } spin_lock(&tree->lock); @@ -743,6 +750,8 @@ int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, */ node = tree_search(tree, start); if (!node) { + prealloc = alloc_extent_state_atomic(prealloc); + BUG_ON(!prealloc); err = insert_state(tree, prealloc, start, end, &bits); prealloc = NULL; BUG_ON(err == -EEXIST); @@ -811,6 +820,9 @@ int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, err = -EEXIST; goto out; } + + prealloc = alloc_extent_state_atomic(prealloc); + BUG_ON(!prealloc); err = split_state(tree, state, prealloc, start); BUG_ON(err == -EEXIST); prealloc = NULL; @@ -841,6 +853,9 @@ int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, this_end = end; else this_end = last_start - 1; + + prealloc = alloc_extent_state_atomic(prealloc); + BUG_ON(!prealloc); err = insert_state(tree, prealloc, start, this_end, &bits); BUG_ON(err == -EEXIST); @@ -865,6 +880,9 @@ int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, err = -EEXIST; goto out; } + + prealloc = alloc_extent_state_atomic(prealloc); + BUG_ON(!prealloc); err = split_state(tree, state, prealloc, end + 1); BUG_ON(err == -EEXIST);