From nobody Tue Dec 2 03:00:42 2025 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (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 506FA271450 for ; Tue, 18 Nov 2025 00:27:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763425659; cv=none; b=SJgu4Vrz4lk7T+qF30HQ7KU/fg2LCN0OOdKLj7UqXz5waSjdqXLzQPOmu0P7lsZFc3Ai2wtDgmB3xbe3UDNGphJAGjV7igPKErrkoh2KRfqdLZ5HqMvKrDwxEqvLkhCEBz8Vb44xF5Ufn5Yymt5Ey3cXu77xi2Nqm4sMDk7O3OI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763425659; c=relaxed/simple; bh=r2r80AC1AABbcwjkeqa459fe8/Tc53amJFmxi/OF0a4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FJgmy/xOhsyjSUw4kK/ZedX/M8RNpZUy3l7SGAuaCQ+A7ydeNj7daxavKdTMqo3GVYMaQE0ceMoToLUe3RqAhagi2DCNt6juFDLGvMRT0Zc0qHNBI/DGnaZRISzdzT64wQ+b4v13gLmAcjgX/2iKjQeRM5NO+nCEMECXZG1qt8k= 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=e4IpF5+3; arc=none smtp.client-ip=209.85.208.49 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="e4IpF5+3" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-640860f97b5so7921574a12.2 for ; Mon, 17 Nov 2025 16:27:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763425655; x=1764030455; 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; bh=7II+12gmozjCQ2NvhjWVSTUgl840K7iM6j+Wh+0OMOE=; b=e4IpF5+3ZVRt3zy0sLgbOC4OLiciO7XRsMv7iVFhUw4lpIKXkNNsk6QWSFdhO6LFcJ 7tcEyhQ753b28jt40RqbrQfwDxTBDVl64mLwaCe7XKdtptTvUkiFGhGq+cZUgAr049iY 7+Hv1e71pebYsCcYBUshmnMPOudPrP5M5e8y6DTLpOXULOANl5yXaLYBD6dWlNwoApGX lG3KPnMF/mw65lPs3ALfc7GAUYb6CeCDki/JJIRhB4E0lwqdioP0Ef+SRvWbCTU1t56E E3XGFuvhxZYwLRFOobM0goy2p8ngp2Dp07LK5DyGsVb1fKQnYPO4VubDeMCOGvlIw99c 8e7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763425656; x=1764030456; 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; bh=7II+12gmozjCQ2NvhjWVSTUgl840K7iM6j+Wh+0OMOE=; b=offatOHTRekTVobZXgFqsE6Z6nlT4UVzy+9bmL+Xh84ms6udT6pgIvCRpY2zQryhY+ hvFcWvh16vSyni8zY+3LCKLDSivqdPW8mamNNb4Rtno114vt4kZRfgN5Y5q2RWTCbAZV jRwCELDHT3+rROOsZWNbDnJ+bLw49WGxy06jnyNPxrYQtNTEEpQtf2556bgTKMJXCvP1 +k7oU9eVMJhOdcmi2fYNZqI4xF0EhXE8gbIvIJNDL2596C8n3gopxoFTwLIm+RMUZ7qv IeoYj+bEW1//t5xvyj9vraInxVUFq3ab2b10Jb5fRewN6QWH5dirAk6PNWF4qh2j8yKf QStw== X-Forwarded-Encrypted: i=1; AJvYcCXTGS1ktfQ9Ufv4AOSpm+agbeP0FapjLZaNb0w9HBozcP51xywigcxfGGPL5xHwiwiMhDDSA1206kWiA84=@vger.kernel.org X-Gm-Message-State: AOJu0Yx1pkUNkvrrxOjAPhuOiC0XYR46nFhTT1bPOpdp0X85DbYCLX73 bi/3FI3Civ/HNkNuARokDMBLpBgIolj4zFEhGrgnEq2OgPmI0+nqj8+I X-Gm-Gg: ASbGncszL0cSgwNXzV2nm/qeHJ+S21EQbR6tUsbzesam4E1UzMy4J9mjYYQ/epT3VaF 9WabhqmI4syhtebjxC/FPZakEG4jzcwD0EXG/X1qBVhA1djz91Gee9d5m7OJZc2pSZEkTKCWsuT kEThZ8m3PgYzuOfyMeIKsaF/BLPu89kn6U8cG7RRSqTRcoZXpwefnaTj1atSTM6wOJz5/oDAoOm GtJzQlGLrwNAJK4zv34iV4+1gCJnNChyObtGIsp9sBThpdANXmK3rwCkqSmtJTz2xav4/tonoiO cGCwrCBXGvwqknVpIRBNC9RMoj8NwaebDTV5906J1J+T2Fc5v/mkdqrRD2jCrpq67xaCZHJkmB+ 60Z7OF4tJQa3bwoI42vOZkC6tfdwvNHrTvEzJacvBWbgMW1oAROcLUfUyboglc0scqHuW9rvEkR 2tVk9wDbZUMFJ6ChKGU7n0Vw== X-Google-Smtp-Source: AGHT+IH7E0M3D2XXIS9vufslhd3Lmf8FPoSeWLitFy6VWcwgaj6CSSMwhUHU579T8towY2nrsMyIQQ== X-Received: by 2002:a17:907:25cc:b0:b70:fede:1b58 with SMTP id a640c23a62f3a-b736780a96emr1175091766b.2.1763425655501; Mon, 17 Nov 2025 16:27:35 -0800 (PST) Received: from eray-kasa.. ([2a02:4e0:2d08:f72:eb64:1d0d:5855:afe7]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b734fda8a86sm1172606466b.52.2025.11.17.16.27.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Nov 2025 16:27:35 -0800 (PST) From: Ahmet Eray Karadag To: mark@fasheh.com, jlbec@evilplan.org, joseph.qi@linux.alibaba.com Cc: ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org, david.hunter.linux@gmail.com, skhan@linuxfoundation.org, Ahmet Eray Karadag , Heming Zhao , Albin Babu Varghese Subject: [PATCH 1/2] ocfs2: Add ocfs2_emergency_state helper and apply to setattr Date: Tue, 18 Nov 2025 03:26:44 +0300 Message-ID: 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: quoted-printable Content-Type: text/plain; charset="utf-8" To centralize error checking, follow the pattern of other filesystems like ext4 (which uses `ext4_emergency_state()`), and prepare for future enhancements, this patch introduces a new helper function: `ocfs2_emergency_state()`. The purpose of this helper is to provide a single, unified location for checking all filesystem-level emergency conditions. In this initial implementation, the function only checks for the existing hard and soft read-only modes, returning -EROFS if either is set. This provides a foundation where future checks (e.g., for fatal error states returning -EIO, or shutdown states) can be easily added in one place. This patch also adds this new check to the beginning of `ocfs2_setattr()`. This ensures that operations like `ftruncate` (which triggered the original BUG) fail-fast with -EROFS when the filesystem is already in a read-only state. Suggested-by: Heming Zhao Co-developed-by: Albin Babu Varghese Signed-off-by: Albin Babu Varghese Signed-off-by: Ahmet Eray Karadag --- fs/ocfs2/file.c | 6 ++++++ fs/ocfs2/ocfs2.h | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c index 21d797ccccd0..03a98985ac92 100644 --- a/fs/ocfs2/file.c +++ b/fs/ocfs2/file.c @@ -1137,6 +1137,12 @@ int ocfs2_setattr(struct mnt_idmap *idmap, struct de= ntry *dentry, from_kgid(&init_user_ns, attr->ia_gid) : 0); =20 /* ensuring we don't even attempt to truncate a symlink */ + status =3D ocfs2_emergency_state(osb); + if (status < 0) { + mlog_errno(status); + goto bail; + } + if (S_ISLNK(inode->i_mode)) attr->ia_valid &=3D ~ATTR_SIZE; =20 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h index 6aaa94c554c1..2ac16632dd19 100644 --- a/fs/ocfs2/ocfs2.h +++ b/fs/ocfs2/ocfs2.h @@ -680,6 +680,14 @@ static inline int ocfs2_is_soft_readonly(struct ocfs2_= super *osb) return ret; } =20 +static inline int ocfs2_emergency_state(struct ocfs2_super *osb) +{ + if (ocfs2_is_soft_readonly(osb) || ocfs2_is_hard_readonly(osb)) { + return -EROFS; + } + return 0; +} + static inline int ocfs2_clusterinfo_valid(struct ocfs2_super *osb) { return (osb->s_feature_incompat & --=20 2.43.0