xfs_message.c revision 742ae1e35b038ed65ddd86182723441ea74db765
110e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner/*
210e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner * Copyright (c) 2011 Red Hat, Inc.  All Rights Reserved.
310e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner *
410e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner * This program is free software; you can redistribute it and/or
510e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner * modify it under the terms of the GNU General Public License as
610e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner * published by the Free Software Foundation.
710e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner *
810e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner * This program is distributed in the hope that it would be useful,
910e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner * but WITHOUT ANY WARRANTY; without even the implied warranty of
1010e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1110e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner * GNU General Public License for more details.
1210e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner *
1310e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner * You should have received a copy of the GNU General Public License
1410e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner * along with this program; if not, write the Free Software Foundation,
1510e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
1610e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner */
1710e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner
1810e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner#include "xfs.h"
1910e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner#include "xfs_fs.h"
2010e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner#include "xfs_types.h"
2110e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner#include "xfs_log.h"
2210e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner#include "xfs_trans.h"
2310e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner#include "xfs_sb.h"
2410e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner#include "xfs_ag.h"
2510e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner#include "xfs_mount.h"
2610e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner
2710e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner/*
2810e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner * XFS logging functions
2910e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner */
30957935dcd8e11d6f789b4ed769b376040e15565bChristoph Hellwigstatic void
3110e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner__xfs_printk(
3210e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	const char		*level,
3310e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	const struct xfs_mount	*mp,
3410e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	struct va_format	*vaf)
3510e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner{
363eff1268994f72266b660782e87f215720c29639Dave Chinner	if (mp && mp->m_fsname) {
37957935dcd8e11d6f789b4ed769b376040e15565bChristoph Hellwig		printk("%sXFS (%s): %pV\n", level, mp->m_fsname, vaf);
383eff1268994f72266b660782e87f215720c29639Dave Chinner		return;
393eff1268994f72266b660782e87f215720c29639Dave Chinner	}
40957935dcd8e11d6f789b4ed769b376040e15565bChristoph Hellwig	printk("%sXFS: %pV\n", level, vaf);
4110e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner}
4210e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner
4310e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner#define define_xfs_printk_level(func, kern_level)		\
44957935dcd8e11d6f789b4ed769b376040e15565bChristoph Hellwigvoid func(const struct xfs_mount *mp, const char *fmt, ...)	\
4510e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner{								\
4610e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	struct va_format	vaf;				\
4710e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	va_list			args;				\
4810e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner								\
4910e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	va_start(args, fmt);					\
5010e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner								\
5110e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	vaf.fmt = fmt;						\
5210e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	vaf.va = &args;						\
5310e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner								\
54957935dcd8e11d6f789b4ed769b376040e15565bChristoph Hellwig	__xfs_printk(kern_level, mp, &vaf);			\
5510e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	va_end(args);						\
5610e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner}								\
5710e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner
5810e38391c0e242e53e30094f6c00553418ab2f2eDave Chinnerdefine_xfs_printk_level(xfs_emerg, KERN_EMERG);
5910e38391c0e242e53e30094f6c00553418ab2f2eDave Chinnerdefine_xfs_printk_level(xfs_alert, KERN_ALERT);
6010e38391c0e242e53e30094f6c00553418ab2f2eDave Chinnerdefine_xfs_printk_level(xfs_crit, KERN_CRIT);
6110e38391c0e242e53e30094f6c00553418ab2f2eDave Chinnerdefine_xfs_printk_level(xfs_err, KERN_ERR);
6210e38391c0e242e53e30094f6c00553418ab2f2eDave Chinnerdefine_xfs_printk_level(xfs_warn, KERN_WARNING);
6310e38391c0e242e53e30094f6c00553418ab2f2eDave Chinnerdefine_xfs_printk_level(xfs_notice, KERN_NOTICE);
6410e38391c0e242e53e30094f6c00553418ab2f2eDave Chinnerdefine_xfs_printk_level(xfs_info, KERN_INFO);
6510e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner#ifdef DEBUG
6610e38391c0e242e53e30094f6c00553418ab2f2eDave Chinnerdefine_xfs_printk_level(xfs_debug, KERN_DEBUG);
6710e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner#endif
6810e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner
69957935dcd8e11d6f789b4ed769b376040e15565bChristoph Hellwigvoid
7010e38391c0e242e53e30094f6c00553418ab2f2eDave Chinnerxfs_alert_tag(
7110e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	const struct xfs_mount	*mp,
7210e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	int			panic_tag,
7310e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	const char		*fmt, ...)
7410e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner{
7510e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	struct va_format	vaf;
7610e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	va_list			args;
770c9ba97318fc9a905bcc1419b6966de061203a70Alex Elder	int			do_panic = 0;
7810e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner
7910e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	if (xfs_panic_mask && (xfs_panic_mask & panic_tag)) {
80e69522a8cc51fbefbfe9d178ad177f7b6ca00ebdJoe Perches		xfs_alert(mp, "Transforming an alert into a BUG.");
810c9ba97318fc9a905bcc1419b6966de061203a70Alex Elder		do_panic = 1;
8210e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	}
8310e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner
8410e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	va_start(args, fmt);
8510e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner
8610e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	vaf.fmt = fmt;
8710e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	vaf.va = &args;
8810e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner
89957935dcd8e11d6f789b4ed769b376040e15565bChristoph Hellwig	__xfs_printk(KERN_ALERT, mp, &vaf);
9010e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	va_end(args);
9110e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner
920c9ba97318fc9a905bcc1419b6966de061203a70Alex Elder	BUG_ON(do_panic);
9310e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner}
949130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinner
959130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinnervoid
96742ae1e35b038ed65ddd86182723441ea74db765Dave Chinnerasswarn(char *expr, char *file, int line)
97742ae1e35b038ed65ddd86182723441ea74db765Dave Chinner{
98742ae1e35b038ed65ddd86182723441ea74db765Dave Chinner	xfs_warn(NULL, "Assertion failed: %s, file: %s, line: %d",
99742ae1e35b038ed65ddd86182723441ea74db765Dave Chinner		expr, file, line);
100742ae1e35b038ed65ddd86182723441ea74db765Dave Chinner	WARN_ON(1);
101742ae1e35b038ed65ddd86182723441ea74db765Dave Chinner}
102742ae1e35b038ed65ddd86182723441ea74db765Dave Chinner
103742ae1e35b038ed65ddd86182723441ea74db765Dave Chinnervoid
1049130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinnerassfail(char *expr, char *file, int line)
1059130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinner{
1069130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinner	xfs_emerg(NULL, "Assertion failed: %s, file: %s, line: %d",
1079130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinner		expr, file, line);
1089130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinner	BUG();
1099130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinner}
1109130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinner
1119130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinnervoid
1129130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinnerxfs_hex_dump(void *p, int length)
1139130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinner{
1149130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinner	print_hex_dump(KERN_ALERT, "", DUMP_PREFIX_ADDRESS, 16, 1, p, length, 1);
1159130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinner}
116