Commit 4a9bca86 authored by Darrick J. Wong's avatar Darrick J. Wong

xfs: fix online fsck handling of v5 feature bits on secondary supers

While I was auditing the code in xfs_repair that adds feature bits to
existing V5 filesystems, I decided to have a look at how online fsck
handles feature bits, and I found a few problems:

1) ATTR2 is added to the primary super when an xattr is set to a file,
but that isn't consistently propagated to secondary supers.  This isn't
a corruption, merely a discrepancy that repair will fix if it ever has
to restore the primary from a secondary.  Hence, if we find a mismatch
on a secondary, this is a preen condition, not a corruption.

2) There are more compat and ro_compat features now than there used to
be, but we mask off the newer features from testing.  This means we
ignore inconsistencies in the INOBTCOUNT and BIGTIME features, which is
wrong.  Get rid of the masking and compare directly.

3) NEEDSREPAIR, when set on a secondary, is ignored by everyone.  Hence
a mismatch here should also be flagged for preening, and online repair
should clear the flag.  Right now we ignore it due to (2).

4) log_incompat features are ephemeral, since we can clear the feature
bit as soon as the log no longer contains live records for a particular
log feature.  As such, the only copy we care about is the one in the
primary super.  If we find any bits set in the secondary super, we
should flag that for preening, and clear the bits if the user elects to
repair it.
Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
Reviewed-by: default avatarDave Chinner <dchinner@redhat.com>
parent 65552b02
...@@ -281,7 +281,7 @@ xchk_superblock( ...@@ -281,7 +281,7 @@ xchk_superblock(
features_mask = cpu_to_be32(XFS_SB_VERSION2_ATTR2BIT); features_mask = cpu_to_be32(XFS_SB_VERSION2_ATTR2BIT);
if ((sb->sb_features2 & features_mask) != if ((sb->sb_features2 & features_mask) !=
(cpu_to_be32(mp->m_sb.sb_features2) & features_mask)) (cpu_to_be32(mp->m_sb.sb_features2) & features_mask))
xchk_block_set_corrupt(sc, bp); xchk_block_set_preen(sc, bp);
if (!xfs_has_crc(mp)) { if (!xfs_has_crc(mp)) {
/* all v5 fields must be zero */ /* all v5 fields must be zero */
...@@ -290,39 +290,38 @@ xchk_superblock( ...@@ -290,39 +290,38 @@ xchk_superblock(
offsetof(struct xfs_dsb, sb_features_compat))) offsetof(struct xfs_dsb, sb_features_compat)))
xchk_block_set_corrupt(sc, bp); xchk_block_set_corrupt(sc, bp);
} else { } else {
/* Check compat flags; all are set at mkfs time. */ /* compat features must match */
features_mask = cpu_to_be32(XFS_SB_FEAT_COMPAT_UNKNOWN); if (sb->sb_features_compat !=
if ((sb->sb_features_compat & features_mask) != cpu_to_be32(mp->m_sb.sb_features_compat))
(cpu_to_be32(mp->m_sb.sb_features_compat) & features_mask)) xchk_block_set_corrupt(sc, bp);
xchk_block_set_corrupt(sc, bp);
/* ro compat features must match */
/* Check ro compat flags; all are set at mkfs time. */ if (sb->sb_features_ro_compat !=
features_mask = cpu_to_be32(XFS_SB_FEAT_RO_COMPAT_UNKNOWN | cpu_to_be32(mp->m_sb.sb_features_ro_compat))
XFS_SB_FEAT_RO_COMPAT_FINOBT | xchk_block_set_corrupt(sc, bp);
XFS_SB_FEAT_RO_COMPAT_RMAPBT |
XFS_SB_FEAT_RO_COMPAT_REFLINK); /*
if ((sb->sb_features_ro_compat & features_mask) != * NEEDSREPAIR is ignored on a secondary super, so we should
(cpu_to_be32(mp->m_sb.sb_features_ro_compat) & * clear it when we find it, though it's not a corruption.
features_mask)) */
xchk_block_set_corrupt(sc, bp); features_mask = cpu_to_be32(XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR);
if ((cpu_to_be32(mp->m_sb.sb_features_incompat) ^
/* Check incompat flags; all are set at mkfs time. */ sb->sb_features_incompat) & features_mask)
features_mask = cpu_to_be32(XFS_SB_FEAT_INCOMPAT_UNKNOWN | xchk_block_set_preen(sc, bp);
XFS_SB_FEAT_INCOMPAT_FTYPE |
XFS_SB_FEAT_INCOMPAT_SPINODES | /* all other incompat features must match */
XFS_SB_FEAT_INCOMPAT_META_UUID); if ((cpu_to_be32(mp->m_sb.sb_features_incompat) ^
if ((sb->sb_features_incompat & features_mask) != sb->sb_features_incompat) & ~features_mask)
(cpu_to_be32(mp->m_sb.sb_features_incompat) &
features_mask))
xchk_block_set_corrupt(sc, bp);
/* Check log incompat flags; all are set at mkfs time. */
features_mask = cpu_to_be32(XFS_SB_FEAT_INCOMPAT_LOG_UNKNOWN);
if ((sb->sb_features_log_incompat & features_mask) !=
(cpu_to_be32(mp->m_sb.sb_features_log_incompat) &
features_mask))
xchk_block_set_corrupt(sc, bp); xchk_block_set_corrupt(sc, bp);
/*
* log incompat features protect newer log record types from
* older log recovery code. Log recovery doesn't check the
* secondary supers, so we can clear these if needed.
*/
if (sb->sb_features_log_incompat)
xchk_block_set_preen(sc, bp);
/* Don't care about sb_crc */ /* Don't care about sb_crc */
if (sb->sb_spino_align != cpu_to_be32(mp->m_sb.sb_spino_align)) if (sb->sb_spino_align != cpu_to_be32(mp->m_sb.sb_spino_align))
......
...@@ -52,6 +52,18 @@ xrep_superblock( ...@@ -52,6 +52,18 @@ xrep_superblock(
xfs_buf_zero(bp, 0, BBTOB(bp->b_length)); xfs_buf_zero(bp, 0, BBTOB(bp->b_length));
xfs_sb_to_disk(bp->b_addr, &mp->m_sb); xfs_sb_to_disk(bp->b_addr, &mp->m_sb);
/*
* Don't write out a secondary super with NEEDSREPAIR or log incompat
* features set, since both are ignored when set on a secondary.
*/
if (xfs_has_crc(mp)) {
struct xfs_dsb *sb = bp->b_addr;
sb->sb_features_incompat &=
~cpu_to_be32(XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR);
sb->sb_features_log_incompat = 0;
}
/* Write this to disk. */ /* Write this to disk. */
xfs_trans_buf_set_type(sc->tp, bp, XFS_BLFT_SB_BUF); xfs_trans_buf_set_type(sc->tp, bp, XFS_BLFT_SB_BUF);
xfs_trans_log_buf(sc->tp, bp, 0, BBTOB(bp->b_length) - 1); xfs_trans_log_buf(sc->tp, bp, 0, BBTOB(bp->b_length) - 1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment