^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) 2019 Oracle. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Author: Darrick J. Wong <darrick.wong@oracle.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #ifndef __XFS_HEALTH_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #define __XFS_HEALTH_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * In-Core Filesystem Health Assessments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * =====================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * We'd like to be able to summarize the current health status of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * filesystem so that the administrator knows when it's necessary to schedule
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * some downtime for repairs. Until then, we would also like to avoid abrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * shutdowns due to corrupt metadata.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * The online scrub feature evaluates the health of all filesystem metadata.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * When scrub detects corruption in a piece of metadata it will set the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * corresponding sickness flag, and repair will clear it if successful. If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * problems remain at unmount time, we can also request manual intervention by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * logging a notice to run xfs_repair.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * Each health tracking group uses a pair of fields for reporting. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * "checked" field tell us if a given piece of metadata has ever been examined,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * and the "sick" field tells us if that piece was found to need repairs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * Therefore we can conclude that for a given sick flag value:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * - checked && sick => metadata needs repair
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * - checked && !sick => metadata is ok
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * - !checked => has not been examined since mount
^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) struct xfs_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct xfs_perag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct xfs_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct xfs_fsop_geom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) /* Observable health issues for metadata spanning the entire filesystem. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define XFS_SICK_FS_COUNTERS (1 << 0) /* summary counters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define XFS_SICK_FS_UQUOTA (1 << 1) /* user quota */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define XFS_SICK_FS_GQUOTA (1 << 2) /* group quota */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define XFS_SICK_FS_PQUOTA (1 << 3) /* project quota */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) /* Observable health issues for realtime volume metadata. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define XFS_SICK_RT_BITMAP (1 << 0) /* realtime bitmap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define XFS_SICK_RT_SUMMARY (1 << 1) /* realtime summary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) /* Observable health issues for AG metadata. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define XFS_SICK_AG_SB (1 << 0) /* superblock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define XFS_SICK_AG_AGF (1 << 1) /* AGF header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define XFS_SICK_AG_AGFL (1 << 2) /* AGFL header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define XFS_SICK_AG_AGI (1 << 3) /* AGI header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define XFS_SICK_AG_BNOBT (1 << 4) /* free space by block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define XFS_SICK_AG_CNTBT (1 << 5) /* free space by length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define XFS_SICK_AG_INOBT (1 << 6) /* inode index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define XFS_SICK_AG_FINOBT (1 << 7) /* free inode index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define XFS_SICK_AG_RMAPBT (1 << 8) /* reverse mappings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define XFS_SICK_AG_REFCNTBT (1 << 9) /* reference counts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) /* Observable health issues for inode metadata. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define XFS_SICK_INO_CORE (1 << 0) /* inode core */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #define XFS_SICK_INO_BMBTD (1 << 1) /* data fork */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #define XFS_SICK_INO_BMBTA (1 << 2) /* attr fork */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #define XFS_SICK_INO_BMBTC (1 << 3) /* cow fork */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #define XFS_SICK_INO_DIR (1 << 4) /* directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #define XFS_SICK_INO_XATTR (1 << 5) /* extended attributes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #define XFS_SICK_INO_SYMLINK (1 << 6) /* symbolic link remote target */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #define XFS_SICK_INO_PARENT (1 << 7) /* parent pointers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) /* Primary evidence of health problems in a given group. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #define XFS_SICK_FS_PRIMARY (XFS_SICK_FS_COUNTERS | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) XFS_SICK_FS_UQUOTA | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) XFS_SICK_FS_GQUOTA | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) XFS_SICK_FS_PQUOTA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #define XFS_SICK_RT_PRIMARY (XFS_SICK_RT_BITMAP | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) XFS_SICK_RT_SUMMARY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #define XFS_SICK_AG_PRIMARY (XFS_SICK_AG_SB | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) XFS_SICK_AG_AGF | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) XFS_SICK_AG_AGFL | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) XFS_SICK_AG_AGI | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) XFS_SICK_AG_BNOBT | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) XFS_SICK_AG_CNTBT | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) XFS_SICK_AG_INOBT | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) XFS_SICK_AG_FINOBT | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) XFS_SICK_AG_RMAPBT | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) XFS_SICK_AG_REFCNTBT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) #define XFS_SICK_INO_PRIMARY (XFS_SICK_INO_CORE | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) XFS_SICK_INO_BMBTD | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) XFS_SICK_INO_BMBTA | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) XFS_SICK_INO_BMBTC | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) XFS_SICK_INO_DIR | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) XFS_SICK_INO_XATTR | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) XFS_SICK_INO_SYMLINK | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) XFS_SICK_INO_PARENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) /* These functions must be provided by the xfs implementation. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) void xfs_fs_mark_sick(struct xfs_mount *mp, unsigned int mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) void xfs_fs_mark_healthy(struct xfs_mount *mp, unsigned int mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) void xfs_fs_measure_sickness(struct xfs_mount *mp, unsigned int *sick,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) unsigned int *checked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) void xfs_rt_mark_sick(struct xfs_mount *mp, unsigned int mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) void xfs_rt_mark_healthy(struct xfs_mount *mp, unsigned int mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) void xfs_rt_measure_sickness(struct xfs_mount *mp, unsigned int *sick,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) unsigned int *checked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) void xfs_ag_mark_sick(struct xfs_perag *pag, unsigned int mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) void xfs_ag_mark_healthy(struct xfs_perag *pag, unsigned int mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) void xfs_ag_measure_sickness(struct xfs_perag *pag, unsigned int *sick,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) unsigned int *checked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) void xfs_inode_mark_sick(struct xfs_inode *ip, unsigned int mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) void xfs_inode_mark_healthy(struct xfs_inode *ip, unsigned int mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) void xfs_inode_measure_sickness(struct xfs_inode *ip, unsigned int *sick,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) unsigned int *checked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) void xfs_health_unmount(struct xfs_mount *mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) /* Now some helpers. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static inline bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) xfs_fs_has_sickness(struct xfs_mount *mp, unsigned int mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) unsigned int sick, checked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) xfs_fs_measure_sickness(mp, &sick, &checked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) return sick & mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static inline bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) xfs_rt_has_sickness(struct xfs_mount *mp, unsigned int mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) unsigned int sick, checked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) xfs_rt_measure_sickness(mp, &sick, &checked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) return sick & mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) static inline bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) xfs_ag_has_sickness(struct xfs_perag *pag, unsigned int mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) unsigned int sick, checked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) xfs_ag_measure_sickness(pag, &sick, &checked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) return sick & mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static inline bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) xfs_inode_has_sickness(struct xfs_inode *ip, unsigned int mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) unsigned int sick, checked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) xfs_inode_measure_sickness(ip, &sick, &checked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) return sick & mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static inline bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) xfs_fs_is_healthy(struct xfs_mount *mp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) return !xfs_fs_has_sickness(mp, -1U);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) static inline bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) xfs_rt_is_healthy(struct xfs_mount *mp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) return !xfs_rt_has_sickness(mp, -1U);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) static inline bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) xfs_ag_is_healthy(struct xfs_perag *pag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) return !xfs_ag_has_sickness(pag, -1U);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) static inline bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) xfs_inode_is_healthy(struct xfs_inode *ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) return !xfs_inode_has_sickness(ip, -1U);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) void xfs_fsop_geom_health(struct xfs_mount *mp, struct xfs_fsop_geom *geo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) void xfs_ag_geom_health(struct xfs_perag *pag, struct xfs_ag_geometry *ageo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) void xfs_bulkstat_health(struct xfs_inode *ip, struct xfs_bulkstat *bs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) #endif /* __XFS_HEALTH_H__ */