Commit | Line | Data |
---|---|---|
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" |
cde410a9 | 20 | #include "spin.h" |
1da177e4 | 21 | |
dc74eaad | 22 | static char message[1024]; /* keep it off the stack */ |
1da177e4 LT |
23 | static DEFINE_SPINLOCK(xfs_err_lock); |
24 | ||
25 | /* Translate from CE_FOO to KERN_FOO, err_level(CE_FOO) == KERN_FOO */ | |
26 | #define XFS_MAX_ERR_LEVEL 7 | |
27 | #define XFS_ERR_MASK ((1 << 3) - 1) | |
1df84c93 | 28 | static const char * const err_level[XFS_MAX_ERR_LEVEL+1] = |
1da177e4 LT |
29 | {KERN_EMERG, KERN_ALERT, KERN_CRIT, |
30 | KERN_ERR, KERN_WARNING, KERN_NOTICE, | |
31 | KERN_INFO, KERN_DEBUG}; | |
32 | ||
1da177e4 LT |
33 | void |
34 | cmn_err(register int level, char *fmt, ...) | |
35 | { | |
36 | char *fp = fmt; | |
37 | int len; | |
38 | ulong flags; | |
39 | va_list ap; | |
40 | ||
41 | level &= XFS_ERR_MASK; | |
42 | if (level > XFS_MAX_ERR_LEVEL) | |
43 | level = XFS_MAX_ERR_LEVEL; | |
44 | spin_lock_irqsave(&xfs_err_lock,flags); | |
45 | va_start(ap, fmt); | |
46 | if (*fmt == '!') fp++; | |
dc74eaad LM |
47 | len = vsnprintf(message, sizeof(message), fp, ap); |
48 | if (len >= sizeof(message)) | |
49 | len = sizeof(message) - 1; | |
50 | if (message[len-1] == '\n') | |
51 | message[len-1] = 0; | |
52 | printk("%s%s\n", err_level[level], message); | |
1da177e4 LT |
53 | va_end(ap); |
54 | spin_unlock_irqrestore(&xfs_err_lock,flags); | |
9ab5aa91 | 55 | BUG_ON(level == CE_PANIC); |
1da177e4 LT |
56 | } |
57 | ||
1da177e4 LT |
58 | void |
59 | icmn_err(register int level, char *fmt, va_list ap) | |
60 | { | |
61 | ulong flags; | |
62 | int len; | |
63 | ||
64 | level &= XFS_ERR_MASK; | |
65 | if(level > XFS_MAX_ERR_LEVEL) | |
66 | level = XFS_MAX_ERR_LEVEL; | |
67 | spin_lock_irqsave(&xfs_err_lock,flags); | |
dc74eaad LM |
68 | len = vsnprintf(message, sizeof(message), fmt, ap); |
69 | if (len >= sizeof(message)) | |
70 | len = sizeof(message) - 1; | |
71 | if (message[len-1] == '\n') | |
72 | message[len-1] = 0; | |
73 | printk("%s%s\n", err_level[level], message); | |
1da177e4 | 74 | spin_unlock_irqrestore(&xfs_err_lock,flags); |
9ab5aa91 | 75 | BUG_ON(level == CE_PANIC); |
1da177e4 | 76 | } |
3762ec6b NS |
77 | |
78 | void | |
79 | assfail(char *expr, char *file, int line) | |
80 | { | |
81 | printk("Assertion failed: %s, file: %s, line: %d\n", expr, file, line); | |
82 | BUG(); | |
83 | } |