All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: Dave Chinner <david@fromorbit.com>
Cc: linux-xfs@vger.kernel.org
Subject: Re: [PATCH 15/16] xfs: introduce xfs_sb_is_v5 helper
Date: Wed, 14 Jul 2021 16:24:28 -0700	[thread overview]
Message-ID: <20210714232428.GI22402@magnolia> (raw)
In-Reply-To: <20210714041912.2625692-16-david@fromorbit.com>

On Wed, Jul 14, 2021 at 02:19:11PM +1000, Dave Chinner wrote:
> From: Dave Chinner <dchinner@redhat.com>
> 
> Rather than open coding XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5
> checks everywhere, add a simple wrapper to encapsulate this and make
> the code easier to read.
> 
> This allows us to remove the xfs_sb_version_has_v3inode() wrapper
> which is only used in xfs_format.h now and is just a version number
> check.
> 
> There are a couple of places where we should be checking the mount
> feature bits rather than the superblock version (e.g. remount), so
> those are converted to use xfs_has_crc(mp) instead.
> 
> Signed-off-by: Dave Chinner <dchinner@redhat.com>

Oh good, these two collapse finally...
Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

> ---
>  fs/xfs/libxfs/xfs_format.h | 16 +++++++-------
>  fs/xfs/libxfs/xfs_sb.c     | 45 +++++++++++++++++++-------------------
>  fs/xfs/scrub/agheader.c    |  2 +-
>  fs/xfs/xfs_log_recover.c   |  2 +-
>  fs/xfs/xfs_super.c         | 11 +++++-----
>  5 files changed, 38 insertions(+), 38 deletions(-)
> 
> diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h
> index 0bd44a780937..e1ecb3237075 100644
> --- a/fs/xfs/libxfs/xfs_format.h
> +++ b/fs/xfs/libxfs/xfs_format.h
> @@ -279,6 +279,11 @@ typedef struct xfs_dsb {
>  
>  #define	XFS_SB_VERSION_NUM(sbp)	((sbp)->sb_versionnum & XFS_SB_VERSION_NUMBITS)
>  
> +static inline bool xfs_sb_is_v5(struct xfs_sb *sbp)
> +{
> +	return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5;
> +}
> +
>  /*
>   * Detect a mismatched features2 field.  Older kernels read/wrote
>   * this into the wrong slot, so to be safe we keep them in sync.
> @@ -290,7 +295,7 @@ static inline bool xfs_sb_has_mismatched_features2(struct xfs_sb *sbp)
>  
>  static inline bool xfs_sb_version_hasmorebits(struct xfs_sb *sbp)
>  {
> -	return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 ||
> +	return xfs_sb_is_v5(sbp) ||
>  	       (sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT);
>  }
>  
> @@ -398,15 +403,10 @@ xfs_sb_has_incompat_log_feature(
>   * v5 file systems support V3 inodes only, earlier file systems support
>   * v2 and v1 inodes.
>   */
> -static inline bool xfs_sb_version_has_v3inode(struct xfs_sb *sbp)
> -{
> -	return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5;
> -}
> -
>  static inline bool xfs_dinode_good_version(struct xfs_sb *sbp,
>  		uint8_t version)
>  {
> -	if (xfs_sb_version_has_v3inode(sbp))
> +	if (xfs_sb_is_v5(sbp))
>  		return version == 3;
>  	return version == 1 || version == 2;
>  }
> @@ -878,7 +878,7 @@ enum xfs_dinode_fmt {
>   * Inode size for given fs.
>   */
>  #define XFS_DINODE_SIZE(sbp) \
> -	(xfs_sb_version_has_v3inode(sbp) ? \
> +	(xfs_sb_is_v5(sbp) ? \
>  		sizeof(struct xfs_dinode) : \
>  		offsetof(struct xfs_dinode, di_crc))
>  #define XFS_LITINO(mp) \
> diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c
> index a4ea6e2a38e2..7bb4a5aa2462 100644
> --- a/fs/xfs/libxfs/xfs_sb.c
> +++ b/fs/xfs/libxfs/xfs_sb.c
> @@ -38,7 +38,7 @@ xfs_sb_good_version(
>  	struct xfs_sb	*sbp)
>  {
>  	/* all v5 filesystems are supported */
> -	if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5)
> +	if (xfs_sb_is_v5(sbp))
>  		return true;
>  
>  	/* versions prior to v4 are not supported */
> @@ -97,7 +97,7 @@ xfs_sb_version_to_features(
>  			features |= XFS_FEAT_FTYPE;
>  	}
>  
> -	if (XFS_SB_VERSION_NUM(sbp) != XFS_SB_VERSION_5)
> +	if (!xfs_sb_is_v5(sbp))
>  		return features;
>  
>  	/* Always on V5 features */
> @@ -133,7 +133,7 @@ xfs_validate_sb_read(
>  	struct xfs_mount	*mp,
>  	struct xfs_sb		*sbp)
>  {
> -	if (XFS_SB_VERSION_NUM(sbp) != XFS_SB_VERSION_5)
> +	if (!xfs_sb_is_v5(sbp))
>  		return 0;
>  
>  	/*
> @@ -200,7 +200,7 @@ xfs_validate_sb_write(
>  		return -EFSCORRUPTED;
>  	}
>  
> -	if (XFS_SB_VERSION_NUM(sbp) != XFS_SB_VERSION_5)
> +	if (!xfs_sb_is_v5(sbp))
>  		return 0;
>  
>  	/*
> @@ -274,7 +274,7 @@ xfs_validate_sb_common(
>  	/*
>  	 * Validate feature flags and state
>  	 */
> -	if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) {
> +	if (xfs_sb_is_v5(sbp)) {
>  		if (sbp->sb_blocksize < XFS_MIN_CRC_BLOCKSIZE) {
>  			xfs_notice(mp,
>  "Block size (%u bytes) too small for Version 5 superblock (minimum %d bytes)",
> @@ -466,7 +466,7 @@ xfs_sb_quota_from_disk(struct xfs_sb *sbp)
>  	 * We need to do these manipilations only if we are working
>  	 * with an older version of on-disk superblock.
>  	 */
> -	if (XFS_SB_VERSION_NUM(sbp) >= XFS_SB_VERSION_5)
> +	if (xfs_sb_is_v5(sbp))
>  		return;
>  
>  	if (sbp->sb_qflags & XFS_OQUOTA_ENFD)
> @@ -559,7 +559,7 @@ __xfs_sb_from_disk(
>  	 * sb_meta_uuid is only on disk if it differs from sb_uuid and the
>  	 * feature flag is set; if not set we keep it only in memory.
>  	 */
> -	if (XFS_SB_VERSION_NUM(to) == XFS_SB_VERSION_5 &&
> +	if (xfs_sb_is_v5(to) &&
>  	    (to->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_META_UUID))
>  		uuid_copy(&to->sb_meta_uuid, &from->sb_meta_uuid);
>  	else
> @@ -590,7 +590,7 @@ xfs_sb_quota_to_disk(
>  	 * The in-memory superblock quota state matches the v5 on-disk format so
>  	 * just write them out and return
>  	 */
> -	if (XFS_SB_VERSION_NUM(from) == XFS_SB_VERSION_5) {
> +	if (xfs_sb_is_v5(from)) {
>  		to->sb_qflags = cpu_to_be16(from->sb_qflags);
>  		to->sb_gquotino = cpu_to_be64(from->sb_gquotino);
>  		to->sb_pquotino = cpu_to_be64(from->sb_pquotino);
> @@ -700,19 +700,20 @@ xfs_sb_to_disk(
>  	to->sb_features2 = cpu_to_be32(from->sb_features2);
>  	to->sb_bad_features2 = cpu_to_be32(from->sb_bad_features2);
>  
> -	if (XFS_SB_VERSION_NUM(from) == XFS_SB_VERSION_5) {
> -		to->sb_features_compat = cpu_to_be32(from->sb_features_compat);
> -		to->sb_features_ro_compat =
> -				cpu_to_be32(from->sb_features_ro_compat);
> -		to->sb_features_incompat =
> -				cpu_to_be32(from->sb_features_incompat);
> -		to->sb_features_log_incompat =
> -				cpu_to_be32(from->sb_features_log_incompat);
> -		to->sb_spino_align = cpu_to_be32(from->sb_spino_align);
> -		to->sb_lsn = cpu_to_be64(from->sb_lsn);
> -		if (from->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_META_UUID)
> -			uuid_copy(&to->sb_meta_uuid, &from->sb_meta_uuid);
> -	}
> +	if (!xfs_sb_is_v5(from))
> +		return;
> +
> +	to->sb_features_compat = cpu_to_be32(from->sb_features_compat);
> +	to->sb_features_ro_compat =
> +			cpu_to_be32(from->sb_features_ro_compat);
> +	to->sb_features_incompat =
> +			cpu_to_be32(from->sb_features_incompat);
> +	to->sb_features_log_incompat =
> +			cpu_to_be32(from->sb_features_log_incompat);
> +	to->sb_spino_align = cpu_to_be32(from->sb_spino_align);
> +	to->sb_lsn = cpu_to_be64(from->sb_lsn);
> +	if (from->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_META_UUID)
> +		uuid_copy(&to->sb_meta_uuid, &from->sb_meta_uuid);
>  }
>  
>  /*
> @@ -815,7 +816,7 @@ xfs_sb_write_verify(
>  	if (error)
>  		goto out_error;
>  
> -	if (XFS_SB_VERSION_NUM(&sb) != XFS_SB_VERSION_5)
> +	if (!xfs_sb_is_v5(&sb))
>  		return;
>  
>  	if (bip)
> diff --git a/fs/xfs/scrub/agheader.c b/fs/xfs/scrub/agheader.c
> index 549e6dda16e6..3b6ca1fc38fc 100644
> --- a/fs/xfs/scrub/agheader.c
> +++ b/fs/xfs/scrub/agheader.c
> @@ -248,7 +248,7 @@ xchk_superblock(
>  			xchk_block_set_corrupt(sc, bp);
>  	} else {
>  		v2_ok = XFS_SB_VERSION2_OKBITS;
> -		if (XFS_SB_VERSION_NUM(&mp->m_sb) >= XFS_SB_VERSION_5)
> +		if (xfs_sb_is_v5(&mp->m_sb))
>  			v2_ok |= XFS_SB_VERSION2_CRCBIT;
>  
>  		if (!!(sb->sb_features2 & cpu_to_be32(~v2_ok)))
> diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c
> index ffa445d24ba4..9048397870ce 100644
> --- a/fs/xfs/xfs_log_recover.c
> +++ b/fs/xfs/xfs_log_recover.c
> @@ -3380,7 +3380,7 @@ xlog_recover(
>  		 * (e.g. unsupported transactions, then simply reject the
>  		 * attempt at recovery before touching anything.
>  		 */
> -		if (XFS_SB_VERSION_NUM(&log->l_mp->m_sb) == XFS_SB_VERSION_5 &&
> +		if (xfs_sb_is_v5(&log->l_mp->m_sb) &&
>  		    xfs_sb_has_incompat_log_feature(&log->l_mp->m_sb,
>  					XFS_SB_FEAT_INCOMPAT_LOG_UNKNOWN)) {
>  			xfs_warn(log->l_mp,
> diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
> index 8dd8398846fa..8851363cd471 100644
> --- a/fs/xfs/xfs_super.c
> +++ b/fs/xfs/xfs_super.c
> @@ -1529,7 +1529,7 @@ xfs_fs_fill_super(
>  	set_posix_acl_flag(sb);
>  
>  	/* version 5 superblocks support inode version counters. */
> -	if (XFS_SB_VERSION_NUM(&mp->m_sb) == XFS_SB_VERSION_5)
> +	if (xfs_has_crc(mp))
>  		sb->s_flags |= SB_I_VERSION;
>  
>  	if (xfs_has_bigtime(mp))
> @@ -1655,7 +1655,7 @@ xfs_remount_rw(
>  		return -EINVAL;
>  	}
>  
> -	if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 &&
> +	if (xfs_sb_is_v5(sbp) &&
>  	    xfs_sb_has_ro_compat_feature(sbp, XFS_SB_FEAT_RO_COMPAT_UNKNOWN)) {
>  		xfs_warn(mp,
>  	"ro->rw transition prohibited on unknown (0x%x) ro-compat filesystem",
> @@ -1763,12 +1763,11 @@ xfs_fs_reconfigure(
>  {
>  	struct xfs_mount	*mp = XFS_M(fc->root->d_sb);
>  	struct xfs_mount        *new_mp = fc->s_fs_info;
> -	xfs_sb_t		*sbp = &mp->m_sb;
>  	int			flags = fc->sb_flags;
>  	int			error;
>  
>  	/* version 5 superblocks always support version counters. */
> -	if (XFS_SB_VERSION_NUM(&mp->m_sb) == XFS_SB_VERSION_5)
> +	if (xfs_has_crc(mp))
>  		fc->sb_flags |= SB_I_VERSION;
>  
>  	error = xfs_fs_validate_params(new_mp);
> @@ -1780,13 +1779,13 @@ xfs_fs_reconfigure(
>  	/* inode32 -> inode64 */
>  	if (xfs_has_small_inums(mp) && !xfs_has_small_inums(new_mp)) {
>  		mp->m_features &= ~XFS_FEAT_SMALL_INUMS;
> -		mp->m_maxagi = xfs_set_inode_alloc(mp, sbp->sb_agcount);
> +		mp->m_maxagi = xfs_set_inode_alloc(mp, mp->m_sb.sb_agcount);
>  	}
>  
>  	/* inode64 -> inode32 */
>  	if (!xfs_has_small_inums(mp) && xfs_has_small_inums(new_mp)) {
>  		mp->m_features |= XFS_FEAT_SMALL_INUMS;
> -		mp->m_maxagi = xfs_set_inode_alloc(mp, sbp->sb_agcount);
> +		mp->m_maxagi = xfs_set_inode_alloc(mp, mp->m_sb.sb_agcount);
>  	}
>  
>  	/* ro -> rw */
> -- 
> 2.31.1
> 

  reply	other threads:[~2021-07-14 23:24 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-14  4:18 [PATCH 00/16] xfs: rework feature flags Dave Chinner
2021-07-14  4:18 ` [PATCH 01/16] xfs: sb verifier doesn't handle uncached sb buffer Dave Chinner
2021-07-14  6:43   ` Christoph Hellwig
2021-07-14  9:37     ` Dave Chinner
2021-07-14 22:44   ` Darrick J. Wong
2021-07-14 23:00     ` Dave Chinner
2021-07-14 23:03       ` Darrick J. Wong
2021-07-14  4:18 ` [PATCH 02/16] xfs: rename xfs_has_attr() Dave Chinner
2021-07-14  6:49   ` Christoph Hellwig
2021-07-14 22:46   ` Darrick J. Wong
2021-07-14  4:18 ` [PATCH 03/16] xfs: rework attr2 feature and mount options Dave Chinner
2021-07-14  6:58   ` Christoph Hellwig
2021-07-14  9:45     ` Dave Chinner
2021-07-15  5:55       ` Christoph Hellwig
2021-07-15 23:47         ` Dave Chinner
2021-07-16  9:43           ` Christoph Hellwig
2021-07-14 22:51   ` Darrick J. Wong
2021-07-14  4:19 ` [PATCH 04/16] xfs: reflect sb features in xfs_mount Dave Chinner
2021-07-14  7:01   ` Christoph Hellwig
2021-07-14 22:56   ` Darrick J. Wong
2021-07-14 23:07     ` Dave Chinner
2021-07-14 23:17       ` Darrick J. Wong
2021-07-14  4:19 ` [PATCH 05/16] xfs: replace xfs_sb_version checks with feature flag checks Dave Chinner
2021-07-14  7:03   ` Christoph Hellwig
2021-07-14 22:57   ` Darrick J. Wong
2021-07-14  4:19 ` [PATCH 06/16] xfs: consolidate mount option features in m_features Dave Chinner
2021-07-14  7:05   ` Christoph Hellwig
2021-07-14  9:55     ` Dave Chinner
2021-07-15  5:59       ` Christoph Hellwig
2021-07-15 23:43         ` Dave Chinner
2021-07-14 23:02   ` Darrick J. Wong
2021-07-14  4:19 ` [PATCH 07/16] xfs: convert mount flags to features Dave Chinner
2021-07-14 23:07   ` Darrick J. Wong
2021-07-14  4:19 ` [PATCH 08/16] xfs: convert remaining mount flags to state flags Dave Chinner
2021-07-14 23:10   ` Darrick J. Wong
2021-07-14  4:19 ` [PATCH 09/16] xfs: replace XFS_FORCED_SHUTDOWN with xfs_is_shutdown Dave Chinner
2021-07-14 23:11   ` Darrick J. Wong
2021-07-14  4:19 ` [PATCH 10/16] xfs: convert xfs_fs_geometry to use mount feature checks Dave Chinner
2021-07-14  7:11   ` Christoph Hellwig
2021-07-14 23:15   ` Darrick J. Wong
2021-07-14 23:35     ` Dave Chinner
2021-07-14 23:38       ` Darrick J. Wong
2021-07-14  4:19 ` [PATCH 11/16] xfs: open code sb verifier " Dave Chinner
2021-07-14  7:19   ` Christoph Hellwig
2021-07-16  0:26   ` Darrick J. Wong
2021-07-14  4:19 ` [PATCH 12/16] xfs: convert scrub to use mount-based " Dave Chinner
2021-07-14 23:18   ` Darrick J. Wong
2021-07-14  4:19 ` [PATCH 13/16] xfs: convert xfs_sb_version_has checks to use mount features Dave Chinner
2021-07-14 23:19   ` Darrick J. Wong
2021-07-14  4:19 ` [PATCH 14/16] xfs: remove unused xfs_sb_version_has wrappers Dave Chinner
2021-07-14 23:21   ` Darrick J. Wong
2021-07-14  4:19 ` [PATCH 15/16] xfs: introduce xfs_sb_is_v5 helper Dave Chinner
2021-07-14 23:24   ` Darrick J. Wong [this message]
2021-07-14  4:19 ` [PATCH 16/16] xfs: kill xfs_sb_version_has_v3inode() Dave Chinner
2021-07-14 23:24   ` Darrick J. Wong
  -- strict thread matches above, loose matches on Subject: below --
2021-08-10  5:24 [PATCH 00/16 v2] xfs: rework feature flags Dave Chinner
2021-08-10  5:24 ` [PATCH 15/16] xfs: introduce xfs_sb_is_v5 helper Dave Chinner
2021-08-18 23:59 [PATCH 00/16 v3] xfs: rework feature flags Dave Chinner
2021-08-18 23:59 ` [PATCH 15/16] xfs: introduce xfs_sb_is_v5 helper Dave Chinner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210714232428.GI22402@magnolia \
    --to=djwong@kernel.org \
    --cc=david@fromorbit.com \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.