@@ -2324,6 +2324,17 @@ static struct page *filemap_create_page(struct file *file,
return ERR_PTR(error);
}
+static int filemap_readahead(struct kiocb *iocb, struct file *file,
+ struct address_space *mapping, struct page *page,
+ pgoff_t last_index)
+{
+ if (iocb->ki_flags & IOCB_NOIO)
+ return -EAGAIN;
+ page_cache_async_readahead(mapping, ra, filp, page,
+ pg_index, last_index - pg_index);
+ return 0;
+}
+
static int filemap_get_pages(struct kiocb *iocb, struct iov_iter *iter,
struct page **pages, unsigned int nr)
{
@@ -2368,23 +2379,14 @@ static int filemap_get_pages(struct kiocb *iocb, struct iov_iter *iter,
(loff_t) pg_index << PAGE_SHIFT);
loff_t pg_count = iocb->ki_pos + iter->count - pg_pos;
- if (PageReadahead(page)) {
- if (iocb->ki_flags & IOCB_NOIO) {
- put_page(page);
- nr_got--;
- err = -EAGAIN;
- goto err;
- }
- page_cache_async_readahead(mapping, ra, filp, page,
- pg_index, last_index - pg_index);
- }
-
- if (!PageUptodate(page)) {
+ if (PageReadahead(page))
+ err = filemap_readahead(iocb, filp, mapping, page,
+ last_index);
+ if (!err && !PageUptodate(page))
err = filemap_update_page(iocb, mapping, iter, page,
pg_pos, pg_count, nr_got == 1);
- if (err)
- nr_got--;
- }
+ if (err)
+ nr_got--;
}
err:
This simplifies the error handling. Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> --- mm/filemap.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-)