From patchwork Mon Jan 9 05:18:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 40662 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1984745wrt; Sun, 8 Jan 2023 21:19:10 -0800 (PST) X-Google-Smtp-Source: AMrXdXsNkU0MX0o5s3ByEa7IWoPsLCEXMPGvkKWiZc3fT+QOX7/N1xaejt2vgKc9ms3VJZzkJFgK X-Received: by 2002:a17:90b:2684:b0:227:203d:4d70 with SMTP id pl4-20020a17090b268400b00227203d4d70mr692246pjb.32.1673241550321; Sun, 08 Jan 2023 21:19:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673241550; cv=none; d=google.com; s=arc-20160816; b=oIvYNwE1reC9bjEjKsWz9lKtI2g1PyLOr1MFaC/z/HvDp0GrwGg2t7cAdW7RxX/0YX N1rjcr4aKmY2aeictAD0s5P5jsN61zzF78ryjMo+30UzF3BzkgAmqteeqWXCP3UEK6a6 X5Hnxi7adXF5npGBPTbg08oqNB1EOinLUQ5v/G+7FmqN71O+kWRsfY8Tfx8lE6aNAHiD oaEJoftVcFzdZaiGJgIwl/dOLsn5hZHtiMu3m4y0SF02YL5ENrAuLCWY6LWJNfDRpl0R iEG7oGJeaPrsSrvF+tc1JYiiDhBeKuA/qyGVXMeJir7Tn1Mk9cQ4+HhIm0dJhiz/eiXX GIYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=b0czJbVeNEC59VHM8B9sq3qAwimTZQLD9J+IkbH6tGY=; b=dvq7LgymG42SD84YdG2jXgxWzokfXsBxPg6DxnGwuMjXpLTQL5HYF6i9iIh5hdeGDq 24O//Sf1gC/GTMNRQKsiJuYvBa3gRgtN4bTciPXZq/QjCya0PD63+Ql/dWm3YjsXowTy NtBzOSKofQgcKUycaGEfjl1u7WtgsqjCZq8pktKriyBia9b66APqTFIvMnAinjzmNk+z +yLtLo8l6jdSPKy48edCUq8ePOZ77EZ+aIgUHxSF5LuS8MyaSyg3bfyaLSWCEqOQyhE+ P+CUdCH9P858gIIQVLOoIvSdV6KN0iblKBLATEKpz1jkfbkzvQfNmSXTDiYzTxZhkVxj hhvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=ROGJTN6U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v36-20020a634824000000b0047866258f1fsi8002756pga.321.2023.01.08.21.18.56; Sun, 08 Jan 2023 21:19:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=ROGJTN6U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231135AbjAIFSa (ORCPT + 99 others); Mon, 9 Jan 2023 00:18:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234167AbjAIFSS (ORCPT ); Mon, 9 Jan 2023 00:18:18 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D669CE17; Sun, 8 Jan 2023 21:18:15 -0800 (PST) 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=b0czJbVeNEC59VHM8B9sq3qAwimTZQLD9J+IkbH6tGY=; b=ROGJTN6UntJy+YzsThEJJrxCJi TtVnoQq6up+P0EtHyGjHt6GeNnEoNZZk5bvjdgDBnt5U65teg3i0Q/vxeBhKrad0sQs5iCaUJ9aai hCoVJCKYxDMlWwNLtSUIdhPNwVYFZp7rjLsp1+yMFDTlOZEtR/uM5wKsrSTfHHqwDseBTLtSg1DqX 9fj9xRKQeflkeQLrCnDNMoea62skAbanZyCf2l5+xZAyzuXC4pRHywBj+sm5Z1MGsJ/DbzLeUgH2w RCVS9uE/Mi1NxFEeqnCNUT4mhbmgSj9IAKRM104Ix+jlmWWqNram/pb4oU6K2cN5Lppll1ajraNhZ 0ddXvYzQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pEkYD-0020x5-JH; Mon, 09 Jan 2023 05:18:25 +0000 From: "Matthew Wilcox (Oracle)" Cc: "Matthew Wilcox (Oracle)" , Jeff Layton , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Christoph Hellwig Subject: [PATCH 06/11] filemap: Convert filemap_write_and_wait_range() to use errseq Date: Mon, 9 Jan 2023 05:18:18 +0000 Message-Id: <20230109051823.480289-7-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230109051823.480289-1-willy@infradead.org> References: <20230109051823.480289-1-willy@infradead.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754520931715409190?= X-GMAIL-MSGID: =?utf-8?q?1754520931715409190?= Use the errseq APIs to discover writeback errors instead of filemap_check_errors(). This gives us more precise information about whether this writeback generated the error. This will no longer clear errors, so they will be visible to other users, which is what we want. Take this opportunity to de-indent filemap_write_and_wait_range(). Signed-off-by: Matthew Wilcox (Oracle) --- mm/filemap.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 48daedc224d9..c72b2e1140d7 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -659,26 +659,27 @@ EXPORT_SYMBOL_GPL(filemap_range_has_writeback); int filemap_write_and_wait_range(struct address_space *mapping, loff_t lstart, loff_t lend) { - int err = 0, err2; + int err; + errseq_t since; if (lend < lstart) return 0; + if (!mapping_needs_writeback(mapping)) + return 0; - if (mapping_needs_writeback(mapping)) { - err = __filemap_fdatawrite_range(mapping, lstart, lend, - WB_SYNC_ALL); - /* - * Even if the above returned error, the pages may be - * written partially (e.g. -ENOSPC), so we wait for it. - * But the -EIO is special case, it may indicate the worst - * thing (e.g. bug) happened, so we avoid waiting for it. - */ - if (err != -EIO) - __filemap_fdatawait_range(mapping, lstart, lend); - } - err2 = filemap_check_errors(mapping); + since = filemap_sample_wb_err(mapping); + err = __filemap_fdatawrite_range(mapping, lstart, lend, WB_SYNC_ALL); + /* + * Even if the above returned an error, the pages may be written + * partially (e.g. -ENOSPC), so we wait for it. But the -EIO + * is a special case, it may indicate the worst thing (e.g. bug) + * happened, so we avoid waiting for it. + */ + if (err != -EIO) + __filemap_fdatawait_range(mapping, lstart, lend); if (!err) - err = err2; + err = filemap_check_wb_err(mapping, since); + return err; } EXPORT_SYMBOL(filemap_write_and_wait_range);