blob: ae5482965424d9ae4dddbed76bbff558bb86bb5d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * 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 Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * 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 Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * 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 Torvalds1da177e2005-04-16 15:20:36 -070017 */
Vlad Apostolov93c189c2006-11-11 18:03:49 +110018#include <xfs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include "debug.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Christoph Hellwigefc55752008-12-17 12:27:36 -050021/* 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"
27
Lachlan McIlroydc74eaa2007-02-10 18:34:38 +110028static char message[1024]; /* keep it off the stack */
Linus Torvalds1da177e2005-04-16 15:20:36 -070029static DEFINE_SPINLOCK(xfs_err_lock);
30
31/* Translate from CE_FOO to KERN_FOO, err_level(CE_FOO) == KERN_FOO */
32#define XFS_MAX_ERR_LEVEL 7
33#define XFS_ERR_MASK ((1 << 3) - 1)
Christoph Hellwig1df84c92006-01-11 15:29:52 +110034static const char * const err_level[XFS_MAX_ERR_LEVEL+1] =
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 {KERN_EMERG, KERN_ALERT, KERN_CRIT,
36 KERN_ERR, KERN_WARNING, KERN_NOTICE,
37 KERN_INFO, KERN_DEBUG};
38
39void
Linus Torvalds1da177e2005-04-16 15:20:36 -070040cmn_err(register int level, char *fmt, ...)
41{
42 char *fp = fmt;
43 int len;
44 ulong flags;
45 va_list ap;
46
47 level &= XFS_ERR_MASK;
48 if (level > XFS_MAX_ERR_LEVEL)
49 level = XFS_MAX_ERR_LEVEL;
50 spin_lock_irqsave(&xfs_err_lock,flags);
51 va_start(ap, fmt);
52 if (*fmt == '!') fp++;
Lachlan McIlroydc74eaa2007-02-10 18:34:38 +110053 len = vsnprintf(message, sizeof(message), fp, ap);
54 if (len >= sizeof(message))
55 len = sizeof(message) - 1;
56 if (message[len-1] == '\n')
57 message[len-1] = 0;
58 printk("%s%s\n", err_level[level], message);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 va_end(ap);
60 spin_unlock_irqrestore(&xfs_err_lock,flags);
Eric Sesterhenn9ab5aa92006-10-03 23:37:55 +020061 BUG_ON(level == CE_PANIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062}
63
Linus Torvalds1da177e2005-04-16 15:20:36 -070064void
Christoph Hellwigefc55752008-12-17 12:27:36 -050065xfs_fs_vcmn_err(
66 int level,
67 struct xfs_mount *mp,
68 char *fmt,
69 va_list ap)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070{
Christoph Hellwigefc55752008-12-17 12:27:36 -050071 unsigned long flags;
72 int len = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74 level &= XFS_ERR_MASK;
Christoph Hellwigefc55752008-12-17 12:27:36 -050075 if (level > XFS_MAX_ERR_LEVEL)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 level = XFS_MAX_ERR_LEVEL;
Christoph Hellwigefc55752008-12-17 12:27:36 -050077
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 spin_lock_irqsave(&xfs_err_lock,flags);
Christoph Hellwigefc55752008-12-17 12:27:36 -050079
80 if (mp) {
81 len = sprintf(message, "Filesystem \"%s\": ", mp->m_fsname);
82
83 /*
84 * Skip the printk if we can't print anything useful
85 * due to an over-long device name.
86 */
87 if (len >= sizeof(message))
88 goto out;
89 }
90
91 len = vsnprintf(message + len, sizeof(message) - len, fmt, ap);
Lachlan McIlroydc74eaa2007-02-10 18:34:38 +110092 if (len >= sizeof(message))
93 len = sizeof(message) - 1;
94 if (message[len-1] == '\n')
95 message[len-1] = 0;
Christoph Hellwigefc55752008-12-17 12:27:36 -050096
Lachlan McIlroydc74eaa2007-02-10 18:34:38 +110097 printk("%s%s\n", err_level[level], message);
Christoph Hellwigefc55752008-12-17 12:27:36 -050098 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 spin_unlock_irqrestore(&xfs_err_lock,flags);
Christoph Hellwigefc55752008-12-17 12:27:36 -0500100
Eric Sesterhenn9ab5aa92006-10-03 23:37:55 +0200101 BUG_ON(level == CE_PANIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102}
Nathan Scott3762ec62006-01-12 10:29:53 +1100103
104void
105assfail(char *expr, char *file, int line)
106{
107 printk("Assertion failed: %s, file: %s, line: %d\n", expr, file, line);
108 BUG();
109}
Eric Sandeend4f3cc02007-10-12 11:13:08 +1000110
111void
112xfs_hex_dump(void *p, int length)
113{
Barry Naujok34519da2008-10-30 17:05:58 +1100114 print_hex_dump(KERN_ALERT, "", DUMP_PREFIX_ADDRESS, 16, 1, p, length, 1);
Eric Sandeend4f3cc02007-10-12 11:13:08 +1000115}