Commit d6837c1a authored by Dave Chinner's avatar Dave Chinner Committed by Darrick J. Wong
Browse files

xfs: introduce xfs_sb_is_v5 helper



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: default avatarDave Chinner <dchinner@redhat.com>
Reviewed-by: default avatarDarrick J. Wong <djwong@kernel.org>
Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
parent 2beb7b50
Loading
Loading
Loading
Loading
+8 −8
Original line number Original line Diff line number Diff line
@@ -279,6 +279,11 @@ typedef struct xfs_dsb {


#define	XFS_SB_VERSION_NUM(sbp)	((sbp)->sb_versionnum & XFS_SB_VERSION_NUMBITS)
#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
 * Detect a mismatched features2 field.  Older kernels read/wrote
 * this into the wrong slot, so to be safe we keep them in sync.
 * 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)
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);
	       (sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT);
}
}


@@ -413,15 +418,10 @@ xfs_sb_add_incompat_log_features(
 * v5 file systems support V3 inodes only, earlier file systems support
 * v5 file systems support V3 inodes only, earlier file systems support
 * v2 and v1 inodes.
 * 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,
static inline bool xfs_dinode_good_version(struct xfs_sb *sbp,
		uint8_t version)
		uint8_t version)
{
{
	if (xfs_sb_version_has_v3inode(sbp))
	if (xfs_sb_is_v5(sbp))
		return version == 3;
		return version == 3;
	return version == 1 || version == 2;
	return version == 1 || version == 2;
}
}
@@ -893,7 +893,7 @@ enum xfs_dinode_fmt {
 * Inode size for given fs.
 * Inode size for given fs.
 */
 */
#define XFS_DINODE_SIZE(sbp) \
#define XFS_DINODE_SIZE(sbp) \
	(xfs_sb_version_has_v3inode(sbp) ? \
	(xfs_sb_is_v5(sbp) ? \
		sizeof(struct xfs_dinode) : \
		sizeof(struct xfs_dinode) : \
		offsetof(struct xfs_dinode, di_crc))
		offsetof(struct xfs_dinode, di_crc))
#define XFS_LITINO(mp) \
#define XFS_LITINO(mp) \
+23 −22
Original line number Original line Diff line number Diff line
@@ -38,7 +38,7 @@ xfs_sb_good_version(
	struct xfs_sb	*sbp)
	struct xfs_sb	*sbp)
{
{
	/* all v5 filesystems are supported */
	/* all v5 filesystems are supported */
	if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5)
	if (xfs_sb_is_v5(sbp))
		return true;
		return true;


	/* versions prior to v4 are not supported */
	/* versions prior to v4 are not supported */
@@ -97,7 +97,7 @@ xfs_sb_version_to_features(
			features |= XFS_FEAT_FTYPE;
			features |= XFS_FEAT_FTYPE;
	}
	}


	if (XFS_SB_VERSION_NUM(sbp) != XFS_SB_VERSION_5)
	if (!xfs_sb_is_v5(sbp))
		return features;
		return features;


	/* Always on V5 features */
	/* Always on V5 features */
