@@ -2213,20 +2213,16 @@ struct io_failure_record *get_state_failrec(struct extent_io_tree *tree, u64 sta
return failrec;
}
-/*
- * searches a range in the state tree for a given mask.
- * If 'filled' == 1, this returns 1 only if every extent in the tree
- * has the bits set. Otherwise, 1 is returned if any bit in the
- * range is found set.
- */
-int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end,
- u32 bits, int filled, struct extent_state *cached)
+static int test_range_bit_nolock(struct extent_io_tree *tree, u64 start,
+ u64 end, u32 bits, int filled,
+ struct extent_state *cached)
{
struct extent_state *state = NULL;
struct rb_node *node;
int bitset = 0;
- spin_lock(&tree->lock);
+ assert_spin_locked(&tree->lock);
+
if (cached && extent_state_in_tree(cached) && cached->start <= start &&
cached->end > start)
node = &cached->rb_node;
@@ -2265,10 +2261,26 @@ int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end,
break;
}
}
- spin_unlock(&tree->lock);
return bitset;
}
+/*
+ * searches a range in the state tree for a given mask.
+ * If 'filled' == 1, this returns 1 only if every extent in the tree
+ * has the bits set. Otherwise, 1 is returned if any bit in the
+ * range is found set.
+ */
+int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end,
+ u32 bits, int filled, struct extent_state *cached)
+{
+ int ret;
+
+ spin_lock(&tree->lock);
+ ret = test_range_bit_nolock(tree, start, end, bits, filled, cached);
+ spin_unlock(&tree->lock);
+ return ret;
+}
+
/*
* helper function to set a given page up to date if all the
* extents in the tree for that page are up to date
This allows later function to utilize test_range_bit_nolock() with caller handling the lock. Signed-off-by: Qu Wenruo <wqu@suse.com> --- fs/btrfs/extent_io.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-)