mm: implement find_get_pages_range()
[sfrench/cifs-2.6.git] / mm / filemap.c
index 65b4b6e7f7bde69620b73af705ecca33629a8f79..129883f160a7ba12e4b327dcf07a58bab4af0ce1 100644 (file)
@@ -130,17 +130,8 @@ static int page_cache_tree_insert(struct address_space *mapping,
                        return -EEXIST;
 
                mapping->nrexceptional--;
-               if (!dax_mapping(mapping)) {
-                       if (shadowp)
-                               *shadowp = p;
-               } else {
-                       /* DAX can replace empty locked entry with a hole */
-                       WARN_ON_ONCE(p !=
-                               dax_radix_locked_entry(0, RADIX_DAX_EMPTY));
-                       /* Wakeup waiters for exceptional entry lock */
-                       dax_wake_mapping_entry_waiter(mapping, page->index, p,
-                                                     true);
-               }
+               if (shadowp)
+                       *shadowp = p;
        }
        __radix_tree_replace(&mapping->page_tree, node, slot, page,
                             workingset_update_node, mapping);
@@ -412,7 +403,7 @@ bool filemap_range_has_page(struct address_space *mapping,
                return false;
 
        pagevec_init(&pvec, 0);
-       if (!pagevec_lookup(&pvec, mapping, index, 1))
+       if (!pagevec_lookup(&pvec, mapping, &index, 1))
                return false;
        ret = (pvec.pages[0]->index <= end);
        pagevec_release(&pvec);
@@ -1566,23 +1557,29 @@ export:
 }
 
 /**
- * find_get_pages - gang pagecache lookup
+ * find_get_pages_range - gang pagecache lookup
  * @mapping:   The address_space to search
  * @start:     The starting page index
+ * @end:       The final page index (inclusive)
  * @nr_pages:  The maximum number of pages
  * @pages:     Where the resulting pages are placed
  *
- * find_get_pages() will search for and return a group of up to
- * @nr_pages pages in the mapping.  The pages are placed at @pages.
- * find_get_pages() takes a reference against the returned pages.
+ * find_get_pages_range() will search for and return a group of up to @nr_pages
+ * pages in the mapping starting at index @start and up to index @end
+ * (inclusive).  The pages are placed at @pages.  find_get_pages_range() takes
+ * a reference against the returned pages.
  *
  * The search returns a group of mapping-contiguous pages with ascending
  * indexes.  There may be holes in the indices due to not-present pages.
+ * We also update @start to index the next page for the traversal.
  *
- * find_get_pages() returns the number of pages which were found.
+ * find_get_pages_range() returns the number of pages which were found. If this
+ * number is smaller than @nr_pages, the end of specified range has been
+ * reached.
  */
-unsigned find_get_pages(struct address_space *mapping, pgoff_t start,
-                           unsigned int nr_pages, struct page **pages)
+unsigned find_get_pages_range(struct address_space *mapping, pgoff_t *start,
+                             pgoff_t end, unsigned int nr_pages,
+                             struct page **pages)
 {
        struct radix_tree_iter iter;
        void **slot;
@@ -1592,8 +1589,11 @@ unsigned find_get_pages(struct address_space *mapping, pgoff_t start,
                return 0;
 
        rcu_read_lock();
-       radix_tree_for_each_slot(slot, &mapping->page_tree, &iter, start) {
+       radix_tree_for_each_slot(slot, &mapping->page_tree, &iter, *start) {
                struct page *head, *page;
+
+               if (iter.index > end)
+                       break;
 repeat:
                page = radix_tree_deref_slot(slot);
                if (unlikely(!page))
@@ -1629,11 +1629,25 @@ repeat:
                }
 
                pages[ret] = page;
-               if (++ret == nr_pages)
-                       break;
+               if (++ret == nr_pages) {
+                       *start = pages[ret - 1]->index + 1;
+                       goto out;
+               }
        }
 
+       /*
+        * We come here when there is no page beyond @end. We take care to not
+        * overflow the index @start as it confuses some of the callers. This
+        * breaks the iteration when there is page at index -1 but that is
+        * already broken anyway.
+        */
+       if (end == (pgoff_t)-1)
+               *start = (pgoff_t)-1;
+       else
+               *start = end + 1;
+out:
        rcu_read_unlock();
+
        return ret;
 }