@@ -133,7 +133,7 @@ xfs_validate_sb_read(
	struct xfs_mount	*mp,
	struct xfs_mount	*mp,
	struct xfs_sb		*sbp)
	struct xfs_sb		*sbp)
{
{
	if (XFS_SB_VERSION_NUM(sbp) != XFS_SB_VERSION_5)
	if (!xfs_sb_is_v5(sbp))
		return 0;
		return 0;


	/*
	/*
@@ -200,7 +200,7 @@ xfs_validate_sb_write(
		return -EFSCORRUPTED;
		return -EFSCORRUPTED;
	}
	}


	if (XFS_SB_VERSION_NUM(sbp) != XFS_SB_VERSION_5)
	if (!xfs_sb_is_v5(sbp))
		return 0;
		return 0;


	/*
	/*
@@ -274,7 +274,7 @@ xfs_validate_sb_common(
	/*
	/*
	 * Validate feature flags and state
	 * 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) {
		if (sbp->sb_blocksize < XFS_MIN_CRC_BLOCKSIZE) {
			xfs_notice(mp,
			xfs_notice(mp,
"Block size (%u bytes) too small for Version 5 superblock (minimum %d bytes)",
"Block size (%u bytes) too small for Version 5 superblock (minimum %d bytes)",
@@ -465,7 +465,7 @@ xfs_sb_quota_from_disk(struct xfs_sb *sbp)
	 * We need to do these manipilations only if we are working
	 * We need to do these manipilations only if we are working
	 * with an older version of on-disk superblock.
	 * 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;
		return;


	if (sbp->sb_qflags & XFS_OQUOTA_ENFD)
	if (sbp->sb_qflags & XFS_OQUOTA_ENFD)
@@ -558,7 +558,7 @@ __xfs_sb_from_disk(
	 * sb_meta_uuid is only on disk if it differs from sb_uuid and the
	 * 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.
	 * 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))
	    (to->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_META_UUID))
		uuid_copy(&to->sb_meta_uuid, &from->sb_meta_uuid);
		uuid_copy(&to->sb_meta_uuid, &from->sb_meta_uuid);
	else
	else
@@ -589,7 +589,7 @@ xfs_sb_quota_to_disk(
	 * The in-memory superblock quota state matches the v5 on-disk format so
	 * The in-memory superblock quota state matches the v5 on-disk format so
	 * just write them out and return
	 * 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_qflags = cpu_to_be16(from->sb_qflags);
		to->sb_gquotino = cpu_to_be64(from->sb_gquotino);
		to->sb_gquotino = cpu_to_be64(from->sb_gquotino);
		to->sb_pquotino = cpu_to_be64(from->sb_pquotino);
		to->sb_pquotino = cpu_to_be64(from->sb_pquotino);
@@ -699,7 +699,9 @@ xfs_sb_to_disk(
	to->sb_features2 = cpu_to_be32(from->sb_features2);
	to->sb_features2 = cpu_to_be32(from->sb_features2);
	to->sb_bad_features2 = cpu_to_be32(from->sb_bad_features2);
	to->sb_bad_features2 = cpu_to_be32(from->sb_bad_features2);


	if (XFS_SB_VERSION_NUM(from) == XFS_SB_VERSION_5) {
	if (!xfs_sb_is_v5(from))
		return;

	to->sb_features_compat = cpu_to_be32(from->sb_features_compat);
	to->sb_features_compat = cpu_to_be32(from->sb_features_compat);
	to->sb_features_ro_compat =
	to->sb_features_ro_compat =
			cpu_to_be32(from->sb_features_ro_compat);
			cpu_to_be32(from->sb_features_ro_compat);
@@ -712,7 +714,6 @@ xfs_sb_to_disk(
	if (from->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_META_UUID)
	if (from->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_META_UUID)
		uuid_copy(&to->sb_meta_uuid, &from->sb_meta_uuid);
		uuid_copy(&to->sb_meta_uuid, &from->sb_meta_uuid);
}
}
}


/*
/*
 * If the superblock has the CRC feature bit set or the CRC field is non-null,
 * If the superblock has the CRC feature bit set or the CRC field is non-null,
@@ -814,7 +815,7 @@ xfs_sb_write_verify(
	if (error)
	if (error)
		goto out_error;
		goto out_error;


	if (XFS_SB_VERSION_NUM(&sb) != XFS_SB_VERSION_5)
	if (!xfs_sb_is_v5(&sb))
		return;
		return;


	if (bip)
	if (bip)
+1 −1
Original line number Original line Diff line number Diff line
@@ -258,7 +258,7 @@ xchk_superblock(
			xchk_block_set_corrupt(sc, bp);
			xchk_block_set_corrupt(sc, bp);
	} else {
	} else {
		v2_ok = XFS_SB_VERSION2_OKBITS;
		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;
			v2_ok |= XFS_SB_VERSION2_CRCBIT;


		if (!!(sb->sb_features2 & cpu_to_be32(~v2_ok)))
		if (!!(sb->sb_features2 & cpu_to_be32(~v2_ok)))
+1 −1
Original line number Original line Diff line number Diff line
@@ -3413,7 +3413,7 @@ xlog_recover(
		 * (e.g. unsupported transactions, then simply reject the
		 * (e.g. unsupported transactions, then simply reject the
		 * attempt at recovery before touching anything.
		 * 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_has_incompat_log_feature(&log->l_mp->m_sb,
					XFS_SB_FEAT_INCOMPAT_LOG_UNKNOWN)) {
					XFS_SB_FEAT_INCOMPAT_LOG_UNKNOWN)) {
			xfs_warn(log->l_mp,
			xfs_warn(log->l_mp,
+5 −6
Original line number Original line Diff line number Diff line
@@ -1581,7 +1581,7 @@ xfs_fs_fill_super(
	set_posix_acl_flag(sb);
	set_posix_acl_flag(sb);


	/* version 5 superblocks support inode version counters. */
	/* 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;
		sb->s_flags |= SB_I_VERSION;


	if (xfs_has_dax_always(mp)) {
	if (xfs_has_dax_always(mp)) {
@@ -1702,7 +1702,7 @@ xfs_remount_rw(
		return -EINVAL;
		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_sb_has_ro_compat_feature(sbp, XFS_SB_FEAT_RO_COMPAT_UNKNOWN)) {
		xfs_warn(mp,
		xfs_warn(mp,
	"ro->rw transition prohibited on unknown (0x%x) ro-compat filesystem",
	"ro->rw transition prohibited on unknown (0x%x) ro-compat filesystem",
@@ -1822,12 +1822,11 @@ xfs_fs_reconfigure(
{
{
	struct xfs_mount	*mp = XFS_M(fc->root->d_sb);
	struct xfs_mount	*mp = XFS_M(fc->root->d_sb);
	struct xfs_mount        *new_mp = fc->s_fs_info;
	struct xfs_mount        *new_mp = fc->s_fs_info;
	xfs_sb_t		*sbp = &mp->m_sb;
	int			flags = fc->sb_flags;
	int			flags = fc->sb_flags;
	int			error;
	int			error;


	/* version 5 superblocks always support version counters. */
	/* 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;
		fc->sb_flags |= SB_I_VERSION;


	error = xfs_fs_validate_params(new_mp);
	error = xfs_fs_validate_params(new_mp);
@@ -1839,13 +1838,13 @@ xfs_fs_reconfigure(
	/* inode32 -> inode64 */
	/* inode32 -> inode64 */
	if (xfs_has_small_inums(mp) && !xfs_has_small_inums(new_mp)) {
	if (xfs_has_small_inums(mp) && !xfs_has_small_inums(new_mp)) {
		mp->m_features &= ~XFS_FEAT_SMALL_INUMS;
		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 */
	/* inode64 -> inode32 */
	if (!xfs_has_small_inums(mp) && xfs_has_small_inums(new_mp)) {
	if (!xfs_has_small_inums(mp) && xfs_has_small_inums(new_mp)) {
		mp->m_features |= XFS_FEAT_SMALL_INUMS;
		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 */
	/* ro -> rw */