From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1108A2C2374 for ; Wed, 3 Dec 2025 08:25:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.110 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764750342; cv=none; b=TsqTyZYP2VWTfiQy6heQvLH9sxpl9JS8EKv5DNd4/G9w4E/IAK9i4uNzlG7WYA9HJZ3FTGosLJlZb4NDvt0jvqTfHGrCNf/EdxLk/ljjBJ73YdGK9rk4yjc5eoDdBG8Wf9S21OTzAtezWTOzFAhXEw9bKoZOVk4JK1zcC7Pmq0s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764750342; c=relaxed/simple; bh=nuBpsrJWkZQHd3tXLeIT/+k2AqpTN1kBFcBdcQ2dTCQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=HDH/zpQCJ3us/lIK1tYSI6NHiaS5KOcJDElH6guci0XxmlcgKwGF8girJE/a4iKeaM/8HkluNfGi1eyJ36By/wVxiUPmhGQc8csTm1bGtsXjZtKFS95sp5v/hrMWPSw52nM+yoaj9CMwxKjPp0ezKhyuPoAkLiS8cX58as2lgKw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=neXBC9gM; arc=none smtp.client-ip=115.124.30.110 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="neXBC9gM" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1764750331; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=lVoWbQOh35MC5sTCdeKx6He6jasgmR1Hybu/2i4gRF8=; b=neXBC9gMpnoKmcg6SsbmKY4SQKDzYSNetp/id+LjiElUFoglr9pHpbCKI1B0kLfzvE1oZHgcI0phwSIT7KO0JYiKU9quzpUQySvQtDrgBqHhY2z7HwRWYtaKxDDk86MY1h74MY6ne4gxbftbDaMexUnUPHVY0OhLCavqX9s0JhM= Received: from 30.221.128.156(mailfrom:joseph.qi@linux.alibaba.com fp:SMTPD_---0Wu-bw.E_1764750330 cluster:ay36) by smtp.aliyun-inc.com; Wed, 03 Dec 2025 16:25:30 +0800 Message-ID: Date: Wed, 3 Dec 2025 16:25:30 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 1/2] ocfs2: Add ocfs2_emergency_state helper and apply to setattr To: Ahmet Eray Karadag , mark@fasheh.com, jlbec@evilplan.org, akpm Cc: ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org, david.hunter.linux@gmail.com, skhan@linuxfoundation.org, Heming Zhao , Albin Babu Varghese References: From: Joseph Qi In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 > Co-developed-by: Albin Babu Varghese > Signed-off-by: Albin Babu Varghese > Signed-off-by: Ahmet Eray Karadag > Reviewed-by: Heming Zhao Reviewed-by: Joseph Qi > --- > 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 &