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 62E8C2FCC04 for ; Fri, 28 Nov 2025 09:06:33 +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=1764320795; cv=none; b=nB/AE/rDi1I5J6UzHCTbHKwRGCXpW0TWdBODsoIRz1AR+XAG7HzPSJQNfs/EZyF9VuYiKqbPgvO+nLcc7RrtylKXTix5q01VYO9ySSiuX059bAok9oqRk/dhw6UnXIvQC4gM5At4VEAIcTwlg9y9S6LcCysAYHbf1oo/Q54EXp8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764320795; c=relaxed/simple; bh=x2avRk/dKm+mCLueN8oiQHD739LXkYF2Blewq9ceHyo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=KsFKE+p5cjeqNVInrnJVG74p4o9Ug6wReBQ1UeJx4K5dxgKNK/d3wjj+rJc6IY+aGPPBYBRLnUdImqToBReJso/FPAd2virAd2kWXfGY99X8ZJwF7+4B2hYlNNcmjMyLYe+4h6FX/QTI3YSnB6MZWc8SdKRYHP0sLW21i2tK6Lo= 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=XUxVy9Km; 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="XUxVy9Km" Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-64162c04f90so2985006a12.0 for ; Fri, 28 Nov 2025 01:06:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764320792; x=1764925592; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Fybugla5irn7/5MQulh1PMDITgT+aYZ/+S7WGxnXfR4=; b=XUxVy9KmGINRVHPk9oN2BlMNzlHf2U/nuUT+v1DJ+gax8Mv6659TR550SG1XjgkBZM Wghkgz1ZiqXcZllVqcUwV6uKtBEjjdIxU+XuiXLpOg+aJZcfwfuD36sHsYQsR6sFuYKV Y4VtDRDB7+PwGhMB8XOZm6axoJpdWwtoVKe2wQaOe+2wLLdEa4reg4FBfCOEJK/umE+c uYPQpi+HUw+6BY57jipXKNfY5NewHSvIzN/F+/qg49e8xSd4d7VPSR0pBd2ynZKZc3iO 7sT9qRNIBW8K/WAaHID63Kkj61O9SWe7RYr3ES0Nat8XwKnL9m1nEyXeN16rdw65ZVRs KnVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764320792; x=1764925592; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Fybugla5irn7/5MQulh1PMDITgT+aYZ/+S7WGxnXfR4=; b=OQl9hvAebFtkB8KA1FtyIXzR/dvm9ANyRI8kROKZXhkr/Zr6H8cbP5LxUVf1qQhWpn m7f8kfeEVHhIG/2ePVukWawtM/WLCE8tAWTMtXcGhZ6bCql5ow8hIDT8C/PkrvI4/Sfb fJxgrRL+uG3OkgcoVSgTuA20Vm8QxZQQJy768nJefhJfOySCmhHQTLwB+0MQQggoE11G jprTVVhjOpzemgW+f9JBx8KvpbUnkkphBeVWobUjXq8125fM+4g3uPSsCNRBUGkXnOgv ZZzVEr00lkQw6dQZU58+IOOR5POFEOCiz84AIlM3KuVYLyZBycQHWnIOHF3VK2Du1AhO dJtA== X-Forwarded-Encrypted: i=1; AJvYcCWdgNkWF05NNWYjYHTTkOKl0KyW9An8LOX0dcrcGzI70YuJHePENK2Bxmkh7V0oyqDHdYXXB5yrbIh5eL8=@vger.kernel.org X-Gm-Message-State: AOJu0YxWQZZgajyL74ubE349HO7J2BFLrB4w41XSB1gVK34X4S6swPRQ kZzz4FazHIa5Op4Np6LlXIDxA6Dem+rw77WIFNmvqE6a0PWHj0imkRir X-Gm-Gg: ASbGnctOFpreOVzhw2tuK2l9GN3nGWPt5DZ7GCtjScBmTGs7dkfl14GKNzrv8E7yBa8 jSvMf+P5ioDNrv8kfy2l0eQopMMrN6LMtUhdb5HRMsKrYXIqHJiXgzfJObwGctUZCBkxoZusoA3 Dq6fBe59p/wgvTWiUhhAOfVKMozPZAJC6I/bnAoJMR51SvEIoytJPnCpWaWSY9aXckbbhJsYxpC SkvlTbsz9wTgL1Wm9WpG9iuDXoQOyAfrhtLO9VSiYXu+0fwnoGF3uGXgcxOwmAlg64Ive5DRjJC Wkj1asn4kF9o979VgmSPCVSYcLE1IdpnP+GyJAwJkfHfReO1HRa6k30OkvkuGp3WQ4HkcF+1XBb E4idojCzWZ/pMM9cmF23nY2nNnBLK8cbbwZf1UDLp4I4EtT6Zvu2QY57vJkKzRnq/QJnWHNGyUq tExKIQCSIuRw== X-Google-Smtp-Source: AGHT+IEh9wemANzw5MUsk3gYyvmUha3wASsp1y4xGHyQ+NAl08Ru0AZk39iUNvmhAhoJJEswEeJRbQ== X-Received: by 2002:a17:907:db16:b0:b73:6474:1ee8 with SMTP id a640c23a62f3a-b7671565a7cmr2818527266b.14.1764320791320; Fri, 28 Nov 2025 01:06:31 -0800 (PST) Received: from eray-kasa ([2a02:4e0:2d05:16ab:8837:f306:fdf3:a46b]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b76f5199852sm400094666b.15.2025.11.28.01.06.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Nov 2025 01:06:31 -0800 (PST) Date: Fri, 28 Nov 2025 12:06:28 +0300 From: Ahmet Eray Karadag To: Heming Zhao Cc: mark@fasheh.com, jlbec@evilplan.org, joseph.qi@linux.alibaba.com, ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org, david.hunter.linux@gmail.com, skhan@linuxfoundation.org, Albin Babu Varghese Subject: Re: [PATCH 1/2] ocfs2: Add ocfs2_emergency_state helper and apply to setattr Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Tue, Nov 25, 2025 at 10:58:32AM +0800, Heming Zhao wrote: > On Tue, Nov 18, 2025 at 03:26:44AM +0300, 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 > > --- > > fs/ocfs2/file.c | 6 ++++++ > > fs/ocfs2/ocfs2.h | 8 ++++++++ > > 2 files changed, 14 insertions(+) > > > > diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c > > index 21d797ccccd0..03a98985ac92 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 (status < 0) { > > + mlog_errno(status); > > + goto bail; > > + } > > + > > I prefer the ext4_emerency_state() style, using "if (unlikely(status))" here. > > > 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..2ac16632dd19 100644 > > --- a/fs/ocfs2/ocfs2.h > > +++ b/fs/ocfs2/ocfs2.h > > @@ -680,6 +680,14 @@ static inline int ocfs2_is_soft_readonly(struct ocfs2_super *osb) > > return ret; > > } > > > > +static inline int ocfs2_emergency_state(struct ocfs2_super *osb) > > +{ > > + if (ocfs2_is_soft_readonly(osb) || ocfs2_is_hard_readonly(osb)) { > > + return -EROFS; > > + } > > + return 0; > > +} > > + > > calling ocfs2_is_[soft|hard]_readonly() is a little expensive because it > involves acquiring the spinlock osb->osb_lock twice. In my view, we could > introduce a new function, such as ocfs2_is_readonly(): In ext4, the helper functions check read-only flags without acquiring a lock. Would it be problematic to do the same in ocfs2? > > ``` > 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 > } > ``` > > Thanks, > Heming > > > static inline int ocfs2_clusterinfo_valid(struct ocfs2_super *osb) > > { > > return (osb->s_feature_incompat & > > -- > > 2.43.0 > > I agree with the other comments. We will send v2.