18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2017 Oracle.  All Rights Reserved.
48c2ecf20Sopenharmony_ci * Author: Darrick J. Wong <darrick.wong@oracle.com>
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci#ifndef __XFS_SCRUB_COMMON_H__
78c2ecf20Sopenharmony_ci#define __XFS_SCRUB_COMMON_H__
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci/*
108c2ecf20Sopenharmony_ci * We /could/ terminate a scrub/repair operation early.  If we're not
118c2ecf20Sopenharmony_ci * in a good place to continue (fatal signal, etc.) then bail out.
128c2ecf20Sopenharmony_ci * Note that we're careful not to make any judgements about *error.
138c2ecf20Sopenharmony_ci */
148c2ecf20Sopenharmony_cistatic inline bool
158c2ecf20Sopenharmony_cixchk_should_terminate(
168c2ecf20Sopenharmony_ci	struct xfs_scrub	*sc,
178c2ecf20Sopenharmony_ci	int			*error)
188c2ecf20Sopenharmony_ci{
198c2ecf20Sopenharmony_ci	/*
208c2ecf20Sopenharmony_ci	 * If preemption is disabled, we need to yield to the scheduler every
218c2ecf20Sopenharmony_ci	 * few seconds so that we don't run afoul of the soft lockup watchdog
228c2ecf20Sopenharmony_ci	 * or RCU stall detector.
238c2ecf20Sopenharmony_ci	 */
248c2ecf20Sopenharmony_ci	cond_resched();
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci	if (fatal_signal_pending(current)) {
278c2ecf20Sopenharmony_ci		if (*error == 0)
288c2ecf20Sopenharmony_ci			*error = -EAGAIN;
298c2ecf20Sopenharmony_ci		return true;
308c2ecf20Sopenharmony_ci	}
318c2ecf20Sopenharmony_ci	return false;
328c2ecf20Sopenharmony_ci}
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ciint xchk_trans_alloc(struct xfs_scrub *sc, uint resblks);
358c2ecf20Sopenharmony_cibool xchk_process_error(struct xfs_scrub *sc, xfs_agnumber_t agno,
368c2ecf20Sopenharmony_ci		xfs_agblock_t bno, int *error);
378c2ecf20Sopenharmony_cibool xchk_fblock_process_error(struct xfs_scrub *sc, int whichfork,
388c2ecf20Sopenharmony_ci		xfs_fileoff_t offset, int *error);
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_cibool xchk_xref_process_error(struct xfs_scrub *sc,
418c2ecf20Sopenharmony_ci		xfs_agnumber_t agno, xfs_agblock_t bno, int *error);
428c2ecf20Sopenharmony_cibool xchk_fblock_xref_process_error(struct xfs_scrub *sc,
438c2ecf20Sopenharmony_ci		int whichfork, xfs_fileoff_t offset, int *error);
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_civoid xchk_block_set_preen(struct xfs_scrub *sc,
468c2ecf20Sopenharmony_ci		struct xfs_buf *bp);
478c2ecf20Sopenharmony_civoid xchk_ino_set_preen(struct xfs_scrub *sc, xfs_ino_t ino);
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_civoid xchk_set_corrupt(struct xfs_scrub *sc);
508c2ecf20Sopenharmony_civoid xchk_block_set_corrupt(struct xfs_scrub *sc,
518c2ecf20Sopenharmony_ci		struct xfs_buf *bp);
528c2ecf20Sopenharmony_civoid xchk_ino_set_corrupt(struct xfs_scrub *sc, xfs_ino_t ino);
538c2ecf20Sopenharmony_civoid xchk_fblock_set_corrupt(struct xfs_scrub *sc, int whichfork,
548c2ecf20Sopenharmony_ci		xfs_fileoff_t offset);
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_civoid xchk_block_xref_set_corrupt(struct xfs_scrub *sc,
578c2ecf20Sopenharmony_ci		struct xfs_buf *bp);
588c2ecf20Sopenharmony_civoid xchk_ino_xref_set_corrupt(struct xfs_scrub *sc,
598c2ecf20Sopenharmony_ci		xfs_ino_t ino);
608c2ecf20Sopenharmony_civoid xchk_fblock_xref_set_corrupt(struct xfs_scrub *sc,
618c2ecf20Sopenharmony_ci		int whichfork, xfs_fileoff_t offset);
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_civoid xchk_ino_set_warning(struct xfs_scrub *sc, xfs_ino_t ino);
648c2ecf20Sopenharmony_civoid xchk_fblock_set_warning(struct xfs_scrub *sc, int whichfork,
658c2ecf20Sopenharmony_ci		xfs_fileoff_t offset);
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_civoid xchk_set_incomplete(struct xfs_scrub *sc);
688c2ecf20Sopenharmony_ciint xchk_checkpoint_log(struct xfs_mount *mp);
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci/* Are we set up for a cross-referencing check? */
718c2ecf20Sopenharmony_cibool xchk_should_check_xref(struct xfs_scrub *sc, int *error,
728c2ecf20Sopenharmony_ci			   struct xfs_btree_cur **curpp);
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci/* Setup functions */
758c2ecf20Sopenharmony_ciint xchk_setup_fs(struct xfs_scrub *sc, struct xfs_inode *ip);
768c2ecf20Sopenharmony_ciint xchk_setup_ag_allocbt(struct xfs_scrub *sc,
778c2ecf20Sopenharmony_ci			       struct xfs_inode *ip);
788c2ecf20Sopenharmony_ciint xchk_setup_ag_iallocbt(struct xfs_scrub *sc,
798c2ecf20Sopenharmony_ci				struct xfs_inode *ip);
808c2ecf20Sopenharmony_ciint xchk_setup_ag_rmapbt(struct xfs_scrub *sc,
818c2ecf20Sopenharmony_ci			      struct xfs_inode *ip);
828c2ecf20Sopenharmony_ciint xchk_setup_ag_refcountbt(struct xfs_scrub *sc,
838c2ecf20Sopenharmony_ci				  struct xfs_inode *ip);
848c2ecf20Sopenharmony_ciint xchk_setup_inode(struct xfs_scrub *sc,
858c2ecf20Sopenharmony_ci			  struct xfs_inode *ip);
868c2ecf20Sopenharmony_ciint xchk_setup_inode_bmap(struct xfs_scrub *sc,
878c2ecf20Sopenharmony_ci			       struct xfs_inode *ip);
888c2ecf20Sopenharmony_ciint xchk_setup_inode_bmap_data(struct xfs_scrub *sc,
898c2ecf20Sopenharmony_ci				    struct xfs_inode *ip);
908c2ecf20Sopenharmony_ciint xchk_setup_directory(struct xfs_scrub *sc,
918c2ecf20Sopenharmony_ci			      struct xfs_inode *ip);
928c2ecf20Sopenharmony_ciint xchk_setup_xattr(struct xfs_scrub *sc,
938c2ecf20Sopenharmony_ci			  struct xfs_inode *ip);
948c2ecf20Sopenharmony_ciint xchk_setup_symlink(struct xfs_scrub *sc,
958c2ecf20Sopenharmony_ci			    struct xfs_inode *ip);
968c2ecf20Sopenharmony_ciint xchk_setup_parent(struct xfs_scrub *sc,
978c2ecf20Sopenharmony_ci			   struct xfs_inode *ip);
988c2ecf20Sopenharmony_ci#ifdef CONFIG_XFS_RT
998c2ecf20Sopenharmony_ciint xchk_setup_rt(struct xfs_scrub *sc, struct xfs_inode *ip);
1008c2ecf20Sopenharmony_ci#else
1018c2ecf20Sopenharmony_cistatic inline int
1028c2ecf20Sopenharmony_cixchk_setup_rt(struct xfs_scrub *sc, struct xfs_inode *ip)
1038c2ecf20Sopenharmony_ci{
1048c2ecf20Sopenharmony_ci	return -ENOENT;
1058c2ecf20Sopenharmony_ci}
1068c2ecf20Sopenharmony_ci#endif
1078c2ecf20Sopenharmony_ci#ifdef CONFIG_XFS_QUOTA
1088c2ecf20Sopenharmony_ciint xchk_setup_quota(struct xfs_scrub *sc, struct xfs_inode *ip);
1098c2ecf20Sopenharmony_ci#else
1108c2ecf20Sopenharmony_cistatic inline int
1118c2ecf20Sopenharmony_cixchk_setup_quota(struct xfs_scrub *sc, struct xfs_inode *ip)
1128c2ecf20Sopenharmony_ci{
1138c2ecf20Sopenharmony_ci	return -ENOENT;
1148c2ecf20Sopenharmony_ci}
1158c2ecf20Sopenharmony_ci#endif
1168c2ecf20Sopenharmony_ciint xchk_setup_fscounters(struct xfs_scrub *sc, struct xfs_inode *ip);
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_civoid xchk_ag_free(struct xfs_scrub *sc, struct xchk_ag *sa);
1198c2ecf20Sopenharmony_ciint xchk_ag_init(struct xfs_scrub *sc, xfs_agnumber_t agno,
1208c2ecf20Sopenharmony_ci		struct xchk_ag *sa);
1218c2ecf20Sopenharmony_civoid xchk_perag_get(struct xfs_mount *mp, struct xchk_ag *sa);
1228c2ecf20Sopenharmony_ciint xchk_ag_read_headers(struct xfs_scrub *sc, xfs_agnumber_t agno,
1238c2ecf20Sopenharmony_ci		struct xfs_buf **agi, struct xfs_buf **agf,
1248c2ecf20Sopenharmony_ci		struct xfs_buf **agfl);
1258c2ecf20Sopenharmony_civoid xchk_ag_btcur_free(struct xchk_ag *sa);
1268c2ecf20Sopenharmony_ciint xchk_ag_btcur_init(struct xfs_scrub *sc, struct xchk_ag *sa);
1278c2ecf20Sopenharmony_ciint xchk_count_rmap_ownedby_ag(struct xfs_scrub *sc, struct xfs_btree_cur *cur,
1288c2ecf20Sopenharmony_ci		const struct xfs_owner_info *oinfo, xfs_filblks_t *blocks);
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ciint xchk_setup_ag_btree(struct xfs_scrub *sc, struct xfs_inode *ip,
1318c2ecf20Sopenharmony_ci		bool force_log);
1328c2ecf20Sopenharmony_ciint xchk_get_inode(struct xfs_scrub *sc, struct xfs_inode *ip_in);
1338c2ecf20Sopenharmony_ciint xchk_setup_inode_contents(struct xfs_scrub *sc, struct xfs_inode *ip,
1348c2ecf20Sopenharmony_ci		unsigned int resblks);
1358c2ecf20Sopenharmony_civoid xchk_buffer_recheck(struct xfs_scrub *sc, struct xfs_buf *bp);
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci/*
1388c2ecf20Sopenharmony_ci * Don't bother cross-referencing if we already found corruption or cross
1398c2ecf20Sopenharmony_ci * referencing discrepancies.
1408c2ecf20Sopenharmony_ci */
1418c2ecf20Sopenharmony_cistatic inline bool xchk_skip_xref(struct xfs_scrub_metadata *sm)
1428c2ecf20Sopenharmony_ci{
1438c2ecf20Sopenharmony_ci	return sm->sm_flags & (XFS_SCRUB_OFLAG_CORRUPT |
1448c2ecf20Sopenharmony_ci			       XFS_SCRUB_OFLAG_XCORRUPT);
1458c2ecf20Sopenharmony_ci}
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ciint xchk_metadata_inode_forks(struct xfs_scrub *sc);
1488c2ecf20Sopenharmony_ciint xchk_ilock_inverted(struct xfs_inode *ip, uint lock_mode);
1498c2ecf20Sopenharmony_civoid xchk_stop_reaping(struct xfs_scrub *sc);
1508c2ecf20Sopenharmony_civoid xchk_start_reaping(struct xfs_scrub *sc);
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci#endif	/* __XFS_SCRUB_COMMON_H__ */
153