common.h 5.1 KB
Newer Older
D
Dave Chinner 已提交
1
// SPDX-License-Identifier: GPL-2.0+
D
Darrick J. Wong 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 * Copyright (C) 2017 Oracle.  All Rights Reserved.
 * Author: Darrick J. Wong <darrick.wong@oracle.com>
 */
#ifndef __XFS_SCRUB_COMMON_H__
#define __XFS_SCRUB_COMMON_H__

/*
 * We /could/ terminate a scrub/repair operation early.  If we're not
 * in a good place to continue (fatal signal, etc.) then bail out.
 * Note that we're careful not to make any judgements about *error.
 */
static inline bool
D
Darrick J. Wong 已提交
15
xchk_should_terminate(
D
Darrick J. Wong 已提交
16 17 18 19 20 21 22 23 24 25 26
	struct xfs_scrub_context	*sc,
	int				*error)
{
	if (fatal_signal_pending(current)) {
		if (*error == 0)
			*error = -EAGAIN;
		return true;
	}
	return false;
}

D
Darrick J. Wong 已提交
27 28
int xchk_trans_alloc(struct xfs_scrub_context *sc, uint resblks);
bool xchk_process_error(struct xfs_scrub_context *sc, xfs_agnumber_t agno,
29
		xfs_agblock_t bno, int *error);
D
Darrick J. Wong 已提交
30
bool xchk_fblock_process_error(struct xfs_scrub_context *sc, int whichfork,
31 32
		xfs_fileoff_t offset, int *error);

D
Darrick J. Wong 已提交
33
bool xchk_xref_process_error(struct xfs_scrub_context *sc,
34
		xfs_agnumber_t agno, xfs_agblock_t bno, int *error);
D
Darrick J. Wong 已提交
35
bool xchk_fblock_xref_process_error(struct xfs_scrub_context *sc,
36 37
		int whichfork, xfs_fileoff_t offset, int *error);

D
Darrick J. Wong 已提交
38
void xchk_block_set_preen(struct xfs_scrub_context *sc,
39
		struct xfs_buf *bp);
D
Darrick J. Wong 已提交
40
void xchk_ino_set_preen(struct xfs_scrub_context *sc, xfs_ino_t ino);
41

D
Darrick J. Wong 已提交
42
void xchk_block_set_corrupt(struct xfs_scrub_context *sc,
43
		struct xfs_buf *bp);
D
Darrick J. Wong 已提交
44 45
void xchk_ino_set_corrupt(struct xfs_scrub_context *sc, xfs_ino_t ino);
void xchk_fblock_set_corrupt(struct xfs_scrub_context *sc, int whichfork,
46 47
		xfs_fileoff_t offset);

D
Darrick J. Wong 已提交
48
void xchk_block_xref_set_corrupt(struct xfs_scrub_context *sc,
49
		struct xfs_buf *bp);
D
Darrick J. Wong 已提交
50
void xchk_ino_xref_set_corrupt(struct xfs_scrub_context *sc,
51
		xfs_ino_t ino);
D
Darrick J. Wong 已提交
52
void xchk_fblock_xref_set_corrupt(struct xfs_scrub_context *sc,
53 54
		int whichfork, xfs_fileoff_t offset);

D
Darrick J. Wong 已提交
55 56
void xchk_ino_set_warning(struct xfs_scrub_context *sc, xfs_ino_t ino);
void xchk_fblock_set_warning(struct xfs_scrub_context *sc, int whichfork,
57 58
		xfs_fileoff_t offset);

D
Darrick J. Wong 已提交
59 60
void xchk_set_incomplete(struct xfs_scrub_context *sc);
int xchk_checkpoint_log(struct xfs_mount *mp);
61

62
/* Are we set up for a cross-referencing check? */
D
Darrick J. Wong 已提交
63
bool xchk_should_check_xref(struct xfs_scrub_context *sc, int *error,
64 65
			   struct xfs_btree_cur **curpp);

D
Darrick J. Wong 已提交
66
/* Setup functions */
D
Darrick J. Wong 已提交
67 68
int xchk_setup_fs(struct xfs_scrub_context *sc, struct xfs_inode *ip);
int xchk_setup_ag_allocbt(struct xfs_scrub_context *sc,
D
Darrick J. Wong 已提交
69
			       struct xfs_inode *ip);
D
Darrick J. Wong 已提交
70
int xchk_setup_ag_iallocbt(struct xfs_scrub_context *sc,
D
Darrick J. Wong 已提交
71
				struct xfs_inode *ip);
D
Darrick J. Wong 已提交
72
int xchk_setup_ag_rmapbt(struct xfs_scrub_context *sc,
D
Darrick J. Wong 已提交
73
			      struct xfs_inode *ip);
D
Darrick J. Wong 已提交
74
int xchk_setup_ag_refcountbt(struct xfs_scrub_context *sc,
D
Darrick J. Wong 已提交
75
				  struct xfs_inode *ip);
