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_COMMON_H__
0007 #define __XFS_SCRUB_COMMON_H__
0008 
0009 /*
0010  * We /could/ terminate a scrub/repair operation early.  If we're not
0011  * in a good place to continue (fatal signal, etc.) then bail out.
0012  * Note that we're careful not to make any judgements about *error.
0013  */
0014 static inline bool
0015 xchk_should_terminate(
0016     struct xfs_scrub    *sc,
0017     int         *error)
0018 {
0019     /*
0020      * If preemption is disabled, we need to yield to the scheduler every
0021      * few seconds so that we don't run afoul of the soft lockup watchdog
0022      * or RCU stall detector.
0023      */
0024     cond_resched();
0025 
0026     if (fatal_signal_pending(current)) {
0027         if (*error == 0)
0028             *error = -EAGAIN;
0029         return true;
0030     }
0031     return false;
0032 }
0033 
0034 int xchk_trans_alloc(struct xfs_scrub *sc, uint resblks);
0035 bool xchk_process_error(struct xfs_scrub *sc, xfs_agnumber_t agno,
0036         xfs_agblock_t bno, int *error);
0037 bool xchk_fblock_process_error(struct xfs_scrub *sc, int whichfork,
0038         xfs_fileoff_t offset, int *error);
0039 
0040 bool xchk_xref_process_error(struct xfs_scrub *sc,
0041         xfs_agnumber_t agno, xfs_agblock_t bno, int *error);
0042 bool xchk_fblock_xref_process_error(struct xfs_scrub *sc,
0043         int whichfork, xfs_fileoff_t offset, int *error);
0044 
0045 void xchk_block_set_preen(struct xfs_scrub *sc,
0046         struct xfs_buf *bp);
0047 void xchk_ino_set_preen(struct xfs_scrub *sc, xfs_ino_t ino);
0048 
0049 void xchk_set_corrupt(struct xfs_scrub *sc);
0050 void xchk_block_set_corrupt(struct xfs_scrub *sc,
0051         struct xfs_buf *bp);
0052 void xchk_ino_set_corrupt(struct xfs_scrub *sc, xfs_ino_t ino);
0053 void xchk_fblock_set_corrupt(struct xfs_scrub *sc, int whichfork,
0054         xfs_fileoff_t offset);
0055 
0056 void xchk_block_xref_set_corrupt(struct xfs_scrub *sc,
0057         struct xfs_buf *bp);
0058 void xchk_ino_xref_set_corrupt(struct xfs_scrub *sc,
0059         xfs_ino_t ino);
0060 void xchk_fblock_xref_set_corrupt(struct xfs_scrub *sc,
0061         int whichfork, xfs_fileoff_t offset);
0062 
0063 void xchk_ino_set_warning(struct xfs_scrub *sc, xfs_ino_t ino);
0064 void xchk_fblock_set_warning(struct xfs_scrub *sc, int whichfork,
0065         xfs_fileoff_t offset);
0066 
0067 void xchk_set_incomplete(struct xfs_scrub *sc);
0068 int xchk_checkpoint_log(struct xfs_mount *mp);
0069 
0070 /* Are we set up for a cross-referencing check? */
0071 bool xchk_should_check_xref(struct xfs_scrub *sc, int *error,
0072                struct xfs_btree_cur **curpp);
0073 
0074 /* Setup functions */
0075 int xchk_setup_fs(struct xfs_scrub *sc);
0076 int xchk_setup_ag_allocbt(struct xfs_scrub *sc);
0077 int xchk_setup_ag_iallocbt(struct xfs_scrub *sc);
0078 int xchk_setup_ag_rmapbt(struct xfs_scrub *sc);
0079 int xchk_setup_ag_refcountbt(struct xfs_scrub *sc);
0080 int xchk_setup_inode(struct xfs_scrub *sc);
0081 int xchk_setup_inode_bmap(struct xfs_scrub *sc);
0082 int xchk_setup_inode_bmap_data(struct xfs_scrub *sc);
0083 int xchk_setup_directory(struct xfs_scrub *sc);
0084 int xchk_setup_xattr(struct xfs_scrub *sc);
0085 int xchk_setup_symlink(struct xfs_scrub *sc);
0086 int xchk_setup_parent(struct xfs_scrub *sc);
0087 #ifdef CONFIG_XFS_RT
0088 int xchk_setup_rt(struct xfs_scrub *sc);
0089 #else
0090 static inline int
0091 xchk_setup_rt(struct xfs_scrub *sc)
0092 {
0093     return -ENOENT;
0094 }
0095 #endif
0096 #ifdef CONFIG_XFS_QUOTA
0097 int xchk_setup_quota(struct xfs_scrub *sc);
0098 #else
0099 static inline int
0100 xchk_setup_quota(struct xfs_scrub *sc)
0101 {
0102     return -ENOENT;
0103 }
0104 #endif
0105 int xchk_setup_fscounters(struct xfs_scrub *sc);
0106 
0107 void xchk_ag_free(struct xfs_scrub *sc, struct xchk_ag *sa);
0108 int xchk_ag_init(struct xfs_scrub *sc, xfs_agnumber_t agno,
0109         struct xchk_ag *sa);
0110 
0111 /*
0112  * Grab all AG resources, treating the inability to grab the perag structure as
0113  * a fs corruption.  This is intended for callers checking an ondisk reference
0114  * to a given AG, which means that the AG must still exist.
0115  */
0116 static inline int
0117 xchk_ag_init_existing(
0118     struct xfs_scrub    *sc,
0119     xfs_agnumber_t      agno,
0120     struct xchk_ag      *sa)
0121 {
0122     int         error = xchk_ag_init(sc, agno, sa);
0123 
0124     return error == -ENOENT ? -EFSCORRUPTED : error;
0125 }
0126 
0127 int xchk_ag_read_headers(struct xfs_scrub *sc, xfs_agnumber_t agno,
0128         struct xchk_ag *sa);
0129 void xchk_ag_btcur_free(struct xchk_ag *sa);
0130 void xchk_ag_btcur_init(struct xfs_scrub *sc, struct xchk_ag *sa);
0131 int xchk_count_rmap_ownedby_ag(struct xfs_scrub *sc, struct xfs_btree_cur *cur,
0132         const struct xfs_owner_info *oinfo, xfs_filblks_t *blocks);
0133 
0134 int xchk_setup_ag_btree(struct xfs_scrub *sc, bool force_log);
0135 int xchk_get_inode(struct xfs_scrub *sc);
0136 int xchk_setup_inode_contents(struct xfs_scrub *sc, unsigned int resblks);
0137 void xchk_buffer_recheck(struct xfs_scrub *sc, struct xfs_buf *bp);
0138 
0139 /*
0140  * Don't bother cross-referencing if we already found corruption or cross
0141  * referencing discrepancies.
0142  */
0143 static inline bool xchk_skip_xref(struct xfs_scrub_metadata *sm)
0144 {
0145     return sm->sm_flags & (XFS_SCRUB_OFLAG_CORRUPT |
0146                    XFS_SCRUB_OFLAG_XCORRUPT);
0147 }
0148 
0149 int xchk_metadata_inode_forks(struct xfs_scrub *sc);
0150 int xchk_ilock_inverted(struct xfs_inode *ip, uint lock_mode);
0151 void xchk_stop_reaping(struct xfs_scrub *sc);
0152 void xchk_start_reaping(struct xfs_scrub *sc);
0153 
0154 #endif  /* __XFS_SCRUB_COMMON_H__ */