diff mbox series

[v4,39/68] btrfs: extent_io: extra the core of test_range_bit() into test_range_bit_nolock()

Message ID 20201021062554.68132-40-wqu@suse.com
State New, archived
Headers show
Series btrfs: add basic rw support for subpage sector size | expand

Commit Message

Qu Wenruo Oct. 21, 2020, 6:25 a.m. UTC
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(-)
diff mbox series

Patch

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 6a34b33be1fc..37593b599522 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -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