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 int			doass = 1;
40 static char		message[256];	/* keep it off the stack */
41 static spinlock_t	xfs_err_lock = SPIN_LOCK_UNLOCKED;
42 
43 /* Translate from CE_FOO to KERN_FOO, err_level(CE_FOO) == KERN_FOO */
44 #define XFS_MAX_ERR_LEVEL	7
45 #define XFS_ERR_MASK		((1 << 3) - 1)
46 static char		*err_level[XFS_MAX_ERR_LEVEL+1] =
47 					{KERN_EMERG, KERN_ALERT, KERN_CRIT,
48 					 KERN_ERR, KERN_WARNING, KERN_NOTICE,
49 					 KERN_INFO, KERN_DEBUG};
50 
51 void
assfail(char * a,char * f,int l)52 assfail(char *a, char *f, int l)
53 {
54     printk("XFS assertion failed: %s, file: %s, line: %d\n", a, f, l);
55     BUG();
56 }
57 
58 #if ((defined(DEBUG) || defined(INDUCE_IO_ERRROR)) && !defined(NO_WANT_RANDOM))
59 
60 unsigned long
random(void)61 random(void)
62 {
63 	static unsigned long	RandomValue = 1;
64 	/* cycles pseudo-randomly through all values between 1 and 2^31 - 2 */
65 	register long	rv = RandomValue;
66 	register long	lo;
67 	register long	hi;
68 
69 	hi = rv / 127773;
70 	lo = rv % 127773;
71 	rv = 16807 * lo - 2836 * hi;
72 	if( rv <= 0 ) rv += 2147483647;
73 	return( RandomValue = rv );
74 }
75 
76 int
get_thread_id(void)77 get_thread_id(void)
78 {
79 	return current->pid;
80 }
81 
82 #endif /* DEBUG || INDUCE_IO_ERRROR || !NO_WANT_RANDOM */
83 
84 void
cmn_err(register int level,char * fmt,...)85 cmn_err(register int level, char *fmt, ...)
86 {
87 	char	*fp = fmt;
88 	int	len;
89 	ulong	flags;
90 	va_list	ap;
91 
92 	level &= XFS_ERR_MASK;
93 	if (level > XFS_MAX_ERR_LEVEL)
94 		level = XFS_MAX_ERR_LEVEL;
95 	spin_lock_irqsave(&xfs_err_lock,flags);
96 	va_start(ap, fmt);
97 	if (*fmt == '!') fp++;
98 	len = vsprintf(message, fp, ap);
99 	if (message[len-1] != '\n')
100 		strcat(message, "\n");
101 	printk("%s%s", err_level[level], message);
102 	va_end(ap);
103 	spin_unlock_irqrestore(&xfs_err_lock,flags);
104 
105 	if (level == CE_PANIC)
106 		BUG();
107 }
108 
109 
110 void
icmn_err(register int level,char * fmt,va_list ap)111 icmn_err(register int level, char *fmt, va_list ap)
112 {
113 	ulong	flags;
114 	int	len;
115 
116 	level &= XFS_ERR_MASK;
117 	if(level > XFS_MAX_ERR_LEVEL)
118 		level = XFS_MAX_ERR_LEVEL;
119 	spin_lock_irqsave(&xfs_err_lock,flags);
120 	len = vsprintf(message, fmt, ap);
121 	if (message[len-1] != '\n')
122 		strcat(message, "\n");
123 	spin_unlock_irqrestore(&xfs_err_lock,flags);
124 	printk("%s%s", err_level[level], message);
125 	if (level == CE_PANIC)
126 		BUG();
127 }
128