blob: bc66d95c8d4c7e7139af816b8bcdbbeaf455a0b4 [file] [log] [blame]
Dave Chinner0b61f8a2018-06-05 19:42:14 -07001// SPDX-License-Identifier: GPL-2.0
Dave Chinner10e38392011-03-02 14:20:59 +11002/*
3 * Copyright (c) 2011 Red Hat, Inc. All Rights Reserved.
Dave Chinner10e38392011-03-02 14:20:59 +11004 */
5
6#include "xfs.h"
7#include "xfs_fs.h"
Eric Sandeen847f9f62015-10-12 16:04:45 +11008#include "xfs_error.h"
Darrick J. Wong5467b342019-06-28 19:25:35 -07009#include "xfs_shared.h"
Christoph Hellwig4fb6e8a2014-11-28 14:25:04 +110010#include "xfs_format.h"
Dave Chinner239880e2013-10-23 10:50:10 +110011#include "xfs_trans_resv.h"
Dave Chinner10e38392011-03-02 14:20:59 +110012#include "xfs_mount.h"
13
14/*
15 * XFS logging functions
16 */
Christoph Hellwig957935d2011-04-02 18:13:40 +000017static void
Dave Chinner10e38392011-03-02 14:20:59 +110018__xfs_printk(
19 const char *level,
20 const struct xfs_mount *mp,
21 struct va_format *vaf)
22{
Ian Kente1d3d212019-11-04 13:58:40 -080023 if (mp && mp->m_super) {
24 printk("%sXFS (%s): %pV\n", level, mp->m_super->s_id, vaf);
Dave Chinner3eff1262011-04-12 13:34:20 +000025 return;
26 }
Christoph Hellwig957935d2011-04-02 18:13:40 +000027 printk("%sXFS: %pV\n", level, vaf);
Dave Chinner10e38392011-03-02 14:20:59 +110028}
29
Dave Chinner10e38392011-03-02 14:20:59 +110030#define define_xfs_printk_level(func, kern_level) \
Christoph Hellwig957935d2011-04-02 18:13:40 +000031void func(const struct xfs_mount *mp, const char *fmt, ...) \
Dave Chinner10e38392011-03-02 14:20:59 +110032{ \
33 struct va_format vaf; \
34 va_list args; \
Eric Sandeen847f9f62015-10-12 16:04:45 +110035 int level; \
Dave Chinner10e38392011-03-02 14:20:59 +110036 \
37 va_start(args, fmt); \
38 \
39 vaf.fmt = fmt; \
40 vaf.va = &args; \
41 \
Christoph Hellwig957935d2011-04-02 18:13:40 +000042 __xfs_printk(kern_level, mp, &vaf); \
Dave Chinner10e38392011-03-02 14:20:59 +110043 va_end(args); \
Eric Sandeen847f9f62015-10-12 16:04:45 +110044 \
45 if (!kstrtoint(kern_level, 0, &level) && \
46 level <= LOGLEVEL_ERR && \
47 xfs_error_level >= XFS_ERRLEVEL_HIGH) \
48 xfs_stack_trace(); \
Dave Chinner10e38392011-03-02 14:20:59 +110049} \
50
51define_xfs_printk_level(xfs_emerg, KERN_EMERG);
52define_xfs_printk_level(xfs_alert, KERN_ALERT);
53define_xfs_printk_level(xfs_crit, KERN_CRIT);
54define_xfs_printk_level(xfs_err, KERN_ERR);
55define_xfs_printk_level(xfs_warn, KERN_WARNING);
56define_xfs_printk_level(xfs_notice, KERN_NOTICE);
57define_xfs_printk_level(xfs_info, KERN_INFO);
58#ifdef DEBUG
59define_xfs_printk_level(xfs_debug, KERN_DEBUG);
60#endif
61
Christoph Hellwig957935d2011-04-02 18:13:40 +000062void
Dave Chinner10e38392011-03-02 14:20:59 +110063xfs_alert_tag(
64 const struct xfs_mount *mp,
65 int panic_tag,
66 const char *fmt, ...)
67{
68 struct va_format vaf;
69 va_list args;
Alex Elder0c9ba972011-03-11 12:39:51 +000070 int do_panic = 0;
Dave Chinner10e38392011-03-02 14:20:59 +110071
72 if (xfs_panic_mask && (xfs_panic_mask & panic_tag)) {
Joe Perchese69522a2011-05-03 20:14:44 +000073 xfs_alert(mp, "Transforming an alert into a BUG.");
Alex Elder0c9ba972011-03-11 12:39:51 +000074 do_panic = 1;
Dave Chinner10e38392011-03-02 14:20:59 +110075 }
76
77 va_start(args, fmt);
78
79 vaf.fmt = fmt;
80 vaf.va = &args;
81
Christoph Hellwig957935d2011-04-02 18:13:40 +000082 __xfs_printk(KERN_ALERT, mp, &vaf);
Dave Chinner10e38392011-03-02 14:20:59 +110083 va_end(args);
84
Alex Elder0c9ba972011-03-11 12:39:51 +000085 BUG_ON(do_panic);
Dave Chinner10e38392011-03-02 14:20:59 +110086}
Dave Chinner91300902011-03-07 10:09:35 +110087
88void
Darrick J. Wong9842b562019-11-02 09:41:19 -070089asswarn(
90 struct xfs_mount *mp,
91 char *expr,
92 char *file,
93 int line)
Dave Chinner742ae1e2013-04-30 21:39:34 +100094{
Darrick J. Wong9842b562019-11-02 09:41:19 -070095 xfs_warn(mp, "Assertion failed: %s, file: %s, line: %d",
Dave Chinner742ae1e2013-04-30 21:39:34 +100096 expr, file, line);
97 WARN_ON(1);
98}
99
100void
Darrick J. Wong9842b562019-11-02 09:41:19 -0700101assfail(
102 struct xfs_mount *mp,
103 char *expr,
104 char *file,
105 int line)
Dave Chinner91300902011-03-07 10:09:35 +1100106{
Darrick J. Wong9842b562019-11-02 09:41:19 -0700107 xfs_emerg(mp, "Assertion failed: %s, file: %s, line: %d",
Dave Chinner91300902011-03-07 10:09:35 +1100108 expr, file, line);
Brian Fosterccdab3d2017-06-14 21:29:12 -0700109 if (xfs_globals.bug_on_assert)
110 BUG();
111 else
112 WARN_ON(1);
Dave Chinner91300902011-03-07 10:09:35 +1100113}
114
115void
Darrick J. Wongd243b892019-11-02 09:40:36 -0700116xfs_hex_dump(const void *p, int length)
Dave Chinner91300902011-03-07 10:09:35 +1100117{
Darrick J. Wongbdec0552018-11-06 07:50:50 -0800118 print_hex_dump(KERN_ALERT, "", DUMP_PREFIX_OFFSET, 16, 1, p, length, 1);
Dave Chinner91300902011-03-07 10:09:35 +1100119}
Brian Fosterf9bccfc2020-05-06 13:25:21 -0700120
121void
122xfs_buf_alert_ratelimited(
123 struct xfs_buf *bp,
124 const char *rlmsg,
125 const char *fmt,
126 ...)
127{
128 struct xfs_mount *mp = bp->b_mount;
129 struct va_format vaf;
130 va_list args;
131
132 /* use the more aggressive per-target rate limit for buffers */
133 if (!___ratelimit(&bp->b_target->bt_ioerror_rl, rlmsg))
134 return;
135
136 va_start(args, fmt);
137 vaf.fmt = fmt;
138 vaf.va = &args;
139 __xfs_printk(KERN_ALERT, mp, &vaf);
140 va_end(args);
141}