From nobody Tue Dec 2 03:00:42 2025 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (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 02817257825 for ; Tue, 2 Dec 2025 02:28:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764642508; cv=none; b=WFAUlDlQs0JT2HQv1q1kFvy7Sct5FVGKxDSgKkUwMxiy85wuVznWG3OXeXzTZ7fH+Bc93Uew4cZ1tuKb+D0IjYXtWiBwn5toNQg/Je2ak8FgZW/YL7NkIyir/0PcqtQxRhwAeLkk4hsQWm76iuAQH1n0zS1d+2urdkwv3hcLdeg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764642508; c=relaxed/simple; bh=fSE083AuicyftJQKZLE7jXiaWhrf5jW0t9xQwan2HMc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YWeJ6UxFwr6n/bVs9vCANF7c2Z0uEwK/uTlp9iRXE1zRRQ6QE6HNu4vwGZcORVEbJudS/g181kKbscmP/gdtFvhb6tnMZew5mltmsRqb2jJmjZnN4y9zjAjIaZT7sYyNgwJkiWiCajqGvq0CJUD2kEVdDPrxHaeNc59/6j4HBIE= 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=RQ+3Wm0B; arc=none smtp.client-ip=209.85.218.41 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="RQ+3Wm0B" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-b7277324054so715974766b.0 for ; Mon, 01 Dec 2025 18:28:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764642505; x=1765247305; 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=1nWhPWmuUWPcNz6n4p1oyrxoe1jA0QGnW1Yt9yXj36A=; b=RQ+3Wm0BPueZh431sPoWEo/FgbIT2L7YgLZ+nDeULvZZuQ9mlYLXCbl+Gs4fQtKrCY wYonxBauUo2zAt6SvJsC+76nE7wTHee/OyPVT6ZR9KmCF0ZPnpDocY0Nx+pF08g9df6D EUdcU4WrhaFDsQJoQELReSRpkm99Ki2+LTF0IfV0eLxzm+ojzLSoqWEOP/POcdESSh9r b/q5n0K6c4wP/RsGJOTu0GIDxtoESmG8FxH3/S7LlDP4rOxdAUR49yQVlpa9LFRoraIv m/fUR84AAexvftpfVmWLf1K7GJp9EldL9hmHpNK6+4ne9UjSNjVa4S/RbbFPMMJwfJqq HARQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764642505; x=1765247305; 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=1nWhPWmuUWPcNz6n4p1oyrxoe1jA0QGnW1Yt9yXj36A=; b=fOnF1Ua0RykWzHU3uhOSlQf3p4HWcw5uoVkPyzGgkub4h+I44/MWl5njaVfTMcM2em 8xY3u3Ih4DrW8rwxENYj64Wx7iEPww6xBpahs+vb7pzrDZfB/FpUspJi+WKPSv+K3UR+ gFLoDn8imC5RsvnSGzv6xaGuBMETf4t2LOy25sd5OmLW8HTdMX7Au9C0F7dN5bM131bt 9ngkEEg+WL/HTfwpHN0uvBLON4APD/RnB8PTdLLcEGIwACVX5bexf7qkFSeTz9BPtztA TmRGt21Kw+0S3SOdEn4g5HKAn6Gm+zEsBdv3qdHk56Fh6WvlNVjvbc1wVS4DsS0bvLq6 E9OQ== X-Forwarded-Encrypted: i=1; AJvYcCWS91xE7sMtDjaatrPebvuXOKwu3xQjE/I6W/7W8WVsPgmkr9WJY7pgMvY4oOu9e1+GmLi+jKoSK7hEL7I=@vger.kernel.org X-Gm-Message-State: AOJu0YxpNzr5MdS946OovWa4j4UQiTmtZimS0ik08jH0LY2h786Iu7++ Cnvfa4YimAGvGN1SrVs+yd01dQjXVdXFmCNFWfgZ6WOlgRASSQuCmPC8 X-Gm-Gg: ASbGncv/LF3lOzjCLKL9dc9/FdRk+i6B+/A/TsPXRjDJON61bcJwh9hjnjhXmqFNwYK EOipcymlXWwkTbT4NyxAhyWCijbwV+T0eF55cWsyWRLhiTX4bmYkuDvhXplWdut3qoyr4Aj3NRF Uz6FkDG9QhfA5xqBPsp14LoPV+YJGXAbq9vBgRfeRgoyOoNOvQFPqZFXFYeri1D8FVARd4jqi/V 9oDzqeCDagkDs9rb3zyB+j2fI/rhb1hBMnVAVoY2K8ZbBbilGo4esWakWRnpGeakwEFjbCiC4SN r8AFDuQb9189McsPBvOdnCqkcbSuR+3PHNpMkz/IjzyDpYA5HxpaXAGRb1hobSbEbptser5npoi yW9ywQgWbg6FlloYcQSlkdh8bvzEeBvPN2J8/ZJ0A9ZD3PZ0B3rtnZM5NR1VBF3Ug3rQeXVUxYt J+30DzYxzwVHY= X-Google-Smtp-Source: AGHT+IGm3NbA4GaGWOqLIeWZsMEh9q/DGd5oWcaZUlNtcad9GF/JDBDWi4QKx39KjJUF5Ok0XPJ9JQ== X-Received: by 2002:a17:906:fd83:b0:b73:3f7d:3ce with SMTP id a640c23a62f3a-b767184c12cmr4550333466b.46.1764642504933; Mon, 01 Dec 2025 18:28:24 -0800 (PST) Received: from eray-kasa.. ([2a02:4e0:2d14:1a1:8eee:b306:2d20:a328]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b76f59a6a5csm1398317766b.41.2025.12.01.18.28.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Dec 2025 18:28:24 -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 v2 1/2] ocfs2: Add ocfs2_emergency_state helper and apply to setattr Date: Tue, 2 Dec 2025 05:28:00 +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 --- v2: - Introducing new function `ocfs2_is_readonly` to lower the cost - Using unlikely for status check --- 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..253b4f300127 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 (unlikely(status)) { + 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..b018c535226e 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; } =20 +static inline int ocfs2_is_readonly(struct ocfs2_super *osb) +{ + int ret; + spin_lock(&osb->osb_lock); + ret =3D 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 & --=20 2.43.0