From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.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 68F8A274B23 for ; Tue, 2 Dec 2025 02:55:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764644112; cv=none; b=NrhV5EEbLcV0AMy0IbNHKR7ErWoHJtHgrg79GPKi0bkWgCkhGY5ndo4vZHOK+a2Vx8c5U1B0wywtCFYi3nW6Z7P+hIyGr9o3RgeJZOs2WYBsNkINp0QW40YQ1vS3i6MTdAh5WcRD1yK+BeZiJLMsw7B/X+5/5YfhVEp4zoVgRmo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764644112; c=relaxed/simple; bh=yH9k7/tFAuvtIW9rGhUTKwseJd0t3U5D9DGzL9whDpQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g/pjWL8gtVj6pzIZ4ABdNKUAoO80HIZ+9REBAi10hHZPap1zmXoE1Ytbc382joYidoPZHaOMezuebpNlIlbgEO5YBURG1EYPwoXNq/8SUyuvv1njqXsX0+DzyQT0tZ9aepfPRmxNmUb7M2sVvqzOaEJCCwfla+3BDCRNfCPYAXk= 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=OVgK6f8q; arc=none smtp.client-ip=209.85.208.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="OVgK6f8q" Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-64312565c10so7668205a12.2 for ; Mon, 01 Dec 2025 18:55:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764644109; x=1765248909; 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=hFDswTxukywhcdHMNKsrI1xSpEMfAznDaDbrbKqsNF4=; b=OVgK6f8qaD1N7tGVrHvz7ERUoNNBl16+TB/WG0xFjEnyduSidLlpxH6VdQYn2daBMq FjqvJfC+Z12iSI17jwKQoH3bwhkom+rUZ6xbavMY6GW7k3DRxwPgJ8VxQ09KBRvklde4 Ls2QQ9Qs2IQqqawAxSgrOdstrngmiFTtPfxPkMelmgXexH3f3VsZJanl/gnb/q4IPyyL pSUOTr3Jo6R+UxevJhnmvKDvttyR6FKyk9DoMYPnZexp11Bbx3cal0wm6KfnD0imtlD8 6YLttRYTkIsWjrj+YcajikYzwVNPKuYQ66ejx+VbuS3YLzKe0CKfvg1E0igR9mc27x1v +bsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764644109; x=1765248909; 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=hFDswTxukywhcdHMNKsrI1xSpEMfAznDaDbrbKqsNF4=; b=vicp69/S/JAVS5HlTVm51DoZGuD9nDKMODpIwXI/MyRNRoUIfhWok7wwXhMreGmmej O5/vPxD9YJ0XXDTtHP25gUc6tRRcJsDme+ABJVp5+pSFULcZn+grib9NWUh86kZRXYyd ArIBQMxruwyewcKNEiZuq8DhcJ8pVyGfIIIquo5PysngZCUCv06AjBdDX5BlUHT0oIFQ N0E597F9SSwVOcDIxudbBIREic9GEXzPSqFOA3aRprgAdaJmCsn/m//SlmtYsBg5Nlir nAjmaLiLe1W6IHjkL415a1OZoYY1oD77XXUnBbb0IzMmhQ6Lo8Pqvr0X5s1TvACCiNI+ qXAw== X-Forwarded-Encrypted: i=1; AJvYcCXR8C4tsFHTwk+e1WR2PYRKEljZ1vd7Al2INwwEpdgwr7JmLwzrxHRdyJ4shRY/3KlY3P8XF0jMdUJ50kU=@vger.kernel.org X-Gm-Message-State: AOJu0YxSO4TI74UdtEf89UZpFIxONe8HT2ZupLAxrfeBajfFmK/wvBHm aAfjvTDMs6/ImI/sPyVltXALptz5e99wLTLWrGFSfcip8A8hsUlx/DRM X-Gm-Gg: ASbGncsGJdNsHZvUyag7wyVAaR9bwAg17JxRiuN342xnaVo/WBqVoQ3GRQ7IqIfczIp 6w41eHzaODNgxCJqrVzVSgN6DIvqzGcPxsmaoYiEoDnErrsfJj2rxtGYnMhUIIuzb7urJ2oFIxI Ls9XKQlyZLolGn/0LcZBaDtW7a1k638/3Nf2V5ce36bmWrxTmiB62YrjpasZKFDzuy5SjmnJGaq WjUvRlULU9fMFAVvnPtbRhj2Kt8Ws8dl1QXm9jIJzDopHCGZ4lC+K9UwjB8RRL803730qBAkRPW KGYIAUvVepdnU9yFxfEeSK1xQLuYVl9EclH0X4W2h9c6D5NUqX1NpdBDdVH+ci+flVf61DT3okr JtlOFSQKUtD5TCakDCh3f5QSnjrf7kEhSNBm88kS5icZWR9xho9B1UtnGkWUGCNiQAWsC5aPlel /T+VhAUDxlvqw= X-Google-Smtp-Source: AGHT+IEoGtVlHjjMVDnZp2+zDl2J/ucvcCY5PTl0CGSsCQayrreQljtqSXTlX46bb8VrfV7G9pAwdQ== X-Received: by 2002:a05:6402:3510:b0:640:464a:56ce with SMTP id 4fb4d7f45d1cf-645eb213954mr24671088a12.2.1764644108707; Mon, 01 Dec 2025 18:55:08 -0800 (PST) Received: from eray-kasa.. ([2a02:4e0:2d14:1a1:8eee:b306:2d20:a328]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-64751062261sm15753978a12.33.2025.12.01.18.55.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Dec 2025 18:55:07 -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 v3 1/2] ocfs2: Add ocfs2_emergency_state helper and apply to setattr Date: Tue, 2 Dec 2025 05:54:57 +0300 Message-ID: <8a26b007729e3f3f813f754eda6eed59431502e1.1764643790.git.eraykrdg1@gmail.com> 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 --- v2: - Introducing new function `ocfs2_is_readonly` to lower the cost - Using unlikely for status check --- v3: - Fix compilation error (missing semicolon). --- 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 dentry *dentry, from_kgid(&init_user_ns, attr->ia_gid) : 0); /* ensuring we don't even attempt to truncate a symlink */ + status = ocfs2_emergency_state(osb); + if (unlikely(status)) { + mlog_errno(status); + goto bail; + } + 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..91a861babf74 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