| 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc. |
| 4 | * All Rights Reserved. |
| 5 | */ |
| 6 | #ifndef __XFS_ERROR_H__ |
| 7 | #define __XFS_ERROR_H__ |
| 8 | |
| 9 | struct xfs_mount; |
| 10 | |
| 11 | void xfs_error_report(const char *tag, int level, struct xfs_mount *mp, |
| 12 | const char *filename, int linenum, xfs_failaddr_t failaddr); |
| 13 | void xfs_corruption_error(const char *tag, int level, struct xfs_mount *mp, |
| 14 | const void *buf, size_t bufsize, const char *filename, |
| 15 | int linenum, xfs_failaddr_t failaddr); |
| 16 | void xfs_buf_corruption_error(struct xfs_buf *bp, xfs_failaddr_t fa); |
| 17 | void xfs_buf_verifier_error(struct xfs_buf *bp, int error, const char *name, |
| 18 | const void *buf, size_t bufsz, xfs_failaddr_t failaddr); |
| 19 | void xfs_verifier_error(struct xfs_buf *bp, int error, xfs_failaddr_t failaddr); |
| 20 | void xfs_inode_verifier_error(struct xfs_inode *ip, int error, const char *name, |
| 21 | const void *buf, size_t bufsz, xfs_failaddr_t failaddr); |
| 22 | |
| 23 | #define XFS_ERROR_REPORT(e, lvl, mp) \ |
| 24 | xfs_error_report(e, lvl, mp, __FILE__, __LINE__, __return_address) |
| 25 | #define XFS_CORRUPTION_ERROR(e, lvl, mp, buf, bufsize) \ |
| 26 | xfs_corruption_error(e, lvl, mp, buf, bufsize, \ |
| 27 | __FILE__, __LINE__, __return_address) |
| 28 | |
| 29 | #define XFS_ERRLEVEL_OFF 0 |
| 30 | #define XFS_ERRLEVEL_LOW 1 |
| 31 | #define XFS_ERRLEVEL_HIGH 5 |
| 32 | |
| 33 | /* Dump 128 bytes of any corrupt buffer */ |
| 34 | #define XFS_CORRUPTION_DUMP_LEN (128) |
| 35 | |
| 36 | #ifdef DEBUG |
| 37 | int xfs_errortag_init(struct xfs_mount *mp); |
| 38 | void xfs_errortag_del(struct xfs_mount *mp); |
| 39 | bool xfs_errortag_test(struct xfs_mount *mp, const char *file, int line, |
| 40 | unsigned int error_tag); |
| 41 | #define XFS_TEST_ERROR(mp, tag) \ |
| 42 | xfs_errortag_test((mp), __FILE__, __LINE__, (tag)) |
| 43 | bool xfs_errortag_enabled(struct xfs_mount *mp, unsigned int tag); |
| 44 | #define XFS_ERRORTAG_DELAY(mp, tag) \ |
| 45 | do { \ |
| 46 | might_sleep(); \ |
| 47 | if (!xfs_errortag_enabled((mp), (tag))) \ |
| 48 | break; \ |
| 49 | xfs_warn_ratelimited((mp), \ |
| 50 | "Injecting %ums delay at file %s, line %d, on filesystem \"%s\"", \ |
| 51 | (mp)->m_errortag[(tag)], __FILE__, __LINE__, \ |
| 52 | (mp)->m_super->s_id); \ |
| 53 | mdelay((mp)->m_errortag[(tag)]); \ |
| 54 | } while (0) |
| 55 | |
| 56 | int xfs_errortag_add(struct xfs_mount *mp, unsigned int error_tag); |
| 57 | int xfs_errortag_clearall(struct xfs_mount *mp); |
| 58 | #else |
| 59 | #define xfs_errortag_init(mp) (0) |
| 60 | #define xfs_errortag_del(mp) |
| 61 | #define XFS_TEST_ERROR(mp, tag) (false) |
| 62 | #define XFS_ERRORTAG_DELAY(mp, tag) ((void)0) |
| 63 | #define xfs_errortag_add(mp, tag) (ENOSYS) |
| 64 | #define xfs_errortag_clearall(mp) (ENOSYS) |
| 65 | #endif /* DEBUG */ |
| 66 | |
| 67 | /* |
| 68 | * XFS panic tags -- allow a call to xfs_alert_tag() be turned into |
| 69 | * a panic by setting fs.xfs.panic_mask in a sysctl. |
| 70 | */ |
| 71 | #define XFS_NO_PTAG 0u |
| 72 | #define XFS_PTAG_IFLUSH (1u << 0) |
| 73 | #define XFS_PTAG_LOGRES (1u << 1) |
| 74 | #define XFS_PTAG_AILDELETE (1u << 2) |
| 75 | #define XFS_PTAG_ERROR_REPORT (1u << 3) |
| 76 | #define XFS_PTAG_SHUTDOWN_CORRUPT (1u << 4) |
| 77 | #define XFS_PTAG_SHUTDOWN_IOERROR (1u << 5) |
| 78 | #define XFS_PTAG_SHUTDOWN_LOGERROR (1u << 6) |
| 79 | #define XFS_PTAG_FSBLOCK_ZERO (1u << 7) |
| 80 | #define XFS_PTAG_VERIFIER_ERROR (1u << 8) |
| 81 | |
| 82 | #define XFS_PTAG_MASK (XFS_PTAG_IFLUSH | \ |
| 83 | XFS_PTAG_LOGRES | \ |
| 84 | XFS_PTAG_AILDELETE | \ |
| 85 | XFS_PTAG_ERROR_REPORT | \ |
| 86 | XFS_PTAG_SHUTDOWN_CORRUPT | \ |
| 87 | XFS_PTAG_SHUTDOWN_IOERROR | \ |
| 88 | XFS_PTAG_SHUTDOWN_LOGERROR | \ |
| 89 | XFS_PTAG_FSBLOCK_ZERO | \ |
| 90 | XFS_PTAG_VERIFIER_ERROR) |
| 91 | |
| 92 | #define XFS_PTAG_STRINGS \ |
| 93 | { XFS_NO_PTAG, "none" }, \ |
| 94 | { XFS_PTAG_IFLUSH, "iflush" }, \ |
| 95 | { XFS_PTAG_LOGRES, "logres" }, \ |
| 96 | { XFS_PTAG_AILDELETE, "aildelete" }, \ |
| 97 | { XFS_PTAG_ERROR_REPORT , "error_report" }, \ |
| 98 | { XFS_PTAG_SHUTDOWN_CORRUPT, "corrupt" }, \ |
| 99 | { XFS_PTAG_SHUTDOWN_IOERROR, "ioerror" }, \ |
| 100 | { XFS_PTAG_SHUTDOWN_LOGERROR, "logerror" }, \ |
| 101 | { XFS_PTAG_FSBLOCK_ZERO, "fsb_zero" }, \ |
| 102 | { XFS_PTAG_VERIFIER_ERROR, "verifier" } |
| 103 | |
| 104 | #endif /* __XFS_ERROR_H__ */ |
| 105 | |