From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-vk1-f180.google.com (mail-vk1-f180.google.com [209.85.221.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CEF144908B2 for ; Thu, 6 Aug 2026 17:00:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786035616; cv=none; b=oDoW1pZ3wJlc1NhmL5MPiQ2/tZ57dzURDpN6NpnTWhkzkCxjNkytBgh/7PFMOxqBSYRyvAB26kzFDAfyR+E5pM8OZF+njgXNfepV8ix8EGJRzrnmckRWTvdMc8DJKoEJfU8fEze+DY+Kn14b9r//GiIJnatQoAMhngVgQ3NEqNE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786035616; c=relaxed/simple; bh=K9/W1FO8N8xTnhyFws4RenGjtbgDOPBPnEUZbmmiB0U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IVD4KfQMNLIgR3OiiX5VeGUd964b1gSLzHJnJmUhUaGuQtip7QYojNiqKQkzpypPq/DM0z7DzVxFucx76T3O6iUSkxzxhK/ZQXEj3+bpbGwTiUzQj6W+iHtZushr2O9paL7VWibZzUDKJKK1+AQqFtCcwHZ1tDXJh64lvo57QsU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=DYMymKr9; arc=none smtp.client-ip=209.85.221.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DYMymKr9" Received: by mail-vk1-f180.google.com with SMTP id 71dfb90a1353d-5bfa6766cf6so1277773e0c.3 for ; Thu, 06 Aug 2026 10:00:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786035613; x=1786640413; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=dBfFE9yENSRT1Ltqp2iNdGevVOH72zBv0XCWLRoCCcc=; b=DYMymKr9iJ0MfWNFmHTMcDp+vfbmJcVQ4S81aC4XPOGI5fJYig+5tGL9yuQ7IjHb4J 5fjgTj8DJ/MP2ApXWr5CxtfH/jEotJgLkxPkTflbko7TdRb/yUmI1lZlVCGtpN3mG86k GsKAHGU84ajwLE1ch2hnLPfL66yAj44ebPDrkLC3IBGK+BEzh9HiS8kuotGS58UNR6Ff 8f/3fcEDC9jjcRSwGDq3fqLEVNyjKQNdllgRt5DjatQ6RDeoLfb+VS3S0TVmD74Ye+OZ vUW/74/GKVa/mnu6Gv8OV7cbDAWDVC03WSNg98YruRvqahYi/g3Lg6Pbj52sND835+Tp u6MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786035613; x=1786640413; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=dBfFE9yENSRT1Ltqp2iNdGevVOH72zBv0XCWLRoCCcc=; b=ll89SzBj+XHbmq+NbFGeKFfesLnAOEyFmKH+dnPVcJKE0/SJ1Q0emfRJO9frNoqpk5 0c1nLsqjr0EtFWZ46ZINEckvb+mv1o8I4NZxPei4akgLG4IX4+TSiAythbwpr6vz2WOp y6TFfzgtJgSPQitppHFQhBBVFDZeD1f8+YSLBCnLU+dRpqbE++yTLjP2EVHCa9uoPYdM mF1sfAGwj09/SkqlzzHc9TEjFTH16spHGHgOJDX5GwAmwvLpWUwc9fOkMosGjC6z/rmi 3z6lyI+36yQcJI4DI1DNwYlNANs/uhC7dtMQtF5X5QJudtpEMukhPdjsZ601qG0XpzRR n/Sw== X-Forwarded-Encrypted: i=1; AHgh+RqRT4QmdtEH5y49PH05+lEynwN7hzHhff6hBAJ2uuaLM/eo28IkSZ71D1m6wyUzB+q0CdU6iaNUZ+I5z8Y=@vger.kernel.org X-Gm-Message-State: AOJu0YzTsePFfm+EMYSou3xcslbDR/s/kK6FU3Z43FGWSk7Hdx+CU8iD O7kJpJe593XVLdst3tqBUoWVTnkNJ0xa5WEU96WA3BGmienFa9F6ttSr X-Gm-Gg: AR+sD12MLEntTZQF3P1fqkz4hwbZuyzeIkblrU8COOvX5/ClJmaycEcx3Pic8wwk0k5 cjEUVGB/IJ1+i0FSyxE9FMn3h0IvQilxQWYqGT2dRgnRE1WE2zX4iVC4JOkK5Yc6UgC0OKD1gig rwVMhXDOWIGpgk+2oDp0yZkCPHfyKJlv3qmgyby/oFXRBZJdQ1JxetEG3eR3Vttu8RLwJ/YkfXJ ykWJCaiQTaEB7yXXy2n7wyggaJYSofh8pigLmba09F+zg5uOr4gUUR4XXC9f6gyrDxrJ/SIYDqb CWKVYeDpKu+4hzhX7KPdtFcRocZzOk9duPT/1PsF4m7+70SpG8uG7SG6wFbnXkV47GSpfy/UGR3 nN9GUized+yzvgLrRuSstoByVGh1kjT2wl/EsxxLVa/mSMJerNfg8crzRX7+5NP3Sc/4jpCm1Ks RuQ4om/unB57uRTRTP1XMshJv28/aZFqDFdlSfl0ekPR7ggoIN1y/QNgi4UaMK5D3gLCcGCB5Ty //bAD4= X-Received: by 2002:a05:6122:d96:b0:5a4:7e8b:3171 with SMTP id 71dfb90a1353d-5c3d91e6c7amr2524108e0c.11.1786035612662; Thu, 06 Aug 2026 10:00:12 -0700 (PDT) Received: from syssplab.cs.fiu.edu (nat1.cs.fiu.edu. [131.94.134.89]) by smtp.gmail.com with ESMTPSA id 71dfb90a1353d-5c3d05c594fsm3706321e0c.8.2026.08.06.10.00.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Aug 2026 10:00:12 -0700 (PDT) From: Chao Shi To: Jan Kara , Christian Brauner , Alexander Viro , Matthew Wilcox , linux-fsdevel@vger.kernel.org Cc: Theodore Ts'o , Andreas Dilger , Baokun Li , Ojaswin Mujoo , Ritesh Harjani , Zhang Yi , Zhang Yi , Bob Copeland , Namjae Jeon , Sungjong Seo , Yuezhang Mo , OGAWA Hirofumi , Mark Fasheh , Joel Becker , Joseph Qi , Andreas Gruenbacher , linux-ext4@vger.kernel.org, ocfs2-devel@lists.linux.dev, gfs2@lists.linux.dev, linux-kernel@vger.kernel.org, Chao Shi , Weidong Zhu Subject: [PATCH v2 21/21] buffer: clear BH_Write_EIO when a write succeeds, not when one starts Date: Thu, 6 Aug 2026 12:58:44 -0400 Message-ID: <1c976fd191aa6e99dbe65d6a1ec63f8706cc0dfa.1785951556.git.coshi036@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit BH_Write_EIO is cleared in __bh_submit(), when a buffer that has been written before is submitted for write again. That is early: it says the error is gone at the moment we start trying to fix it, rather than when we have. It also loses errors. A task whose write fails sets the flag and then goes to look at it; if another task redirties the buffer and resubmits it in between, the submission clears the flag and the first task sees no error at all. Neither of them is doing anything wrong. Clear it on successful write completion instead, in the end io handlers - the same four the rest of this series has been converting, plus gfs2's, which already marked errors this way. Then the flag means what it says: the last write of this buffer that finished, failed. A resubmission no longer hides an error that has not been fixed yet, and one that has been fixed clears the flag when the data reaches the disk. __bh_submit() keeps setting BH_Req, which is what the rest of the tree reads it for. Suggested-by: Jan Kara Acked-by: Weidong Zhu Signed-off-by: Chao Shi --- fs/buffer.c | 15 +++++++-------- fs/ext4/fast_commit.c | 1 + fs/gfs2/lops.c | 2 ++ fs/jbd2/commit.c | 4 +++- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index 425fbfe72ad1..68ea0ef8470e 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -202,7 +202,9 @@ void bh_end_write(struct bio *bio) struct buffer_head *bh; bool success = bio_endio_bh(bio, &bh); - if (!success) { + if (success) { + clear_buffer_write_io_error(bh); + } else { buffer_io_error(bh, ", lost sync page write"); mark_buffer_write_io_error(bh); } @@ -433,7 +435,9 @@ void bh_end_async_write(struct bio *bio) BUG_ON(!buffer_async_write(bh)); folio = bh->b_folio; - if (!success) { + if (success) { + clear_buffer_write_io_error(bh); + } else { buffer_io_error(bh, ", lost async page write"); mark_buffer_write_io_error(bh); } @@ -1114,7 +1118,6 @@ static void __bh_submit(struct buffer_head *bh, blk_opf_t opf, enum rw_hint write_hint, struct writeback_control *wbc, bio_end_io_t end_bio) { - const enum req_op op = opf & REQ_OP_MASK; struct bio *bio; BUG_ON(!buffer_locked(bh)); @@ -1122,11 +1125,7 @@ static void __bh_submit(struct buffer_head *bh, blk_opf_t opf, BUG_ON(buffer_delay(bh)); BUG_ON(buffer_unwritten(bh)); - /* - * Only clear out a write error when rewriting - */ - if (test_set_buffer_req(bh) && (op == REQ_OP_WRITE)) - clear_buffer_write_io_error(bh); + set_buffer_req(bh); if (buffer_meta(bh)) opf |= REQ_META; diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index a2028fbd4540..95998827ff01 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -209,6 +209,7 @@ static void ext4_end_buffer_io_sync(struct bio *bio) if (success) { ext4_debug("%s: Block %lld written", __func__, bh->b_blocknr); + clear_buffer_write_io_error(bh); } else { ext4_debug("%s: Block %lld write failed", __func__, bh->b_blocknr); diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index 3df6e4b7e8b9..7440e5b72f8a 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c @@ -179,6 +179,8 @@ static void gfs2_end_log_write_bh(struct gfs2_sbd *sdp, struct folio *folio, do { if (error) mark_buffer_write_io_error(bh); + else + clear_buffer_write_io_error(bh); unlock_buffer(bh); next = bh->b_this_page; size -= bh->b_size; diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c index cd7ef783bd36..ebf6ba58ff4d 100644 --- a/fs/jbd2/commit.c +++ b/fs/jbd2/commit.c @@ -36,7 +36,9 @@ static void journal_end_buffer_io_sync(struct bio *bio) struct buffer_head *orig_bh = bh->b_private; BUFFER_TRACE(bh, ""); - if (!success) + if (success) + clear_buffer_write_io_error(bh); + else mark_buffer_write_io_error(bh); if (orig_bh) { clear_and_wake_up_bit(BH_Shadow, &orig_bh->b_state); -- 2.43.0