| 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" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 |  | 
| Lachlan McIlroy | dc74eaa | 2007-02-10 18:34:38 +1100 | [diff] [blame] | 21 | static char		message[1024];	/* keep it off the stack */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | static DEFINE_SPINLOCK(xfs_err_lock); | 
|  | 23 |  | 
|  | 24 | /* Translate from CE_FOO to KERN_FOO, err_level(CE_FOO) == KERN_FOO */ | 
|  | 25 | #define XFS_MAX_ERR_LEVEL	7 | 
|  | 26 | #define XFS_ERR_MASK		((1 << 3) - 1) | 
| Christoph Hellwig | 1df84c9 | 2006-01-11 15:29:52 +1100 | [diff] [blame] | 27 | static const char * const	err_level[XFS_MAX_ERR_LEVEL+1] = | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | {KERN_EMERG, KERN_ALERT, KERN_CRIT, | 
|  | 29 | KERN_ERR, KERN_WARNING, KERN_NOTICE, | 
|  | 30 | KERN_INFO, KERN_DEBUG}; | 
|  | 31 |  | 
|  | 32 | void | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | cmn_err(register int level, char *fmt, ...) | 
|  | 34 | { | 
|  | 35 | char	*fp = fmt; | 
|  | 36 | int	len; | 
|  | 37 | ulong	flags; | 
|  | 38 | va_list	ap; | 
|  | 39 |  | 
|  | 40 | level &= XFS_ERR_MASK; | 
|  | 41 | if (level > XFS_MAX_ERR_LEVEL) | 
|  | 42 | level = XFS_MAX_ERR_LEVEL; | 
|  | 43 | spin_lock_irqsave(&xfs_err_lock,flags); | 
|  | 44 | va_start(ap, fmt); | 
|  | 45 | if (*fmt == '!') fp++; | 
| Lachlan McIlroy | dc74eaa | 2007-02-10 18:34:38 +1100 | [diff] [blame] | 46 | len = vsnprintf(message, sizeof(message), fp, ap); | 
|  | 47 | if (len >= sizeof(message)) | 
|  | 48 | len = sizeof(message) - 1; | 
|  | 49 | if (message[len-1] == '\n') | 
|  | 50 | message[len-1] = 0; | 
|  | 51 | printk("%s%s\n", err_level[level], message); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | va_end(ap); | 
|  | 53 | spin_unlock_irqrestore(&xfs_err_lock,flags); | 
| 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); | 
| Lachlan McIlroy | dc74eaa | 2007-02-10 18:34:38 +1100 | [diff] [blame] | 67 | len = vsnprintf(message, sizeof(message), fmt, ap); | 
|  | 68 | if (len >= sizeof(message)) | 
|  | 69 | len = sizeof(message) - 1; | 
|  | 70 | if (message[len-1] == '\n') | 
|  | 71 | message[len-1] = 0; | 
|  | 72 | printk("%s%s\n", err_level[level], message); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | spin_unlock_irqrestore(&xfs_err_lock,flags); | 
| Eric Sesterhenn | 9ab5aa9 | 2006-10-03 23:37:55 +0200 | [diff] [blame] | 74 | BUG_ON(level == CE_PANIC); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | } | 
| Nathan Scott | 3762ec6 | 2006-01-12 10:29:53 +1100 | [diff] [blame] | 76 |  | 
|  | 77 | void | 
|  | 78 | assfail(char *expr, char *file, int line) | 
|  | 79 | { | 
|  | 80 | printk("Assertion failed: %s, file: %s, line: %d\n", expr, file, line); | 
|  | 81 | BUG(); | 
|  | 82 | } | 
| Eric Sandeen | d4f3cc0 | 2007-10-12 11:13:08 +1000 | [diff] [blame] | 83 |  | 
|  | 84 | void | 
|  | 85 | xfs_hex_dump(void *p, int length) | 
|  | 86 | { | 
|  | 87 | print_hex_dump(KERN_ALERT, "", DUMP_PREFIX_OFFSET, 16, 1, p, length, 1); | 
|  | 88 | } |