All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Kent Overstreet <kent.overstreet@gmail.com>,
	Matthew Wilcox <willy@infradead.org>,
	linux-mm@kvack.org, linux-fsdevel@vger.kernel.org
Subject: [PATCH 01/13] mm: simplify generic_file_buffered_read_readpage
Date: Sat, 31 Oct 2020 09:59:52 +0100	[thread overview]
Message-ID: <20201031090004.452516-2-hch@lst.de> (raw)
In-Reply-To: <20201031090004.452516-1-hch@lst.de>

Stop passing pointless arguments, and return an int instead of a page
struct that contains either the passed in page, an ERR_PTR or NULL and
use goto labels to share common code.  Also rename the function to
filemap_readpage as it is a fairly generic wrapper around ->readpage
that isn't really specific to generic_file_buffered_read.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 mm/filemap.c | 66 ++++++++++++++++++++++++++++------------------------
 1 file changed, 36 insertions(+), 30 deletions(-)

diff --git a/mm/filemap.c b/mm/filemap.c
index d90614f501daa5..2e997890cc81c2 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2168,59 +2168,53 @@ static int lock_page_for_iocb(struct kiocb *iocb, struct page *page)
 		return lock_page_killable(page);
 }
 
-static struct page *
-generic_file_buffered_read_readpage(struct kiocb *iocb,
-				    struct file *filp,
-				    struct address_space *mapping,
-				    struct page *page)
+static int filemap_readpage(struct kiocb *iocb, struct page *page)
 {
-	struct file_ra_state *ra = &filp->f_ra;
-	int error;
+	struct file *file = iocb->ki_filp;
+	int error = -EAGAIN;
 
 	if (iocb->ki_flags & (IOCB_NOIO | IOCB_NOWAIT)) {
 		unlock_page(page);
-		put_page(page);
-		return ERR_PTR(-EAGAIN);
+		goto out_put_page;
 	}
 
 	/*
-	 * A previous I/O error may have been due to temporary
-	 * failures, eg. multipath errors.
-	 * PG_error will be set again if readpage fails.
+	 * A previous I/O error may have been due to temporary failures, e.g.
+	 * multipath errors.  PG_error will be set again if readpage fails.
 	 */
 	ClearPageError(page);
 	/* Start the actual read. The read will unlock the page. */
-	error = mapping->a_ops->readpage(filp, page);
-
-	if (unlikely(error)) {
-		put_page(page);
-		return error != AOP_TRUNCATED_PAGE ? ERR_PTR(error) : NULL;
-	}
+	error = file->f_mapping->a_ops->readpage(file, page);
+	if (unlikely(error))
+		goto out_put_page;
 
 	if (!PageUptodate(page)) {
 		error = lock_page_for_iocb(iocb, page);
-		if (unlikely(error)) {
-			put_page(page);
-			return ERR_PTR(error);
-		}
+		if (unlikely(error))
+			goto out_put_page;
+
 		if (!PageUptodate(page)) {
 			if (page->mapping == NULL) {
 				/*
 				 * invalidate_mapping_pages got it
 				 */
 				unlock_page(page);
-				put_page(page);
-				return NULL;
+				error = AOP_TRUNCATED_PAGE;
+				goto out_put_page;
 			}
 			unlock_page(page);
-			shrink_readahead_size_eio(ra);
-			put_page(page);
-			return ERR_PTR(-EIO);
+			shrink_readahead_size_eio(&file->f_ra);
+			error = -EIO;
+			goto out_put_page;
 		}
+
 		unlock_page(page);
 	}
+	return 0;
 
-	return page;
+out_put_page:
+	put_page(page);
+	return error;
 }
 
 static struct page *
@@ -2291,7 +2285,13 @@ generic_file_buffered_read_pagenotuptodate(struct kiocb *iocb,
 		return page;
 	}
 
-	return generic_file_buffered_read_readpage(iocb, filp, mapping, page);
+	error = filemap_readpage(iocb, page);
+	if (error) {
+		if (error == AOP_TRUNCATED_PAGE)
+			return NULL;
+		return ERR_PTR(error);
+	}
+	return page;
 }
 
 static struct page *
@@ -2322,7 +2322,13 @@ generic_file_buffered_read_no_cached_page(struct kiocb *iocb,
 		return error != -EEXIST ? ERR_PTR(error) : NULL;
 	}
 
-	return generic_file_buffered_read_readpage(iocb, filp, mapping, page);
+	error = filemap_readpage(iocb, page);
+	if (error) {
+		if (error == AOP_TRUNCATED_PAGE)
+			return NULL;
+		return ERR_PTR(error);
+	}
+	return page;
 }
 
 static int generic_file_buffered_read_get_pages(struct kiocb *iocb,
-- 
2.28.0


  reply	other threads:[~2020-10-31  9:04 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-31  8:59 clean up the generic pagecache read helpers Christoph Hellwig
2020-10-31  8:59 ` Christoph Hellwig [this message]
2020-10-31  8:59 ` [PATCH 02/13] mm: simplify generic_file_buffered_read_pagenotuptodate Christoph Hellwig
2020-10-31  8:59 ` [PATCH 03/13] mm: lift the nowait checks into generic_file_buffered_read_pagenotuptodate Christoph Hellwig
2020-10-31  8:59 ` [PATCH 04/13] mm: handle readahead in generic_file_buffered_read_pagenotuptodate Christoph Hellwig
2020-10-31 17:06   ` Matthew Wilcox
2020-11-01 10:31     ` Christoph Hellwig
2020-11-01 10:49       ` Matthew Wilcox
2020-11-01 10:51         ` Christoph Hellwig
2020-11-01 10:51           ` Christoph Hellwig
2020-11-01 11:04             ` Matthew Wilcox
2020-11-01 11:52               ` Christoph Hellwig
2020-11-01 14:55                 ` Matthew Wilcox
2020-11-02  8:18                   ` Christoph Hellwig
2020-10-31  8:59 ` [PATCH 05/13] mm: simplify generic_file_buffered_read_no_cached_page Christoph Hellwig
2020-10-31 16:20   ` Matthew Wilcox
2020-10-31 16:28   ` Matthew Wilcox
2020-11-01 10:29     ` Christoph Hellwig
2020-10-31  8:59 ` [PATCH 06/13] mm: factor out a filemap_find_get_pages helper Christoph Hellwig
2020-10-31  8:59 ` [PATCH 07/13] mm: refactor generic_file_buffered_read_get_pages Christoph Hellwig
2020-11-01 11:18   ` Matthew Wilcox
2020-10-31  8:59 ` [PATCH 08/13] mm: move putting the page on error out of filemap_readpage Christoph Hellwig
2020-10-31  9:00 ` [PATCH 09/13] mm: move putting the page on error out of filemap_make_page_uptodate Christoph Hellwig
2020-10-31  9:00 ` [PATCH 10/13] mm: open code readahead in filemap_new_page Christoph Hellwig
2020-11-01 11:20   ` Matthew Wilcox
2020-10-31  9:00 ` [PATCH 11/13] mm: streamline the partially uptodate checks in filemap_make_page_uptodate Christoph Hellwig
2020-11-01 11:23   ` Matthew Wilcox
2020-10-31  9:00 ` [PATCH 12/13] mm: rename generic_file_buffered_read to filemap_read Christoph Hellwig
2020-10-31  9:00 ` [PATCH 13/13] mm: simplify generic_file_read_iter Christoph Hellwig
2020-10-31 15:42 ` clean up the generic pagecache read helpers Matthew Wilcox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201031090004.452516-2-hch@lst.de \
    --to=hch@lst.de \
    --cc=akpm@linux-foundation.org \
    --cc=kent.overstreet@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.