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_BTREE_H__
7 #define __XFS_SCRUB_BTREE_H__
8
9 /* btree scrub */
10
11 /* Check for btree operation errors. */
12 bool xchk_btree_process_error(struct xfs_scrub *sc,
13 struct xfs_btree_cur *cur, int level, int *error);
14
15 /* Check for btree xref operation errors. */
16 bool xchk_btree_xref_process_error(struct xfs_scrub *sc,
17 struct xfs_btree_cur *cur, int level, int *error);
18
19 /* Check for btree corruption. */
20 void xchk_btree_set_corrupt(struct xfs_scrub *sc,
21 struct xfs_btree_cur *cur, int level);
22
23 /* Check for btree xref discrepancies. */
24 void xchk_btree_xref_set_corrupt(struct xfs_scrub *sc,
25 struct xfs_btree_cur *cur, int level);
26
27 struct xchk_btree;
28 typedef int (*xchk_btree_rec_fn)(
29 struct xchk_btree *bs,
30 const union xfs_btree_rec *rec);
31
32 struct xchk_btree {
33 /* caller-provided scrub state */
34 struct xfs_scrub *sc;
35 struct xfs_btree_cur *cur;
36 xchk_btree_rec_fn scrub_rec;
37 const struct xfs_owner_info *oinfo;
38 void *private;
39
40 /* internal scrub state */
41 union xfs_btree_rec lastrec;
42 struct list_head to_check;
43
44 /* this element must come last! */
45 union xfs_btree_key lastkey[];
46 };
47
48 /*
49 * Calculate the size of a xchk_btree structure. There are nlevels-1 slots for
50 * keys because we track leaf records separately in lastrec.
51 */
52 static inline size_t
xchk_btree_sizeof(unsigned int nlevels)53 xchk_btree_sizeof(unsigned int nlevels)
54 {
55 return struct_size((struct xchk_btree *)NULL, lastkey, nlevels - 1);
56 }
57
58 int xchk_btree(struct xfs_scrub *sc, struct xfs_btree_cur *cur,
59 xchk_btree_rec_fn scrub_fn, const struct xfs_owner_info *oinfo,
60 void *private);
61
62 #endif /* __XFS_SCRUB_BTREE_H__ */
63