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) || defined(CONFIG_JFS_STATISTICS))
34 	#define PROC_FS_JFS
35 #endif
36 
37 /*
38  *	assert with traditional printf/panic
39  */
40 #ifdef CONFIG_KERNEL_ASSERTS
41 /* kgdb stuff */
42 #define assert(p) KERNEL_ASSERT(#p, p)
43 #else
44 #define assert(p) do {	\
45 	if (!(p)) {	\
46 		printk(KERN_CRIT "BUG at %s:%d assert(%s)\n",	\
47 		       __FILE__, __LINE__, #p);			\
48 		BUG();	\
49 	}		\
50 } while (0)
51 #endif
52 
53 /*
54  *	debug ON
55  *	--------
56  */
57 #ifdef CONFIG_JFS_DEBUG
58 #define ASSERT(p) assert(p)
59 
60 /* printk verbosity */
61 #define JFS_LOGLEVEL_ERR 1
62 #define JFS_LOGLEVEL_WARN 2
63 #define JFS_LOGLEVEL_DEBUG 3
64 #define JFS_LOGLEVEL_INFO 4
65 
66 extern int jfsloglevel;
67 
68 /* dump memory contents */
69 extern void dump_mem(char *label, void *data, int length);
70 
71 /* information message: e.g., configuration, major event */
72 #define jfs_info(fmt, arg...) do {			\
73 	if (jfsloglevel >= JFS_LOGLEVEL_INFO)		\
74 		printk(KERN_INFO fmt "\n", ## arg);	\
75 } while (0)
76 
77 /* debug message: ad hoc */
78 #define jfs_debug(fmt, arg...) do {			\
79 	if (jfsloglevel >= JFS_LOGLEVEL_DEBUG)		\
80 		printk(KERN_DEBUG fmt "\n", ## arg);	\
81 } while (0)
82 
83 /* warn message: */
84 #define jfs_warn(fmt, arg...) do {			\
85 	if (jfsloglevel >= JFS_LOGLEVEL_WARN)		\
86 		printk(KERN_WARNING fmt "\n", ## arg);	\
87 } while (0)
88 
89 /* error event message: e.g., i/o error */
90 #define jfs_err(fmt, arg...) do {			\
91 	if (jfsloglevel >= JFS_LOGLEVEL_ERR)		\
92 		printk(KERN_ERR fmt "\n", ## arg);	\
93 } while (0)
94 
95 /*
96  *	debug OFF
97  *	---------
98  */
99 #else				/* CONFIG_JFS_DEBUG */
100 #define dump_mem(label,data,length) do {} while (0)
101 #define ASSERT(p) do {} while (0)
102 #define jfs_info(fmt, arg...) do {} while (0)
103 #define jfs_debug(fmt, arg...) do {} while (0)
104 #define jfs_warn(fmt, arg...) do {} while (0)
105 #define jfs_err(fmt, arg...) do {} while (0)
106 #endif				/* CONFIG_JFS_DEBUG */
107 
108 /*
109  *	statistics
110  *	----------
111  */
112 #ifdef	CONFIG_JFS_STATISTICS
113 #define	INCREMENT(x)		((x)++)
114 #define	DECREMENT(x)		((x)--)
115 #define	HIGHWATERMARK(x,y)	((x) = max((x), (y)))
116 #else
117 #define	INCREMENT(x)
118 #define	DECREMENT(x)
119 #define	HIGHWATERMARK(x,y)
120 #endif				/* CONFIG_JFS_STATISTICS */
121 
122 #endif				/* _H_JFS_DEBUG */
123