Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 /*
0003  * Copyright (C) 2017 Oracle.  All Rights Reserved.
0004  * Author: Darrick J. Wong <darrick.wong@oracle.com>
0005  */
0006 #ifndef __XFS_SCRUB_SCRUB_H__
0007 #define __XFS_SCRUB_SCRUB_H__
0008 
0009 struct xfs_scrub;
0010 
0011 /* Type info and names for the scrub types. */
0012 enum xchk_type {
0013     ST_NONE = 1,    /* disabled */
0014     ST_PERAG,   /* per-AG metadata */
0015     ST_FS,      /* per-FS metadata */
0016     ST_INODE,   /* per-inode metadata */
0017 };
0018 
0019 struct xchk_meta_ops {
0020     /* Acquire whatever resources are needed for the operation. */
0021     int     (*setup)(struct xfs_scrub *sc);
0022 
0023     /* Examine metadata for errors. */
0024     int     (*scrub)(struct xfs_scrub *);
0025 
0026     /* Repair or optimize the metadata. */
0027     int     (*repair)(struct xfs_scrub *);
0028 
0029     /* Decide if we even have this piece of metadata. */
0030     bool        (*has)(struct xfs_mount *);
0031 
0032     /* type describing required/allowed inputs */
0033     enum xchk_type  type;
0034 };
0035 
0036 /* Buffer pointers and btree cursors for an entire AG. */
0037 struct xchk_ag {
0038     struct xfs_perag    *pag;
0039 
0040     /* AG btree roots */
0041     struct xfs_buf      *agf_bp;
0042     struct xfs_buf      *agfl_bp;
0043     struct xfs_buf      *agi_bp;
0044 
0045     /* AG btrees */
0046     struct xfs_btree_cur    *bno_cur;
0047     struct xfs_btree_cur    *cnt_cur;
0048     struct xfs_btree_cur    *ino_cur;
0049     struct xfs_btree_cur    *fino_cur;
0050     struct xfs_btree_cur    *rmap_cur;
0051     struct xfs_btree_cur    *refc_cur;
0052 };
0053 
0054 struct xfs_scrub {
0055     /* General scrub state. */
0056     struct xfs_mount        *mp;
0057     struct xfs_scrub_metadata   *sm;
0058     const struct xchk_meta_ops  *ops;
0059     struct xfs_trans        *tp;
0060 
0061     /* File that scrub was called with. */
0062     struct file         *file;
0063 
0064     /*
0065      * File that is undergoing the scrub operation.  This can differ from
0066      * the file that scrub was called with if we're checking file-based fs
0067      * metadata (e.g. rt bitmaps) or if we're doing a scrub-by-handle for
0068      * something that can't be opened directly (e.g. symlinks).
0069      */
0070     struct xfs_inode        *ip;
0071 
0072     void                *buf;
0073     uint                ilock_flags;
0074 
0075     /* See the XCHK/XREP state flags below. */
0076     unsigned int            flags;
0077 
0078     /*
0079      * The XFS_SICK_* flags that correspond to the metadata being scrubbed
0080      * or repaired.  We will use this mask to update the in-core fs health
0081      * status with whatever we find.
0082      */
0083     unsigned int            sick_mask;
0084 
0085     /* State tracking for single-AG operations. */
0086     struct xchk_ag          sa;
0087 };
0088 
0089 /* XCHK state flags grow up from zero, XREP state flags grown down from 2^31 */
0090 #define XCHK_TRY_HARDER     (1 << 0)  /* can't get resources, try again */
0091 #define XCHK_REAPING_DISABLED   (1 << 2)  /* background block reaping paused */
0092 #define XREP_ALREADY_FIXED  (1 << 31) /* checking our repair work */
0093 
0094 /* Metadata scrubbers */
0095 int xchk_tester(struct xfs_scrub *sc);
0096 int xchk_superblock(struct xfs_scrub *sc);
0097 int xchk_agf(struct xfs_scrub *sc);
0098 int xchk_agfl(struct xfs_scrub *sc);
0099 int xchk_agi(struct xfs_scrub *sc);
0100 int xchk_bnobt(struct xfs_scrub *sc);
0101 int xchk_cntbt(struct xfs_scrub *sc);
0102 int xchk_inobt(struct xfs_scrub *sc);
0103 int xchk_finobt(struct xfs_scrub *sc);
0104 int xchk_rmapbt(struct xfs_scrub *sc);
0105 int xchk_refcountbt(struct xfs_scrub *sc);
0106 int xchk_inode(struct xfs_scrub *sc);
0107 int xchk_bmap_data(struct xfs_scrub *sc);
0108 int xchk_bmap_attr(struct xfs_scrub *sc);
0109 int xchk_bmap_cow(struct xfs_scrub *sc);
0110 int xchk_directory(struct xfs_scrub *sc);
0111 int xchk_xattr(struct xfs_scrub *sc);
0112 int xchk_symlink(struct xfs_scrub *sc);
0113 int xchk_parent(struct xfs_scrub *sc);
0114 #ifdef CONFIG_XFS_RT
0115 int xchk_rtbitmap(struct xfs_scrub *sc);
0116 int xchk_rtsummary(struct xfs_scrub *sc);
0117 #else
0118 static inline int
0119 xchk_rtbitmap(struct xfs_scrub *sc)
0120 {
0121     return -ENOENT;
0122 }
0123 static inline int
0124 xchk_rtsummary(struct xfs_scrub *sc)
0125 {
0126     return -ENOENT;
0127 }
0128 #endif
0129 #ifdef CONFIG_XFS_QUOTA
0130 int xchk_quota(struct xfs_scrub *sc);
0131 #else
0132 static inline int
0133 xchk_quota(struct xfs_scrub *sc)
0134 {
0135     return -ENOENT;
0136 }
0137 #endif
0138 int xchk_fscounters(struct xfs_scrub *sc);
0139 
0140 /* cross-referencing helpers */
0141 void xchk_xref_is_used_space(struct xfs_scrub *sc, xfs_agblock_t agbno,
0142         xfs_extlen_t len);
0143 void xchk_xref_is_not_inode_chunk(struct xfs_scrub *sc, xfs_agblock_t agbno,
0144         xfs_extlen_t len);
0145 void xchk_xref_is_inode_chunk(struct xfs_scrub *sc, xfs_agblock_t agbno,
0146         xfs_extlen_t len);
0147 void xchk_xref_is_owned_by(struct xfs_scrub *sc, xfs_agblock_t agbno,
0148         xfs_extlen_t len, const struct xfs_owner_info *oinfo);
0149 void xchk_xref_is_not_owned_by(struct xfs_scrub *sc, xfs_agblock_t agbno,
0150         xfs_extlen_t len, const struct xfs_owner_info *oinfo);
0151 void xchk_xref_has_no_owner(struct xfs_scrub *sc, xfs_agblock_t agbno,
0152         xfs_extlen_t len);
0153 void xchk_xref_is_cow_staging(struct xfs_scrub *sc, xfs_agblock_t bno,
0154         xfs_extlen_t len);
0155 void xchk_xref_is_not_shared(struct xfs_scrub *sc, xfs_agblock_t bno,
0156         xfs_extlen_t len);
0157 #ifdef CONFIG_XFS_RT
0158 void xchk_xref_is_used_rt_space(struct xfs_scrub *sc, xfs_rtblock_t rtbno,
0159         xfs_extlen_t len);
0160 #else
0161 # define xchk_xref_is_used_rt_space(sc, rtbno, len) do { } while (0)
0162 #endif
0163 
0164 struct xchk_fscounters {
0165     uint64_t        icount;
0166     uint64_t        ifree;
0167     uint64_t        fdblocks;
0168     unsigned long long  icount_min;
0169     unsigned long long  icount_max;
0170 };
0171 
0172 #endif  /* __XFS_SCRUB_SCRUB_H__ */