Merge branches 'tracing/kmemtrace2' and 'tracing/ftrace' into tracing/urgent
[deliverable/linux.git] / fs / xfs / support / debug.c
CommitLineData
1da177e4 1/*
7b718769
NS
2 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
1da177e4 4 *
7b718769
NS
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
1da177e4
LT
7 * published by the Free Software Foundation.
8 *
7b718769
NS
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
1da177e4 13 *
7b718769
NS
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1da177e4 17 */
93c189c1 18#include <xfs.h>
1da177e4 19#include "debug.h"
1da177e4 20
efc55757
CH
21/* xfs_mount.h drags a lot of crap in, sorry.. */
22#include "xfs_sb.h"
23#include "xfs_inum.h"
24#include "xfs_ag.h"
25#include "xfs_dmapi.h"
26#include "xfs_mount.h"
27
dc74eaad 28static char message[1024]; /* keep it off the stack */
1da177e4
LT
29static DEFINE_SPINLOCK(xfs_err_lock);
30
31/* Translate from CE_FOO to KERN_FOO, err_level(CE_FOO) == KERN_FOO */
32#define XFS_MAX_ERR_LEVEL 7
33#define XFS_ERR_MASK ((1 << 3) - 1)
1df84c93 34static const char * const err_level[XFS_MAX_ERR_LEVEL+1] =
1da177e4
LT
35 {KERN_EMERG, KERN_ALERT, KERN_CRIT,
36 KERN_ERR, KERN_WARNING, KERN_NOTICE,
37 KERN_INFO, KERN_DEBUG};
38
1da177e4
LT
39void
40cmn_err(register int level, char *fmt, ...)
41{
42 char *fp = fmt;
43 int len;
44 ulong flags;
45 va_list ap;
46
47 level &= XFS_ERR_MASK;
48 if (level > XFS_MAX_ERR_LEVEL)
49 level = XFS_MAX_ERR_LEVEL;
50 spin_lock_irqsave(&xfs_err_lock,flags);
51 va_start(ap, fmt);
52 if (*fmt == '!') fp++;
dc74eaad
LM
53 len = vsnprintf(message, sizeof(message), fp, ap);
54 if (len >= sizeof(message))
55 len = sizeof(message) - 1;
56 if (message[len-1] == '\n')
57 message[len-1] = 0;
58 printk("%s%s\n", err_level[level], message);
1da177e4
LT
59 va_end(ap);
60 spin_unlock_irqrestore(&xfs_err_lock,flags);
9ab5aa91 61 BUG_ON(level == CE_PANIC);
1da177e4
LT
62}
63
1da177e4 64void
efc55757
CH
65xfs_fs_vcmn_err(
66 int level,
67 struct xfs_mount *mp,
68 char *fmt,
69 va_list ap)
1da177e4 70{
efc55757
CH
71 unsigned long flags;
72 int len = 0;
1da177e4
LT
73
74 level &= XFS_ERR_MASK;
efc55757 75 if (level > XFS_MAX_ERR_LEVEL)
1da177e4 76 level = XFS_MAX_ERR_LEVEL;
efc55757 77
1da177e4 78 spin_lock_irqsave(&xfs_err_lock,flags);
efc55757
CH
79
80 if (mp) {
81 len = sprintf(message, "Filesystem \"%s\": ", mp->m_fsname);
82
83 /*
84 * Skip the printk if we can't print anything useful
85 * due to an over-long device name.
86 */
87 if (len >= sizeof(message))
88 goto out;
89 }
90
91 len = vsnprintf(message + len, sizeof(message) - len, fmt, ap);
dc74eaad
LM
92 if (len >= sizeof(message))
93 len = sizeof(message) - 1;
94 if (message[len-1] == '\n')
95 message[len-1] = 0;
efc55757 96
dc74eaad 97 printk("%s%s\n", err_level[level], message);
efc55757 98 out:
1da177e4 99 spin_unlock_irqrestore(&xfs_err_lock,flags);
efc55757 100
9ab5aa91 101 BUG_ON(level == CE_PANIC);
1da177e4 102}
3762ec6b
NS
103
104void
105assfail(char *expr, char *file, int line)
106{
107 printk("Assertion failed: %s, file: %s, line: %d\n", expr, file, line);
108 BUG();
109}
d4f3cc01
ES
110
111void
112xfs_hex_dump(void *p, int length)
113{
34519daa 114 print_hex_dump(KERN_ALERT, "", DUMP_PREFIX_ADDRESS, 16, 1, p, length, 1);
d4f3cc01 115}
This page took 0.436802 seconds and 5 git commands to generate.