| 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 |  | 
| Christoph Hellwig | efc5575 | 2008-12-17 12:27:36 -0500 | [diff] [blame] | 21 | /* xfs_mount.h drags a lot of crap in, sorry.. */ | 
|  | 22 | #include "xfs_sb.h" | 
|  | 23 | #include "xfs_inum.h" | 
|  | 24 | #include "xfs_ag.h" | 
|  | 25 | #include "xfs_dmapi.h" | 
|  | 26 | #include "xfs_mount.h" | 
| Felix Blyakher | da5309c | 2009-03-12 09:33:37 -0500 | [diff] [blame] | 27 | #include "xfs_error.h" | 
| Christoph Hellwig | efc5575 | 2008-12-17 12:27:36 -0500 | [diff] [blame] | 28 |  | 
| Lachlan McIlroy | dc74eaa | 2007-02-10 18:34:38 +1100 | [diff] [blame] | 29 | static char		message[1024];	/* keep it off the stack */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | static DEFINE_SPINLOCK(xfs_err_lock); | 
|  | 31 |  | 
|  | 32 | /* Translate from CE_FOO to KERN_FOO, err_level(CE_FOO) == KERN_FOO */ | 
|  | 33 | #define XFS_MAX_ERR_LEVEL	7 | 
|  | 34 | #define XFS_ERR_MASK		((1 << 3) - 1) | 
| Christoph Hellwig | 1df84c9 | 2006-01-11 15:29:52 +1100 | [diff] [blame] | 35 | static const char * const	err_level[XFS_MAX_ERR_LEVEL+1] = | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | {KERN_EMERG, KERN_ALERT, KERN_CRIT, | 
|  | 37 | KERN_ERR, KERN_WARNING, KERN_NOTICE, | 
|  | 38 | KERN_INFO, KERN_DEBUG}; | 
|  | 39 |  | 
|  | 40 | void | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | cmn_err(register int level, char *fmt, ...) | 
|  | 42 | { | 
|  | 43 | char	*fp = fmt; | 
|  | 44 | int	len; | 
|  | 45 | ulong	flags; | 
|  | 46 | va_list	ap; | 
|  | 47 |  | 
|  | 48 | level &= XFS_ERR_MASK; | 
|  | 49 | if (level > XFS_MAX_ERR_LEVEL) | 
|  | 50 | level = XFS_MAX_ERR_LEVEL; | 
|  | 51 | spin_lock_irqsave(&xfs_err_lock,flags); | 
|  | 52 | va_start(ap, fmt); | 
|  | 53 | if (*fmt == '!') fp++; | 
| Lachlan McIlroy | dc74eaa | 2007-02-10 18:34:38 +1100 | [diff] [blame] | 54 | len = vsnprintf(message, sizeof(message), fp, ap); | 
|  | 55 | if (len >= sizeof(message)) | 
|  | 56 | len = sizeof(message) - 1; | 
|  | 57 | if (message[len-1] == '\n') | 
|  | 58 | message[len-1] = 0; | 
|  | 59 | printk("%s%s\n", err_level[level], message); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | va_end(ap); | 
|  | 61 | spin_unlock_irqrestore(&xfs_err_lock,flags); | 
| Eric Sesterhenn | 9ab5aa9 | 2006-10-03 23:37:55 +0200 | [diff] [blame] | 62 | BUG_ON(level == CE_PANIC); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | } | 
|  | 64 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | void | 
| Christoph Hellwig | efc5575 | 2008-12-17 12:27:36 -0500 | [diff] [blame] | 66 | xfs_fs_vcmn_err( | 
|  | 67 | int			level, | 
|  | 68 | struct xfs_mount	*mp, | 
|  | 69 | char			*fmt, | 
|  | 70 | va_list			ap) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | { | 
| Christoph Hellwig | efc5575 | 2008-12-17 12:27:36 -0500 | [diff] [blame] | 72 | unsigned long		flags; | 
|  | 73 | int			len = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 |  | 
|  | 75 | level &= XFS_ERR_MASK; | 
| Christoph Hellwig | efc5575 | 2008-12-17 12:27:36 -0500 | [diff] [blame] | 76 | if (level > XFS_MAX_ERR_LEVEL) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | level = XFS_MAX_ERR_LEVEL; | 
| Christoph Hellwig | efc5575 | 2008-12-17 12:27:36 -0500 | [diff] [blame] | 78 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | spin_lock_irqsave(&xfs_err_lock,flags); | 
| Christoph Hellwig | efc5575 | 2008-12-17 12:27:36 -0500 | [diff] [blame] | 80 |  | 
|  | 81 | if (mp) { | 
|  | 82 | len = sprintf(message, "Filesystem \"%s\": ", mp->m_fsname); | 
|  | 83 |  | 
|  | 84 | /* | 
|  | 85 | * Skip the printk if we can't print anything useful | 
|  | 86 | * due to an over-long device name. | 
|  | 87 | */ | 
|  | 88 | if (len >= sizeof(message)) | 
|  | 89 | goto out; | 
|  | 90 | } | 
|  | 91 |  | 
|  | 92 | len = vsnprintf(message + len, sizeof(message) - len, fmt, ap); | 
| Lachlan McIlroy | dc74eaa | 2007-02-10 18:34:38 +1100 | [diff] [blame] | 93 | if (len >= sizeof(message)) | 
|  | 94 | len = sizeof(message) - 1; | 
|  | 95 | if (message[len-1] == '\n') | 
|  | 96 | message[len-1] = 0; | 
| Christoph Hellwig | efc5575 | 2008-12-17 12:27:36 -0500 | [diff] [blame] | 97 |  | 
| Lachlan McIlroy | dc74eaa | 2007-02-10 18:34:38 +1100 | [diff] [blame] | 98 | printk("%s%s\n", err_level[level], message); | 
| Christoph Hellwig | efc5575 | 2008-12-17 12:27:36 -0500 | [diff] [blame] | 99 | out: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | spin_unlock_irqrestore(&xfs_err_lock,flags); | 
| Christoph Hellwig | efc5575 | 2008-12-17 12:27:36 -0500 | [diff] [blame] | 101 |  | 
| Eric Sesterhenn | 9ab5aa9 | 2006-10-03 23:37:55 +0200 | [diff] [blame] | 102 | BUG_ON(level == CE_PANIC); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | } | 
| Nathan Scott | 3762ec6 | 2006-01-12 10:29:53 +1100 | [diff] [blame] | 104 |  | 
|  | 105 | void | 
|  | 106 | assfail(char *expr, char *file, int line) | 
|  | 107 | { | 
|  | 108 | printk("Assertion failed: %s, file: %s, line: %d\n", expr, file, line); | 
|  | 109 | BUG(); | 
|  | 110 | } | 
| Eric Sandeen | d4f3cc0 | 2007-10-12 11:13:08 +1000 | [diff] [blame] | 111 |  | 
|  | 112 | void | 
|  | 113 | xfs_hex_dump(void *p, int length) | 
|  | 114 | { | 
| Barry Naujok | 34519da | 2008-10-30 17:05:58 +1100 | [diff] [blame] | 115 | print_hex_dump(KERN_ALERT, "", DUMP_PREFIX_ADDRESS, 16, 1, p, length, 1); | 
| Eric Sandeen | d4f3cc0 | 2007-10-12 11:13:08 +1000 | [diff] [blame] | 116 | } |