xref: /openbmc/linux/fs/xfs/scrub/scrub.h (revision a17922de)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2017 Oracle.  All Rights Reserved.
4  * Author: Darrick J. Wong <darrick.wong@oracle.com>
5  */
6 #ifndef __XFS_SCRUB_SCRUB_H__
7 #define __XFS_SCRUB_SCRUB_H__
8 
9 struct xfs_scrub_context;
10 
11 /* Type info and names for the scrub types. */
12 enum xfs_scrub_type {
13 	ST_NONE = 1,	/* disabled */
14 	ST_PERAG,	/* per-AG metadata */
15 	ST_FS,		/* per-FS metadata */
16 	ST_INODE,	/* per-inode metadata */
17 };
18 
19 struct xfs_scrub_meta_ops {
20 	/* Acquire whatever resources are needed for the operation. */
21 	int		(*setup)(struct xfs_scrub_context *,
22 				 struct xfs_inode *);
23 
24 	/* Examine metadata for errors. */
25 	int		(*scrub)(struct xfs_scrub_context *);
26 
27 	/* Repair or optimize the metadata. */
28 	int		(*repair)(struct xfs_scrub_context *);
29 
30 	/* Decide if we even have this piece of metadata. */
31 	bool		(*has)(struct xfs_sb *);
32 
33 	/* type describing required/allowed inputs */
34 	enum xfs_scrub_type	type;
35 };
36 
37 /* Buffer pointers and btree cursors for an entire AG. */
38 struct xfs_scrub_ag {
39 	xfs_agnumber_t			agno;
40 	struct xfs_perag		*pag;
41 
42 	/* AG btree roots */
43 	struct xfs_buf			*agf_bp;
44 	struct xfs_buf			*agfl_bp;
45 	struct xfs_buf			*agi_bp;
46 
47 	/* AG btrees */
48 	struct xfs_btree_cur		*bno_cur;
49 	struct xfs_btree_cur		*cnt_cur;
50 	struct xfs_btree_cur		*ino_cur;
51 	struct xfs_btree_cur		*fino_cur;
52 	struct xfs_btree_cur		*rmap_cur;
53 	struct xfs_btree_cur		*refc_cur;
54 };
55 
56 struct xfs_scrub_context {
57 	/* General scrub state. */
58 	struct xfs_mount		*mp;
59 	struct xfs_scrub_metadata	*sm;
60 	const struct xfs_scrub_meta_ops	*ops;
61 	struct xfs_trans		*tp;
62 	struct xfs_inode		*ip;
63 	void				*buf;
64 	uint				ilock_flags;
65 	bool				try_harder;
66 	bool				has_quotaofflock;
67 
68 	/* State tracking for single-AG operations. */
69 	struct xfs_scrub_ag		sa;
70 };
71 
72 /* Metadata scrubbers */
73 int xfs_scrub_tester(struct xfs_scrub_context *sc);
74 int xfs_scrub_superblock(struct xfs_scrub_context *sc);
75 int xfs_scrub_agf(struct xfs_scrub_context *sc);
76 int xfs_scrub_agfl(struct xfs_scrub_context *sc);
77 int xfs_scrub_agi(struct xfs_scrub_context *sc);
78 int xfs_scrub_bnobt(struct xfs_scrub_context *sc);
79 int xfs_scrub_cntbt(struct xfs_scrub_context *sc);
80 int xfs_scrub_inobt(struct xfs_scrub_context *sc);
81 int xfs_scrub_finobt(struct xfs_scrub_context *sc);
82 int xfs_scrub_rmapbt(struct xfs_scrub_context *sc);
83 int xfs_scrub_refcountbt(struct xfs_scrub_context *sc);
84 int xfs_scrub_inode(struct xfs_scrub_context *sc);
85 int xfs_scrub_bmap_data(struct xfs_scrub_context *sc);
86 int xfs_scrub_bmap_attr(struct xfs_scrub_context *sc);
87 int xfs_scrub_bmap_cow(struct xfs_scrub_context *sc);
88 int xfs_scrub_directory(struct xfs_scrub_context *sc);
89 int xfs_scrub_xattr(struct xfs_scrub_context *sc);
90 int xfs_scrub_symlink(struct xfs_scrub_context *sc);
91 int xfs_scrub_parent(struct xfs_scrub_context *sc);
92 #ifdef CONFIG_XFS_RT
93 int xfs_scrub_rtbitmap(struct xfs_scrub_context *sc);
94 int xfs_scrub_rtsummary(struct xfs_scrub_context *sc);
95 #else
96 static inline int
97 xfs_scrub_rtbitmap(struct xfs_scrub_context *sc)
98 {
99 	return -ENOENT;
100 }
101 static inline int
102 xfs_scrub_rtsummary(struct xfs_scrub_context *sc)
103 {
104 	return -ENOENT;
105 }
106 #endif
107 #ifdef CONFIG_XFS_QUOTA
108 int xfs_scrub_quota(struct xfs_scrub_context *sc);
109 #else
110 static inline int
111 xfs_scrub_quota(struct xfs_scrub_context *sc)
112 {
113 	return -ENOENT;
114 }
115 #endif
116 
117 /* cross-referencing helpers */
118 void xfs_scrub_xref_is_used_space(struct xfs_scrub_context *sc,
119 		xfs_agblock_t agbno, xfs_extlen_t len);
120 void xfs_scrub_xref_is_not_inode_chunk(struct xfs_scrub_context *sc,
121 		xfs_agblock_t agbno, xfs_extlen_t len);
122 void xfs_scrub_xref_is_inode_chunk(struct xfs_scrub_context *sc,
123 		xfs_agblock_t agbno, xfs_extlen_t len);
124 void xfs_scrub_xref_is_owned_by(struct xfs_scrub_context *sc,
125 		xfs_agblock_t agbno, xfs_extlen_t len,
126 		struct xfs_owner_info *oinfo);
127 void xfs_scrub_xref_is_not_owned_by(struct xfs_scrub_context *sc,
128 		xfs_agblock_t agbno, xfs_extlen_t len,
129 		struct xfs_owner_info *oinfo);
130 void xfs_scrub_xref_has_no_owner(struct xfs_scrub_context *sc,
131 		xfs_agblock_t agbno, xfs_extlen_t len);
132 void xfs_scrub_xref_is_cow_staging(struct xfs_scrub_context *sc,
133 		xfs_agblock_t bno, xfs_extlen_t len);
134 void xfs_scrub_xref_is_not_shared(struct xfs_scrub_context *sc,
135 		xfs_agblock_t bno, xfs_extlen_t len);
136 #ifdef CONFIG_XFS_RT
137 void xfs_scrub_xref_is_used_rt_space(struct xfs_scrub_context *sc,
138 		xfs_rtblock_t rtbno, xfs_extlen_t len);
139 #else
140 # define xfs_scrub_xref_is_used_rt_space(sc, rtbno, len) do { } while (0)
141 #endif
142 
143 #endif	/* __XFS_SCRUB_SCRUB_H__ */
144