[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ff4cfa59-f5f1-47dd-8ee4-606e7201bc4e@linux.alibaba.com>
Date: Wed, 3 Dec 2025 16:25:30 +0800
From: Joseph Qi <joseph.qi@...ux.alibaba.com>
To: Ahmet Eray Karadag <eraykrdg1@...il.com>, mark@...heh.com,
jlbec@...lplan.org, akpm <akpm@...ux-foundation.org>
Cc: ocfs2-devel@...ts.linux.dev, linux-kernel@...r.kernel.org,
david.hunter.linux@...il.com, skhan@...uxfoundation.org,
Heming Zhao <heming.zhao@...e.com>,
Albin Babu Varghese <albinbabuvarghese20@...il.com>
Subject: Re: [PATCH v4 1/2] ocfs2: Add ocfs2_emergency_state helper and apply
to setattr
On 2025/12/3 11:34, Ahmet Eray Karadag wrote:
> 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 <heming.zhao@...e.com>
> Co-developed-by: Albin Babu Varghese <albinbabuvarghese20@...il.com>
> Signed-off-by: Albin Babu Varghese <albinbabuvarghese20@...il.com>
> Signed-off-by: Ahmet Eray Karadag <eraykrdg1@...il.com>
> Reviewed-by: Heming Zhao <heming.zhao@...e.com>
Reviewed-by: Joseph Qi <joseph.qi@...ux.alibaba.com>
> ---
> 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 &
Powered by blists - more mailing lists