D
Darrick J. Wong 已提交
76
int xchk_setup_inode(struct xfs_scrub_context *sc,
D
Darrick J. Wong 已提交
77
			  struct xfs_inode *ip);
D
Darrick J. Wong 已提交
78
int xchk_setup_inode_bmap(struct xfs_scrub_context *sc,
D
Darrick J. Wong 已提交
79
			       struct xfs_inode *ip);
D
Darrick J. Wong 已提交
80
int xchk_setup_inode_bmap_data(struct xfs_scrub_context *sc,
D
Darrick J. Wong 已提交
81
				    struct xfs_inode *ip);
D
Darrick J. Wong 已提交
82
int xchk_setup_directory(struct xfs_scrub_context *sc,
D
Darrick J. Wong 已提交
83
			      struct xfs_inode *ip);
D
Darrick J. Wong 已提交
84
int xchk_setup_xattr(struct xfs_scrub_context *sc,
D
Darrick J. Wong 已提交
85
			  struct xfs_inode *ip);
D
Darrick J. Wong 已提交
86
int xchk_setup_symlink(struct xfs_scrub_context *sc,
D
Darrick J. Wong 已提交
87
			    struct xfs_inode *ip);
D
Darrick J. Wong 已提交
88
int xchk_setup_parent(struct xfs_scrub_context *sc,
89
			   struct xfs_inode *ip);
90
#ifdef CONFIG_XFS_RT
D
Darrick J. Wong 已提交
91
int xchk_setup_rt(struct xfs_scrub_context *sc, struct xfs_inode *ip);
92 93
#else
static inline int
D
Darrick J. Wong 已提交
94
xchk_setup_rt(struct xfs_scrub_context *sc, struct xfs_inode *ip)
D
Darrick J. Wong 已提交
95 96 97 98 99
{
	return -ENOENT;
}
#endif
#ifdef CONFIG_XFS_QUOTA
D
Darrick J. Wong 已提交
100
int xchk_setup_quota(struct xfs_scrub_context *sc, struct xfs_inode *ip);
D
Darrick J. Wong 已提交
101 102
#else
static inline int
D
Darrick J. Wong 已提交
103
xchk_setup_quota(struct xfs_scrub_context *sc, struct xfs_inode *ip)
104 105 106 107
{
	return -ENOENT;
}
#endif
D
Darrick J. Wong 已提交
108

D
Darrick J. Wong 已提交
109 110 111 112 113
void xchk_ag_free(struct xfs_scrub_context *sc, struct xchk_ag *sa);
int xchk_ag_init(struct xfs_scrub_context *sc, xfs_agnumber_t agno,
		      struct xchk_ag *sa);
void xchk_perag_get(struct xfs_mount *mp, struct xchk_ag *sa);
int xchk_ag_read_headers(struct xfs_scrub_context *sc, xfs_agnumber_t agno,
114 115
			      struct xfs_buf **agi, struct xfs_buf **agf,
			      struct xfs_buf **agfl);
D
Darrick J. Wong 已提交
116 117 118 119
void xchk_ag_btcur_free(struct xchk_ag *sa);
int xchk_ag_btcur_init(struct xfs_scrub_context *sc,
			    struct xchk_ag *sa);
int xchk_count_rmap_ownedby_ag(struct xfs_scrub_context *sc,
120 121 122
				    struct xfs_btree_cur *cur,
				    struct xfs_owner_info *oinfo,
				    xfs_filblks_t *blocks);
123

D
Darrick J. Wong 已提交
124
int xchk_setup_ag_btree(struct xfs_scrub_context *sc,
D
Darrick J. Wong 已提交
125
			     struct xfs_inode *ip, bool force_log);
D
Darrick J. Wong 已提交
126 127
int xchk_get_inode(struct xfs_scrub_context *sc, struct xfs_inode *ip_in);
int xchk_setup_inode_contents(struct xfs_scrub_context *sc,
D
Darrick J. Wong 已提交
128
				   struct xfs_inode *ip, unsigned int resblks);
D
Darrick J. Wong 已提交
129
void xchk_buffer_recheck(struct xfs_scrub_context *sc, struct xfs_buf *bp);
D
Darrick J. Wong 已提交
130

131 132 133 134
/*
 * Don't bother cross-referencing if we already found corruption or cross
 * referencing discrepancies.
 */
D
Darrick J. Wong 已提交
135
static inline bool xchk_skip_xref(struct xfs_scrub_metadata *sm)
136 137 138 139 140
{
	return sm->sm_flags & (XFS_SCRUB_OFLAG_CORRUPT |
			       XFS_SCRUB_OFLAG_XCORRUPT);
}

D
Darrick J. Wong 已提交
141 142
int xchk_metadata_inode_forks(struct xfs_scrub_context *sc);
int xchk_ilock_inverted(struct xfs_inode *ip, uint lock_mode);
143

D
Darrick J. Wong 已提交
144
#endif	/* __XFS_SCRUB_COMMON_H__ */