public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] xfs: compile out v4 support if disabled
@ 2024-03-25  3:13 Christoph Hellwig
  2024-03-26  0:02 ` Darrick J. Wong
  0 siblings, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2024-03-25  3:13 UTC (permalink / raw)
  To: chandan.babu, djwong; +Cc: linux-xfs

Add a few strategic IS_ENABLED statements to let the compiler eliminate
unused code when CONFIG_XFS_SUPPORT_V4 is disabled.

This saves multiple kilobytes of .text in my .config:

$ size xfs.o.*
text	   data	    bss	    dec	    hex	filename
1363633	 294836	    592	1659061	 1950b5	xfs.o.new
1371453	 294868	    592	1666913	 196f61	xfs.o.old

Signed-off-by: Christoph Hellwig <hch@lst.de>
---

Changes since v1:
 - compile out the right bits, and more of them

 fs/xfs/xfs_mount.h | 40 +++++++++++++++++++++++++++++++---------
 fs/xfs/xfs_super.c | 22 +++++++++++++---------
 2 files changed, 44 insertions(+), 18 deletions(-)

diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h
index 0e8d7779c0a561..85e327bf05041f 100644
--- a/fs/xfs/xfs_mount.h
+++ b/fs/xfs/xfs_mount.h
@@ -337,19 +337,10 @@ static inline void xfs_add_ ## name (struct xfs_mount *mp) \
 __XFS_ADD_FEAT(attr, ATTR)
 __XFS_HAS_FEAT(nlink, NLINK)
 __XFS_ADD_FEAT(quota, QUOTA)
-__XFS_HAS_FEAT(align, ALIGN)
 __XFS_HAS_FEAT(dalign, DALIGN)
-__XFS_HAS_FEAT(logv2, LOGV2)
 __XFS_HAS_FEAT(sector, SECTOR)
-__XFS_HAS_FEAT(extflg, EXTFLG)
 __XFS_HAS_FEAT(asciici, ASCIICI)
-__XFS_HAS_FEAT(lazysbcount, LAZYSBCOUNT)
-__XFS_ADD_FEAT(attr2, ATTR2)
 __XFS_HAS_FEAT(parent, PARENT)
-__XFS_ADD_FEAT(projid32, PROJID32)
-__XFS_HAS_FEAT(crc, CRC)
-__XFS_HAS_FEAT(v3inodes, V3INODES)
-__XFS_HAS_FEAT(pquotino, PQUOTINO)
 __XFS_HAS_FEAT(ftype, FTYPE)
 __XFS_HAS_FEAT(finobt, FINOBT)
 __XFS_HAS_FEAT(rmapbt, RMAPBT)
@@ -362,6 +353,37 @@ __XFS_HAS_FEAT(bigtime, BIGTIME)
 __XFS_HAS_FEAT(needsrepair, NEEDSREPAIR)
 __XFS_HAS_FEAT(large_extent_counts, NREXT64)
 
+/*
+ * Some features are always on for v5 file systems, allow the compiler to
+ * eliminiate dead code when building without v4 support.
+ */
+#define __XFS_HAS_V4_FEAT(name, NAME) \
+static inline bool xfs_has_ ## name (struct xfs_mount *mp) \
+{ \
+	return !IS_ENABLED(CONFIG_XFS_SUPPORT_V4) || \
+		(mp->m_features & XFS_FEAT_ ## NAME); \
+}
+
+#define __XFS_ADD_V4_FEAT(name, NAME) \
+	__XFS_HAS_V4_FEAT(name, NAME); \
+static inline void xfs_add_ ## name (struct xfs_mount *mp) \
+{ \
+	if (IS_ENABLED(CONFIG_XFS_SUPPORT_V4)) { \
+		mp->m_features |= XFS_FEAT_ ## NAME; \
+		xfs_sb_version_add ## name(&mp->m_sb); \
+	} \
+}
+
+__XFS_HAS_V4_FEAT(align, ALIGN)
+__XFS_HAS_V4_FEAT(logv2, LOGV2)
+__XFS_HAS_V4_FEAT(extflg, EXTFLG)
+__XFS_HAS_V4_FEAT(lazysbcount, LAZYSBCOUNT)
+__XFS_ADD_V4_FEAT(attr2, ATTR2)
+__XFS_ADD_V4_FEAT(projid32, PROJID32)
+__XFS_HAS_V4_FEAT(v3inodes, V3INODES)
+__XFS_HAS_V4_FEAT(crc, CRC)
+__XFS_HAS_V4_FEAT(pquotino, PQUOTINO)
+
 /*
  * Mount features
  *
diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
index 71732457583370..f325a2d1b3a902 100644
--- a/fs/xfs/xfs_super.c
+++ b/fs/xfs/xfs_super.c
@@ -1589,17 +1589,21 @@ xfs_fs_fill_super(
 	if (error)
 		goto out_free_sb;
 
-	/* V4 support is undergoing deprecation. */
-	if (!xfs_has_crc(mp)) {
-#ifdef CONFIG_XFS_SUPPORT_V4
+	/*
+	 * V4 support is undergoing deprecation.
+	 *
+	 * Note: this has to use an open coded m_features check as xfs_has_crc
+	 * always returns false for !CONFIG_XFS_SUPPORT_V4.
+	 */
+	if (!(mp->m_features & XFS_FEAT_CRC)) {
+		if (!IS_ENABLED(CONFIG_XFS_SUPPORT_V4)) {
+			xfs_warn(mp,
+	"Deprecated V4 format (crc=0) not supported by kernel.");
+			error = -EINVAL;
+			goto out_free_sb;
+		}
 		xfs_warn_once(mp,
 	"Deprecated V4 format (crc=0) will not be supported after September 2030.");
-#else
-		xfs_warn(mp,
-	"Deprecated V4 format (crc=0) not supported by kernel.");
-		error = -EINVAL;
-		goto out_free_sb;
-#endif
 	}
 
 	/* ASCII case insensitivity is undergoing deprecation. */
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] xfs: compile out v4 support if disabled
  2024-03-25  3:13 [PATCH v2] xfs: compile out v4 support if disabled Christoph Hellwig
@ 2024-03-26  0:02 ` Darrick J. Wong
  2024-03-26  5:50   ` Christoph Hellwig
  0 siblings, 1 reply; 4+ messages in thread
From: Darrick J. Wong @ 2024-03-26  0:02 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: chandan.babu, linux-xfs

On Mon, Mar 25, 2024 at 11:13:18AM +0800, Christoph Hellwig wrote:
> Add a few strategic IS_ENABLED statements to let the compiler eliminate
> unused code when CONFIG_XFS_SUPPORT_V4 is disabled.
> 
> This saves multiple kilobytes of .text in my .config:
> 
> $ size xfs.o.*
> text	   data	    bss	    dec	    hex	filename
> 1363633	 294836	    592	1659061	 1950b5	xfs.o.new
> 1371453	 294868	    592	1666913	 196f61	xfs.o.old
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> 
> Changes since v1:
>  - compile out the right bits, and more of them
> 
>  fs/xfs/xfs_mount.h | 40 +++++++++++++++++++++++++++++++---------
>  fs/xfs/xfs_super.c | 22 +++++++++++++---------
>  2 files changed, 44 insertions(+), 18 deletions(-)
> 
> diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h
> index 0e8d7779c0a561..85e327bf05041f 100644
> --- a/fs/xfs/xfs_mount.h
> +++ b/fs/xfs/xfs_mount.h
> @@ -337,19 +337,10 @@ static inline void xfs_add_ ## name (struct xfs_mount *mp) \
>  __XFS_ADD_FEAT(attr, ATTR)
>  __XFS_HAS_FEAT(nlink, NLINK)
>  __XFS_ADD_FEAT(quota, QUOTA)
> -__XFS_HAS_FEAT(align, ALIGN)
>  __XFS_HAS_FEAT(dalign, DALIGN)
> -__XFS_HAS_FEAT(logv2, LOGV2)
>  __XFS_HAS_FEAT(sector, SECTOR)
> -__XFS_HAS_FEAT(extflg, EXTFLG)
>  __XFS_HAS_FEAT(asciici, ASCIICI)
> -__XFS_HAS_FEAT(lazysbcount, LAZYSBCOUNT)
> -__XFS_ADD_FEAT(attr2, ATTR2)
>  __XFS_HAS_FEAT(parent, PARENT)
> -__XFS_ADD_FEAT(projid32, PROJID32)
> -__XFS_HAS_FEAT(crc, CRC)
> -__XFS_HAS_FEAT(v3inodes, V3INODES)
> -__XFS_HAS_FEAT(pquotino, PQUOTINO)
>  __XFS_HAS_FEAT(ftype, FTYPE)
>  __XFS_HAS_FEAT(finobt, FINOBT)
>  __XFS_HAS_FEAT(rmapbt, RMAPBT)
> @@ -362,6 +353,37 @@ __XFS_HAS_FEAT(bigtime, BIGTIME)
>  __XFS_HAS_FEAT(needsrepair, NEEDSREPAIR)
>  __XFS_HAS_FEAT(large_extent_counts, NREXT64)
>  
> +/*
> + * Some features are always on for v5 file systems, allow the compiler to
> + * eliminiate dead code when building without v4 support.
> + */
> +#define __XFS_HAS_V4_FEAT(name, NAME) \

Shouldn't this be called __XFS_HAS_V5_FEAT?

> +static inline bool xfs_has_ ## name (struct xfs_mount *mp) \
> +{ \
> +	return !IS_ENABLED(CONFIG_XFS_SUPPORT_V4) || \
> +		(mp->m_features & XFS_FEAT_ ## NAME); \
> +}
> +
> +#define __XFS_ADD_V4_FEAT(name, NAME) \
> +	__XFS_HAS_V4_FEAT(name, NAME); \

This too?

The rest of the patch looks ok. :)

--D

> +static inline void xfs_add_ ## name (struct xfs_mount *mp) \
> +{ \
> +	if (IS_ENABLED(CONFIG_XFS_SUPPORT_V4)) { \
> +		mp->m_features |= XFS_FEAT_ ## NAME; \
> +		xfs_sb_version_add ## name(&mp->m_sb); \
> +	} \
> +}
> +
> +__XFS_HAS_V4_FEAT(align, ALIGN)
> +__XFS_HAS_V4_FEAT(logv2, LOGV2)
> +__XFS_HAS_V4_FEAT(extflg, EXTFLG)
> +__XFS_HAS_V4_FEAT(lazysbcount, LAZYSBCOUNT)
> +__XFS_ADD_V4_FEAT(attr2, ATTR2)
> +__XFS_ADD_V4_FEAT(projid32, PROJID32)
> +__XFS_HAS_V4_FEAT(v3inodes, V3INODES)
> +__XFS_HAS_V4_FEAT(crc, CRC)
> +__XFS_HAS_V4_FEAT(pquotino, PQUOTINO)
> +
>  /*
>   * Mount features
>   *
> diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
> index 71732457583370..f325a2d1b3a902 100644
> --- a/fs/xfs/xfs_super.c
> +++ b/fs/xfs/xfs_super.c
> @@ -1589,17 +1589,21 @@ xfs_fs_fill_super(
>  	if (error)
>  		goto out_free_sb;
>  
> -	/* V4 support is undergoing deprecation. */
> -	if (!xfs_has_crc(mp)) {
> -#ifdef CONFIG_XFS_SUPPORT_V4
> +	/*
> +	 * V4 support is undergoing deprecation.
> +	 *
> +	 * Note: this has to use an open coded m_features check as xfs_has_crc
> +	 * always returns false for !CONFIG_XFS_SUPPORT_V4.
> +	 */
> +	if (!(mp->m_features & XFS_FEAT_CRC)) {
> +		if (!IS_ENABLED(CONFIG_XFS_SUPPORT_V4)) {
> +			xfs_warn(mp,
> +	"Deprecated V4 format (crc=0) not supported by kernel.");
> +			error = -EINVAL;
> +			goto out_free_sb;
> +		}
>  		xfs_warn_once(mp,
>  	"Deprecated V4 format (crc=0) will not be supported after September 2030.");
> -#else
> -		xfs_warn(mp,
> -	"Deprecated V4 format (crc=0) not supported by kernel.");
> -		error = -EINVAL;
> -		goto out_free_sb;
> -#endif
>  	}
>  
>  	/* ASCII case insensitivity is undergoing deprecation. */
> -- 
> 2.39.2
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] xfs: compile out v4 support if disabled
  2024-03-26  0:02 ` Darrick J. Wong
