^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (c) 2000-2005 Silicon Graphics, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include "xfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include "xfs_fs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include "xfs_shared.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include "xfs_format.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "xfs_log_format.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "xfs_trans_resv.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "xfs_bit.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "xfs_sb.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "xfs_mount.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "xfs_ialloc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "xfs_alloc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "xfs_error.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include "xfs_trace.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include "xfs_trans.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include "xfs_buf_item.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include "xfs_bmap_btree.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include "xfs_alloc_btree.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include "xfs_log.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include "xfs_rmap_btree.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include "xfs_refcount_btree.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include "xfs_da_format.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include "xfs_health.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * Physical superblock buffer manipulations. Shared with libxfs in userspace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * Reference counting access wrappers to the perag structures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * Because we never free per-ag structures, the only thing we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * have to protect against changes is the tree structure itself.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct xfs_perag *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) xfs_perag_get(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct xfs_mount *mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) xfs_agnumber_t agno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct xfs_perag *pag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) int ref = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) pag = radix_tree_lookup(&mp->m_perag_tree, agno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) if (pag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) ASSERT(atomic_read(&pag->pag_ref) >= 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) ref = atomic_inc_return(&pag->pag_ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) trace_xfs_perag_get(mp, agno, ref, _RET_IP_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) return pag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * search from @first to find the next perag with the given tag set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct xfs_perag *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) xfs_perag_get_tag(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct xfs_mount *mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) xfs_agnumber_t first,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) int tag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct xfs_perag *pag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) int found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) int ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) found = radix_tree_gang_lookup_tag(&mp->m_perag_tree,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) (void **)&pag, first, 1, tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (found <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) ref = atomic_inc_return(&pag->pag_ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) trace_xfs_perag_get_tag(mp, pag->pag_agno, ref, _RET_IP_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) return pag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) xfs_perag_put(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct xfs_perag *pag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) int ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) ASSERT(atomic_read(&pag->pag_ref) > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) ref = atomic_dec_return(&pag->pag_ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) trace_xfs_perag_put(pag->pag_mount, pag->pag_agno, ref, _RET_IP_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) /* Check all the superblock fields we care about when reading one in. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) STATIC int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) xfs_validate_sb_read(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) struct xfs_mount *mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) struct xfs_sb *sbp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (XFS_SB_VERSION_NUM(sbp) != XFS_SB_VERSION_5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * Version 5 superblock feature mask validation. Reject combinations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * the kernel cannot support up front before checking anything else.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (xfs_sb_has_compat_feature(sbp, XFS_SB_FEAT_COMPAT_UNKNOWN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) xfs_warn(mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) "Superblock has unknown compatible features (0x%x) enabled.",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) (sbp->sb_features_compat & XFS_SB_FEAT_COMPAT_UNKNOWN));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) xfs_warn(mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) "Using a more recent kernel is recommended.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) if (xfs_sb_has_ro_compat_feature(sbp, XFS_SB_FEAT_RO_COMPAT_UNKNOWN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) xfs_alert(mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) "Superblock has unknown read-only compatible features (0x%x) enabled.",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) (sbp->sb_features_ro_compat &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) XFS_SB_FEAT_RO_COMPAT_UNKNOWN));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) if (!(mp->m_flags & XFS_MOUNT_RDONLY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) xfs_warn(mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) "Attempted to mount read-only compatible filesystem read-write.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) xfs_warn(mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) "Filesystem can only be safely mounted read only.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) if (xfs_sb_has_incompat_feature(sbp, XFS_SB_FEAT_INCOMPAT_UNKNOWN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) xfs_warn(mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) "Superblock has unknown incompatible features (0x%x) enabled.",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) (sbp->sb_features_incompat &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) XFS_SB_FEAT_INCOMPAT_UNKNOWN));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) xfs_warn(mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) "Filesystem cannot be safely mounted by this kernel.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) /* Check all the superblock fields we care about when writing one out. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) STATIC int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) xfs_validate_sb_write(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) struct xfs_mount *mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct xfs_buf *bp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct xfs_sb *sbp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) * Carry out additional sb summary counter sanity checks when we write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * the superblock. We skip this in the read validator because there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * could be newer superblocks in the log and if the values are garbage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * even after replay we'll recalculate them at the end of log mount.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * mkfs has traditionally written zeroed counters to inprogress and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * secondary superblocks, so allow this usage to continue because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) * we never read counters from such superblocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) if (XFS_BUF_ADDR(bp) == XFS_SB_DADDR && !sbp->sb_inprogress &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) (sbp->sb_fdblocks > sbp->sb_dblocks ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) !xfs_verify_icount(mp, sbp->sb_icount) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) sbp->sb_ifree > sbp->sb_icount)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) xfs_warn(mp, "SB summary counter sanity check failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) return -EFSCORRUPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (XFS_SB_VERSION_NUM(sbp) != XFS_SB_VERSION_5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * Version 5 superblock feature mask validation. Reject combinations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * the kernel cannot support since we checked for unsupported bits in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * the read verifier, which means that memory is corrupt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) if (xfs_sb_has_compat_feature(sbp, XFS_SB_FEAT_COMPAT_UNKNOWN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) xfs_warn(mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) "Corruption detected in superblock compatible features (0x%x)!",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) (sbp->sb_features_compat & XFS_SB_FEAT_COMPAT_UNKNOWN));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) return -EFSCORRUPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if (xfs_sb_has_ro_compat_feature(sbp, XFS_SB_FEAT_RO_COMPAT_UNKNOWN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) xfs_alert(mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) "Corruption detected in superblock read-only compatible features (0x%x)!",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) (sbp->sb_features_ro_compat &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) XFS_SB_FEAT_RO_COMPAT_UNKNOWN));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) return -EFSCORRUPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if (xfs_sb_has_incompat_feature(sbp, XFS_SB_FEAT_INCOMPAT_UNKNOWN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) xfs_warn(mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) "Corruption detected in superblock incompatible features (0x%x)!",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) (sbp->sb_features_incompat &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) XFS_SB_FEAT_INCOMPAT_UNKNOWN));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) return -EFSCORRUPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (xfs_sb_has_incompat_log_feature(sbp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) XFS_SB_FEAT_INCOMPAT_LOG_UNKNOWN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) xfs_warn(mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) "Corruption detected in superblock incompatible log features (0x%x)!",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) (sbp->sb_features_log_incompat &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) XFS_SB_FEAT_INCOMPAT_LOG_UNKNOWN));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) return -EFSCORRUPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) * We can't read verify the sb LSN because the read verifier is called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) * before the log is allocated and processed. We know the log is set up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * before write verifier calls, so check it here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) if (!xfs_log_check_lsn(mp, sbp->sb_lsn))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) return -EFSCORRUPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) /* Check the validity of the SB. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) STATIC int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) xfs_validate_sb_common(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) struct xfs_mount *mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) struct xfs_buf *bp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) struct xfs_sb *sbp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) struct xfs_dsb *dsb = bp->b_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) uint32_t agcount = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) uint32_t rem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (!xfs_verify_magic(bp, dsb->sb_magicnum)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) xfs_warn(mp, "bad magic number");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) return -EWRONGFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) if (!xfs_sb_good_version(sbp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) xfs_warn(mp, "bad version");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) return -EWRONGFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) if (xfs_sb_version_has_pquotino(sbp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) if (sbp->sb_qflags & (XFS_OQUOTA_ENFD | XFS_OQUOTA_CHKD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) xfs_notice(mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) "Version 5 of Super block has XFS_OQUOTA bits.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) return -EFSCORRUPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) } else if (sbp->sb_qflags & (XFS_PQUOTA_ENFD | XFS_GQUOTA_ENFD |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) XFS_PQUOTA_CHKD | XFS_GQUOTA_CHKD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) xfs_notice(mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) "Superblock earlier than Version 5 has XFS_{P|G}QUOTA_{ENFD|CHKD} bits.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) return -EFSCORRUPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * Full inode chunks must be aligned to inode chunk size when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) * sparse inodes are enabled to support the sparse chunk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) * allocation algorithm and prevent overlapping inode records.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (xfs_sb_version_hassparseinodes(sbp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) uint32_t align;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) align = XFS_INODES_PER_CHUNK * sbp->sb_inodesize
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) >> sbp->sb_blocklog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) if (sbp->sb_inoalignmt != align) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) xfs_warn(mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) "Inode block alignment (%u) must match chunk size (%u) for sparse inodes.",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) sbp->sb_inoalignmt, align);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) if (unlikely(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) sbp->sb_logstart == 0 && mp->m_logdev_targp == mp->m_ddev_targp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) xfs_warn(mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) "filesystem is marked as having an external log; "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) "specify logdev on the mount command line.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) if (unlikely(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) sbp->sb_logstart != 0 && mp->m_logdev_targp != mp->m_ddev_targp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) xfs_warn(mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) "filesystem is marked as having an internal log; "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) "do not specify logdev on the mount command line.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) /* Compute agcount for this number of dblocks and agblocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) if (sbp->sb_agblocks) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) agcount = div_u64_rem(sbp->sb_dblocks, sbp->sb_agblocks, &rem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) if (rem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) agcount++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) * More sanity checking. Most of these were stolen directly from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) * xfs_repair.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) if (unlikely(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) sbp->sb_agcount <= 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) sbp->sb_sectsize < XFS_MIN_SECTORSIZE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) sbp->sb_sectsize > XFS_MAX_SECTORSIZE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) sbp->sb_sectlog < XFS_MIN_SECTORSIZE_LOG ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) sbp->sb_sectlog > XFS_MAX_SECTORSIZE_LOG ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) sbp->sb_sectsize != (1 << sbp->sb_sectlog) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) sbp->sb_blocksize < XFS_MIN_BLOCKSIZE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) sbp->sb_blocksize > XFS_MAX_BLOCKSIZE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) sbp->sb_blocklog < XFS_MIN_BLOCKSIZE_LOG ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) sbp->sb_blocklog > XFS_MAX_BLOCKSIZE_LOG ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) sbp->sb_blocksize != (1 << sbp->sb_blocklog) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) sbp->sb_dirblklog + sbp->sb_blocklog > XFS_MAX_BLOCKSIZE_LOG ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) sbp->sb_inodesize < XFS_DINODE_MIN_SIZE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) sbp->sb_inodesize > XFS_DINODE_MAX_SIZE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) sbp->sb_inodelog < XFS_DINODE_MIN_LOG ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) sbp->sb_inodelog > XFS_DINODE_MAX_LOG ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) sbp->sb_inodesize != (1 << sbp->sb_inodelog) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) sbp->sb_logsunit > XLOG_MAX_RECORD_BSIZE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) sbp->sb_inopblock != howmany(sbp->sb_blocksize,sbp->sb_inodesize) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) XFS_FSB_TO_B(mp, sbp->sb_agblocks) < XFS_MIN_AG_BYTES ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) XFS_FSB_TO_B(mp, sbp->sb_agblocks) > XFS_MAX_AG_BYTES ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) sbp->sb_agblklog != xfs_highbit32(sbp->sb_agblocks - 1) + 1 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) agcount == 0 || agcount != sbp->sb_agcount ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) (sbp->sb_blocklog - sbp->sb_inodelog != sbp->sb_inopblog) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) (sbp->sb_rextsize * sbp->sb_blocksize > XFS_MAX_RTEXTSIZE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) (sbp->sb_rextsize * sbp->sb_blocksize < XFS_MIN_RTEXTSIZE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) (sbp->sb_imax_pct > 100 /* zero sb_imax_pct is valid */) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) sbp->sb_dblocks == 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) sbp->sb_dblocks > XFS_MAX_DBLOCKS(sbp) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) sbp->sb_dblocks < XFS_MIN_DBLOCKS(sbp) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) sbp->sb_shared_vn != 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) xfs_notice(mp, "SB sanity check failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) return -EFSCORRUPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) /* Validate the realtime geometry; stolen from xfs_repair */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) if (sbp->sb_rextsize * sbp->sb_blocksize > XFS_MAX_RTEXTSIZE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) sbp->sb_rextsize * sbp->sb_blocksize < XFS_MIN_RTEXTSIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) xfs_notice(mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) "realtime extent sanity check failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) return -EFSCORRUPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) if (sbp->sb_rblocks == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) if (sbp->sb_rextents != 0 || sbp->sb_rbmblocks != 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) sbp->sb_rextslog != 0 || sbp->sb_frextents != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) xfs_notice(mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) "realtime zeroed geometry check failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) return -EFSCORRUPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) uint64_t rexts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) uint64_t rbmblocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) rexts = div_u64(sbp->sb_rblocks, sbp->sb_rextsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) rbmblocks = howmany_64(sbp->sb_rextents,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) NBBY * sbp->sb_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) if (sbp->sb_rextents != rexts ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) sbp->sb_rextslog != xfs_highbit32(sbp->sb_rextents) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) sbp->sb_rbmblocks != rbmblocks) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) xfs_notice(mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) "realtime geometry sanity check failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) return -EFSCORRUPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) if (sbp->sb_unit) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) if (!xfs_sb_version_hasdalign(sbp) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) sbp->sb_unit > sbp->sb_width ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) (sbp->sb_width % sbp->sb_unit) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) xfs_notice(mp, "SB stripe unit sanity check failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) return -EFSCORRUPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) } else if (xfs_sb_version_hasdalign(sbp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) xfs_notice(mp, "SB stripe alignment sanity check failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) return -EFSCORRUPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) } else if (sbp->sb_width) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) xfs_notice(mp, "SB stripe width sanity check failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) return -EFSCORRUPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) if (xfs_sb_version_hascrc(&mp->m_sb) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) sbp->sb_blocksize < XFS_MIN_CRC_BLOCKSIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) xfs_notice(mp, "v5 SB sanity check failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) return -EFSCORRUPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) * Until this is fixed only page-sized or smaller data blocks work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) if (unlikely(sbp->sb_blocksize > PAGE_SIZE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) xfs_warn(mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) "File system with blocksize %d bytes. "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) "Only pagesize (%ld) or less will currently work.",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) sbp->sb_blocksize, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) * Currently only very few inode sizes are supported.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) switch (sbp->sb_inodesize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) case 256:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) case 512:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) case 1024:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) case 2048:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) xfs_warn(mp, "inode size of %d bytes not supported",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) sbp->sb_inodesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) if (xfs_sb_validate_fsb_count(sbp, sbp->sb_dblocks) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) xfs_sb_validate_fsb_count(sbp, sbp->sb_rblocks)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) xfs_warn(mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) "file system too large to be mounted on this system.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) return -EFBIG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) * Don't touch the filesystem if a user tool thinks it owns the primary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) * superblock. mkfs doesn't clear the flag from secondary supers, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) * we don't check them at all.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) if (XFS_BUF_ADDR(bp) == XFS_SB_DADDR && sbp->sb_inprogress) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) xfs_warn(mp, "Offline file system operation in progress!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) return -EFSCORRUPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) xfs_sb_quota_from_disk(struct xfs_sb *sbp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) * older mkfs doesn't initialize quota inodes to NULLFSINO. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) * leads to in-core values having two different values for a quota
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) * inode to be invalid: 0 and NULLFSINO. Change it to a single value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) * NULLFSINO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) * Note that this change affect only the in-core values. These
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) * values are not written back to disk unless any quota information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) * is written to the disk. Even in that case, sb_pquotino field is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) * not written to disk unless the superblock supports pquotino.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) if (sbp->sb_uquotino == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) sbp->sb_uquotino = NULLFSINO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) if (sbp->sb_gquotino == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) sbp->sb_gquotino = NULLFSINO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) if (sbp->sb_pquotino == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) sbp->sb_pquotino = NULLFSINO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) * We need to do these manipilations only if we are working
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) * with an older version of on-disk superblock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) if (xfs_sb_version_has_pquotino(sbp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) if (sbp->sb_qflags & XFS_OQUOTA_ENFD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) sbp->sb_qflags |= (sbp->sb_qflags & XFS_PQUOTA_ACCT) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) XFS_PQUOTA_ENFD : XFS_GQUOTA_ENFD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) if (sbp->sb_qflags & XFS_OQUOTA_CHKD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) sbp->sb_qflags |= (sbp->sb_qflags & XFS_PQUOTA_ACCT) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) XFS_PQUOTA_CHKD : XFS_GQUOTA_CHKD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) sbp->sb_qflags &= ~(XFS_OQUOTA_ENFD | XFS_OQUOTA_CHKD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) if (sbp->sb_qflags & XFS_PQUOTA_ACCT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) sbp->sb_gquotino != NULLFSINO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) * In older version of superblock, on-disk superblock only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) * has sb_gquotino, and in-core superblock has both sb_gquotino
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) * and sb_pquotino. But, only one of them is supported at any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) * point of time. So, if PQUOTA is set in disk superblock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) * copy over sb_gquotino to sb_pquotino. The NULLFSINO test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) * above is to make sure we don't do this twice and wipe them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) * both out!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) sbp->sb_pquotino = sbp->sb_gquotino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) sbp->sb_gquotino = NULLFSINO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) __xfs_sb_from_disk(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) struct xfs_sb *to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) xfs_dsb_t *from,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) bool convert_xquota)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) to->sb_magicnum = be32_to_cpu(from->sb_magicnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) to->sb_blocksize = be32_to_cpu(from->sb_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) to->sb_dblocks = be64_to_cpu(from->sb_dblocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) to->sb_rblocks = be64_to_cpu(from->sb_rblocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) to->sb_rextents = be64_to_cpu(from->sb_rextents);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) memcpy(&to->sb_uuid, &from->sb_uuid, sizeof(to->sb_uuid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) to->sb_logstart = be64_to_cpu(from->sb_logstart);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) to->sb_rootino = be64_to_cpu(from->sb_rootino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) to->sb_rbmino = be64_to_cpu(from->sb_rbmino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) to->sb_rsumino = be64_to_cpu(from->sb_rsumino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) to->sb_rextsize = be32_to_cpu(from->sb_rextsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) to->sb_agblocks = be32_to_cpu(from->sb_agblocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) to->sb_agcount = be32_to_cpu(from->sb_agcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) to->sb_rbmblocks = be32_to_cpu(from->sb_rbmblocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) to->sb_logblocks = be32_to_cpu(from->sb_logblocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) to->sb_versionnum = be16_to_cpu(from->sb_versionnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) to->sb_sectsize = be16_to_cpu(from->sb_sectsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) to->sb_inodesize = be16_to_cpu(from->sb_inodesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) to->sb_inopblock = be16_to_cpu(from->sb_inopblock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) memcpy(&to->sb_fname, &from->sb_fname, sizeof(to->sb_fname));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) to->sb_blocklog = from->sb_blocklog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) to->sb_sectlog = from->sb_sectlog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) to->sb_inodelog = from->sb_inodelog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) to->sb_inopblog = from->sb_inopblog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) to->sb_agblklog = from->sb_agblklog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) to->sb_rextslog = from->sb_rextslog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) to->sb_inprogress = from->sb_inprogress;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) to->sb_imax_pct = from->sb_imax_pct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) to->sb_icount = be64_to_cpu(from->sb_icount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) to->sb_ifree = be64_to_cpu(from->sb_ifree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) to->sb_fdblocks = be64_to_cpu(from->sb_fdblocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) to->sb_frextents = be64_to_cpu(from->sb_frextents);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) to->sb_uquotino = be64_to_cpu(from->sb_uquotino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) to->sb_gquotino = be64_to_cpu(from->sb_gquotino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) to->sb_qflags = be16_to_cpu(from->sb_qflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) to->sb_flags = from->sb_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) to->sb_shared_vn = from->sb_shared_vn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) to->sb_inoalignmt = be32_to_cpu(from->sb_inoalignmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) to->sb_unit = be32_to_cpu(from->sb_unit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) to->sb_width = be32_to_cpu(from->sb_width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) to->sb_dirblklog = from->sb_dirblklog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) to->sb_logsectlog = from->sb_logsectlog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) to->sb_logsectsize = be16_to_cpu(from->sb_logsectsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) to->sb_logsunit = be32_to_cpu(from->sb_logsunit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) to->sb_features2 = be32_to_cpu(from->sb_features2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) to->sb_bad_features2 = be32_to_cpu(from->sb_bad_features2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) to->sb_features_compat = be32_to_cpu(from->sb_features_compat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) to->sb_features_ro_compat = be32_to_cpu(from->sb_features_ro_compat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) to->sb_features_incompat = be32_to_cpu(from->sb_features_incompat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) to->sb_features_log_incompat =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) be32_to_cpu(from->sb_features_log_incompat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) /* crc is only used on disk, not in memory; just init to 0 here. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) to->sb_crc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) to->sb_spino_align = be32_to_cpu(from->sb_spino_align);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) to->sb_pquotino = be64_to_cpu(from->sb_pquotino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) to->sb_lsn = be64_to_cpu(from->sb_lsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) * sb_meta_uuid is only on disk if it differs from sb_uuid and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) * feature flag is set; if not set we keep it only in memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) if (xfs_sb_version_hasmetauuid(to))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) uuid_copy(&to->sb_meta_uuid, &from->sb_meta_uuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) uuid_copy(&to->sb_meta_uuid, &from->sb_uuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) /* Convert on-disk flags to in-memory flags? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) if (convert_xquota)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) xfs_sb_quota_from_disk(to);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) xfs_sb_from_disk(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) struct xfs_sb *to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) xfs_dsb_t *from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) __xfs_sb_from_disk(to, from, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) xfs_sb_quota_to_disk(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) struct xfs_dsb *to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) struct xfs_sb *from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) uint16_t qflags = from->sb_qflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) to->sb_uquotino = cpu_to_be64(from->sb_uquotino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) if (xfs_sb_version_has_pquotino(from)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) to->sb_qflags = cpu_to_be16(from->sb_qflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) to->sb_gquotino = cpu_to_be64(from->sb_gquotino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) to->sb_pquotino = cpu_to_be64(from->sb_pquotino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) * The in-core version of sb_qflags do not have XFS_OQUOTA_*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) * flags, whereas the on-disk version does. So, convert incore
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) * XFS_{PG}QUOTA_* flags to on-disk XFS_OQUOTA_* flags.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) qflags &= ~(XFS_PQUOTA_ENFD | XFS_PQUOTA_CHKD |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) XFS_GQUOTA_ENFD | XFS_GQUOTA_CHKD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) if (from->sb_qflags &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) (XFS_PQUOTA_ENFD | XFS_GQUOTA_ENFD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) qflags |= XFS_OQUOTA_ENFD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) if (from->sb_qflags &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) (XFS_PQUOTA_CHKD | XFS_GQUOTA_CHKD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) qflags |= XFS_OQUOTA_CHKD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) to->sb_qflags = cpu_to_be16(qflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) * GQUOTINO and PQUOTINO cannot be used together in versions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) * of superblock that do not have pquotino. from->sb_flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) * tells us which quota is active and should be copied to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) * disk. If neither are active, we should NULL the inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) * In all cases, the separate pquotino must remain 0 because it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) * is beyond the "end" of the valid non-pquotino superblock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) if (from->sb_qflags & XFS_GQUOTA_ACCT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) to->sb_gquotino = cpu_to_be64(from->sb_gquotino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) else if (from->sb_qflags & XFS_PQUOTA_ACCT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) to->sb_gquotino = cpu_to_be64(from->sb_pquotino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) * We can't rely on just the fields being logged to tell us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) * that it is safe to write NULLFSINO - we should only do that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) * if quotas are not actually enabled. Hence only write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) * NULLFSINO if both in-core quota inodes are NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) if (from->sb_gquotino == NULLFSINO &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) from->sb_pquotino == NULLFSINO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) to->sb_gquotino = cpu_to_be64(NULLFSINO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) to->sb_pquotino = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) xfs_sb_to_disk(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) struct xfs_dsb *to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) struct xfs_sb *from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) xfs_sb_quota_to_disk(to, from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) to->sb_magicnum = cpu_to_be32(from->sb_magicnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) to->sb_blocksize = cpu_to_be32(from->sb_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) to->sb_dblocks = cpu_to_be64(from->sb_dblocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) to->sb_rblocks = cpu_to_be64(from->sb_rblocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) to->sb_rextents = cpu_to_be64(from->sb_rextents);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) memcpy(&to->sb_uuid, &from->sb_uuid, sizeof(to->sb_uuid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) to->sb_logstart = cpu_to_be64(from->sb_logstart);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) to->sb_rootino = cpu_to_be64(from->sb_rootino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) to->sb_rbmino = cpu_to_be64(from->sb_rbmino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) to->sb_rsumino = cpu_to_be64(from->sb_rsumino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) to->sb_rextsize = cpu_to_be32(from->sb_rextsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) to->sb_agblocks = cpu_to_be32(from->sb_agblocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) to->sb_agcount = cpu_to_be32(from->sb_agcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) to->sb_rbmblocks = cpu_to_be32(from->sb_rbmblocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) to->sb_logblocks = cpu_to_be32(from->sb_logblocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) to->sb_versionnum = cpu_to_be16(from->sb_versionnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) to->sb_sectsize = cpu_to_be16(from->sb_sectsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) to->sb_inodesize = cpu_to_be16(from->sb_inodesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) to->sb_inopblock = cpu_to_be16(from->sb_inopblock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) memcpy(&to->sb_fname, &from->sb_fname, sizeof(to->sb_fname));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) to->sb_blocklog = from->sb_blocklog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) to->sb_sectlog = from->sb_sectlog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) to->sb_inodelog = from->sb_inodelog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) to->sb_inopblog = from->sb_inopblog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) to->sb_agblklog = from->sb_agblklog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) to->sb_rextslog = from->sb_rextslog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) to->sb_inprogress = from->sb_inprogress;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) to->sb_imax_pct = from->sb_imax_pct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) to->sb_icount = cpu_to_be64(from->sb_icount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) to->sb_ifree = cpu_to_be64(from->sb_ifree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) to->sb_fdblocks = cpu_to_be64(from->sb_fdblocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) to->sb_frextents = cpu_to_be64(from->sb_frextents);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) to->sb_flags = from->sb_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) to->sb_shared_vn = from->sb_shared_vn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) to->sb_inoalignmt = cpu_to_be32(from->sb_inoalignmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) to->sb_unit = cpu_to_be32(from->sb_unit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) to->sb_width = cpu_to_be32(from->sb_width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) to->sb_dirblklog = from->sb_dirblklog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) to->sb_logsectlog = from->sb_logsectlog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) to->sb_logsectsize = cpu_to_be16(from->sb_logsectsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) to->sb_logsunit = cpu_to_be32(from->sb_logsunit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) * We need to ensure that bad_features2 always matches features2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) * Hence we enforce that here rather than having to remember to do it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) * everywhere else that updates features2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) from->sb_bad_features2 = from->sb_features2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) to->sb_features2 = cpu_to_be32(from->sb_features2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) to->sb_bad_features2 = cpu_to_be32(from->sb_bad_features2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) if (xfs_sb_version_hascrc(from)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) to->sb_features_compat = cpu_to_be32(from->sb_features_compat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) to->sb_features_ro_compat =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) cpu_to_be32(from->sb_features_ro_compat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) to->sb_features_incompat =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) cpu_to_be32(from->sb_features_incompat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) to->sb_features_log_incompat =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) cpu_to_be32(from->sb_features_log_incompat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) to->sb_spino_align = cpu_to_be32(from->sb_spino_align);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) to->sb_lsn = cpu_to_be64(from->sb_lsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) if (xfs_sb_version_hasmetauuid(from))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) uuid_copy(&to->sb_meta_uuid, &from->sb_meta_uuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) * If the superblock has the CRC feature bit set or the CRC field is non-null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) * check that the CRC is valid. We check the CRC field is non-null because a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) * single bit error could clear the feature bit and unused parts of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) * superblock are supposed to be zero. Hence a non-null crc field indicates that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) * we've potentially lost a feature bit and we should check it anyway.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) * However, past bugs (i.e. in growfs) left non-zeroed regions beyond the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) * last field in V4 secondary superblocks. So for secondary superblocks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) * we are more forgiving, and ignore CRC failures if the primary doesn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) * indicate that the fs version is V5.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) xfs_sb_read_verify(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) struct xfs_buf *bp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) struct xfs_sb sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) struct xfs_mount *mp = bp->b_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) struct xfs_dsb *dsb = bp->b_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) * open code the version check to avoid needing to convert the entire
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) * superblock from disk order just to check the version number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) if (dsb->sb_magicnum == cpu_to_be32(XFS_SB_MAGIC) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) (((be16_to_cpu(dsb->sb_versionnum) & XFS_SB_VERSION_NUMBITS) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) XFS_SB_VERSION_5) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) dsb->sb_crc != 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) if (!xfs_buf_verify_cksum(bp, XFS_SB_CRC_OFF)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) /* Only fail bad secondaries on a known V5 filesystem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) if (bp->b_bn == XFS_SB_DADDR ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) xfs_sb_version_hascrc(&mp->m_sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) error = -EFSBADCRC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) goto out_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) * Check all the superblock fields. Don't byteswap the xquota flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) * because _verify_common checks the on-disk values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) __xfs_sb_from_disk(&sb, dsb, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) error = xfs_validate_sb_common(mp, bp, &sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) goto out_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) error = xfs_validate_sb_read(mp, &sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) out_error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) if (error == -EFSCORRUPTED || error == -EFSBADCRC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) xfs_verifier_error(bp, error, __this_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) else if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) xfs_buf_ioerror(bp, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) * We may be probed for a filesystem match, so we may not want to emit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) * messages when the superblock buffer is not actually an XFS superblock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) * If we find an XFS superblock, then run a normal, noisy mount because we are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) * really going to mount it and want to know about errors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) xfs_sb_quiet_read_verify(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) struct xfs_buf *bp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) struct xfs_dsb *dsb = bp->b_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) if (dsb->sb_magicnum == cpu_to_be32(XFS_SB_MAGIC)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) /* XFS filesystem, verify noisily! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) xfs_sb_read_verify(bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) /* quietly fail */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) xfs_buf_ioerror(bp, -EWRONGFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) xfs_sb_write_verify(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) struct xfs_buf *bp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) struct xfs_sb sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) struct xfs_mount *mp = bp->b_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) struct xfs_buf_log_item *bip = bp->b_log_item;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) struct xfs_dsb *dsb = bp->b_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) * Check all the superblock fields. Don't byteswap the xquota flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) * because _verify_common checks the on-disk values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) __xfs_sb_from_disk(&sb, dsb, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) error = xfs_validate_sb_common(mp, bp, &sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) goto out_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) error = xfs_validate_sb_write(mp, bp, &sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) goto out_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) if (!xfs_sb_version_hascrc(&mp->m_sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) if (bip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) dsb->sb_lsn = cpu_to_be64(bip->bli_item.li_lsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) xfs_buf_update_cksum(bp, XFS_SB_CRC_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) out_error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) xfs_verifier_error(bp, error, __this_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) const struct xfs_buf_ops xfs_sb_buf_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) .name = "xfs_sb",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) .magic = { cpu_to_be32(XFS_SB_MAGIC), cpu_to_be32(XFS_SB_MAGIC) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) .verify_read = xfs_sb_read_verify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) .verify_write = xfs_sb_write_verify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) const struct xfs_buf_ops xfs_sb_quiet_buf_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) .name = "xfs_sb_quiet",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) .magic = { cpu_to_be32(XFS_SB_MAGIC), cpu_to_be32(XFS_SB_MAGIC) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) .verify_read = xfs_sb_quiet_read_verify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) .verify_write = xfs_sb_write_verify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) * xfs_mount_common
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) * Mount initialization code establishing various mount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) * fields from the superblock associated with the given
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) * mount structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) * Inode geometry are calculated in xfs_ialloc_setup_geometry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) xfs_sb_mount_common(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) struct xfs_mount *mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) struct xfs_sb *sbp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) mp->m_agfrotor = mp->m_agirotor = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) mp->m_maxagi = mp->m_sb.sb_agcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) mp->m_blkbit_log = sbp->sb_blocklog + XFS_NBBYLOG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) mp->m_blkbb_log = sbp->sb_blocklog - BBSHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) mp->m_sectbb_log = sbp->sb_sectlog - BBSHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) mp->m_agno_log = xfs_highbit32(sbp->sb_agcount - 1) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) mp->m_blockmask = sbp->sb_blocksize - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) mp->m_blockwsize = sbp->sb_blocksize >> XFS_WORDLOG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) mp->m_blockwmask = mp->m_blockwsize - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) mp->m_alloc_mxr[0] = xfs_allocbt_maxrecs(mp, sbp->sb_blocksize, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) mp->m_alloc_mxr[1] = xfs_allocbt_maxrecs(mp, sbp->sb_blocksize, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) mp->m_alloc_mnr[0] = mp->m_alloc_mxr[0] / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) mp->m_alloc_mnr[1] = mp->m_alloc_mxr[1] / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) mp->m_bmap_dmxr[0] = xfs_bmbt_maxrecs(mp, sbp->sb_blocksize, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) mp->m_bmap_dmxr[1] = xfs_bmbt_maxrecs(mp, sbp->sb_blocksize, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) mp->m_bmap_dmnr[0] = mp->m_bmap_dmxr[0] / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) mp->m_bmap_dmnr[1] = mp->m_bmap_dmxr[1] / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) mp->m_rmap_mxr[0] = xfs_rmapbt_maxrecs(sbp->sb_blocksize, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) mp->m_rmap_mxr[1] = xfs_rmapbt_maxrecs(sbp->sb_blocksize, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) mp->m_rmap_mnr[0] = mp->m_rmap_mxr[0] / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) mp->m_rmap_mnr[1] = mp->m_rmap_mxr[1] / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) mp->m_refc_mxr[0] = xfs_refcountbt_maxrecs(sbp->sb_blocksize, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) mp->m_refc_mxr[1] = xfs_refcountbt_maxrecs(sbp->sb_blocksize, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) mp->m_refc_mnr[0] = mp->m_refc_mxr[0] / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) mp->m_refc_mnr[1] = mp->m_refc_mxr[1] / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) mp->m_bsize = XFS_FSB_TO_BB(mp, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) mp->m_alloc_set_aside = xfs_alloc_set_aside(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) mp->m_ag_max_usable = xfs_alloc_ag_max_usable(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) * xfs_initialize_perag_data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) * Read in each per-ag structure so we can count up the number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) * allocated inodes, free inodes and used filesystem blocks as this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) * information is no longer persistent in the superblock. Once we have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) * this information, write it into the in-core superblock structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) xfs_initialize_perag_data(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) struct xfs_mount *mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) xfs_agnumber_t agcount)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) xfs_agnumber_t index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) xfs_perag_t *pag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) xfs_sb_t *sbp = &mp->m_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) uint64_t ifree = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) uint64_t ialloc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) uint64_t bfree = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) uint64_t bfreelst = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) uint64_t btree = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) uint64_t fdblocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) for (index = 0; index < agcount; index++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) * read the agf, then the agi. This gets us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) * all the information we need and populates the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) * per-ag structures for us.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) error = xfs_alloc_pagf_init(mp, NULL, index, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) error = xfs_ialloc_pagi_init(mp, NULL, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) pag = xfs_perag_get(mp, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) ifree += pag->pagi_freecount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) ialloc += pag->pagi_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) bfree += pag->pagf_freeblks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) bfreelst += pag->pagf_flcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) btree += pag->pagf_btreeblks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) xfs_perag_put(pag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) fdblocks = bfree + bfreelst + btree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) * If the new summary counts are obviously incorrect, fail the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) * mount operation because that implies the AGFs are also corrupt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) * Clear FS_COUNTERS so that we don't unmount with a dirty log, which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) * will prevent xfs_repair from fixing anything.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) if (fdblocks > sbp->sb_dblocks || ifree > ialloc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) xfs_alert(mp, "AGF corruption. Please run xfs_repair.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) error = -EFSCORRUPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) /* Overwrite incore superblock counters with just-read data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) spin_lock(&mp->m_sb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) sbp->sb_ifree = ifree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) sbp->sb_icount = ialloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) sbp->sb_fdblocks = fdblocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) spin_unlock(&mp->m_sb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) xfs_reinit_percpu_counters(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) xfs_fs_mark_healthy(mp, XFS_SICK_FS_COUNTERS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) * xfs_log_sb() can be used to copy arbitrary changes to the in-core superblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) * into the superblock buffer to be logged. It does not provide the higher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) * level of locking that is needed to protect the in-core superblock from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) * concurrent access.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) xfs_log_sb(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) struct xfs_trans *tp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) struct xfs_mount *mp = tp->t_mountp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) struct xfs_buf *bp = xfs_trans_getsb(tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) mp->m_sb.sb_icount = percpu_counter_sum(&mp->m_icount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) mp->m_sb.sb_ifree = percpu_counter_sum(&mp->m_ifree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) mp->m_sb.sb_fdblocks = percpu_counter_sum(&mp->m_fdblocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) xfs_sb_to_disk(bp->b_addr, &mp->m_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) xfs_trans_buf_set_type(tp, bp, XFS_BLFT_SB_BUF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) xfs_trans_log_buf(tp, bp, 0, sizeof(struct xfs_dsb) - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) * xfs_sync_sb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) * Sync the superblock to disk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) * Note that the caller is responsible for checking the frozen state of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) * filesystem. This procedure uses the non-blocking transaction allocator and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) * thus will allow modifications to a frozen fs. This is required because this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) * code can be called during the process of freezing where use of the high-level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) * allocator would deadlock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) xfs_sync_sb(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) struct xfs_mount *mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) bool wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) struct xfs_trans *tp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) error = xfs_trans_alloc(mp, &M_RES(mp)->tr_sb, 0, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) XFS_TRANS_NO_WRITECOUNT, &tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) xfs_log_sb(tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) if (wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) xfs_trans_set_sync(tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) return xfs_trans_commit(tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) * Update all the secondary superblocks to match the new state of the primary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) * Because we are completely overwriting all the existing fields in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) * secondary superblock buffers, there is no need to read them in from disk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) * Just get a new buffer, stamp it and write it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) * The sb buffers need to be cached here so that we serialise against other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) * operations that access the secondary superblocks, but we don't want to keep
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) * them in memory once it is written so we mark it as a one-shot buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) xfs_update_secondary_sbs(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) struct xfs_mount *mp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) xfs_agnumber_t agno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) int saved_error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) LIST_HEAD (buffer_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) /* update secondary superblocks. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) for (agno = 1; agno < mp->m_sb.sb_agcount; agno++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) struct xfs_buf *bp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) error = xfs_buf_get(mp->m_ddev_targp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) XFS_AG_DADDR(mp, agno, XFS_SB_DADDR),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) XFS_FSS_TO_BB(mp, 1), &bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) * If we get an error reading or writing alternate superblocks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) * continue. xfs_repair chooses the "best" superblock based
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) * on most matches; if we break early, we'll leave more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) * superblocks un-updated than updated, and xfs_repair may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) * pick them over the properly-updated primary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) xfs_warn(mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) "error allocating secondary superblock for ag %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) agno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) if (!saved_error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) saved_error = error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) bp->b_ops = &xfs_sb_buf_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) xfs_buf_oneshot(bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) xfs_buf_zero(bp, 0, BBTOB(bp->b_length));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) xfs_sb_to_disk(bp->b_addr, &mp->m_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) xfs_buf_delwri_queue(bp, &buffer_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) xfs_buf_relse(bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) /* don't hold too many buffers at once */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) if (agno % 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) error = xfs_buf_delwri_submit(&buffer_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) xfs_warn(mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) "write error %d updating a secondary superblock near ag %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) error, agno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) if (!saved_error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) saved_error = error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) error = xfs_buf_delwri_submit(&buffer_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) xfs_warn(mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) "write error %d updating a secondary superblock near ag %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) error, agno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) return saved_error ? saved_error : error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) * Same behavior as xfs_sync_sb, except that it is always synchronous and it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) * also writes the superblock buffer to disk sector 0 immediately.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) xfs_sync_sb_buf(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) struct xfs_mount *mp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) struct xfs_trans *tp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) struct xfs_buf *bp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) error = xfs_trans_alloc(mp, &M_RES(mp)->tr_sb, 0, 0, 0, &tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) bp = xfs_trans_getsb(tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) xfs_log_sb(tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) xfs_trans_bhold(tp, bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) xfs_trans_set_sync(tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) error = xfs_trans_commit(tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) * write out the sb buffer to get the changes to disk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) error = xfs_bwrite(bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) xfs_buf_relse(bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) xfs_fs_geometry(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) struct xfs_sb *sbp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) struct xfs_fsop_geom *geo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) int struct_version)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) memset(geo, 0, sizeof(struct xfs_fsop_geom));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) geo->blocksize = sbp->sb_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) geo->rtextsize = sbp->sb_rextsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) geo->agblocks = sbp->sb_agblocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) geo->agcount = sbp->sb_agcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) geo->logblocks = sbp->sb_logblocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) geo->sectsize = sbp->sb_sectsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) geo->inodesize = sbp->sb_inodesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) geo->imaxpct = sbp->sb_imax_pct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) geo->datablocks = sbp->sb_dblocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) geo->rtblocks = sbp->sb_rblocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) geo->rtextents = sbp->sb_rextents;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) geo->logstart = sbp->sb_logstart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) BUILD_BUG_ON(sizeof(geo->uuid) != sizeof(sbp->sb_uuid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) memcpy(geo->uuid, &sbp->sb_uuid, sizeof(sbp->sb_uuid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) if (struct_version < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) geo->sunit = sbp->sb_unit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) geo->swidth = sbp->sb_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) if (struct_version < 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) geo->version = XFS_FSOP_GEOM_VERSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) geo->flags = XFS_FSOP_GEOM_FLAGS_NLINK |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) XFS_FSOP_GEOM_FLAGS_DIRV2 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) XFS_FSOP_GEOM_FLAGS_EXTFLG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) if (xfs_sb_version_hasattr(sbp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) geo->flags |= XFS_FSOP_GEOM_FLAGS_ATTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) if (xfs_sb_version_hasquota(sbp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) geo->flags |= XFS_FSOP_GEOM_FLAGS_QUOTA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) if (xfs_sb_version_hasalign(sbp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) geo->flags |= XFS_FSOP_GEOM_FLAGS_IALIGN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) if (xfs_sb_version_hasdalign(sbp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) geo->flags |= XFS_FSOP_GEOM_FLAGS_DALIGN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) if (xfs_sb_version_hassector(sbp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) geo->flags |= XFS_FSOP_GEOM_FLAGS_SECTOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) if (xfs_sb_version_hasasciici(sbp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) geo->flags |= XFS_FSOP_GEOM_FLAGS_DIRV2CI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) if (xfs_sb_version_haslazysbcount(sbp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) geo->flags |= XFS_FSOP_GEOM_FLAGS_LAZYSB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) if (xfs_sb_version_hasattr2(sbp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) geo->flags |= XFS_FSOP_GEOM_FLAGS_ATTR2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) if (xfs_sb_version_hasprojid32bit(sbp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) geo->flags |= XFS_FSOP_GEOM_FLAGS_PROJID32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) if (xfs_sb_version_hascrc(sbp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) geo->flags |= XFS_FSOP_GEOM_FLAGS_V5SB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) if (xfs_sb_version_hasftype(sbp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) geo->flags |= XFS_FSOP_GEOM_FLAGS_FTYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) if (xfs_sb_version_hasfinobt(sbp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) geo->flags |= XFS_FSOP_GEOM_FLAGS_FINOBT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) if (xfs_sb_version_hassparseinodes(sbp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) geo->flags |= XFS_FSOP_GEOM_FLAGS_SPINODES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) if (xfs_sb_version_hasrmapbt(sbp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) geo->flags |= XFS_FSOP_GEOM_FLAGS_RMAPBT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) if (xfs_sb_version_hasreflink(sbp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) geo->flags |= XFS_FSOP_GEOM_FLAGS_REFLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) if (xfs_sb_version_hasbigtime(sbp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) geo->flags |= XFS_FSOP_GEOM_FLAGS_BIGTIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) if (xfs_sb_version_hassector(sbp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) geo->logsectsize = sbp->sb_logsectsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) geo->logsectsize = BBSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) geo->rtsectsize = sbp->sb_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) geo->dirblocksize = xfs_dir2_dirblock_bytes(sbp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) if (struct_version < 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) if (xfs_sb_version_haslogv2(sbp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) geo->flags |= XFS_FSOP_GEOM_FLAGS_LOGV2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) geo->logsunit = sbp->sb_logsunit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) if (struct_version < 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) geo->version = XFS_FSOP_GEOM_VERSION_V5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) /* Read a secondary superblock. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) xfs_sb_read_secondary(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) struct xfs_mount *mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) struct xfs_trans *tp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) xfs_agnumber_t agno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) struct xfs_buf **bpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) struct xfs_buf *bp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) ASSERT(agno != 0 && agno != NULLAGNUMBER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) XFS_AG_DADDR(mp, agno, XFS_SB_BLOCK(mp)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) XFS_FSS_TO_BB(mp, 1), 0, &bp, &xfs_sb_buf_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) xfs_buf_set_ref(bp, XFS_SSB_REF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) *bpp = bp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) /* Get an uninitialised secondary superblock buffer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) xfs_sb_get_secondary(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) struct xfs_mount *mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) struct xfs_trans *tp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) xfs_agnumber_t agno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) struct xfs_buf **bpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) struct xfs_buf *bp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) ASSERT(agno != 0 && agno != NULLAGNUMBER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) error = xfs_trans_get_buf(tp, mp->m_ddev_targp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) XFS_AG_DADDR(mp, agno, XFS_SB_BLOCK(mp)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) XFS_FSS_TO_BB(mp, 1), 0, &bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) bp->b_ops = &xfs_sb_buf_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) xfs_buf_oneshot(bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) *bpp = bp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) }