From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (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 5418D23AB87 for ; Wed, 3 Dec 2025 03:34:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764732887; cv=none; b=HlqNcQJc6l16bY+2XzeO2q3142oKsF1/hVs1wgdwPr7++ZHpivk1OtUoAyO12bCcqPfx3ci3iKky25INDPs2BYHpksOYYShPcVmgrHDjhohbZakhTZwssVJUXfcUXo/jjNrCOIirh8lAJ8AMA7UjaMoC31JGO8LFLNh6t4l9jaw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764732887; c=relaxed/simple; bh=J8nwCyeg94DnVaqWCEfUw6ETwfGA7GobiAsmhz5+eaw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gEHolN8rMLr6fx9DH5HP6r3leotjePQk/VgYq2daVxqCO45lIk+Q757XQLOu1yYD77MoXfW20VmPjC41VpJd18PbK1ng9ZPX5FB56AxxcbZYODXmgp0+v/AmOlY43qiSdtHlT6bBw0Dq7ykvw6D5cnBqXE8McUnQbArz0LfkEko= 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=MmEx+oDu; arc=none smtp.client-ip=209.85.218.53 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="MmEx+oDu" Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-b72bf7e703fso1033595366b.2 for ; Tue, 02 Dec 2025 19:34:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764732885; x=1765337685; 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=RTNIQ6359N4GdAi3JYN7MZ1EQCxAqmS9GD/eyiPSc1Q=; b=MmEx+oDu8+DEZQ5EVHE91H+ROubXpjD7UQctiUW8EUyfeY7/8Vt45MAKCXUXdHGD7d 9omjiq6SIOYc916yTwUR66rT3XVReYTri8Nv2VRfitO+8qOy4MMrnZdq+Z9Zd0YZ7UV/ lEuNREztLMFRnGyxcKM6Xboggy5XAUYvbkQkS7x8AtfJt0VgpckW40pCu1GX9sr83j4w tJCE11DTn5HJamywqLfkQD8dQ1ziC/ntSjrarlZKgAEvbBrC6ti7WxBFiJCnAwPJaFmU NfHvdpMbyMC2KIBGiqjLWrIDEPthpiJtNB7XQUIi4qzHMkp/yj95TJQ77RsUACteJhqW mSWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764732885; x=1765337685; 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=RTNIQ6359N4GdAi3JYN7MZ1EQCxAqmS9GD/eyiPSc1Q=; b=Ckn9kNmYbp3y8aQ22FhwQiA8BMRqY9i8paMYGsJh3pxR3xiBI6NMGtUkxIaYOTftpO Na188XBF4llAc/bXz76g9yfpIUO1HXwTy4V33bfuofm3DFndscC+iqzkxBCwVUsGfyS3 bav+RPiQORKdIkanzl/N1xXBJWowgG7zPBDl/HDWLMLn9xuNjcifMVQH+24c59OIn+At gcPzK8cowWet2m3dztE/XilI6eqzWA+74ke2JDuv2jrcyXeq8qUZfsfo9uxALXAH+UN3 f+Vpa7mm3xLKL78qbUqi29dyvGdryRPf48y3gDfTxoP7NyV//agkIi36rZ4goHHcdvAD tAag== X-Forwarded-Encrypted: i=1; AJvYcCXe5F0fr8puqC5vkAOrgMrEiplAhIBz0HimWl+1FdxNGbl7FfxN5vmPJVjCUG5YfW3qd2zNyYs660k/Jn4=@vger.kernel.org X-Gm-Message-State: AOJu0YwmpHLkV7mzKqqb8WsNOw03ByRKaV42d6B9Yr2kdFzHgQvDRBSC fMw8Gli/zirMIt7QSrQS9ItNigMAyLZhdTBKbW9Rhmzl1DxoKAIgbCHu X-Gm-Gg: ASbGncugt+uz4zBSCzRunwtliLo9EP/g6M3sGTXAgJCQeVyh6e39nt6BI0b7U287VqZ zl8MaEpc9eFkmzDTjdFQG0l2+Nt+YVRp7O6CbN0EfQDYNzZhwTC2ZrojdxXgk84OQutSGnRPa8O VRXgs+O7l/yvCRWVsXckvfBHw4apzaa1Dxk25uRptp0Ob3tt5aj9ImF98QuR1wsI15wFfnQ37SI QnLLbbgqEqdM875S7+mpFlVD0LJ+T76zOEjsorjgK67TsfSmVxUaK0CPgmiDjihrwtO3O6o1VZo wGUDF5XMC6Cw0oYr3Fc2n5gLNY6OAYzgbj7Hesd4YAswKhs83WSogIUVydd68ruey9YIUmMemoM LHySHXg9120Mh/7G01Bc5tBpdckasTbwiqLgoKtwEexSVJhEYS68rFsIEnmE40NZwb+uYyMrq2s ZaoIBAObj1bIY= X-Google-Smtp-Source: AGHT+IGZpjjL2vDegZyx8kF9oRaWEizjVikkzRNu1M6cNO4h0r+ykfFRWqignrAxH3E/lo2cYWdQyg== X-Received: by 2002:a17:906:478f:b0:b75:7b39:847a with SMTP id a640c23a62f3a-b79dc782b79mr66011466b.60.1764732884656; Tue, 02 Dec 2025 19:34:44 -0800 (PST) Received: from eray-kasa.. ([2a02:4e0:2d14:1a1:acf7:8de5:59bc:44c3]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b76f5a4b757sm1658570066b.66.2025.12.02.19.34.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Dec 2025 19:34:44 -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 v4 1/2] ocfs2: Add ocfs2_emergency_state helper and apply to setattr Date: Wed, 3 Dec 2025 06:34:25 +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: 8bit 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 Reviewed-by: Heming Zhao --- v2: - Introducing new function `ocfs2_is_readonly` to lower the cost - Using unlikely for status check --- v3: - Fix compilation error (missing semicolon). --- v4: - Fix code alignment --- fs/ocfs2/file.c | 6 ++++++ fs/ocfs2/ocfs2.h | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c index 21d797ccccd0..ddca292944d7 100644 --- a/fs/ocfs2/file.c +++ b/fs/ocfs2/file.c @@ -1136,6 +1136,12 @@ int ocfs2_setattr(struct mnt_idmap *idmap, struct dentry *dentry, attr->ia_valid & ATTR_GID ? from_kgid(&init_user_ns, attr->ia_gid) : 0); + status = ocfs2_emergency_state(osb); + if (unlikely(status)) { + mlog_errno(status); + goto bail; + } + /* ensuring we don't even attempt to truncate a symlink */ if (S_ISLNK(inode->i_mode)) attr->ia_valid &= ~ATTR_SIZE; diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h index 6aaa94c554c1..7b50e03dfa66 100644 --- a/fs/ocfs2/ocfs2.h +++ b/fs/ocfs2/ocfs2.h @@ -680,6 +680,24 @@ static inline int ocfs2_is_soft_readonly(struct ocfs2_super *osb) return ret; } +static inline int ocfs2_is_readonly(struct ocfs2_super *osb) +{ + int ret; + spin_lock(&osb->osb_lock); + ret = osb->osb_flags & (OCFS2_OSB_SOFT_RO | OCFS2_OSB_HARD_RO); + spin_unlock(&osb->osb_lock); + + return ret; +} + +static inline int ocfs2_emergency_state(struct ocfs2_super *osb) +{ + if (ocfs2_is_readonly(osb)) + return -EROFS; + + return 0; +} + static inline int ocfs2_clusterinfo_valid(struct ocfs2_super *osb) { return (osb->s_feature_incompat & -- 2.43.0