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 | */ |
Vlad Apostolov | 93c189c | 2006-11-11 18:03:49 +1100 | [diff] [blame] | 18 | #include <xfs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include "debug.h" |
Nathan Scott | cde410a | 2005-09-05 11:47:01 +1000 | [diff] [blame] | 20 | #include "spin.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | static char message[256]; /* keep it off the stack */ |
| 23 | static DEFINE_SPINLOCK(xfs_err_lock); |
| 24 | |
| 25 | /* Translate from CE_FOO to KERN_FOO, err_level(CE_FOO) == KERN_FOO */ |
| 26 | #define XFS_MAX_ERR_LEVEL 7 |
| 27 | #define XFS_ERR_MASK ((1 << 3) - 1) |
Christoph Hellwig | 1df84c9 | 2006-01-11 15:29:52 +1100 | [diff] [blame] | 28 | static const char * const err_level[XFS_MAX_ERR_LEVEL+1] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | {KERN_EMERG, KERN_ALERT, KERN_CRIT, |
| 30 | KERN_ERR, KERN_WARNING, KERN_NOTICE, |
| 31 | KERN_INFO, KERN_DEBUG}; |
| 32 | |
| 33 | void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | cmn_err(register int level, char *fmt, ...) |
| 35 | { |
| 36 | char *fp = fmt; |
| 37 | int len; |
| 38 | ulong flags; |
| 39 | va_list ap; |
| 40 | |
| 41 | level &= XFS_ERR_MASK; |
| 42 | if (level > XFS_MAX_ERR_LEVEL) |
| 43 | level = XFS_MAX_ERR_LEVEL; |
| 44 | spin_lock_irqsave(&xfs_err_lock,flags); |
| 45 | va_start(ap, fmt); |
| 46 | if (*fmt == '!') fp++; |
| 47 | len = vsprintf(message, fp, ap); |
Nathan Scott | b657452 | 2006-06-09 15:29:40 +1000 | [diff] [blame] | 48 | if (level != CE_DEBUG && message[len-1] != '\n') |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | strcat(message, "\n"); |
| 50 | printk("%s%s", err_level[level], message); |
| 51 | va_end(ap); |
| 52 | spin_unlock_irqrestore(&xfs_err_lock,flags); |
| 53 | |
Eric Sesterhenn | 9ab5aa9 | 2006-10-03 23:37:55 +0200 | [diff] [blame] | 54 | BUG_ON(level == CE_PANIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | void |
| 58 | icmn_err(register int level, char *fmt, va_list ap) |
| 59 | { |
| 60 | ulong flags; |
| 61 | int len; |
| 62 | |
| 63 | level &= XFS_ERR_MASK; |
| 64 | if(level > XFS_MAX_ERR_LEVEL) |
| 65 | level = XFS_MAX_ERR_LEVEL; |
| 66 | spin_lock_irqsave(&xfs_err_lock,flags); |
| 67 | len = vsprintf(message, fmt, ap); |
Nathan Scott | b657452 | 2006-06-09 15:29:40 +1000 | [diff] [blame] | 68 | if (level != CE_DEBUG && message[len-1] != '\n') |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | strcat(message, "\n"); |
| 70 | spin_unlock_irqrestore(&xfs_err_lock,flags); |
| 71 | printk("%s%s", err_level[level], message); |
Eric Sesterhenn | 9ab5aa9 | 2006-10-03 23:37:55 +0200 | [diff] [blame] | 72 | BUG_ON(level == CE_PANIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | } |
Nathan Scott | 3762ec6 | 2006-01-12 10:29:53 +1100 | [diff] [blame] | 74 | |
| 75 | void |
| 76 | assfail(char *expr, char *file, int line) |
| 77 | { |
| 78 | printk("Assertion failed: %s, file: %s, line: %d\n", expr, file, line); |
| 79 | BUG(); |
| 80 | } |
| 81 | |
| 82 | #if ((defined(DEBUG) || defined(INDUCE_IO_ERRROR)) && !defined(NO_WANT_RANDOM)) |
| 83 | unsigned long random(void) |
| 84 | { |
| 85 | static unsigned long RandomValue = 1; |
| 86 | /* cycles pseudo-randomly through all values between 1 and 2^31 - 2 */ |
| 87 | register long rv = RandomValue; |
| 88 | register long lo; |
| 89 | register long hi; |
| 90 | |
| 91 | hi = rv / 127773; |
| 92 | lo = rv % 127773; |
| 93 | rv = 16807 * lo - 2836 * hi; |
| 94 | if (rv <= 0) rv += 2147483647; |
| 95 | return RandomValue = rv; |
| 96 | } |
| 97 | #endif /* DEBUG || INDUCE_IO_ERRROR || !NO_WANT_RANDOM */ |