Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 2 | * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc. |
| 3 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * published by the Free Software Foundation. |
| 8 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 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. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include "debug.h" |
Nathan Scott | cde410a | 2005-09-05 11:47:01 +1000 | [diff] [blame] | 19 | #include "spin.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <asm/page.h> |
| 21 | #include <linux/sched.h> |
| 22 | #include <linux/kernel.h> |
| 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | static char message[256]; /* keep it off the stack */ |
| 25 | static 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 Hellwig | 1df84c9 | 2006-01-11 15:29:52 +1100 | [diff] [blame] | 30 | static const char * const err_level[XFS_MAX_ERR_LEVEL+1] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | {KERN_EMERG, KERN_ALERT, KERN_CRIT, |
| 32 | KERN_ERR, KERN_WARNING, KERN_NOTICE, |
| 33 | KERN_INFO, KERN_DEBUG}; |
| 34 | |
| 35 | void |
| 36 | assfail(char *a, char *f, int l) |
| 37 | { |
| 38 | printk("XFS assertion failed: %s, file: %s, line: %d\n", a, f, l); |
| 39 | BUG(); |
| 40 | } |
| 41 | |
| 42 | #if ((defined(DEBUG) || defined(INDUCE_IO_ERRROR)) && !defined(NO_WANT_RANDOM)) |
| 43 | |
| 44 | unsigned long |
| 45 | random(void) |
| 46 | { |
| 47 | static unsigned long RandomValue = 1; |
| 48 | /* cycles pseudo-randomly through all values between 1 and 2^31 - 2 */ |
| 49 | register long rv = RandomValue; |
| 50 | register long lo; |
| 51 | register long hi; |
| 52 | |
| 53 | hi = rv / 127773; |
| 54 | lo = rv % 127773; |
| 55 | rv = 16807 * lo - 2836 * hi; |
| 56 | if( rv <= 0 ) rv += 2147483647; |
| 57 | return( RandomValue = rv ); |
| 58 | } |
| 59 | |
| 60 | int |
| 61 | get_thread_id(void) |
| 62 | { |
| 63 | return current->pid; |
| 64 | } |
| 65 | |
| 66 | #endif /* DEBUG || INDUCE_IO_ERRROR || !NO_WANT_RANDOM */ |
| 67 | |
| 68 | void |
| 69 | cmn_err(register int level, char *fmt, ...) |
| 70 | { |
| 71 | char *fp = fmt; |
| 72 | int len; |
| 73 | ulong flags; |
| 74 | va_list ap; |
| 75 | |
| 76 | level &= XFS_ERR_MASK; |
| 77 | if (level > XFS_MAX_ERR_LEVEL) |
| 78 | level = XFS_MAX_ERR_LEVEL; |
| 79 | spin_lock_irqsave(&xfs_err_lock,flags); |
| 80 | va_start(ap, fmt); |
| 81 | if (*fmt == '!') fp++; |
| 82 | len = vsprintf(message, fp, ap); |
| 83 | if (message[len-1] != '\n') |
| 84 | strcat(message, "\n"); |
| 85 | printk("%s%s", err_level[level], message); |
| 86 | va_end(ap); |
| 87 | spin_unlock_irqrestore(&xfs_err_lock,flags); |
| 88 | |
| 89 | if (level == CE_PANIC) |
| 90 | BUG(); |
| 91 | } |
| 92 | |
| 93 | |
| 94 | void |
| 95 | icmn_err(register int level, char *fmt, va_list ap) |
| 96 | { |
| 97 | ulong flags; |
| 98 | int len; |
| 99 | |
| 100 | level &= XFS_ERR_MASK; |
| 101 | if(level > XFS_MAX_ERR_LEVEL) |
| 102 | level = XFS_MAX_ERR_LEVEL; |
| 103 | spin_lock_irqsave(&xfs_err_lock,flags); |
| 104 | len = vsprintf(message, fmt, ap); |
| 105 | if (message[len-1] != '\n') |
| 106 | strcat(message, "\n"); |
| 107 | spin_unlock_irqrestore(&xfs_err_lock,flags); |
| 108 | printk("%s%s", err_level[level], message); |
| 109 | if (level == CE_PANIC) |
| 110 | BUG(); |
| 111 | } |