Merge tag 'for-linus' of git://github.com/openrisc/linux
[linux-2.6-microblaze.git] / fs / xfs / scrub / scrub.h
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;
10
11 /* Type info and names for the scrub types. */
12 enum xchk_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 xchk_meta_ops {
20         /* Acquire whatever resources are needed for the operation. */
21         int             (*setup)(struct xfs_scrub *sc);
22
23         /* Examine metadata for errors. */
24         int             (*scrub)(struct xfs_scrub *);
25
26         /* Repair or optimize the metadata. */
27         int             (*repair)(struct xfs_scrub *);
28
29         /* Decide if we even have this piece of metadata. */
30         bool            (*has)(struct xfs_sb *);
31
32         /* type describing required/allowed inputs */
33         enum xchk_type  type;
34 };
35
36 /* Buffer pointers and btree cursors for an entire AG. */
37 struct xchk_ag {
38         xfs_agnumber_t          agno;
39         struct xfs_perag        *pag;
40
41         /* AG btree roots */
42         struct xfs_buf          *agf_bp;
43         struct xfs_buf          *agfl_bp;
44         struct xfs_buf          *agi_bp;
45
46         /* AG btrees */
47         struct xfs_btree_cur    *bno_cur;
48         struct xfs_btree_cur    *cnt_cur;
49         struct xfs_btree_cur    *ino_cur;
50         struct xfs_btree_cur    *fino_cur;
51         struct xfs_btree_cur    *rmap_cur;
52         struct xfs_btree_cur    *refc_cur;
53 };
54
55 struct xfs_scrub {
56         /* General scrub state. */
57         struct xfs_mount                *mp;
58         struct xfs_scrub_metadata       *sm;
59         const struct xchk_meta_ops      *ops;
60         struct xfs_trans                *tp;
61
62         /* File that scrub was called with. */
63         struct file                     *file;
64
65         /*
66          * File that is undergoing the scrub operation.  This can differ from
67          * the file that scrub was called with if we're checking file-based fs
68          * metadata (e.g. rt bitmaps) or if we're doing a scrub-by-handle for
69          * something that can't be opened directly (e.g. symlinks).
70          */
71         struct xfs_inode                *ip;
72
73         void                            *buf;
74         uint                            ilock_flags;
75
76         /* See the XCHK/XREP state flags below. */
77         unsigned int                    flags;
78
79         /*
80          * The XFS_SICK_* flags that correspond to the metadata being scrubbed
81          * or repaired.  We will use this mask to update the in-core fs health
82          * status with whatever we find.
83          */
84         unsigned int                    sick_mask;
85
86         /* State tracking for single-AG operations. */
87         struct xchk_ag                  sa;
88 };
89
90 /* XCHK state flags grow up from zero, XREP state flags grown down from 2^31 */
91 #define XCHK_TRY_HARDER         (1 << 0)  /* can't get resources, try again */
92 #define XCHK_HAS_QUOTAOFFLOCK   (1 << 1)  /* we hold the quotaoff lock */
93 #define XCHK_REAPING_DISABLED   (1 << 2)  /* background block reaping paused */
94 #define XREP_ALREADY_FIXED      (1 << 31) /* checking our repair work */
95
96 /* Metadata scrubbers */
97 int xchk_tester(struct xfs_scrub *sc);
98 int xchk_superblock(struct xfs_scrub *sc);
99 int xchk_agf(struct xfs_scrub *sc);
100 int xchk_agfl(struct xfs_scrub *sc);
101 int xchk_agi(struct xfs_scrub *sc);
102 int xchk_bnobt(struct xfs_scrub *sc);
103 int xchk_cntbt(struct xfs_scrub *sc);
104 int xchk_inobt(struct xfs_scrub *sc);
105 int xchk_finobt(struct xfs_scrub *sc);
106 int xchk_rmapbt(struct xfs_scrub *sc);
107 int xchk_refcountbt(struct xfs_scrub *sc);
108 int xchk_inode(struct xfs_scrub *sc);
109 int xchk_bmap_data(struct xfs_scrub *sc);
110 int xchk_bmap_attr(struct xfs_scrub *sc);
111 int xchk_bmap_cow(struct xfs_scrub *sc);
112 int xchk_directory(struct xfs_scrub *sc);
113 int xchk_xattr(struct xfs_scrub *sc);
114 int xchk_symlink(struct xfs_scrub *sc);
115 int xchk_parent(struct xfs_scrub *sc);
116 #ifdef CONFIG_XFS_RT
117 int xchk_rtbitmap(struct xfs_scrub *sc);
118 int xchk_rtsummary(struct xfs_scrub *sc);
119 #else
120 static inline int
121 xchk_rtbitmap(struct xfs_scrub *sc)
122 {
123         return -ENOENT;
124 }
125 static inline int
126 xchk_rtsummary(struct xfs_scrub *sc)
127 {
128         return -ENOENT;
129 }
130 #endif
131 #ifdef CONFIG_XFS_QUOTA
132 int xchk_quota(struct xfs_scrub *sc);
133 #else
134 static inline int
135 xchk_quota(struct xfs_scrub *sc)
136 {
137         return -ENOENT;
138 }
139 #endif
140 int xchk_fscounters(struct xfs_scrub *sc);
141
142 /* cross-referencing helpers */
143 void xchk_xref_is_used_space(struct xfs_scrub *sc, xfs_agblock_t agbno,
144                 xfs_extlen_t len);
145 void xchk_xref_is_not_inode_chunk(struct xfs_scrub *sc, xfs_agblock_t agbno,
146                 xfs_extlen_t len);
147 void xchk_xref_is_inode_chunk(struct xfs_scrub *sc, xfs_agblock_t agbno,
148                 xfs_extlen_t len);
149 void xchk_xref_is_owned_by(struct xfs_scrub *sc, xfs_agblock_t agbno,
150                 xfs_extlen_t len, const struct xfs_owner_info *oinfo);
151 void xchk_xref_is_not_owned_by(struct xfs_scrub *sc, xfs_agblock_t agbno,
152                 xfs_extlen_t len, const struct xfs_owner_info *oinfo);
153 void xchk_xref_has_no_owner(struct xfs_scrub *sc, xfs_agblock_t agbno,
154                 xfs_extlen_t len);
155 void xchk_xref_is_cow_staging(struct xfs_scrub *sc, xfs_agblock_t bno,
156                 xfs_extlen_t len);
157 void xchk_xref_is_not_shared(struct xfs_scrub *sc, xfs_agblock_t bno,
158                 xfs_extlen_t len);
159 #ifdef CONFIG_XFS_RT
160 void xchk_xref_is_used_rt_space(struct xfs_scrub *sc, xfs_rtblock_t rtbno,
161                 xfs_extlen_t len);
162 #else
163 # define xchk_xref_is_used_rt_space(sc, rtbno, len) do { } while (0)
164 #endif
165
166 struct xchk_fscounters {
167         uint64_t                icount;
168         uint64_t                ifree;
169         uint64_t                fdblocks;
170         unsigned long long      icount_min;
171         unsigned long long      icount_max;
172 };
173
174 #endif  /* __XFS_SCRUB_SCRUB_H__ */