@ 2024-03-26  5:50   ` Christoph Hellwig
  2024-03-26 17:24     ` Darrick J. Wong
  0 siblings, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2024-03-26  5:50 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: Christoph Hellwig, chandan.babu, linux-xfs

On Mon, Mar 25, 2024 at 05:02:37PM -0700, Darrick J. Wong wrote:
> > +/*
> > + * Some features are always on for v5 file systems, allow the compiler to
> > + * eliminiate dead code when building without v4 support.
> > + */
> > +#define __XFS_HAS_V4_FEAT(name, NAME) \
> 
> Shouldn't this be called __XFS_HAS_V5_FEAT?

They are features for v4 and unconditional for v5.  Given that Dave
came up with the same names independently they can't be all bad,
although I don't really care very strongly.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] xfs: compile out v4 support if disabled
  2024-03-26  5:50   ` Christoph Hellwig
@ 2024-03-26 17:24     ` Darrick J. Wong
  0 siblings, 0 replies; 4+ messages in thread
From: Darrick J. Wong @ 2024-03-26 17:24 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: chandan.babu, linux-xfs

On Tue, Mar 26, 2024 at 06:50:47AM +0100, Christoph Hellwig wrote:
> On Mon, Mar 25, 2024 at 05:02:37PM -0700, Darrick J. Wong wrote:
> > > +/*
> > > + * Some features are always on for v5 file systems, allow the compiler to
> > > + * eliminiate dead code when building without v4 support.
> > > + */
> > > +#define __XFS_HAS_V4_FEAT(name, NAME) \
> > 
> > Shouldn't this be called __XFS_HAS_V5_FEAT?
> 
> They are features for v4 and unconditional for v5.  Given that Dave
> came up with the same names independently they can't be all bad,
> although I don't really care very strongly.

Ok, you've both persuaded me then.

Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-03-26 17:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-25  3:13 [PATCH v2] xfs: compile out v4 support if disabled Christoph Hellwig
2024-03-26  0:02 ` Darrick J. Wong
2024-03-26  5:50   ` Christoph Hellwig
2024-03-26 17:24     ` Darrick J. Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox