From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
To: linux-fsdevel@vger.kernel.org
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
linux-xfs@vger.kernel.org
Subject: [PATCH 16/13] iomap: Make readpage synchronous
Date: Thu, 17 Sep 2020 23:56:47 +0100 [thread overview]
Message-ID: <20200917225647.26481-3-willy@infradead.org> (raw)
In-Reply-To: <20200917225647.26481-1-willy@infradead.org>
A synchronous readpage lets us report the actual errno instead of
ineffectively setting PageError.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
fs/iomap/buffered-io.c | 64 +++++++++++++++++++++++++-----------------
1 file changed, 38 insertions(+), 26 deletions(-)
diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index 13b56d656337..aec95996bd4b 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -146,9 +146,6 @@ void iomap_set_range_uptodate(struct page *page, unsigned off, unsigned len)
unsigned long flags;
unsigned int i;
- if (PageError(page))
- return;
-
if (!iop) {
SetPageUptodate(page);
return;
@@ -167,32 +164,41 @@ void iomap_set_range_uptodate(struct page *page, unsigned off, unsigned len)
spin_unlock_irqrestore(&iop->uptodate_lock, flags);
}
-static void
-iomap_read_page_end_io(struct bio_vec *bvec, int error)
+struct iomap_sync_end {
+ blk_status_t status;
+ struct completion done;
+};
+
+static void iomap_read_page_end_io(struct bio_vec *bvec,
+ struct iomap_sync_end *end, bool error)
{
struct page *page = bvec->bv_page;
struct iomap_page *iop = to_iomap_page(page);
- if (unlikely(error)) {
- ClearPageUptodate(page);
- SetPageError(page);
- } else {
+ if (!error)
iomap_set_range_uptodate(page, bvec->bv_offset, bvec->bv_len);
- }
- if (!iop || atomic_dec_and_test(&iop->read_count))
- unlock_page(page);
+ if (!iop || atomic_dec_and_test(&iop->read_count)) {
+ if (end)
+ complete(&end->done);
+ else
+ unlock_page(page);
+ }
}
static void
iomap_read_end_io(struct bio *bio)
{
- int error = blk_status_to_errno(bio->bi_status);
+ struct iomap_sync_end *end = bio->bi_private;
struct bio_vec *bvec;
struct bvec_iter_all iter_all;
+ /* Capture the first error */
+ if (end && end->status == BLK_STS_OK)
+ end->status = bio->bi_status;
+
bio_for_each_segment_all(bvec, bio, iter_all)
- iomap_read_page_end_io(bvec, error);
+ iomap_read_page_end_io(bvec, end, bio->bi_status != BLK_STS_OK);
bio_put(bio);
}
@@ -201,6 +207,7 @@ struct iomap_readpage_ctx {
bool cur_page_in_bio;
struct bio *bio;
struct readahead_control *rac;
+ struct iomap_sync_end *end;
};
static void
@@ -307,6 +314,7 @@ iomap_readpage_actor(struct inode *inode, loff_t pos, loff_t length, void *data,
ctx->bio->bi_opf |= REQ_RAHEAD;
ctx->bio->bi_iter.bi_sector = sector;
bio_set_dev(ctx->bio, iomap->bdev);
+ ctx->bio->bi_private = ctx->end;
ctx->bio->bi_end_io = iomap_read_end_io;
}
@@ -324,22 +332,25 @@ iomap_readpage_actor(struct inode *inode, loff_t pos, loff_t length, void *data,
int
iomap_readpage(struct page *page, const struct iomap_ops *ops)
{
- struct iomap_readpage_ctx ctx = { .cur_page = page };
+ struct iomap_sync_end end;
+ struct iomap_readpage_ctx ctx = { .cur_page = page, .end = &end, };
struct inode *inode = page->mapping->host;
unsigned poff;
loff_t ret;
trace_iomap_readpage(page->mapping->host, 1);
+ end.status = BLK_STS_OK;
+ init_completion(&end.done);
+
for (poff = 0; poff < PAGE_SIZE; poff += ret) {
ret = iomap_apply(inode, page_offset(page) + poff,
PAGE_SIZE - poff, 0, ops, &ctx,
iomap_readpage_actor);
- if (ret <= 0) {
- WARN_ON_ONCE(ret == 0);
- SetPageError(page);
+ if (WARN_ON_ONCE(ret == 0))
+ ret = -EIO;
+ if (ret < 0)
break;
- }
}
if (ctx.bio) {
@@ -347,15 +358,16 @@ iomap_readpage(struct page *page, const struct iomap_ops *ops)
WARN_ON_ONCE(!ctx.cur_page_in_bio);
} else {
WARN_ON_ONCE(ctx.cur_page_in_bio);
- unlock_page(page);
+ complete(&end.done);
}
- /*
- * Just like mpage_readahead and block_read_full_page we always
- * return 0 and just mark the page as PageError on errors. This
- * should be cleaned up all through the stack eventually.
- */
- return 0;
+ wait_for_completion(&end.done);
+ if (ret >= 0)
+ ret = blk_status_to_errno(end.status);
+ if (ret == 0)
+ return AOP_UPDATED_PAGE;
+ unlock_page(page);
+ return ret;
}
EXPORT_SYMBOL_GPL(iomap_readpage);
--
2.28.0
next prev parent reply other threads:[~2020-09-17 22:56 UTC|newest]
Thread overview: 73+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-17 15:10 [PATCH 00/13] Allow readpage to return a locked page Matthew Wilcox (Oracle)
2020-09-17 15:10 ` Matthew Wilcox (Oracle)
2020-09-17 15:10 ` Matthew Wilcox (Oracle)
2020-09-17 15:10 ` [PATCH 01/13] mm: Add AOP_UPDATED_PAGE return value Matthew Wilcox (Oracle)
2020-09-17 15:10 ` Matthew Wilcox (Oracle)
2020-09-17 15:10 ` Matthew Wilcox (Oracle)
2020-09-17 22:03 ` Matthew Wilcox
2020-09-17 22:03 ` Matthew Wilcox
2020-09-17 22:03 ` Matthew Wilcox
2020-09-17 15:10 ` [PATCH 02/13] 9p: Tell the VFS that readpage was synchronous Matthew Wilcox (Oracle)
2020-09-17 15:10 ` Matthew Wilcox (Oracle)
2020-09-17 15:10 ` Matthew Wilcox (Oracle)
2020-09-18 5:59 ` [V9fs-developer] " Dominique Martinet
2020-09-18 5:59 ` Dominique Martinet
2020-09-18 5:59 ` Dominique Martinet
2020-09-18 11:19 ` Matthew Wilcox
2020-09-18 11:19 ` Matthew Wilcox
2020-09-18 11:19 ` Matthew Wilcox
2020-09-18 12:30 ` Dominique Martinet
2020-09-18 12:30 ` Dominique Martinet
2020-09-18 12:30 ` Dominique Martinet
2020-09-17 15:10 ` [PATCH 03/13] afs: " Matthew Wilcox (Oracle)
2020-09-17 15:10 ` Matthew Wilcox (Oracle)
2020-09-17 15:10 ` Matthew Wilcox (Oracle)
2020-09-17 15:10 ` [PATCH 04/13] ceph: " Matthew Wilcox (Oracle)
2020-09-17 15:10 ` Matthew Wilcox (Oracle)
2020-09-17 15:10 ` Matthew Wilcox (Oracle)
2020-09-17 16:49 ` Jeff Layton
2020-09-17 16:49 ` Jeff Layton
2020-09-17 16:49 ` Jeff Layton
2020-09-17 15:10 ` [PATCH 05/13] cifs: " Matthew Wilcox (Oracle)
2020-09-17 15:10 ` Matthew Wilcox (Oracle)
2020-09-17 15:10 ` Matthew Wilcox (Oracle)
2020-09-17 15:10 ` [PATCH 06/13] cramfs: " Matthew Wilcox (Oracle)
2020-09-17 15:10 ` Matthew Wilcox (Oracle)
2020-09-17 15:10 ` Matthew Wilcox (Oracle)
2020-09-17 15:10 ` [PATCH 07/13] ecryptfs: " Matthew Wilcox (Oracle)
2020-09-17 15:10 ` Matthew Wilcox (Oracle)
2020-09-17 15:10 ` Matthew Wilcox (Oracle)
2020-09-17 15:10 ` [PATCH 08/13] fuse: " Matthew Wilcox (Oracle)
2020-09-17 15:10 ` Matthew Wilcox (Oracle)
2020-09-17 15:10 ` Matthew Wilcox (Oracle)
2020-09-17 15:10 ` [PATCH 09/13] hostfs: " Matthew Wilcox (Oracle)
2020-09-17 15:10 ` Matthew Wilcox (Oracle)
2020-09-17 15:10 ` Matthew Wilcox (Oracle)
2020-09-17 15:10 ` [PATCH 10/13] jffs2: " Matthew Wilcox (Oracle)
2020-09-17 15:10 ` Matthew Wilcox (Oracle)
2020-09-17 15:10 ` Matthew Wilcox (Oracle)
2020-09-17 15:10 ` [PATCH 11/13] ubifs: " Matthew Wilcox (Oracle)
2020-09-17 15:10 ` Matthew Wilcox (Oracle)
2020-09-17 15:10 ` Matthew Wilcox (Oracle)
2020-09-17 20:46 ` Richard Weinberger
2020-09-17 20:46 ` Richard Weinberger
2020-09-17 20:46 ` Richard Weinberger
2020-09-17 20:46 ` Richard Weinberger
2020-09-17 15:10 ` [PATCH 12/13] udf: " Matthew Wilcox (Oracle)
2020-09-17 15:10 ` Matthew Wilcox (Oracle)
2020-09-17 15:10 ` Matthew Wilcox (Oracle)
2020-09-24 9:00 ` Jan Kara
2020-09-24 9:00 ` Jan Kara
2020-09-24 9:00 ` Jan Kara
2020-09-17 15:10 ` [PATCH 13/13] vboxsf: " Matthew Wilcox (Oracle)
2020-09-17 15:10 ` Matthew Wilcox (Oracle)
2020-09-17 15:10 ` Matthew Wilcox (Oracle)
2020-09-17 22:56 ` [PATCH 14/13] iomap: Inline iomap_iop_set_range_uptodate into its one caller Matthew Wilcox (Oracle)
2020-09-17 22:56 ` [PATCH 15/13] iomap: Inline iomap_read_finish " Matthew Wilcox (Oracle)
2020-09-19 6:31 ` Christoph Hellwig
2020-09-17 22:56 ` Matthew Wilcox (Oracle) [this message]
2020-09-19 6:39 ` [PATCH 16/13] iomap: Make readpage synchronous Christoph Hellwig
2020-09-19 6:43 ` Christoph Hellwig
2020-09-19 17:03 ` Matthew Wilcox
2020-09-19 17:10 ` Matthew Wilcox
2020-09-19 6:31 ` [PATCH 14/13] iomap: Inline iomap_iop_set_range_uptodate into its one caller Christoph Hellwig
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=20200917225647.26481-3-willy@infradead.org \
--to=willy@infradead.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.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.