]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/splice.c
[ALSA] usbusx2yaudio: kfree(NULL) is valid
[linux-2.6-omap-h63xx.git] / fs / splice.c
index 722449f7d5d6bdea920ee92635e6c6d30a296f07..22496d2a73fa1ab5efe6f663cfc1a92a9a316543 100644 (file)
@@ -265,7 +265,7 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
                           unsigned int flags)
 {
        struct address_space *mapping = in->f_mapping;
-       unsigned int loff, nr_pages;
+       unsigned int loff, nr_pages, req_pages;
        struct page *pages[PIPE_BUFFERS];
        struct partial_page partial[PIPE_BUFFERS];
        struct page *page;
@@ -281,22 +281,24 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
 
        index = *ppos >> PAGE_CACHE_SHIFT;
        loff = *ppos & ~PAGE_CACHE_MASK;
-       nr_pages = (len + loff + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
-
-       if (nr_pages > PIPE_BUFFERS)
-               nr_pages = PIPE_BUFFERS;
+       req_pages = (len + loff + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
+       nr_pages = min(req_pages, (unsigned)PIPE_BUFFERS);
 
        /*
         * Lookup the (hopefully) full range of pages we need.
         */
        spd.nr_pages = find_get_pages_contig(mapping, index, nr_pages, pages);
+       index += spd.nr_pages;
 
        /*
         * If find_get_pages_contig() returned fewer pages than we needed,
-        * allocate the rest and fill in the holes.
+        * readahead/allocate the rest and fill in the holes.
         */
+       if (spd.nr_pages < nr_pages)
+               page_cache_sync_readahead(mapping, &in->f_ra, in,
+                               index, req_pages - spd.nr_pages);
+
        error = 0;
-       index += spd.nr_pages;
        while (spd.nr_pages < nr_pages) {
                /*
                 * Page could be there, find_get_pages_contig() breaks on
@@ -304,9 +306,6 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
                 */
                page = find_get_page(mapping, index);
                if (!page) {
-                       page_cache_readahead_ondemand(mapping, &in->f_ra, in,
-                                       NULL, index, nr_pages - spd.nr_pages);
-
                        /*
                         * page didn't exist, allocate one.
                         */
@@ -353,8 +352,8 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
                page = pages[page_nr];
 
                if (PageReadahead(page))
-                       page_cache_readahead_ondemand(mapping, &in->f_ra, in,
-                                       page, index, nr_pages - page_nr);
+                       page_cache_async_readahead(mapping, &in->f_ra, in,
+                                       page, index, req_pages - page_nr);
 
                /*
                 * If the page isn't uptodate, we may need to start io on it