Commit 06b20ef0 authored by Darrick J. Wong's avatar Darrick J. Wong
Browse files

xfs: check pre-metadir fields correctly



The checks that were added to the superblock scrubber for metadata
directories aren't quite right -- the old inode pointers are now defined
to be zeroes until someone else reuses them.  Also consolidate the new
metadir field checks to one place; they were inexplicably scattered
around.

Cc: <stable@vger.kernel.org> # v6.13-rc1
Fixes: 28d756d4 ("xfs: update sb field checks when metadir is turned on")
Signed-off-by: default avatar"Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
parent e57e083b
Loading
Loading
Loading
Loading
+27 −13
Original line number Diff line number Diff line
@@ -145,8 +145,11 @@ xchk_superblock(
		xchk_block_set_preen(sc, bp);

	if (xfs_has_metadir(sc->mp)) {
		if (sb->sb_metadirino != cpu_to_be64(mp->m_sb.sb_metadirino))
			xchk_block_set_preen(sc, bp);
		if (sb->sb_rbmino != cpu_to_be64(0))
			xchk_block_set_corrupt(sc, bp);

		if (sb->sb_rsumino != cpu_to_be64(0))
			xchk_block_set_corrupt(sc, bp);
	} else {
		if (sb->sb_rbmino != cpu_to_be64(mp->m_sb.sb_rbmino))
			xchk_block_set_preen(sc, bp);
@@ -229,7 +232,13 @@ xchk_superblock(
	 * sb_icount, sb_ifree, sb_fdblocks, sb_frexents
	 */

	if (!xfs_has_metadir(mp)) {
	if (xfs_has_metadir(mp)) {
		if (sb->sb_uquotino != cpu_to_be64(0))
			xchk_block_set_corrupt(sc, bp);

		if (sb->sb_gquotino != cpu_to_be64(0))
			xchk_block_set_preen(sc, bp);
	} else {
		if (sb->sb_uquotino != cpu_to_be64(mp->m_sb.sb_uquotino))
			xchk_block_set_preen(sc, bp);

@@ -281,16 +290,9 @@ xchk_superblock(
		if (!!(sb->sb_features2 & cpu_to_be32(~v2_ok)))
			xchk_block_set_corrupt(sc, bp);

		if (xfs_has_metadir(mp)) {
			if (sb->sb_rgblklog != mp->m_sb.sb_rgblklog)
				xchk_block_set_corrupt(sc, bp);
			if (memchr_inv(sb->sb_pad, 0, sizeof(sb->sb_pad)))
				xchk_block_set_preen(sc, bp);
		} else {
		if (sb->sb_features2 != sb->sb_bad_features2)
			xchk_block_set_preen(sc, bp);
	}
	}

	/* Check sb_features2 flags that are set at mkfs time. */
	features_mask = cpu_to_be32(XFS_SB_VERSION2_LAZYSBCOUNTBIT |
@@ -351,7 +353,10 @@ xchk_superblock(
		if (sb->sb_spino_align != cpu_to_be32(mp->m_sb.sb_spino_align))
			xchk_block_set_corrupt(sc, bp);

		if (!xfs_has_metadir(mp)) {
		if (xfs_has_metadir(mp)) {
			if (sb->sb_pquotino != cpu_to_be64(0))
				xchk_block_set_corrupt(sc, bp);
		} else {
			if (sb->sb_pquotino != cpu_to_be64(mp->m_sb.sb_pquotino))
				xchk_block_set_preen(sc, bp);
		}
@@ -366,11 +371,20 @@ xchk_superblock(
	}

	if (xfs_has_metadir(mp)) {
		if (sb->sb_metadirino != cpu_to_be64(mp->m_sb.sb_metadirino))
			xchk_block_set_preen(sc, bp);

		if (sb->sb_rgcount != cpu_to_be32(mp->m_sb.sb_rgcount))
			xchk_block_set_corrupt(sc, bp);

		if (sb->sb_rgextents != cpu_to_be32(mp->m_sb.sb_rgextents))
			xchk_block_set_corrupt(sc, bp);

		if (sb->sb_rgblklog != mp->m_sb.sb_rgblklog)
			xchk_block_set_corrupt(sc, bp);

		if (memchr_inv(sb->sb_pad, 0, sizeof(sb->sb_pad)))
			xchk_block_set_corrupt(sc, bp);
	}

	/* Everything else must be zero. */