blob: 246d3e989c6c92770ac0dff3af1bcb5dbdcb23c0 [file] [log] [blame]
Dave Chinner0b61f8a2018-06-05 19:42:14 -07001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Nathan Scott7b718762005-11-02 14:58:39 +11003 * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
6#ifndef __XFS_ERROR_H__
7#define __XFS_ERROR_H__
8
Linus Torvalds1da177e2005-04-16 15:20:36 -07009struct xfs_mount;
10
Alex Eldera0e856b2010-04-13 15:22:08 +100011extern void xfs_error_report(const char *tag, int level, struct xfs_mount *mp,
Darrick J. Wongd9418ed2018-01-08 10:51:25 -080012 const char *filename, int linenum,
13 xfs_failaddr_t failaddr);
Alex Eldera0e856b2010-04-13 15:22:08 +100014extern void xfs_corruption_error(const char *tag, int level,
Darrick J. Wong2551a532018-06-04 10:23:54 -070015 struct xfs_mount *mp, void *buf, size_t bufsize,
16 const char *filename, int linenum,
17 xfs_failaddr_t failaddr);
Darrick J. Wong6edb1812018-03-23 10:06:53 -070018extern void xfs_buf_verifier_error(struct xfs_buf *bp, int error,
19 const char *name, void *buf, size_t bufsz,
20 xfs_failaddr_t failaddr);
Darrick J. Wongbc1a09b2018-01-08 10:51:03 -080021extern void xfs_verifier_error(struct xfs_buf *bp, int error,
22 xfs_failaddr_t failaddr);
Darrick J. Wong22431bf2018-01-22 18:09:48 -080023extern void xfs_inode_verifier_error(struct xfs_inode *ip, int error,
24 const char *name, void *buf, size_t bufsz,
25 xfs_failaddr_t failaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#define XFS_ERROR_REPORT(e, lvl, mp) \
28 xfs_error_report(e, lvl, mp, __FILE__, __LINE__, __return_address)
Darrick J. Wong2551a532018-06-04 10:23:54 -070029#define XFS_CORRUPTION_ERROR(e, lvl, mp, buf, bufsize) \
30 xfs_corruption_error(e, lvl, mp, buf, bufsize, \
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 __FILE__, __LINE__, __return_address)
32
33#define XFS_ERRLEVEL_OFF 0
34#define XFS_ERRLEVEL_LOW 1
35#define XFS_ERRLEVEL_HIGH 5
36
Darrick J. Wong9c712a12018-01-08 10:51:26 -080037/* Dump 128 bytes of any corrupt buffer */
38#define XFS_CORRUPTION_DUMP_LEN (128)
39
Linus Torvalds1da177e2005-04-16 15:20:36 -070040/*
Nathan Scotta844f452005-11-02 14:38:42 +110041 * Macros to set EFSCORRUPTED & return/branch.
42 */
Eric Sandeenc29aad42015-02-23 22:39:08 +110043#define XFS_WANT_CORRUPTED_GOTO(mp, x, l) \
Nathan Scotta844f452005-11-02 14:38:42 +110044 { \
45 int fs_is_ok = (x); \
46 ASSERT(fs_is_ok); \
47 if (unlikely(!fs_is_ok)) { \
48 XFS_ERROR_REPORT("XFS_WANT_CORRUPTED_GOTO", \
Eric Sandeenc29aad42015-02-23 22:39:08 +110049 XFS_ERRLEVEL_LOW, mp); \
Dave Chinner24513372014-06-25 14:58:08 +100050 error = -EFSCORRUPTED; \
Nathan Scotta844f452005-11-02 14:38:42 +110051 goto l; \
52 } \
53 }
54
Eric Sandeen5fb5aee2015-02-23 22:39:13 +110055#define XFS_WANT_CORRUPTED_RETURN(mp, x) \
Nathan Scotta844f452005-11-02 14:38:42 +110056 { \
57 int fs_is_ok = (x); \
58 ASSERT(fs_is_ok); \
59 if (unlikely(!fs_is_ok)) { \
60 XFS_ERROR_REPORT("XFS_WANT_CORRUPTED_RETURN", \
Eric Sandeen5fb5aee2015-02-23 22:39:13 +110061 XFS_ERRLEVEL_LOW, mp); \
Dave Chinner24513372014-06-25 14:58:08 +100062 return -EFSCORRUPTED; \
Nathan Scotta844f452005-11-02 14:38:42 +110063 } \
64 }
65
Christoph Hellwig1550d0b2008-08-13 16:17:37 +100066#ifdef DEBUG
Darrick J. Wong31965ef2017-06-20 17:54:46 -070067extern int xfs_errortag_init(struct xfs_mount *mp);
68extern void xfs_errortag_del(struct xfs_mount *mp);
69extern bool xfs_errortag_test(struct xfs_mount *mp, const char *expression,
70 const char *file, int line, unsigned int error_tag);
Darrick J. Wong9e24cfd2017-06-20 17:54:47 -070071#define XFS_TEST_ERROR(expr, mp, tag) \
Darrick J. Wong31965ef2017-06-20 17:54:46 -070072 ((expr) || xfs_errortag_test((mp), #expr, __FILE__, __LINE__, (tag)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Darrick J. Wongc6840102017-06-20 17:54:47 -070074extern int xfs_errortag_get(struct xfs_mount *mp, unsigned int error_tag);
Darrick J. Wong31965ef2017-06-20 17:54:46 -070075extern int xfs_errortag_set(struct xfs_mount *mp, unsigned int error_tag,
76 unsigned int tag_value);
77extern int xfs_errortag_add(struct xfs_mount *mp, unsigned int error_tag);
78extern int xfs_errortag_clearall(struct xfs_mount *mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079#else
Darrick J. Wong31965ef2017-06-20 17:54:46 -070080#define xfs_errortag_init(mp) (0)
81#define xfs_errortag_del(mp)
Darrick J. Wong9e24cfd2017-06-20 17:54:47 -070082#define XFS_TEST_ERROR(expr, mp, tag) (expr)
Darrick J. Wong31965ef2017-06-20 17:54:46 -070083#define xfs_errortag_set(mp, tag, val) (ENOSYS)
84#define xfs_errortag_add(mp, tag) (ENOSYS)
85#define xfs_errortag_clearall(mp) (ENOSYS)
Christoph Hellwig1550d0b2008-08-13 16:17:37 +100086#endif /* DEBUG */
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88/*
Dave Chinner6a19d932011-03-07 10:02:35 +110089 * XFS panic tags -- allow a call to xfs_alert_tag() be turned into
90 * a panic by setting xfs_panic_mask in a sysctl.
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 */
92#define XFS_NO_PTAG 0
93#define XFS_PTAG_IFLUSH 0x00000001
94#define XFS_PTAG_LOGRES 0x00000002
95#define XFS_PTAG_AILDELETE 0x00000004
96#define XFS_PTAG_ERROR_REPORT 0x00000008
97#define XFS_PTAG_SHUTDOWN_CORRUPT 0x00000010
98#define XFS_PTAG_SHUTDOWN_IOERROR 0x00000020
99#define XFS_PTAG_SHUTDOWN_LOGERROR 0x00000040
Nathan Scott572d95f2006-09-28 11:03:20 +1000100#define XFS_PTAG_FSBLOCK_ZERO 0x00000080
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102#endif /* __XFS_ERROR_H__ */