blob: c75f68361e33dda4276b29583b5d45d8f33afd15 [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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include "debug.h"
Nathan Scottcde410a2005-09-05 11:47:01 +100019#include "spin.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <asm/page.h>
21#include <linux/sched.h>
22#include <linux/kernel.h>
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024static char message[256]; /* keep it off the stack */
25static DEFINE_SPINLOCK(xfs_err_lock);
26
27/* Translate from CE_FOO to KERN_FOO, err_level(CE_FOO) == KERN_FOO */
28#define XFS_MAX_ERR_LEVEL 7
29#define XFS_ERR_MASK ((1 << 3) - 1)
Christoph Hellwig1df84c92006-01-11 15:29:52 +110030static const char * const err_level[XFS_MAX_ERR_LEVEL+1] =
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 {KERN_EMERG, KERN_ALERT, KERN_CRIT,
32 KERN_ERR, KERN_WARNING, KERN_NOTICE,
33 KERN_INFO, KERN_DEBUG};
34
35void
Linus Torvalds1da177e2005-04-16 15:20:36 -070036cmn_err(register int level, char *fmt, ...)
37{
38 char *fp = fmt;
39 int len;
40 ulong flags;
41 va_list ap;
42
43 level &= XFS_ERR_MASK;
44 if (level > XFS_MAX_ERR_LEVEL)
45 level = XFS_MAX_ERR_LEVEL;
46 spin_lock_irqsave(&xfs_err_lock,flags);
47 va_start(ap, fmt);
48 if (*fmt == '!') fp++;
49 len = vsprintf(message, fp, ap);
Nathan Scottb6574522006-06-09 15:29:40 +100050 if (level != CE_DEBUG && message[len-1] != '\n')
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 strcat(message, "\n");
52 printk("%s%s", err_level[level], message);
53 va_end(ap);
54 spin_unlock_irqrestore(&xfs_err_lock,flags);
55
Eric Sesterhenn9ab5aa92006-10-03 23:37:55 +020056 BUG_ON(level == CE_PANIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057}
58
Linus Torvalds1da177e2005-04-16 15:20:36 -070059void
60icmn_err(register int level, char *fmt, va_list ap)
61{
62 ulong flags;
63 int len;
64
65 level &= XFS_ERR_MASK;
66 if(level > XFS_MAX_ERR_LEVEL)
67 level = XFS_MAX_ERR_LEVEL;
68 spin_lock_irqsave(&xfs_err_lock,flags);
69 len = vsprintf(message, fmt, ap);
Nathan Scottb6574522006-06-09 15:29:40 +100070 if (level != CE_DEBUG && message[len-1] != '\n')
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 strcat(message, "\n");
72 spin_unlock_irqrestore(&xfs_err_lock,flags);
73 printk("%s%s", err_level[level], message);
Eric Sesterhenn9ab5aa92006-10-03 23:37:55 +020074 BUG_ON(level == CE_PANIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075}
Nathan Scott3762ec62006-01-12 10:29:53 +110076
77void
78assfail(char *expr, char *file, int line)
79{
80 printk("Assertion failed: %s, file: %s, line: %d\n", expr, file, line);
81 BUG();
82}
83
84#if ((defined(DEBUG) || defined(INDUCE_IO_ERRROR)) && !defined(NO_WANT_RANDOM))
85unsigned long random(void)
86{
87 static unsigned long RandomValue = 1;
88 /* cycles pseudo-randomly through all values between 1 and 2^31 - 2 */
89 register long rv = RandomValue;
90 register long lo;
91 register long hi;
92
93 hi = rv / 127773;
94 lo = rv % 127773;
95 rv = 16807 * lo - 2836 * hi;
96 if (rv <= 0) rv += 2147483647;
97 return RandomValue = rv;
98}
99#endif /* DEBUG || INDUCE_IO_ERRROR || !NO_WANT_RANDOM */