xfs_message.c revision 3eff1268994f72266b660782e87f215720c29639
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_inum.h"
2310e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner#include "xfs_trans.h"
2410e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner#include "xfs_sb.h"
2510e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner#include "xfs_ag.h"
2610e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner#include "xfs_mount.h"
2710e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner
2810e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner/*
2910e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner * XFS logging functions
3010e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner */
31957935dcd8e11d6f789b4ed769b376040e15565bChristoph Hellwigstatic void
3210e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner__xfs_printk(
3310e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	const char		*level,
3410e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	const struct xfs_mount	*mp,
3510e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	struct va_format	*vaf)
3610e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner{
373eff1268994f72266b660782e87f215720c29639Dave Chinner	if (mp && mp->m_fsname) {
38957935dcd8e11d6f789b4ed769b376040e15565bChristoph Hellwig		printk("%sXFS (%s): %pV\n", level, mp->m_fsname, vaf);
393eff1268994f72266b660782e87f215720c29639Dave Chinner		return;
403eff1268994f72266b660782e87f215720c29639Dave Chinner	}
41957935dcd8e11d6f789b4ed769b376040e15565bChristoph Hellwig	printk("%sXFS: %pV\n", level, vaf);
4210e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner}
4310e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner
44957935dcd8e11d6f789b4ed769b376040e15565bChristoph Hellwigvoid xfs_printk(
4510e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	const char		*level,
4610e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	const struct xfs_mount	*mp,
4710e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	const char		*fmt, ...)
4810e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner{
4910e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	struct va_format	vaf;
5010e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	va_list			args;
5110e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner
5210e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	va_start(args, fmt);
5310e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner
5410e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	vaf.fmt = fmt;
5510e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	vaf.va = &args;
5610e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner
57957935dcd8e11d6f789b4ed769b376040e15565bChristoph Hellwig	__xfs_printk(level, mp, &vaf);
5810e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	va_end(args);
5910e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner}
6010e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner
6110e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner#define define_xfs_printk_level(func, kern_level)		\
62957935dcd8e11d6f789b4ed769b376040e15565bChristoph Hellwigvoid func(const struct xfs_mount *mp, const char *fmt, ...)	\
6310e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner{								\
6410e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	struct va_format	vaf;				\
6510e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	va_list			args;				\
6610e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner								\
6710e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	va_start(args, fmt);					\
6810e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner								\
6910e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	vaf.fmt = fmt;						\
7010e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	vaf.va = &args;						\
7110e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner								\
72957935dcd8e11d6f789b4ed769b376040e15565bChristoph Hellwig	__xfs_printk(kern_level, mp, &vaf);			\
7310e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	va_end(args);						\
7410e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner}								\
7510e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner
7610e38391c0e242e53e30094f6c00553418ab2f2eDave Chinnerdefine_xfs_printk_level(xfs_emerg, KERN_EMERG);
7710e38391c0e242e53e30094f6c00553418ab2f2eDave Chinnerdefine_xfs_printk_level(xfs_alert, KERN_ALERT);
7810e38391c0e242e53e30094f6c00553418ab2f2eDave Chinnerdefine_xfs_printk_level(xfs_crit, KERN_CRIT);
7910e38391c0e242e53e30094f6c00553418ab2f2eDave Chinnerdefine_xfs_printk_level(xfs_err, KERN_ERR);
8010e38391c0e242e53e30094f6c00553418ab2f2eDave Chinnerdefine_xfs_printk_level(xfs_warn, KERN_WARNING);
8110e38391c0e242e53e30094f6c00553418ab2f2eDave Chinnerdefine_xfs_printk_level(xfs_notice, KERN_NOTICE);
8210e38391c0e242e53e30094f6c00553418ab2f2eDave Chinnerdefine_xfs_printk_level(xfs_info, KERN_INFO);
8310e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner#ifdef DEBUG
8410e38391c0e242e53e30094f6c00553418ab2f2eDave Chinnerdefine_xfs_printk_level(xfs_debug, KERN_DEBUG);
8510e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner#endif
8610e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner
87957935dcd8e11d6f789b4ed769b376040e15565bChristoph Hellwigvoid
8810e38391c0e242e53e30094f6c00553418ab2f2eDave Chinnerxfs_alert_tag(
8910e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	const struct xfs_mount	*mp,
9010e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	int			panic_tag,
9110e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	const char		*fmt, ...)
9210e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner{
9310e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	struct va_format	vaf;
9410e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	va_list			args;
950c9ba97318fc9a905bcc1419b6966de061203a70Alex Elder	int			do_panic = 0;
9610e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner
9710e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	if (xfs_panic_mask && (xfs_panic_mask & panic_tag)) {
9810e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner		xfs_printk(KERN_ALERT, mp,
9910e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner			"XFS: Transforming an alert into a BUG.");
1000c9ba97318fc9a905bcc1419b6966de061203a70Alex Elder		do_panic = 1;
10110e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	}
10210e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner
10310e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	va_start(args, fmt);
10410e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner
10510e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	vaf.fmt = fmt;
10610e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	vaf.va = &args;
10710e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner
108957935dcd8e11d6f789b4ed769b376040e15565bChristoph Hellwig	__xfs_printk(KERN_ALERT, mp, &vaf);
10910e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner	va_end(args);
11010e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner
1110c9ba97318fc9a905bcc1419b6966de061203a70Alex Elder	BUG_ON(do_panic);
11210e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner}
1139130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinner
1149130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinnervoid
1159130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinnerassfail(char *expr, char *file, int line)
1169130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinner{
1179130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinner	xfs_emerg(NULL, "Assertion failed: %s, file: %s, line: %d",
1189130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinner		expr, file, line);
1199130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinner	BUG();
1209130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinner}
1219130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinner
1229130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinnervoid
1239130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinnerxfs_hex_dump(void *p, int length)
1249130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinner{
1259130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinner	print_hex_dump(KERN_ALERT, "", DUMP_PREFIX_ADDRESS, 16, 1, p, length, 1);
1269130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinner}
127