From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8AB28C433E7 for ; Fri, 9 Oct 2020 14:31:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 34BF1222D9 for ; Fri, 9 Oct 2020 14:31:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="ekyZ0RqH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 34BF1222D9 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0525C6B0082; Fri, 9 Oct 2020 10:31:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7EBF86B0081; Fri, 9 Oct 2020 10:31:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4C6B56B0081; Fri, 9 Oct 2020 10:31:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0159.hostedemail.com [216.40.44.159]) by kanga.kvack.org (Postfix) with ESMTP id D5D6B6B0089 for ; Fri, 9 Oct 2020 10:31:15 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 5F7D8362A for ; Fri, 9 Oct 2020 14:31:15 +0000 (UTC) X-FDA: 77352624510.26.paint38_5c11b51271e1 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id 48B001804B65C for ; Fri, 9 Oct 2020 14:31:15 +0000 (UTC) X-HE-Tag: paint38_5c11b51271e1 X-Filterd-Recvd-Size: 6070 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf49.hostedemail.com (Postfix) with ESMTP for ; Fri, 9 Oct 2020 14:31:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=XENkUyBYEqQdDJViwbkj3PXnyvtkG9pwyINW5T48dY0=; b=ekyZ0RqHciHT6w0FRtBIb74RNP ATW28QGWmqsNnH/vLrqBZaFXuDhEx3ApS3w+jFzpx2X/taHl+6rpgUjut8ndwr5pqa+DLjv4Gx50+ 6+70qpWiZ3+++j70k/q90ALYSczVw6/4PCbVL3Y2U2L6Y23KLl4a3w8gd03srsRFuXNg/GmrWwXYN vTNgqiQtCBrX8BYOQuu/fsNDHXqjKDBLsVhD/vQ09kXf7CReTOSNh1XplEPkeYBls5zfzru3+gi4I EhS0MsH/dvccHF4LZQeeilzTBaCqLN8cLE90npHEUozqFLYE3kkEPktZ4a+EFwfYQ8aTrZOR6RQUm 0EdAxQ2A==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kQtQN-0005wc-Vg; Fri, 09 Oct 2020 14:31:12 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, v9fs-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org, linux-afs@lists.infradead.org, ceph-devel@vger.kernel.org, linux-cifs@vger.kernel.org, ecryptfs@vger.kernel.org, linux-um@lists.infradead.org, linux-mtd@lists.infradead.org, Richard Weinberger , linux-xfs@vger.kernel.org Subject: [PATCH v2 16/16] iomap: Make readpage synchronous Date: Fri, 9 Oct 2020 15:31:04 +0100 Message-Id: <20201009143104.22673-17-willy@infradead.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20201009143104.22673-1-willy@infradead.org> References: <20201009143104.22673-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: A synchronous readpage lets us report the actual errno instead of ineffectively setting PageError. Signed-off-by: Matthew Wilcox (Oracle) --- fs/iomap/buffered-io.c | 74 ++++++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 32 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index e60f572e1590..887bf871ca9b 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -150,9 +150,6 @@ static void iomap_set_range_uptodate(struct page *pag= e, unsigned off, unsigned last =3D (off + len - 1) >> inode->i_blkbits; unsigned long flags; =20 - if (PageError(page)) - return; - if (!iop) { SetPageUptodate(page); return; @@ -165,42 +162,50 @@ static void iomap_set_range_uptodate(struct page *p= age, unsigned off, spin_unlock_irqrestore(&iop->uptodate_lock, flags); } =20 -static void -iomap_read_page_end_io(struct bio_vec *bvec, int error) +static void iomap_read_page_end_io(struct bio_vec *bvec, + struct completion *done, bool error) { struct page *page =3D bvec->bv_page; struct iomap_page *iop =3D to_iomap_page(page); =20 - if (unlikely(error)) { - ClearPageUptodate(page); - SetPageError(page); - } else { + if (!error) iomap_set_range_uptodate(page, bvec->bv_offset, bvec->bv_len); - } =20 - if (!iop || atomic_sub_and_test(bvec->bv_len, &iop->read_bytes_pending)= ) - unlock_page(page); + if (!iop || + atomic_sub_and_test(bvec->bv_len, &iop->read_bytes_pending)) { + if (done) + complete(done); + else + unlock_page(page); + } } =20 +struct iomap_readpage_ctx { + struct page *cur_page; + bool cur_page_in_bio; + blk_status_t status; + struct bio *bio; + struct readahead_control *rac; + struct completion done; +}; + static void iomap_read_end_io(struct bio *bio) { - int error =3D blk_status_to_errno(bio->bi_status); + struct iomap_readpage_ctx *ctx =3D bio->bi_private; struct bio_vec *bvec; struct bvec_iter_all iter_all; =20 + /* Capture the first error */ + if (ctx && ctx->status =3D=3D BLK_STS_OK) + ctx->status =3D 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, ctx ? &ctx->done : NULL, + bio->bi_status !=3D BLK_STS_OK); bio_put(bio); } =20 -struct iomap_readpage_ctx { - struct page *cur_page; - bool cur_page_in_bio; - struct bio *bio; - struct readahead_control *rac; -}; - static void iomap_read_inline_data(struct inode *inode, struct page *page, struct iomap *iomap) @@ -292,6 +297,8 @@ iomap_readpage_actor(struct inode *inode, loff_t pos,= loff_t length, void *data, ctx->bio->bi_opf =3D REQ_OP_READ; if (ctx->rac) ctx->bio->bi_opf |=3D REQ_RAHEAD; + else + ctx->bio->bi_private =3D ctx; ctx->bio->bi_iter.bi_sector =3D sector; bio_set_dev(ctx->bio, iomap->bdev); ctx->bio->bi_end_io =3D iomap_read_end_io; @@ -318,15 +325,17 @@ iomap_readpage(struct page *page, const struct ioma= p_ops *ops) =20 trace_iomap_readpage(page->mapping->host, 1); =20 + ctx.status =3D BLK_STS_OK; + init_completion(&ctx.done); + for (poff =3D 0; poff < PAGE_SIZE; poff +=3D ret) { ret =3D iomap_apply(inode, page_offset(page) + poff, PAGE_SIZE - poff, 0, ops, &ctx, iomap_readpage_actor); - if (ret <=3D 0) { - WARN_ON_ONCE(ret =3D=3D 0); - SetPageError(page); + if (WARN_ON_ONCE(ret =3D=3D 0)) + ret =3D -EIO; + if (ret < 0) break; - } } =20 if (ctx.bio) { @@ -334,15 +343,16 @@ iomap_readpage(struct page *page, const struct ioma= p_ops *ops) WARN_ON_ONCE(!ctx.cur_page_in_bio); } else { WARN_ON_ONCE(ctx.cur_page_in_bio); - unlock_page(page); + complete(&ctx.done); } =20 - /* - * 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(&ctx.done); + if (ret >=3D 0) + ret =3D blk_status_to_errno(ctx.status); + if (ret =3D=3D 0) + return AOP_UPDATED_PAGE; + unlock_page(page); + return ret; } EXPORT_SYMBOL_GPL(iomap_readpage); =20 --=20 2.28.0