Merge /spare/repo/linux-2.6/
[powerpc.git] / fs / xfs / support / debug.c
1 /*
2  * Copyright (c) 2000-2003 Silicon Graphics, Inc.  All Rights Reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of version 2 of the GNU General Public License as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it would be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  *
12  * Further, this software is distributed without any warranty that it is
13  * free of the rightful claim of any third person regarding infringement
14  * or the like.  Any license provided herein, whether implied or
15  * otherwise, applies only to this software file.  Patent licenses, if
16  * any, provided herein do not apply to combinations of this program with
17  * other software, or any other product whatsoever.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write the Free Software Foundation, Inc., 59
21  * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22  *
23  * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24  * Mountain View, CA  94043, or:
25  *
26  * http://www.sgi.com
27  *
28  * For further information regarding this notice, see:
29  *
30  * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31  */
32
33 #include "debug.h"
34
35 #include <asm/page.h>
36 #include <linux/sched.h>
37 #include <linux/kernel.h>
38
39 static char             message[256];   /* keep it off the stack */
40 static DEFINE_SPINLOCK(xfs_err_lock);
41
42 /* Translate from CE_FOO to KERN_FOO, err_level(CE_FOO) == KERN_FOO */
43 #define XFS_MAX_ERR_LEVEL       7
44 #define XFS_ERR_MASK            ((1 << 3) - 1)
45 static char             *err_level[XFS_MAX_ERR_LEVEL+1] =
46                                         {KERN_EMERG, KERN_ALERT, KERN_CRIT,
47                                          KERN_ERR, KERN_WARNING, KERN_NOTICE,
48                                          KERN_INFO, KERN_DEBUG};
49
50 void
51 assfail(char *a, char *f, int l)
52 {
53     printk("XFS assertion failed: %s, file: %s, line: %d\n", a, f, l);
54     BUG();
55 }
56
57 #if ((defined(DEBUG) || defined(INDUCE_IO_ERRROR)) && !defined(NO_WANT_RANDOM))
58
59 unsigned long
60 random(void)
61 {
62         static unsigned long    RandomValue = 1;
63         /* cycles pseudo-randomly through all values between 1 and 2^31 - 2 */
64         register long   rv = RandomValue;
65         register long   lo;
66         register long   hi;
67
68         hi = rv / 127773;
69         lo = rv % 127773;
70         rv = 16807 * lo - 2836 * hi;
71         if( rv <= 0 ) rv += 2147483647;
72         return( RandomValue = rv );
73 }
74
75 int
76 get_thread_id(void)
77 {
78         return current->pid;
79 }
80
81 #endif /* DEBUG || INDUCE_IO_ERRROR || !NO_WANT_RANDOM */
82
83 void
84 cmn_err(register int level, char *fmt, ...)
85 {
86         char    *fp = fmt;
87         int     len;
88         ulong   flags;
89         va_list ap;
90
91         level &= XFS_ERR_MASK;
92         if (level > XFS_MAX_ERR_LEVEL)
93                 level = XFS_MAX_ERR_LEVEL;
94         spin_lock_irqsave(&xfs_err_lock,flags);
95         va_start(ap, fmt);
96         if (*fmt == '!') fp++;
97         len = vsprintf(message, fp, ap);
98         if (message[len-1] != '\n')
99                 strcat(message, "\n");
100         printk("%s%s", err_level[level], message);
101         va_end(ap);
102         spin_unlock_irqrestore(&xfs_err_lock,flags);
103
104         if (level == CE_PANIC)
105                 BUG();
106 }
107
108
109 void
110 icmn_err(register int level, char *fmt, va_list ap)
111 {
112         ulong   flags;
113         int     len;
114
115         level &= XFS_ERR_MASK;
116         if(level > XFS_MAX_ERR_LEVEL)
117                 level = XFS_MAX_ERR_LEVEL;
118         spin_lock_irqsave(&xfs_err_lock,flags);
119         len = vsprintf(message, fmt, ap);
120         if (message[len-1] != '\n')
121                 strcat(message, "\n");
122         spin_unlock_irqrestore(&xfs_err_lock,flags);
123         printk("%s%s", err_level[level], message);
124         if (level == CE_PANIC)
125                 BUG();
126 }