From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-f171.google.com (mail-yw1-f171.google.com [209.85.128.171]) (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 C679E3C10AA for ; Sat, 1 Aug 2026 22:01:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785621694; cv=none; b=Fr1My18QtWMpncki4FkXTkRLHP0Y62i9mjBy/Fl2vOQl70kbrxtd0hcc2fazBsNwtKBuu3Y1r7EvZMZJtSjnFvnnt1MpnVtuC2vmKVHgqJHS1iNIybtJ0r034Pc6w/ROPew4XLUQvknOURlU/Yr9HG3ExRjlZD3OkiQG10TU24E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785621694; c=relaxed/simple; bh=njsuMFgQW9XgoUDzJC8DUF4aImr/QOgd49oen3uWUEs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uEc4kGix1G7bcUhYcNPh6bqSOZGB4Xxh3T7EKDEvIBL7iNNeazFrzn0wiMvHGvDvs9OrYCdtdDQRS/myEx0ox69j6sYWPEYv7qF0+YtiCZe0u4ssOiXvyXUdDE0ExG7IlZi7/J1BnXzVs3B27hjg9ZFphNwAojaBm3I/aDTgIys= 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=GMURzrMd; arc=none smtp.client-ip=209.85.128.171 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="GMURzrMd" Received: by mail-yw1-f171.google.com with SMTP id 00721157ae682-81e6f2ee60bso42983387b3.1 for ; Sat, 01 Aug 2026 15:01:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785621689; x=1786226489; 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=nQgNx97XjQWdnRUlGoDKYUMjSoMBL5tDz0tOo1NQ/rc=; b=GMURzrMdQ+0fCw3lI2AlYxm2541TapXakDa4FRTLpuF9BBkzpyEeoJXFKdW6YwWTIX yFl2b5Ai4tPDsQWM1420067C7pIVz/ho5qyqdpyNZMHQMNhGUb+VGPIcjfLJgtGuW6i6 wFlKnOlTMQY1AX6TOHxlJWAPONXvwFfSMzL+Brx2S22U9Zdng1JIjq6wwkGuGiovpcC1 L1dCTBpUiSloYeMTRMPc236X34icQBnowXCsHv846XBzdnXCROvUnjoaJqsUwoklM3ym 7/AK1Ub/6dJ01t7/EqyswYFx1Ce3Q73CvXd38rVyZNmOOxnkZ3QHIox2onpR+o1GoEfA 7suQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785621689; x=1786226489; 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=nQgNx97XjQWdnRUlGoDKYUMjSoMBL5tDz0tOo1NQ/rc=; b=B/l5W7fKwMTkifKl8/nCvDAcB9Z3rDqDncmZ4+O4Ae5jXOlFx2k49tPA1D7u8tlDWw i7wwG09SI2qxcQlakpfSX1bWpnxL1sTM35nMlSHfXsSbhGkv2U04lgl+ghY7geiEqH6K DQnXVrJxiYbOSgl6wyy+NEQNRAfjl6lx/K+d7s+1Eg/XntY/EIeUFzzhCibJcgu/vMXu w/DE/iu4bEqE/cF6j2tu5cTa8+xu0RhHgCIdXt0JEeJL8TLsTN3pCpDj1fBPe60sj8OO 3XlDPdmsoppwWfXnFAeF+arr62Ml4A9bzIxFdl7SZvfNvUnnu6n9sHFEevNTkuAMcbYe SaoA== X-Forwarded-Encrypted: i=1; AHgh+RowoYO9swwiK7SRUI+KMLX+77T/dQx7w8Dg9LSOavdd2fVtct2BUiUsWdGbc2VVMYY8xIV9h4ZAe83eoU8=@vger.kernel.org X-Gm-Message-State: AOJu0YzMmFq5nv3jepZn7+QI7urlCKIHh6OeA3a8eXjGEsQrlLOLSu3m FM98FDzgvXtIfNAUXb7kl9XjefDe+g/DoooqSe/gWkLbwL+BgDQBgw2Z X-Gm-Gg: AR+sD11tmd0m/bouNP7qOXQAQ+8eSeZ0C4eHlI6xdjXZ7/YtcpQE4czEY/gEnApGZDk XzYDcaK2JboGJIjmpA5JyW/ywL2qX6v2Cs0G9mrz2BCxJ0IqkGOibm/YFk/rTfVvnFPHmHHXpEJ 8dJLX2gdOoxsOQA/E1Maal4xxf7vQLxVDfRTcGxZSsUzrX8icAn2aIagO9T6VCm0FUnlXSV0vyu H6dTjAu/CEgQaA46eFuHCTcpl0MAr8XBlHYDEguMnvvwKiMZBZeTpCvb2nENOmVLYIDO0mUEL1G dVjHgmD9BBwSjBAfwS7FXX/qEmkmmEpq3Cp5OyHXViXak5AUH/7gFtJ9qSt73J9O6ITJ6bdM2tX u470v/DX6teIt5jgE0P1mNezzREVYtxfALgT8+O72XHFY4cddiCoBmVssvpQ/ZR7VU0ZVKS4mLM eQjvMdWd3Hrw3s+b9vSAvWAbMw/ynt0KbtmCTBcPOqf4PpOjj9XTwK17b0f11x2QFTze67sOHj0 IjiaPGBXKlOUkgvfw== X-Received: by 2002:a05:690c:e3c6:b0:81f:69a:3739 with SMTP id 00721157ae682-81fcbd4e504mr95002497b3.18.1785621689541; Sat, 01 Aug 2026 15:01:29 -0700 (PDT) Received: from syssplab.cs.fiu.edu (nat1.cs.fiu.edu. [131.94.134.89]) by smtp.gmail.com with ESMTPSA id 00721157ae682-81fcd0d6fbbsm29903767b3.25.2026.08.01.15.01.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Aug 2026 15:01:29 -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 , 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-karma-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Shi Subject: [PATCH 14/19] ocfs2: check for a stale write error before reusing a metadata buffer Date: Sat, 1 Aug 2026 18:00:58 -0400 Message-ID: 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 __ocfs2_journal_access() refuses to journal a buffer whose previous write failed, and turns the filesystem read-only rather than risk metadata inconsistency. That check sits inside an if (!buffer_uptodate(bh)) block, because until now a failed write also cleared BH_Uptodate. This series stops clearing BH_Uptodate on write error, so that outer test would never fire again and ocfs2 would silently start reusing buffers whose last write failed. Hoist the check out of the debug block, where it does not depend on BH_Uptodate any more, and drop the now dead second half of its condition. The mlog() pair keeps its own !buffer_uptodate() guard: it is a separate "we can safely remove this assertion after testing" debug aid about being handed a buffer with no valid contents, which is a different question from whether the last write of that buffer failed. The unlocked test followed by a locked retest is deliberate. BH_Write_EIO is cleared under the buffer lock when the buffer is submitted for write again, so taking the lock and looking a second time avoids turning the filesystem read-only over an error that a concurrent rewrite has already cleared, while keeping the common case lock-free. The code in this patch is Jan's, from the review discussion linked in the cover letter. Suggested-by: Jan Kara Signed-off-by: Chao Shi --- fs/ocfs2/journal.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c index d8afbc1a76bb..ea6802d894c2 100644 --- a/fs/ocfs2/journal.c +++ b/fs/ocfs2/journal.c @@ -676,19 +676,20 @@ static int __ocfs2_journal_access(handle_t *handle, mlog(ML_ERROR, "giving me a buffer that's not uptodate!\n"); mlog(ML_ERROR, "b_blocknr=%llu, b_state=0x%lx\n", (unsigned long long)bh->b_blocknr, bh->b_state); - + } + /* + * A previous transaction with a couple of buffer heads fail + * to checkpoint, so all the bhs are marked as BH_Write_EIO. + * For current transaction, the bh is just among those error + * bhs which previous transaction handle. We can't just clear + * its BH_Write_EIO and reuse directly, since other bhs are + * not written to disk yet and that will cause metadata + * inconsistency. So we should set fs read-only to avoid + * further damage. + */ + if (buffer_write_io_error(bh)) { lock_buffer(bh); - /* - * A previous transaction with a couple of buffer heads fail - * to checkpoint, so all the bhs are marked as BH_Write_EIO. - * For current transaction, the bh is just among those error - * bhs which previous transaction handle. We can't just clear - * its BH_Write_EIO and reuse directly, since other bhs are - * not written to disk yet and that will cause metadata - * inconsistency. So we should set fs read-only to avoid - * further damage. - */ - if (buffer_write_io_error(bh) && !buffer_uptodate(bh)) { + if (buffer_write_io_error(bh)) { unlock_buffer(bh); return ocfs2_error(osb->sb, "A previous attempt to " "write this buffer head failed\n"); -- 2.43.0