]> www.infradead.org Git - users/hch/block.git/commitdiff
mm: lift the nowait checks into generic_file_buffered_read_pagenotuptodate
authorChristoph Hellwig <hch@lst.de>
Fri, 30 Oct 2020 15:15:09 +0000 (16:15 +0100)
committerChristoph Hellwig <hch@lst.de>
Fri, 30 Oct 2020 15:38:11 +0000 (16:38 +0100)
Move the checks for IOCB_NOWAIT and IOCB_WAITQ from the only caller into
generic_file_buffered_read_pagenotuptodate, which simplifies the error
unwinding.

Signed-off-by: Christoph Hellwig <hch@lst.de>
mm/filemap.c

index 332f3a6781addcfbc98bebb01ad32ab67984f5eb..934ed93b1fb32523a0cb27d17411d1134b562487 100644 (file)
@@ -2219,19 +2219,22 @@ out_put_page:
 
 static int generic_file_buffered_read_pagenotuptodate(struct kiocb *iocb,
                struct iov_iter *iter, struct page *page, loff_t pos,
-               loff_t count)
+               loff_t count, bool first)
 {
        struct address_space *mapping = iocb->ki_filp->f_mapping;
-       int error;
+       int error = -EAGAIN;
+
+       if (iocb->ki_flags & IOCB_NOWAIT)
+               goto put_page;
 
        /*
-        * See comment in do_read_cache_page on why
-        * wait_on_page_locked is used to avoid unnecessarily
-        * serialisations and why it's safe.
+        * See comment in do_read_cache_page on why wait_on_page_locked is used
+        * to avoid unnecessarily serialisations and why it's safe.
         */
        if (iocb->ki_flags & IOCB_WAITQ) {
-               error = wait_on_page_locked_async(page,
-                                               iocb->ki_waitq);
+               if (!first)
+                       goto put_page;
+               error = wait_on_page_locked_async(page, iocb->ki_waitq);
        } else {
                error = wait_on_page_locked_killable(page);
        }
@@ -2376,17 +2379,8 @@ got_pages:
                }
 
                if (!PageUptodate(page)) {
-                       if ((iocb->ki_flags & IOCB_NOWAIT) ||
-                           ((iocb->ki_flags & IOCB_WAITQ) && i)) {
-                               for (j = i; j < nr_got; j++)
-                                       put_page(pages[j]);
-                               nr_got = i;
-                               err = -EAGAIN;
-                               break;
-                       }
-
                        err = generic_file_buffered_read_pagenotuptodate(iocb,
-                                       iter, page, pg_pos, pg_count);
+                                       iter, page, pg_pos, pg_count, i == 0);
                        if (err) {
                                if (err == AOP_TRUNCATED_PAGE)
                                        err = 0;