blob: f45a49ffd3a34907f6b1ca2aceaea7dce40e2133 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
Vlad Apostolov93c189c2006-11-11 18:03:49 +110018#include <xfs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include "debug.h"
Nathan Scottcde410a2005-09-05 11:47:01 +100020#include "spin.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Lachlan McIlroydc74eaa2007-02-10 18:34:38 +110022static char message[1024]; /* keep it off the stack */
Linus Torvalds1da177e2005-04-16 15:20:36 -070023static 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)
Christoph Hellwig1df84c92006-01-11 15:29:52 +110028static const char * const err_level[XFS_MAX_ERR_LEVEL+1] =
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 {KERN_EMERG, KERN_ALERT, KERN_CRIT,
30 KERN_ERR, KERN_WARNING, KERN_NOTICE,
31 KERN_INFO, KERN_DEBUG};
32
33void
Linus Torvalds1da177e2005-04-16 15:20:36 -070034cmn_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++;
Lachlan McIlroydc74eaa2007-02-10 18:34:38 +110047 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 va_end(ap);
54 spin_unlock_irqrestore(&xfs_err_lock,flags);
Eric Sesterhenn9ab5aa92006-10-03 23:37:55 +020055 BUG_ON(level == CE_PANIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056}
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058void
59icmn_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);
Lachlan McIlroydc74eaa2007-02-10 18:34:38 +110068 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 spin_unlock_irqrestore(&xfs_err_lock,flags);
Eric Sesterhenn9ab5aa92006-10-03 23:37:55 +020075 BUG_ON(level == CE_PANIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076}
Nathan Scott3762ec62006-01-12 10:29:53 +110077
78void
79assfail(char *expr, char *file, int line)
80{
81 printk("Assertion failed: %s, file: %s, line: %d\n", expr, file, line);
82 BUG();
83}