search_again:
        node = tree_search(&tree->state, cur_start);
        if (!node || IS_ERR(node)) {
+               *end = (u64)-1;
                goto out;
        }
 
                        goto out;
                }
                if (!(state->state & EXTENT_DELALLOC)) {
+                       if (!found)
+                               *end = state->end;
                        goto out;
                }
                if (!found) {
                nr_delalloc = find_lock_delalloc_range(tree, &delalloc_start,
                                                       &delalloc_end,
                                                       128 * 1024 * 1024);
-               if (nr_delalloc <= 0)
-                       break;
+               if (nr_delalloc == 0) {
+                       delalloc_start = delalloc_end + 1;
+                       continue;
+               }
                tree->ops->fill_delalloc(inode, delalloc_start,
                                         delalloc_end);
                clear_extent_bit(tree, delalloc_start,
 
        u64 page_start = (u64)page->index << PAGE_CACHE_SHIFT;
        u64 page_end = page_start + PAGE_CACHE_SIZE - 1;
 
+       WARN_ON(!PageLocked(page));
        set_page_extent_mapped(page);
 
        lock_extent(em_tree, page_start, page_end, GFP_NOFS);