| 1 |
// SPDX-License-Identifier: GPL-2.0-or-later |
| 2 |
/* |
| 3 |
* Copyright (C) 2018-2023 Oracle. All Rights Reserved. |
| 4 |
* Author: Darrick J. Wong <[email protected]> |
| 5 |
*/ |
| 6 |
#ifndef __XFS_SCRUB_REPAIR_H__ |
| 7 |
#define __XFS_SCRUB_REPAIR_H__ |
| 8 |
|
| 9 |
#include "xfs_quota_defs.h" |
| 10 |
|
| 11 |
struct xfs_rtgroup; |
| 12 |
struct xchk_stats_run; |
| 13 |
|
| 14 |
static inline int xrep_notsupported(struct xfs_scrub *sc) |
| 15 |
{ |
| 16 |
return -EOPNOTSUPP; |
| 17 |
} |
| 18 |
|
| 19 |
#ifdef CONFIG_XFS_ONLINE_REPAIR |
| 20 |
|
| 21 |
/* Repair helpers */ |
| 22 |
|
| 23 |
int xrep_attempt(struct xfs_scrub *sc, struct xchk_stats_run *run); |
| 24 |
bool xrep_will_attempt(struct xfs_scrub *sc); |
| 25 |
void xrep_failure(struct xfs_mount *mp); |
| 26 |
int xrep_roll_ag_trans(struct xfs_scrub *sc); |
| 27 |
int xrep_roll_trans(struct xfs_scrub *sc); |
| 28 |
int xrep_defer_finish(struct xfs_scrub *sc); |
| 29 |
bool xrep_ag_has_space(struct xfs_perag *pag, xfs_extlen_t nr_blocks, |
| 30 |
enum xfs_ag_resv_type type); |
| 31 |
xfs_extlen_t xrep_calc_ag_resblks(struct xfs_scrub *sc); |
| 32 |
|
| 33 |
static inline int |
| 34 |
xrep_trans_commit( |
| 35 |
struct xfs_scrub *sc) |
| 36 |
{ |
| 37 |
int error = xfs_trans_commit(sc->tp); |
| 38 |
|
| 39 |
sc->tp = NULL; |
| 40 |
return error; |
| 41 |
} |
| 42 |
|
| 43 |
struct xbitmap; |
| 44 |
struct xagb_bitmap; |
| 45 |
struct xrgb_bitmap; |
| 46 |
struct xfsb_bitmap; |
| 47 |
struct xrtb_bitmap; |
| 48 |
|
| 49 |
int xrep_fix_freelist(struct xfs_scrub *sc, int alloc_flags); |
| 50 |
|
| 51 |
struct xrep_find_ag_btree { |
| 52 |
/* in: rmap owner of the btree we're looking for */ |
| 53 |
uint64_t rmap_owner; |
| 54 |
|
| 55 |
/* in: buffer ops */ |
| 56 |
const struct xfs_buf_ops *buf_ops; |
| 57 |
|
| 58 |
/* in: maximum btree height */ |
| 59 |
unsigned int maxlevels; |
| 60 |
|
| 61 |
/* out: the highest btree block found and the tree height */ |
| 62 |
xfs_agblock_t root; |
| 63 |
unsigned int height; |
| 64 |
}; |
| 65 |
|
| 66 |
int xrep_find_ag_btree_roots(struct xfs_scrub *sc, struct xfs_buf *agf_bp, |
| 67 |
struct xrep_find_ag_btree *btree_info, struct xfs_buf *agfl_bp); |
| 68 |
|
| 69 |
#ifdef CONFIG_XFS_QUOTA |
| 70 |
void xrep_update_qflags(struct xfs_scrub *sc, unsigned int clear_flags, |
| 71 |
unsigned int set_flags); |
| 72 |
void xrep_force_quotacheck(struct xfs_scrub *sc, xfs_dqtype_t type); |
| 73 |
int xrep_ino_dqattach(struct xfs_scrub *sc); |
| 74 |
#else |
| 75 |
# define xrep_force_quotacheck(sc, type) ((void)0) |
| 76 |
# define xrep_ino_dqattach(sc) (0) |
| 77 |
#endif /* CONFIG_XFS_QUOTA */ |
| 78 |
|
| 79 |
int xrep_setup_xfbtree(struct xfs_scrub *sc, const char *descr); |
| 80 |
|
| 81 |
int xrep_ino_ensure_extent_count(struct xfs_scrub *sc, int whichfork, |
| 82 |
xfs_extnum_t nextents); |
| 83 |
int xrep_reset_perag_resv(struct xfs_scrub *sc); |
| 84 |
int xrep_bmap(struct xfs_scrub *sc, int whichfork, bool allow_unwritten); |
| 85 |
int xrep_metadata_inode_forks(struct xfs_scrub *sc); |
| 86 |
int xrep_setup_ag_rmapbt(struct xfs_scrub *sc); |
| 87 |
int xrep_setup_ag_refcountbt(struct xfs_scrub *sc); |
| 88 |
int xrep_setup_xattr(struct xfs_scrub *sc); |
| 89 |
int xrep_setup_directory(struct xfs_scrub *sc); |
| 90 |
int xrep_setup_parent(struct xfs_scrub *sc); |
| 91 |
int xrep_setup_nlinks(struct xfs_scrub *sc); |
| 92 |
int xrep_setup_symlink(struct xfs_scrub *sc, unsigned int *resblks); |
| 93 |
int xrep_setup_dirtree(struct xfs_scrub *sc); |
| 94 |
int xrep_setup_rtrmapbt(struct xfs_scrub *sc); |
| 95 |
int xrep_setup_rtrefcountbt(struct xfs_scrub *sc); |
| 96 |
|
| 97 |
/* Repair setup functions */ |
| 98 |
int xrep_setup_ag_allocbt(struct xfs_scrub *sc); |
| 99 |
|
| 100 |
struct xfs_imap; |
| 101 |
int xrep_setup_inode(struct xfs_scrub *sc, const struct xfs_imap *imap); |
| 102 |
|
| 103 |
void xrep_ag_btcur_init(struct xfs_scrub *sc, struct xchk_ag *sa); |
| 104 |
int xrep_ag_init(struct xfs_scrub *sc, struct xfs_perag *pag, |
| 105 |
struct xchk_ag *sa); |
| 106 |
#ifdef CONFIG_XFS_RT |
| 107 |
int xrep_rtgroup_init(struct xfs_scrub *sc, struct xfs_rtgroup *rtg, |
| 108 |
struct xchk_rt *sr, unsigned int rtglock_flags); |
| 109 |
void xrep_rtgroup_btcur_init(struct xfs_scrub *sc, struct xchk_rt *sr); |
| 110 |
int xrep_require_rtext_inuse(struct xfs_scrub *sc, xfs_rgblock_t rgbno, |
| 111 |
xfs_filblks_t len); |
| 112 |
xfs_extlen_t xrep_calc_rtgroup_resblks(struct xfs_scrub *sc); |
| 113 |
#else |
| 114 |
# define xrep_rtgroup_init(sc, rtg, sr, lockflags) (-ENOSYS) |
| 115 |
# define xrep_calc_rtgroup_resblks(sc) (0) |
| 116 |
#endif /* CONFIG_XFS_RT */ |
| 117 |
|
| 118 |
int xrep_check_ino_btree_mapping(struct xfs_scrub *sc, |
| 119 |
const struct xfs_rmap_irec *rec); |
| 120 |
|
| 121 |
/* Metadata revalidators */ |
| 122 |
|
| 123 |
int xrep_revalidate_allocbt(struct xfs_scrub *sc); |
| 124 |
int xrep_revalidate_iallocbt(struct xfs_scrub *sc); |
| 125 |
|
| 126 |
/* Metadata repairers */ |
| 127 |
|
| 128 |
int xrep_probe(struct xfs_scrub *sc); |
| 129 |
int xrep_superblock(struct xfs_scrub *sc); |
| 130 |
int xrep_agf(struct xfs_scrub *sc); |
| 131 |
int xrep_agfl(struct xfs_scrub *sc); |
| 132 |
int xrep_agi(struct xfs_scrub *sc); |
| 133 |
int xrep_allocbt(struct xfs_scrub *sc); |
| 134 |
int xrep_iallocbt(struct xfs_scrub *sc); |
| 135 |
int xrep_rmapbt(struct xfs_scrub *sc); |
| 136 |
int xrep_refcountbt(struct xfs_scrub *sc); |
| 137 |
int xrep_inode(struct xfs_scrub *sc); |
| 138 |
int xrep_bmap_data(struct xfs_scrub *sc); |
| 139 |
int xrep_bmap_attr(struct xfs_scrub *sc); |
| 140 |
int xrep_bmap_cow(struct xfs_scrub *sc); |
| 141 |
int xrep_nlinks(struct xfs_scrub *sc); |
| 142 |
int xrep_fscounters(struct xfs_scrub *sc); |
| 143 |
int xrep_xattr(struct xfs_scrub *sc); |
| 144 |
int xrep_directory(struct xfs_scrub *sc); |
| 145 |
int xrep_parent(struct xfs_scrub *sc); |
| 146 |
int xrep_symlink(struct xfs_scrub *sc); |
| 147 |
int xrep_dirtree(struct xfs_scrub *sc); |
| 148 |
int xrep_metapath(struct xfs_scrub *sc); |
| 149 |
|
| 150 |
#ifdef CONFIG_XFS_RT |
| 151 |
int xrep_rtbitmap(struct xfs_scrub *sc); |
| 152 |
int xrep_rtsummary(struct xfs_scrub *sc); |
| 153 |
int xrep_rgsuperblock(struct xfs_scrub *sc); |
| 154 |
int xrep_rtrmapbt(struct xfs_scrub *sc); |
| 155 |
int xrep_rtrefcountbt(struct xfs_scrub *sc); |
| 156 |
#else |
| 157 |
# define xrep_rtbitmap xrep_notsupported |
| 158 |
# define xrep_rtsummary xrep_notsupported |
| 159 |
# define xrep_rgsuperblock xrep_notsupported |
| 160 |
# define xrep_rtrmapbt xrep_notsupported |
| 161 |
# define xrep_rtrefcountbt xrep_notsupported |
| 162 |
#endif /* CONFIG_XFS_RT */ |
| 163 |
|
| 164 |
#ifdef CONFIG_XFS_QUOTA |
| 165 |
int xrep_quota(struct xfs_scrub *sc); |
| 166 |
int xrep_quotacheck(struct xfs_scrub *sc); |
| 167 |
#else |
| 168 |
# define xrep_quota xrep_notsupported |
| 169 |
# define xrep_quotacheck xrep_notsupported |
| 170 |
#endif /* CONFIG_XFS_QUOTA */ |
| 171 |
|
| 172 |
int xrep_reinit_pagf(struct xfs_scrub *sc); |
| 173 |
int xrep_reinit_pagi(struct xfs_scrub *sc); |
| 174 |
|
| 175 |
bool xrep_buf_verify_struct(struct xfs_buf *bp, const struct xfs_buf_ops *ops); |
| 176 |
void xrep_inode_set_nblocks(struct xfs_scrub *sc, int64_t new_blocks); |
| 177 |
int xrep_reset_metafile_resv(struct xfs_scrub *sc); |
| 178 |
|
| 179 |
#else |
| 180 |
|
| 181 |
#define xrep_ino_dqattach(sc) (0) |
| 182 |
|
| 183 |
/* |
| 184 |
* When online repair is not built into the kernel, we still want to attempt |
| 185 |
* the repair so that the stub xrep_attempt below will return EOPNOTSUPP. |
| 186 |
*/ |
| 187 |
static inline bool xrep_will_attempt(const struct xfs_scrub *sc) |
| 188 |
{ |
| 189 |
return (sc->sm->sm_flags & XFS_SCRUB_IFLAG_FORCE_REBUILD) || |
| 190 |
xchk_needs_repair(sc->sm); |
| 191 |
} |
| 192 |
|
| 193 |
static inline int |
| 194 |
xrep_attempt( |
| 195 |
struct xfs_scrub *sc, |
| 196 |
struct xchk_stats_run *run) |
| 197 |
{ |
| 198 |
return -EOPNOTSUPP; |
| 199 |
} |
| 200 |
|
| 201 |
static inline void xrep_failure(struct xfs_mount *mp) {} |
| 202 |
|
| 203 |
static inline xfs_extlen_t |
| 204 |
xrep_calc_ag_resblks( |
| 205 |
struct xfs_scrub *sc) |
| 206 |
{ |
| 207 |
return 0; |
| 208 |
} |
| 209 |
|
| 210 |
#define xrep_calc_rtgroup_resblks xrep_calc_ag_resblks |
| 211 |
|
| 212 |
static inline int |
| 213 |
xrep_reset_perag_resv( |
| 214 |
struct xfs_scrub *sc) |
| 215 |
{ |
| 216 |
if (!(sc->flags & XREP_RESET_PERAG_RESV)) |
| 217 |
return 0; |
| 218 |
|
| 219 |
ASSERT(0); |
| 220 |
return -EOPNOTSUPP; |
| 221 |
} |
| 222 |
|
| 223 |
/* repair setup functions for no-repair */ |
| 224 |
static inline int |
| 225 |
xrep_setup_nothing( |
| 226 |
struct xfs_scrub *sc) |
| 227 |
{ |
| 228 |
return 0; |
| 229 |
} |
| 230 |
#define xrep_setup_ag_allocbt xrep_setup_nothing |
| 231 |
#define xrep_setup_ag_rmapbt xrep_setup_nothing |
| 232 |
#define xrep_setup_ag_refcountbt xrep_setup_nothing |
| 233 |
#define xrep_setup_xattr xrep_setup_nothing |
| 234 |
#define xrep_setup_directory xrep_setup_nothing |
| 235 |
#define xrep_setup_parent xrep_setup_nothing |
| 236 |
#define xrep_setup_nlinks xrep_setup_nothing |
| 237 |
#define xrep_setup_dirtree xrep_setup_nothing |
| 238 |
#define xrep_setup_metapath xrep_setup_nothing |
| 239 |
#define xrep_setup_rtrmapbt xrep_setup_nothing |
| 240 |
#define xrep_setup_rtrefcountbt xrep_setup_nothing |
| 241 |
|
| 242 |
#define xrep_setup_inode(sc, imap) ((void)0) |
| 243 |
|
| 244 |
static inline int xrep_setup_symlink(struct xfs_scrub *sc, unsigned int *x) |
| 245 |
{ |
| 246 |
return 0; |
| 247 |
} |
| 248 |
|
| 249 |
#define xrep_revalidate_allocbt (NULL) |
| 250 |
#define xrep_revalidate_iallocbt (NULL) |
| 251 |
|
| 252 |
#define xrep_probe xrep_notsupported |
| 253 |
#define xrep_superblock xrep_notsupported |
| 254 |
#define xrep_agf xrep_notsupported |
| 255 |
#define xrep_agfl xrep_notsupported |
| 256 |
#define xrep_agi xrep_notsupported |
| 257 |
#define xrep_allocbt xrep_notsupported |
| 258 |
#define xrep_iallocbt xrep_notsupported |
| 259 |
#define xrep_rmapbt xrep_notsupported |
| 260 |
#define xrep_refcountbt xrep_notsupported |
| 261 |
#define xrep_inode xrep_notsupported |
| 262 |
#define xrep_bmap_data xrep_notsupported |
| 263 |
#define xrep_bmap_attr xrep_notsupported |
| 264 |
#define xrep_bmap_cow xrep_notsupported |
| 265 |
#define xrep_rtbitmap xrep_notsupported |
| 266 |
#define xrep_quota xrep_notsupported |
| 267 |
#define xrep_quotacheck xrep_notsupported |
| 268 |
#define xrep_nlinks xrep_notsupported |
| 269 |
#define xrep_fscounters xrep_notsupported |
| 270 |
#define xrep_rtsummary xrep_notsupported |
| 271 |
#define xrep_xattr xrep_notsupported |
| 272 |
#define xrep_directory xrep_notsupported |
| 273 |
#define xrep_parent xrep_notsupported |
| 274 |
#define xrep_symlink xrep_notsupported |
| 275 |
#define xrep_dirtree xrep_notsupported |
| 276 |
#define xrep_metapath xrep_notsupported |
| 277 |
#define xrep_rgsuperblock xrep_notsupported |
| 278 |
#define xrep_rtrmapbt xrep_notsupported |
| 279 |
#define xrep_rtrefcountbt xrep_notsupported |
| 280 |
|
| 281 |
#endif /* CONFIG_XFS_ONLINE_REPAIR */ |
| 282 |
|
| 283 |
#endif /* __XFS_SCRUB_REPAIR_H__ */ |