Commit 2642fca6 authored by Matthew Wilcox (Oracle)'s avatar Matthew Wilcox (Oracle) Committed by Linus Torvalds

mm/filemap: restructure filemap_get_pages

Remove the got_pages label, remove indentation, rename find_page to retry,
simplify error handling.

Link: https://lkml.kernel.org/r/20210122160140.223228-16-willy@infradead.orgSigned-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Cc: Miaohe Lin <linmiaohe@huawei.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 5963fe03
...@@ -2349,70 +2349,55 @@ static int filemap_get_pages(struct kiocb *iocb, struct iov_iter *iter, ...@@ -2349,70 +2349,55 @@ static int filemap_get_pages(struct kiocb *iocb, struct iov_iter *iter,
struct file_ra_state *ra = &filp->f_ra; struct file_ra_state *ra = &filp->f_ra;
pgoff_t index = iocb->ki_pos >> PAGE_SHIFT; pgoff_t index = iocb->ki_pos >> PAGE_SHIFT;
pgoff_t last_index; pgoff_t last_index;
struct page *page;
int err = 0; int err = 0;
last_index = DIV_ROUND_UP(iocb->ki_pos + iter->count, PAGE_SIZE); last_index = DIV_ROUND_UP(iocb->ki_pos + iter->count, PAGE_SIZE);
find_page: retry:
if (fatal_signal_pending(current)) if (fatal_signal_pending(current))
return -EINTR; return -EINTR;
filemap_get_read_batch(mapping, index, last_index, pvec);
if (pvec->nr)
goto got_pages;
if (iocb->ki_flags & IOCB_NOIO)
return -EAGAIN;
page_cache_sync_readahead(mapping, ra, filp, index, last_index - index);
filemap_get_read_batch(mapping, index, last_index, pvec); filemap_get_read_batch(mapping, index, last_index, pvec);
if (!pagevec_count(pvec)) {
if (iocb->ki_flags & IOCB_NOIO)
return -EAGAIN;
page_cache_sync_readahead(mapping, ra, filp, index,
last_index - index);
filemap_get_read_batch(mapping, index, last_index, pvec);
}
if (!pagevec_count(pvec)) { if (!pagevec_count(pvec)) {
if (iocb->ki_flags & (IOCB_NOWAIT | IOCB_WAITQ)) if (iocb->ki_flags & (IOCB_NOWAIT | IOCB_WAITQ))
return -EAGAIN; return -EAGAIN;
err = filemap_create_page(filp, mapping, err = filemap_create_page(filp, mapping,
iocb->ki_pos >> PAGE_SHIFT, pvec); iocb->ki_pos >> PAGE_SHIFT, pvec);
if (err == AOP_TRUNCATED_PAGE) if (err == AOP_TRUNCATED_PAGE)
goto find_page; goto retry;
return err; return err;
} }
got_pages:
{
struct page *page = pvec->pages[pvec->nr - 1];
if (PageReadahead(page)) {
err = filemap_readahead(iocb, filp, mapping, page,
last_index);
if (err) {
put_page(page);
pvec->nr--;
goto err;
}
}
if (!PageUptodate(page)) { page = pvec->pages[pagevec_count(pvec) - 1];
if ((iocb->ki_flags & IOCB_WAITQ) && if (PageReadahead(page)) {
pagevec_count(pvec) > 1) err = filemap_readahead(iocb, filp, mapping, page, last_index);
iocb->ki_flags |= IOCB_NOWAIT; if (err)
err = filemap_update_page(iocb, mapping, iter, page); goto err;
if (err) { }
if (err < 0) if (!PageUptodate(page)) {
put_page(page); if ((iocb->ki_flags & IOCB_WAITQ) && pagevec_count(pvec) > 1)
pvec->nr--; iocb->ki_flags |= IOCB_NOWAIT;
} err = filemap_update_page(iocb, mapping, iter, page);
} if (err)
goto err;
} }
return 0;
err: err:
if (likely(pvec->nr)) if (err < 0)
put_page(page);
if (likely(--pvec->nr))
return 0; return 0;
if (err == AOP_TRUNCATED_PAGE) if (err == AOP_TRUNCATED_PAGE)
goto find_page; goto retry;
if (err) return err;
return err;
/*
* No pages and no error means we raced and should retry:
*/
goto find_page;
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment