1/*
2 *   Copyright (C) International Business Machines Corp., 2000-2002
3 *   Portions Copyright (C) Christoph Hellwig, 2001-2002
4 *
5 *   This program is free software;  you can redistribute it and/or modify
6 *   it under the terms of the GNU General Public License as published by
7 *   the Free Software Foundation; either version 2 of the License, or
8 *   (at your option) any later version.
9 *
10 *   This program is distributed in the hope that it will be useful,
11 *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
12 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13 *   the GNU General Public License for more details.
14 *
15 *   You should have received a copy of the GNU General Public License
16 *   along with this program;  if not, write to the Free Software
17 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19#ifndef _H_JFS_DEBUG
20#define _H_JFS_DEBUG
21
22/*
23 *	jfs_debug.h
24 *
25 * global debug message, data structure/macro definitions
26 * under control of CONFIG_JFS_DEBUG, CONFIG_JFS_STATISTICS;
27 */
28
29/*
30 * Create /proc/fs/jfs if procfs is enabled andeither
31 * CONFIG_JFS_DEBUG or CONFIG_JFS_STATISTICS is defined
32 */
33#if defined(CONFIG_PROC_FS) && (defined(CONFIG_JFS_DEBUG) || \
34	defined(CONFIG_JFS_STATISTICS))
35#define PROC_FS_JFS
36extern void jfs_proc_init(void);
37extern void jfs_proc_clean(void);
38#endif
39
40/*
41 *	assert with traditional printf/panic
42 */
43#define assert(p) do {	\
44	if (!(p)) {	\
45		printk(KERN_CRIT "BUG at %s:%d assert(%s)\n",	\
46		       __FILE__, __LINE__, #p);			\
47		BUG();	\
48	}		\
49} while (0)
50
51/*
52 *	debug ON
53 *	--------
54 */
55#ifdef CONFIG_JFS_DEBUG
56#define ASSERT(p) assert(p)
57
58/* printk verbosity */
59#define JFS_LOGLEVEL_ERR 1
60#define JFS_LOGLEVEL_WARN 2
61#define JFS_LOGLEVEL_DEBUG 3
62#define JFS_LOGLEVEL_INFO 4
63
64extern int jfsloglevel;
65
66extern void dump_mem(char *label, void *data, int length);
67extern int jfs_txanchor_read(char *, char **, off_t, int, int *, void *);
68
69/* information message: e.g., configuration, major event */
70#define jfs_info(fmt, arg...) do {			\
71	if (jfsloglevel >= JFS_LOGLEVEL_INFO)		\
72		printk(KERN_INFO fmt "\n", ## arg);	\
73} while (0)
74
75/* debug message: ad hoc */
76#define jfs_debug(fmt, arg...) do {			\
77	if (jfsloglevel >= JFS_LOGLEVEL_DEBUG)		\
78		printk(KERN_DEBUG fmt "\n", ## arg);	\
79} while (0)
80
81/* warn message: */
82#define jfs_warn(fmt, arg...) do {			\
83	if (jfsloglevel >= JFS_LOGLEVEL_WARN)		\
84		printk(KERN_WARNING fmt "\n", ## arg);	\
85} while (0)
86
87/* error event message: e.g., i/o error */
88#define jfs_err(fmt, arg...) do {			\
89	if (jfsloglevel >= JFS_LOGLEVEL_ERR)		\
90		printk(KERN_ERR fmt "\n", ## arg);	\
91} while (0)
92
93/*
94 *	debug OFF
95 *	---------
96 */
97#else				/* CONFIG_JFS_DEBUG */
98#define dump_mem(label,data,length) do {} while (0)
99#define ASSERT(p) do {} while (0)
100#define jfs_info(fmt, arg...) do {} while (0)
101#define jfs_debug(fmt, arg...) do {} while (0)
102#define jfs_warn(fmt, arg...) do {} while (0)
103#define jfs_err(fmt, arg...) do {} while (0)
104#endif				/* CONFIG_JFS_DEBUG */
105
106/*
107 *	statistics
108 *	----------
109 */
110#ifdef	CONFIG_JFS_STATISTICS
111extern int jfs_lmstats_read(char *, char **, off_t, int, int *, void *);
112extern int jfs_txstats_read(char *, char **, off_t, int, int *, void *);
113extern int jfs_mpstat_read(char *, char **, off_t, int, int *, void *);
114extern int jfs_xtstat_read(char *, char **, off_t, int, int *, void *);
115
116#define	INCREMENT(x)		((x)++)
117#define	DECREMENT(x)		((x)--)
118#define	HIGHWATERMARK(x,y)	((x) = max((x), (y)))
119#else
120#define	INCREMENT(x)
121#define	DECREMENT(x)
122#define	HIGHWATERMARK(x,y)
123#endif				/* CONFIG_JFS_STATISTICS */
124
125#endif				/* _H_JFS_DEBUG */
126