]> asedeno.scripts.mit.edu Git - linux.git/blob - fs/xfs/scrub/scrub.h
636424d5e2ee743a695bbd5cd25c8764c339d0a9
[linux.git] / fs / xfs / scrub / scrub.h
1 /*
2  * Copyright (C) 2017 Oracle.  All Rights Reserved.
3  *
4  * Author: Darrick J. Wong <darrick.wong@oracle.com>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it would be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write the Free Software Foundation,
18  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
19  */
20 #ifndef __XFS_SCRUB_SCRUB_H__
21 #define __XFS_SCRUB_SCRUB_H__
22
23 struct xfs_scrub_context;
24
25 /* Type info and names for the scrub types. */
26 enum xfs_scrub_type {
27         ST_NONE = 1,    /* disabled */
28         ST_PERAG,       /* per-AG metadata */
29         ST_FS,          /* per-FS metadata */
30         ST_INODE,       /* per-inode metadata */
31 };
32
33 struct xfs_scrub_meta_ops {
34         /* Acquire whatever resources are needed for the operation. */
35         int             (*setup)(struct xfs_scrub_context *,
36                                  struct xfs_inode *);
37
38         /* Examine metadata for errors. */
39         int             (*scrub)(struct xfs_scrub_context *);
40
41         /* Repair or optimize the metadata. */
42         int             (*repair)(struct xfs_scrub_context *);
43
44         /* Decide if we even have this piece of metadata. */
45         bool            (*has)(struct xfs_sb *);
46
47         /* type describing required/allowed inputs */
48         enum xfs_scrub_type     type;
49 };
50
51 /* Buffer pointers and btree cursors for an entire AG. */
52 struct xfs_scrub_ag {
53         xfs_agnumber_t                  agno;
54         struct xfs_perag                *pag;
55
56         /* AG btree roots */
57         struct xfs_buf                  *agf_bp;
58         struct xfs_buf                  *agfl_bp;
59         struct xfs_buf                  *agi_bp;
60
61         /* AG btrees */
62         struct xfs_btree_cur            *bno_cur;
63         struct xfs_btree_cur            *cnt_cur;
64         struct xfs_btree_cur            *ino_cur;
65         struct xfs_btree_cur            *fino_cur;
66         struct xfs_btree_cur            *rmap_cur;
67         struct xfs_btree_cur            *refc_cur;
68 };
69
70 struct xfs_scrub_context {
71         /* General scrub state. */
72         struct xfs_mount                *mp;
73         struct xfs_scrub_metadata       *sm;
74         const struct xfs_scrub_meta_ops *ops;
75         struct xfs_trans                *tp;
76         struct xfs_inode                *ip;
77         void                            *buf;
78         uint                            ilock_flags;
79         bool                            try_harder;
80         bool                            has_quotaofflock;
81
82         /* State tracking for single-AG operations. */
83         struct xfs_scrub_ag             sa;
84 };
85
86 /* Metadata scrubbers */
87 int xfs_scrub_tester(struct xfs_scrub_context *sc);
88 int xfs_scrub_superblock(struct xfs_scrub_context *sc);
89 int xfs_scrub_agf(struct xfs_scrub_context *sc);
90 int xfs_scrub_agfl(struct xfs_scrub_context *sc);
91 int xfs_scrub_agi(struct xfs_scrub_context *sc);
92 int xfs_scrub_bnobt(struct xfs_scrub_context *sc);
93 int xfs_scrub_cntbt(struct xfs_scrub_context *sc);
94 int xfs_scrub_inobt(struct xfs_scrub_context *sc);
95 int xfs_scrub_finobt(struct xfs_scrub_context *sc);
96 int xfs_scrub_rmapbt(struct xfs_scrub_context *sc);
97 int xfs_scrub_refcountbt(struct xfs_scrub_context *sc);
98 int xfs_scrub_inode(struct xfs_scrub_context *sc);
99 int xfs_scrub_bmap_data(struct xfs_scrub_context *sc);
100 int xfs_scrub_bmap_attr(struct xfs_scrub_context *sc);
101 int xfs_scrub_bmap_cow(struct xfs_scrub_context *sc);
102 int xfs_scrub_directory(struct xfs_scrub_context *sc);
103 int xfs_scrub_xattr(struct xfs_scrub_context *sc);
104 int xfs_scrub_symlink(struct xfs_scrub_context *sc);
105 int xfs_scrub_parent(struct xfs_scrub_context *sc);
106 #ifdef CONFIG_XFS_RT
107 int xfs_scrub_rtbitmap(struct xfs_scrub_context *sc);
108 int xfs_scrub_rtsummary(struct xfs_scrub_context *sc);
109 #else
110 static inline int
111 xfs_scrub_rtbitmap(struct xfs_scrub_context *sc)
112 {
113         return -ENOENT;
114 }
115 static inline int
116 xfs_scrub_rtsummary(struct xfs_scrub_context *sc)
117 {
118         return -ENOENT;
119 }
120 #endif
121 #ifdef CONFIG_XFS_QUOTA
122 int xfs_scrub_quota(struct xfs_scrub_context *sc);
123 #else
124 static inline int
125 xfs_scrub_quota(struct xfs_scrub_context *sc)
126 {
127         return -ENOENT;
128 }
129 #endif
130
131 /* cross-referencing helpers */
132 void xfs_scrub_xref_is_used_space(struct xfs_scrub_context *sc,
133                 xfs_agblock_t agbno, xfs_extlen_t len);
134 void xfs_scrub_xref_is_not_inode_chunk(struct xfs_scrub_context *sc,
135                 xfs_agblock_t agbno, xfs_extlen_t len);
136 void xfs_scrub_xref_is_inode_chunk(struct xfs_scrub_context *sc,
137                 xfs_agblock_t agbno, xfs_extlen_t len);
138 void xfs_scrub_xref_is_owned_by(struct xfs_scrub_context *sc,
139                 xfs_agblock_t agbno, xfs_extlen_t len,
140                 struct xfs_owner_info *oinfo);
141 void xfs_scrub_xref_is_not_owned_by(struct xfs_scrub_context *sc,
142                 xfs_agblock_t agbno, xfs_extlen_t len,
143                 struct xfs_owner_info *oinfo);
144 void xfs_scrub_xref_has_no_owner(struct xfs_scrub_context *sc,
145                 xfs_agblock_t agbno, xfs_extlen_t len);
146 void xfs_scrub_xref_is_cow_staging(struct xfs_scrub_context *sc,
147                 xfs_agblock_t bno, xfs_extlen_t len);
148 void xfs_scrub_xref_is_not_shared(struct xfs_scrub_context *sc,
149                 xfs_agblock_t bno, xfs_extlen_t len);
150 #ifdef CONFIG_XFS_RT
151 void xfs_scrub_xref_is_used_rt_space(struct xfs_scrub_context *sc,
152                 xfs_rtblock_t rtbno, xfs_extlen_t len);
153 #else
154 # define xfs_scrub_xref_is_used_rt_space(sc, rtbno, len) do { } while (0)
155 #endif
156
157 #endif  /* __XFS_SCRUB_SCRUB_H__ */