xref: /openbmc/linux/fs/xfs/libxfs/xfs_health.h (revision 4b4193256c8d3bc3a5397b5cd9494c2ad386317d)
1*508578f2SNishad Kamdar /* SPDX-License-Identifier: GPL-2.0+ */
26772c1f1SDarrick J. Wong /*
36772c1f1SDarrick J. Wong  * Copyright (C) 2019 Oracle.  All Rights Reserved.
46772c1f1SDarrick J. Wong  * Author: Darrick J. Wong <darrick.wong@oracle.com>
56772c1f1SDarrick J. Wong  */
66772c1f1SDarrick J. Wong #ifndef __XFS_HEALTH_H__
76772c1f1SDarrick J. Wong #define __XFS_HEALTH_H__
86772c1f1SDarrick J. Wong 
96772c1f1SDarrick J. Wong /*
106772c1f1SDarrick J. Wong  * In-Core Filesystem Health Assessments
116772c1f1SDarrick J. Wong  * =====================================
126772c1f1SDarrick J. Wong  *
136772c1f1SDarrick J. Wong  * We'd like to be able to summarize the current health status of the
146772c1f1SDarrick J. Wong  * filesystem so that the administrator knows when it's necessary to schedule
156772c1f1SDarrick J. Wong  * some downtime for repairs.  Until then, we would also like to avoid abrupt
166772c1f1SDarrick J. Wong  * shutdowns due to corrupt metadata.
176772c1f1SDarrick J. Wong  *
186772c1f1SDarrick J. Wong  * The online scrub feature evaluates the health of all filesystem metadata.
196772c1f1SDarrick J. Wong  * When scrub detects corruption in a piece of metadata it will set the
206772c1f1SDarrick J. Wong  * corresponding sickness flag, and repair will clear it if successful.  If
216772c1f1SDarrick J. Wong  * problems remain at unmount time, we can also request manual intervention by
226772c1f1SDarrick J. Wong  * logging a notice to run xfs_repair.
236772c1f1SDarrick J. Wong  *
246772c1f1SDarrick J. Wong  * Each health tracking group uses a pair of fields for reporting.  The
256772c1f1SDarrick J. Wong  * "checked" field tell us if a given piece of metadata has ever been examined,
266772c1f1SDarrick J. Wong  * and the "sick" field tells us if that piece was found to need repairs.
276772c1f1SDarrick J. Wong  * Therefore we can conclude that for a given sick flag value:
286772c1f1SDarrick J. Wong  *
296772c1f1SDarrick J. Wong  *  - checked && sick  => metadata needs repair
306772c1f1SDarrick J. Wong  *  - checked && !sick => metadata is ok
316772c1f1SDarrick J. Wong  *  - !checked         => has not been examined since mount
326772c1f1SDarrick J. Wong  */
336772c1f1SDarrick J. Wong 
346772c1f1SDarrick J. Wong struct xfs_mount;
356772c1f1SDarrick J. Wong struct xfs_perag;
366772c1f1SDarrick J. Wong struct xfs_inode;
37c23232d4SDarrick J. Wong struct xfs_fsop_geom;
386772c1f1SDarrick J. Wong 
396772c1f1SDarrick J. Wong /* Observable health issues for metadata spanning the entire filesystem. */
406772c1f1SDarrick J. Wong #define XFS_SICK_FS_COUNTERS	(1 << 0)  /* summary counters */
416772c1f1SDarrick J. Wong #define XFS_SICK_FS_UQUOTA	(1 << 1)  /* user quota */
426772c1f1SDarrick J. Wong #define XFS_SICK_FS_GQUOTA	(1 << 2)  /* group quota */
436772c1f1SDarrick J. Wong #define XFS_SICK_FS_PQUOTA	(1 << 3)  /* project quota */
446772c1f1SDarrick J. Wong 
456772c1f1SDarrick J. Wong /* Observable health issues for realtime volume metadata. */
466772c1f1SDarrick J. Wong #define XFS_SICK_RT_BITMAP	(1 << 0)  /* realtime bitmap */
476772c1f1SDarrick J. Wong #define XFS_SICK_RT_SUMMARY	(1 << 1)  /* realtime summary */
486772c1f1SDarrick J. Wong 
496772c1f1SDarrick J. Wong /* Observable health issues for AG metadata. */
506772c1f1SDarrick J. Wong #define XFS_SICK_AG_SB		(1 << 0)  /* superblock */
516772c1f1SDarrick J. Wong #define XFS_SICK_AG_AGF		(1 << 1)  /* AGF header */
526772c1f1SDarrick J. Wong #define XFS_SICK_AG_AGFL	(1 << 2)  /* AGFL header */
536772c1f1SDarrick J. Wong #define XFS_SICK_AG_AGI		(1 << 3)  /* AGI header */
546772c1f1SDarrick J. Wong #define XFS_SICK_AG_BNOBT	(1 << 4)  /* free space by block */
556772c1f1SDarrick J. Wong #define XFS_SICK_AG_CNTBT	(1 << 5)  /* free space by length */
566772c1f1SDarrick J. Wong #define XFS_SICK_AG_INOBT	(1 << 6)  /* inode index */
576772c1f1SDarrick J. Wong #define XFS_SICK_AG_FINOBT	(1 << 7)  /* free inode index */
586772c1f1SDarrick J. Wong #define XFS_SICK_AG_RMAPBT	(1 << 8)  /* reverse mappings */
596772c1f1SDarrick J. Wong #define XFS_SICK_AG_REFCNTBT	(1 << 9)  /* reference counts */
606772c1f1SDarrick J. Wong 
616772c1f1SDarrick J. Wong /* Observable health issues for inode metadata. */
626772c1f1SDarrick J. Wong #define XFS_SICK_INO_CORE	(1 << 0)  /* inode core */
636772c1f1SDarrick J. Wong #define XFS_SICK_INO_BMBTD	(1 << 1)  /* data fork */
646772c1f1SDarrick J. Wong #define XFS_SICK_INO_BMBTA	(1 << 2)  /* attr fork */
656772c1f1SDarrick J. Wong #define XFS_SICK_INO_BMBTC	(1 << 3)  /* cow fork */
666772c1f1SDarrick J. Wong #define XFS_SICK_INO_DIR	(1 << 4)  /* directory */
676772c1f1SDarrick J. Wong #define XFS_SICK_INO_XATTR	(1 << 5)  /* extended attributes */
686772c1f1SDarrick J. Wong #define XFS_SICK_INO_SYMLINK	(1 << 6)  /* symbolic link remote target */
696772c1f1SDarrick J. Wong #define XFS_SICK_INO_PARENT	(1 << 7)  /* parent pointers */
706772c1f1SDarrick J. Wong 
716772c1f1SDarrick J. Wong /* Primary evidence of health problems in a given group. */
726772c1f1SDarrick J. Wong #define XFS_SICK_FS_PRIMARY	(XFS_SICK_FS_COUNTERS | \
736772c1f1SDarrick J. Wong 				 XFS_SICK_FS_UQUOTA | \
746772c1f1SDarrick J. Wong 				 XFS_SICK_FS_GQUOTA | \
756772c1f1SDarrick J. Wong 				 XFS_SICK_FS_PQUOTA)
766772c1f1SDarrick J. Wong 
776772c1f1SDarrick J. Wong #define XFS_SICK_RT_PRIMARY	(XFS_SICK_RT_BITMAP | \
786772c1f1SDarrick J. Wong 				 XFS_SICK_RT_SUMMARY)
796772c1f1SDarrick J. Wong 
806772c1f1SDarrick J. Wong #define XFS_SICK_AG_PRIMARY	(XFS_SICK_AG_SB | \
816772c1f1SDarrick J. Wong 				 XFS_SICK_AG_AGF | \
826772c1f1SDarrick J. Wong 				 XFS_SICK_AG_AGFL | \
836772c1f1SDarrick J. Wong 				 XFS_SICK_AG_AGI | \
846772c1f1SDarrick J. Wong 				 XFS_SICK_AG_BNOBT | \
856772c1f1SDarrick J. Wong 				 XFS_SICK_AG_CNTBT | \
866772c1f1SDarrick J. Wong 				 XFS_SICK_AG_INOBT | \
876772c1f1SDarrick J. Wong 				 XFS_SICK_AG_FINOBT | \
886772c1f1SDarrick J. Wong 				 XFS_SICK_AG_RMAPBT | \
896772c1f1SDarrick J. Wong 				 XFS_SICK_AG_REFCNTBT)
906772c1f1SDarrick J. Wong 
916772c1f1SDarrick J. Wong #define XFS_SICK_INO_PRIMARY	(XFS_SICK_INO_CORE | \
926772c1f1SDarrick J. Wong 				 XFS_SICK_INO_BMBTD | \
936772c1f1SDarrick J. Wong 				 XFS_SICK_INO_BMBTA | \
946772c1f1SDarrick J. Wong 				 XFS_SICK_INO_BMBTC | \
956772c1f1SDarrick J. Wong 				 XFS_SICK_INO_DIR | \
966772c1f1SDarrick J. Wong 				 XFS_SICK_INO_XATTR | \
976772c1f1SDarrick J. Wong 				 XFS_SICK_INO_SYMLINK | \
986772c1f1SDarrick J. Wong 				 XFS_SICK_INO_PARENT)
996772c1f1SDarrick J. Wong 
1006772c1f1SDarrick J. Wong /* These functions must be provided by the xfs implementation. */
1016772c1f1SDarrick J. Wong 
1026772c1f1SDarrick J. Wong void xfs_fs_mark_sick(struct xfs_mount *mp, unsigned int mask);
1036772c1f1SDarrick J. Wong void xfs_fs_mark_healthy(struct xfs_mount *mp, unsigned int mask);
1046772c1f1SDarrick J. Wong void xfs_fs_measure_sickness(struct xfs_mount *mp, unsigned int *sick,
1056772c1f1SDarrick J. Wong 		unsigned int *checked);
1066772c1f1SDarrick J. Wong 
1076772c1f1SDarrick J. Wong void xfs_rt_mark_sick(struct xfs_mount *mp, unsigned int mask);
1086772c1f1SDarrick J. Wong void xfs_rt_mark_healthy(struct xfs_mount *mp, unsigned int mask);
1096772c1f1SDarrick J. Wong void xfs_rt_measure_sickness(struct xfs_mount *mp, unsigned int *sick,
1106772c1f1SDarrick J. Wong 		unsigned int *checked);
1116772c1f1SDarrick J. Wong 
1126772c1f1SDarrick J. Wong void xfs_ag_mark_sick(struct xfs_perag *pag, unsigned int mask);
1136772c1f1SDarrick J. Wong void xfs_ag_mark_healthy(struct xfs_perag *pag, unsigned int mask);
1146772c1f1SDarrick J. Wong void xfs_ag_measure_sickness(struct xfs_perag *pag, unsigned int *sick,
1156772c1f1SDarrick J. Wong 		unsigned int *checked);
1166772c1f1SDarrick J. Wong 
1176772c1f1SDarrick J. Wong void xfs_inode_mark_sick(struct xfs_inode *ip, unsigned int mask);
1186772c1f1SDarrick J. Wong void xfs_inode_mark_healthy(struct xfs_inode *ip, unsigned int mask);
1196772c1f1SDarrick J. Wong void xfs_inode_measure_sickness(struct xfs_inode *ip, unsigned int *sick,
1206772c1f1SDarrick J. Wong 		unsigned int *checked);
1216772c1f1SDarrick J. Wong 
122519841c2SDarrick J. Wong void xfs_health_unmount(struct xfs_mount *mp);
123519841c2SDarrick J. Wong 
1246772c1f1SDarrick J. Wong /* Now some helpers. */
1256772c1f1SDarrick J. Wong 
1266772c1f1SDarrick J. Wong static inline bool
xfs_fs_has_sickness(struct xfs_mount * mp,unsigned int mask)1276772c1f1SDarrick J. Wong xfs_fs_has_sickness(struct xfs_mount *mp, unsigned int mask)
1286772c1f1SDarrick J. Wong {
1296772c1f1SDarrick J. Wong 	unsigned int	sick, checked;
1306772c1f1SDarrick J. Wong 
1316772c1f1SDarrick J. Wong 	xfs_fs_measure_sickness(mp, &sick, &checked);
1326772c1f1SDarrick J. Wong 	return sick & mask;
1336772c1f1SDarrick J. Wong }
1346772c1f1SDarrick J. Wong 
1356772c1f1SDarrick J. Wong static inline bool
xfs_rt_has_sickness(struct xfs_mount * mp,unsigned int mask)1366772c1f1SDarrick J. Wong xfs_rt_has_sickness(struct xfs_mount *mp, unsigned int mask)
1376772c1f1SDarrick J. Wong {
1386772c1f1SDarrick J. Wong 	unsigned int	sick, checked;
1396772c1f1SDarrick J. Wong 
1406772c1f1SDarrick J. Wong 	xfs_rt_measure_sickness(mp, &sick, &checked);
1416772c1f1SDarrick J. Wong 	return sick & mask;
1426772c1f1SDarrick J. Wong }
1436772c1f1SDarrick J. Wong 
1446772c1f1SDarrick J. Wong static inline bool
xfs_ag_has_sickness(struct xfs_perag * pag,unsigned int mask)1456772c1f1SDarrick J. Wong xfs_ag_has_sickness(struct xfs_perag *pag, unsigned int mask)
1466772c1f1SDarrick J. Wong {
1476772c1f1SDarrick J. Wong 	unsigned int	sick, checked;
1486772c1f1SDarrick J. Wong 
1496772c1f1SDarrick J. Wong 	xfs_ag_measure_sickness(pag, &sick, &checked);
1506772c1f1SDarrick J. Wong 	return sick & mask;
1516772c1f1SDarrick J. Wong }
1526772c1f1SDarrick J. Wong 
1536772c1f1SDarrick J. Wong static inline bool
xfs_inode_has_sickness(struct xfs_inode * ip,unsigned int mask)1546772c1f1SDarrick J. Wong xfs_inode_has_sickness(struct xfs_inode *ip, unsigned int mask)
1556772c1f1SDarrick J. Wong {
1566772c1f1SDarrick J. Wong 	unsigned int	sick, checked;
1576772c1f1SDarrick J. Wong 
1586772c1f1SDarrick J. Wong 	xfs_inode_measure_sickness(ip, &sick, &checked);
1596772c1f1SDarrick J. Wong 	return sick & mask;
1606772c1f1SDarrick J. Wong }
1616772c1f1SDarrick J. Wong 
1626772c1f1SDarrick J. Wong static inline bool
xfs_fs_is_healthy(struct xfs_mount * mp)1636772c1f1SDarrick J. Wong xfs_fs_is_healthy(struct xfs_mount *mp)
1646772c1f1SDarrick J. Wong {
1656772c1f1SDarrick J. Wong 	return !xfs_fs_has_sickness(mp, -1U);
1666772c1f1SDarrick J. Wong }
1676772c1f1SDarrick J. Wong 
1686772c1f1SDarrick J. Wong static inline bool
xfs_rt_is_healthy(struct xfs_mount * mp)1696772c1f1SDarrick J. Wong xfs_rt_is_healthy(struct xfs_mount *mp)
1706772c1f1SDarrick J. Wong {
1716772c1f1SDarrick J. Wong 	return !xfs_rt_has_sickness(mp, -1U);
1726772c1f1SDarrick J. Wong }
1736772c1f1SDarrick J. Wong 
1746772c1f1SDarrick J. Wong static inline bool
xfs_ag_is_healthy(struct xfs_perag * pag)1756772c1f1SDarrick J. Wong xfs_ag_is_healthy(struct xfs_perag *pag)
1766772c1f1SDarrick J. Wong {
1776772c1f1SDarrick J. Wong 	return !xfs_ag_has_sickness(pag, -1U);
1786772c1f1SDarrick J. Wong }
1796772c1f1SDarrick J. Wong 
1806772c1f1SDarrick J. Wong static inline bool
xfs_inode_is_healthy(struct xfs_inode * ip)1816772c1f1SDarrick J. Wong xfs_inode_is_healthy(struct xfs_inode *ip)
1826772c1f1SDarrick J. Wong {
1836772c1f1SDarrick J. Wong 	return !xfs_inode_has_sickness(ip, -1U);
1846772c1f1SDarrick J. Wong }
1856772c1f1SDarrick J. Wong 
186c23232d4SDarrick J. Wong void xfs_fsop_geom_health(struct xfs_mount *mp, struct xfs_fsop_geom *geo);
1871302c6a2SDarrick J. Wong void xfs_ag_geom_health(struct xfs_perag *pag, struct xfs_ag_geometry *ageo);
1887035f972SDarrick J. Wong void xfs_bulkstat_health(struct xfs_inode *ip, struct xfs_bulkstat *bs);
189c23232d4SDarrick J. Wong 
1906772c1f1SDarrick J. Wong #endif	/* __XFS_HEALTH_H__ */
191