BUG_ON() conversion in fs/nfsd/
[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 */
1da177e4 18#include "debug.h"
cde410a9 19#include "spin.h"
1da177e4
LT
20#include <asm/page.h>
21#include <linux/sched.h>
22#include <linux/kernel.h>
23
1da177e4
LT
24static 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)
1df84c93 30static const char * const err_level[XFS_MAX_ERR_LEVEL+1] =
1da177e4
LT
31 {KERN_EMERG, KERN_ALERT, KERN_CRIT,
32 KERN_ERR, KERN_WARNING, KERN_NOTICE,
33 KERN_INFO, KERN_DEBUG};
34
1da177e4
LT
35void
36cmn_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);
b6574520 50 if (level != CE_DEBUG && message[len-1] != '\n')
1da177e4
LT
51 strcat(message, "\n");
52 printk("%s%s", err_level[level], message);
53 va_end(ap);
54 spin_unlock_irqrestore(&xfs_err_lock,flags);
55
56 if (level == CE_PANIC)
57 BUG();
58}
59
1da177e4
LT
60void
61icmn_err(register int level, char *fmt, va_list ap)
62{
63 ulong flags;
64 int len;
65
66 level &= XFS_ERR_MASK;
67 if(level > XFS_MAX_ERR_LEVEL)
68 level = XFS_MAX_ERR_LEVEL;
69 spin_lock_irqsave(&xfs_err_lock,flags);
70 len = vsprintf(message, fmt, ap);
b6574520 71 if (level != CE_DEBUG && message[len-1] != '\n')
1da177e4
LT
72 strcat(message, "\n");
73 spin_unlock_irqrestore(&xfs_err_lock,flags);
74 printk("%s%s", err_level[level], message);
75 if (level == CE_PANIC)
76 BUG();
77}
3762ec6b
NS
78
79void
80assfail(char *expr, char *file, int line)
81{
82 printk("Assertion failed: %s, file: %s, line: %d\n", expr, file, line);
83 BUG();
84}
85
86#if ((defined(DEBUG) || defined(INDUCE_IO_ERRROR)) && !defined(NO_WANT_RANDOM))
87unsigned long random(void)
88{
89 static unsigned long RandomValue = 1;
90 /* cycles pseudo-randomly through all values between 1 and 2^31 - 2 */
91 register long rv = RandomValue;
92 register long lo;
93 register long hi;
94
95 hi = rv / 127773;
96 lo = rv % 127773;
97 rv = 16807 * lo - 2836 * hi;
98 if (rv <= 0) rv += 2147483647;
99 return RandomValue = rv;
100}
101#endif /* DEBUG || INDUCE_IO_ERRROR || !NO_WANT_RANDOM */
This page took 0.185248 seconds and 5 git commands to generate.