]> git.ipfire.org Git - thirdparty/linux.git/blobdiff - fs/btrfs/extent-io-tree.c
btrfs: make sure we cache next state in find_first_extent_bit()
[thirdparty/linux.git] / fs / btrfs / extent-io-tree.c
index f9f7cf028ffbd0e86d7ecc60e9ab7eb9b929a8d1..ea149be28dffeea58f2e435410979c3dc526e3a5 100644 (file)
@@ -885,10 +885,19 @@ bool find_first_extent_bit(struct extent_io_tree *tree, u64 start,
                if (state->end == start - 1 && extent_state_in_tree(state)) {
                        while ((state = next_state(state)) != NULL) {
                                if (state->state & bits)
-                                       goto got_it;
+                                       break;
                        }
+                       /*
+                        * If we found the next extent state, clear cached_state
+                        * so that we can cache the next extent state below and
+                        * avoid future calls going over the same extent state
+                        * again. If we haven't found any, clear as well since
+                        * it's now useless.
+                        */
                        free_extent_state(*cached_state);
                        *cached_state = NULL;
+                       if (state)
+                               goto got_it;
                        goto out;
                }
                free_extent_state(*cached_state);