summaryrefslogtreecommitdiffstats
path: root/mm/filemap.c
diff options
context:
space:
mode:
authorMatthew Wilcox (Oracle) <willy@infradead.org>2021-02-24 12:02:35 -0800
committerLinus Torvalds <torvalds@linux-foundation.org>2021-02-24 13:38:28 -0800
commit2642fca647257210bf6127297748d472c22702cd (patch)
tree30362d96dc4ca6a279cdb3b47b9950caa516840c /mm/filemap.c
parent5963fe031638bb812c49ddf5adcdc783a57430f7 (diff)
downloadlinux-2642fca647257210bf6127297748d472c22702cd.tar.bz2
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.org Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Reviewed-by: Kent Overstreet <kent.overstreet@gmail.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Cc: Miaohe Lin <linmiaohe@huawei.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/filemap.c')
-rw-r--r--mm/filemap.c71
1 files changed, 28 insertions, 43 deletions
diff --git a/mm/filemap.c b/mm/filemap.c
index f8181beded38..3311b2af9061 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2349,70 +2349,55 @@ static int filemap_get_pages(struct kiocb *iocb, struct iov_iter *iter,
struct file_ra_state *ra = &filp->f_ra;
pgoff_t index = iocb->ki_pos >> PAGE_SHIFT;
pgoff_t last_index;
+ struct page *page;
int err = 0;
last_index = DIV_ROUND_UP(iocb->ki_pos + iter->count, PAGE_SIZE);
-find_page:
+retry:
if (fatal_signal_pending(current))
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);
+ 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 (iocb->ki_flags & (IOCB_NOWAIT | IOCB_WAITQ))
return -EAGAIN;
err = filemap_create_page(filp, mapping,
iocb->ki_pos >> PAGE_SHIFT, pvec);
if (err == AOP_TRUNCATED_PAGE)
- goto find_page;
+ goto retry;
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)) {
- if ((iocb->ki_flags & IOCB_WAITQ) &&
- pagevec_count(pvec) > 1)
- iocb->ki_flags |= IOCB_NOWAIT;
- err = filemap_update_page(iocb, mapping, iter, page);
- if (err) {
- if (err < 0)
- put_page(page);
- pvec->nr--;
- }
- }
+ page = pvec->pages[pagevec_count(pvec) - 1];
+ if (PageReadahead(page)) {
+ err = filemap_readahead(iocb, filp, mapping, page, last_index);
+ if (err)
+ goto err;
+ }
+ if (!PageUptodate(page)) {
+ if ((iocb->ki_flags & IOCB_WAITQ) && pagevec_count(pvec) > 1)
+ iocb->ki_flags |= IOCB_NOWAIT;
+ err = filemap_update_page(iocb, mapping, iter, page);
+ if (err)
+ goto err;
}
+ return 0;
err:
- if (likely(pvec->nr))
+ if (err < 0)
+ put_page(page);
+ if (likely(--pvec->nr))
return 0;
if (err == AOP_TRUNCATED_PAGE)
- goto find_page;
- if (err)
- return err;
- /*
- * No pages and no error means we raced and should retry:
- */
- goto find_page;
+ goto retry;
+ return err;
}
/**