From patchwork Tue Nov 10 03:36:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 11893119 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E45E6697 for ; Tue, 10 Nov 2020 03:38:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8388821527 for ; Tue, 10 Nov 2020 03:37:34 +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="ZhVL+Sf9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8388821527 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 159396B0075; Mon, 9 Nov 2020 22:37:17 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0E3406B0074; Mon, 9 Nov 2020 22:37:17 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E9BE46B007D; Mon, 9 Nov 2020 22:37:16 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0093.hostedemail.com [216.40.44.93]) by kanga.kvack.org (Postfix) with ESMTP id B65596B0074 for ; Mon, 9 Nov 2020 22:37:16 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 5F9A2181AEF1A for ; Tue, 10 Nov 2020 03:37:16 +0000 (UTC) X-FDA: 77467098072.29.shelf30_150d39d272f1 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin29.hostedemail.com (Postfix) with ESMTP id 463CE18086CDD for ; Tue, 10 Nov 2020 03:37:16 +0000 (UTC) X-Spam-Summary: 1,0,0,d7f38391bebd3ccd,d41d8cd98f00b204,willy@infradead.org,,RULES_HIT:41:69:355:379:541:800:960:968:973:988:989:1260:1311:1314:1345:1359:1437:1515:1534:1542:1711:1730:1747:1777:1792:2198:2199:2393:2559:2562:2693:3138:3139:3140:3141:3142:3354:3865:3867:3870:3871:3874:5007:6261:6653:7514:10004:11026:11473:11658:11914:12043:12296:12297:12438:12555:12679:12683:12895:13894:14096:14110:14181:14394:14721:21080:21324:21451:21627:21939:21987:21990:30054,0,RBL:90.155.50.34:@infradead.org:.lbl8.mailshell.net-64.201.201.201 62.8.15.100;04yrbebc7cuxyte3h9ajg1rny7hcryp35aqd9ckt9nj88f83aed7om8r43ac1tm.tw5gymiz7kk4hwje94w79mdjig6uiwom8pettb5id9impuqex5fdjnazig9chea.g-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:72,LUA_SUMMARY:none X-HE-Tag: shelf30_150d39d272f1 X-Filterd-Recvd-Size: 4551 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf28.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 03:37:15 +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=QHs5v1YUXVPwXe5xLPhKJGU4nL7RPpQ66tQpFDSktyk=; b=ZhVL+Sf93+xtmAEFEcO++LSC/1 RDMbcAJb01vlxAK5e5QhAcNa6/lY2++fXF0F6ErXPRs2N/uBi3IGh006Ix3Jyx7fndTTUuAQ8qLKN awFQR0b9UVuh4ICLrBmlh/CZQBXFAXhcNzAA0O1wzdnUu1MdTNq35zcaGu2Jooh9jVPmN+jVe0F9S SU36qaZe6q4loORH8mIueLOuCvY9nnDa1AT5x9huLU2QbyY5ydOQO2fwTUWdLbMyRpaCCFGCekJNV OIuHW8HSi40R/vu4dS7t7+OcnNfe2VyzoeRd5KUD2l43ua9k0CZZKCCW4Rm5QeZdmzx6DVItaNvcP Jb2aXd9w==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcKT2-000662-Fi; Tue, 10 Nov 2020 03:37:12 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , hch@lst.de, kent.overstreet@gmail.com Subject: [PATCH v3 11/18] mm/filemap: Convert filemap_update_page to return an errno Date: Tue, 10 Nov 2020 03:36:56 +0000 Message-Id: <20201110033703.23261-12-willy@infradead.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20201110033703.23261-1-willy@infradead.org> References: <20201110033703.23261-1-willy@infradead.org> MIME-Version: 1.0 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: Use AOP_TRUNCATED_PAGE to indicate that no error occurred, but the page we looked up is no longer valid. In this case, the reference to the page will have been removed; if we hit any other error, the caller will release the reference. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Kent Overstreet Reviewed-by: Christoph Hellwig --- mm/filemap.c | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index ddc881c9d253..60ce7f15cc7e 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2231,24 +2231,21 @@ static int filemap_read_page(struct file *file, struct address_space *mapping, return error; } -static struct page *filemap_update_page(struct kiocb *iocb, struct file *filp, - struct iov_iter *iter, struct page *page, loff_t pos, - loff_t count) +static int filemap_update_page(struct kiocb *iocb, + struct address_space *mapping, struct iov_iter *iter, + struct page *page, loff_t pos, loff_t count) { - struct address_space *mapping = filp->f_mapping; struct inode *inode = mapping->host; int error; if (iocb->ki_flags & IOCB_WAITQ) { error = lock_page_async(page, iocb->ki_waitq); - if (error) { - put_page(page); - return ERR_PTR(error); - } + if (error) + return error; } else { if (!trylock_page(page)) { put_and_wait_on_page_locked(page, TASK_KILLABLE); - return NULL; + return AOP_TRUNCATED_PAGE; } } @@ -2267,25 +2264,21 @@ static struct page *filemap_update_page(struct kiocb *iocb, struct file *filp, goto readpage; uptodate: unlock_page(page); - return page; + return 0; readpage: if (iocb->ki_flags & (IOCB_NOIO | IOCB_NOWAIT | IOCB_WAITQ)) { unlock_page(page); - put_page(page); - return ERR_PTR(-EAGAIN); + return -EAGAIN; } error = filemap_read_page(iocb->ki_filp, mapping, page); - if (!error) - return page; - put_page(page); if (error == AOP_TRUNCATED_PAGE) - return NULL; - return ERR_PTR(error); + put_page(page); + return error; truncated: unlock_page(page); put_page(page); - return NULL; + return AOP_TRUNCATED_PAGE; } static int filemap_create_page(struct file *file, @@ -2379,11 +2372,12 @@ static int filemap_get_pages(struct kiocb *iocb, struct iov_iter *iter, goto err; } - page = filemap_update_page(iocb, filp, iter, page, + err = filemap_update_page(iocb, mapping, iter, page, pg_pos, pg_count); - if (IS_ERR_OR_NULL(page)) { + if (err) { + if (err < 0) + put_page(page); pvec->nr--; - err = PTR_ERR_OR_ZERO(page); } } } @@ -2391,6 +2385,8 @@ static int filemap_get_pages(struct kiocb *iocb, struct iov_iter *iter, err: if (likely(pvec->nr)) return 0; + if (err == AOP_TRUNCATED_PAGE) + goto find_page; if (err) return err; /*