]> git.proxmox.com Git - mirror_spl-debian.git/blob - include/spl-debug.h
42da3e4e80763d3a5b43f3c6717fd0b321626eed
[mirror_spl-debian.git] / include / spl-debug.h
1 /*****************************************************************************\
2 * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
3 * Copyright (C) 2007 The Regents of the University of California.
4 * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
5 * Written by Brian Behlendorf <behlendorf1@llnl.gov>.
6 * UCRL-CODE-235197
7 *
8 * This file is part of the SPL, Solaris Porting Layer.
9 * For details, see <http://github.com/behlendorf/spl/>.
10 *
11 * The SPL is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 *
16 * The SPL is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 * for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with the SPL. If not, see <http://www.gnu.org/licenses/>.
23 \*****************************************************************************/
24
25 /*
26 * Available debug functions. These function should be used by any
27 * package which needs to integrate with the SPL log infrastructure.
28 *
29 * SDEBUG() - Log debug message with specified mask.
30 * SDEBUG_LIMIT() - Log just 1 debug message with specified mask.
31 * SWARN() - Log a warning message.
32 * SERROR() - Log an error message.
33 * SEMERG() - Log an emergency error message.
34 * SCONSOLE() - Log a generic message to the console.
35 *
36 * SENTRY - Log entry point to a function.
37 * SEXIT - Log exit point from a function.
38 * SRETURN(x) - Log return from a function.
39 * SGOTO(x, y) - Log goto within a function.
40 */
41
42 #ifndef _SPL_DEBUG_INTERNAL_H
43 #define _SPL_DEBUG_INTERNAL_H
44
45 #include <linux/limits.h>
46 #include <linux/sched.h>
47
48 #define SS_UNDEFINED 0x00000001
49 #define SS_ATOMIC 0x00000002
50 #define SS_KOBJ 0x00000004
51 #define SS_VNODE 0x00000008
52 #define SS_TIME 0x00000010
53 #define SS_RWLOCK 0x00000020
54 #define SS_THREAD 0x00000040
55 #define SS_CONDVAR 0x00000080
56 #define SS_MUTEX 0x00000100
57 #define SS_RNG 0x00000200
58 #define SS_TASKQ 0x00000400
59 #define SS_KMEM 0x00000800
60 #define SS_DEBUG 0x00001000
61 #define SS_GENERIC 0x00002000
62 #define SS_PROC 0x00004000
63 #define SS_MODULE 0x00008000
64 #define SS_CRED 0x00010000
65 #define SS_KSTAT 0x00020000
66 #define SS_XDR 0x00040000
67 #define SS_TSD 0x00080000
68 #define SS_ZLIB 0x00100000
69 #define SS_USER1 0x01000000
70 #define SS_USER2 0x02000000
71 #define SS_USER3 0x04000000
72 #define SS_USER4 0x08000000
73 #define SS_USER5 0x10000000
74 #define SS_USER6 0x20000000
75 #define SS_USER7 0x40000000
76 #define SS_USER8 0x80000000
77 #define SS_DEBUG_SUBSYS SS_UNDEFINED
78
79 #define SD_TRACE 0x00000001
80 #define SD_INFO 0x00000002
81 #define SD_WARNING 0x00000004
82 #define SD_ERROR 0x00000008
83 #define SD_EMERG 0x00000010
84 #define SD_CONSOLE 0x00000020
85 #define SD_IOCTL 0x00000040
86 #define SD_DPRINTF 0x00000080
87 #define SD_OTHER 0x00000100
88 #define SD_CANTMASK (SD_ERROR | SD_EMERG | SD_WARNING | SD_CONSOLE)
89
90 /* Debug log support enabled */
91 #ifdef DEBUG_LOG
92
93 #define __SDEBUG(cdls, subsys, mask, format, a...) \
94 do { \
95 if (((mask) & SD_CANTMASK) != 0 || \
96 ((spl_debug_mask & (mask)) != 0 && \
97 (spl_debug_subsys & (subsys)) != 0)) \
98 spl_debug_msg(cdls, subsys, mask, __FILE__, \
99 __FUNCTION__, __LINE__, format, ## a); \
100 } while (0)
101
102 #define SDEBUG(mask, format, a...) \
103 __SDEBUG(NULL, SS_DEBUG_SUBSYS, mask, format, ## a)
104
105 #define __SDEBUG_LIMIT(subsys, mask, format, a...) \
106 do { \
107 static spl_debug_limit_state_t cdls; \
108 \
109 __SDEBUG(&cdls, subsys, mask, format, ## a); \
110 } while (0)
111
112 #define SDEBUG_LIMIT(mask, format, a...) \
113 __SDEBUG_LIMIT(SS_DEBUG_SUBSYS, mask, format, ## a)
114
115 #define SWARN(fmt, a...) SDEBUG_LIMIT(SD_WARNING, fmt, ## a)
116 #define SERROR(fmt, a...) SDEBUG_LIMIT(SD_ERROR, fmt, ## a)
117 #define SEMERG(fmt, a...) SDEBUG_LIMIT(SD_EMERG, fmt, ## a)
118 #define SCONSOLE(mask, fmt, a...) SDEBUG(SD_CONSOLE | (mask), fmt, ## a)
119
120 #define SENTRY SDEBUG(SD_TRACE, "Process entered\n")
121 #define SEXIT SDEBUG(SD_TRACE, "Process leaving\n")
122
123 #define SRETURN(rc) \
124 do { \
125 typeof(rc) RETURN__ret = (rc); \
126 SDEBUG(SD_TRACE, "Process leaving (rc=%lu : %ld : %lx)\n", \
127 (long)RETURN__ret, (long)RETURN__ret, (long)RETURN__ret); \
128 return RETURN__ret; \
129 } while (0)
130
131 #define SGOTO(label, rc) \
132 do { \
133 long GOTO__ret = (long)(rc); \
134 SDEBUG(SD_TRACE,"Process leaving via %s (rc=%lu : %ld : %lx)\n",\
135 #label, (unsigned long)GOTO__ret, (signed long)GOTO__ret, \
136 (signed long)GOTO__ret); \
137 goto label; \
138 } while (0)
139
140 typedef struct {
141 unsigned long cdls_next;
142 int cdls_count;
143 long cdls_delay;
144 } spl_debug_limit_state_t;
145
146 /* Global debug variables */
147 extern unsigned long spl_debug_subsys;
148 extern unsigned long spl_debug_mask;
149 extern unsigned long spl_debug_printk;
150 extern int spl_debug_mb;
151 extern unsigned int spl_debug_binary;
152 extern unsigned int spl_debug_catastrophe;
153 extern unsigned int spl_debug_panic_on_bug;
154 extern char spl_debug_file_path[PATH_MAX];
155 extern unsigned int spl_console_ratelimit;
156 extern long spl_console_max_delay;
157 extern long spl_console_min_delay;
158 extern unsigned int spl_console_backoff;
159 extern unsigned int spl_debug_stack;
160
161 /* Exported debug functions */
162 extern int spl_debug_mask2str(char *str, int size, unsigned long mask, int ss);
163 extern int spl_debug_str2mask(unsigned long *mask, const char *str, int ss);
164 extern unsigned long spl_debug_set_mask(unsigned long mask);
165 extern unsigned long spl_debug_get_mask(void);
166 extern unsigned long spl_debug_set_subsys(unsigned long mask);
167 extern unsigned long spl_debug_get_subsys(void);
168 extern int spl_debug_set_mb(int mb);
169 extern int spl_debug_get_mb(void);
170 extern int spl_debug_dumplog(int flags);
171 extern void spl_debug_dumpstack(struct task_struct *tsk);
172 extern void spl_debug_bug(char *file, const char *fn, const int line, int fl);
173 extern int spl_debug_msg(void *arg, int subsys, int mask, const char *file,
174 const char *fn, const int line, const char *format, ...);
175 extern int spl_debug_clear_buffer(void);
176 extern int spl_debug_mark_buffer(char *text);
177
178 int spl_debug_init(void);
179 void spl_debug_fini(void);
180
181 /* Debug log support disabled */
182 #else /* DEBUG_LOG */
183
184 #define __SDEBUG(x, y, mask, fmt, a...) ((void)0)
185 #define SDEBUG(mask, fmt, a...) ((void)0)
186 #define SDEBUG_LIMIT(x, y, fmt, a...) ((void)0)
187 #define SWARN(fmt, a...) ((void)0)
188 #define SERROR(fmt, a...) ((void)0)
189 #define SEMERG(fmt, a...) ((void)0)
190 #define SCONSOLE(mask, fmt, a...) ((void)0)
191
192 #define SENTRY ((void)0)
193 #define SEXIT ((void)0)
194 #define SRETURN(x) return (x)
195 #define SGOTO(x, y) { ((void)(y)); goto x; }
196
197 static inline unsigned long
198 spl_debug_set_mask(unsigned long mask) {
199 return (0);
200 }
201
202 static inline unsigned long
203 spl_debug_get_mask(void) {
204 return (0);
205 }
206
207 static inline unsigned long
208 spl_debug_set_subsys(unsigned long mask) {
209 return (0);
210 }
211
212 static inline unsigned long
213 spl_debug_get_subsys(void) {
214 return (0);
215 }
216
217 static inline int
218 spl_debug_set_mb(int mb) {
219 return (0);
220 }
221
222 static inline int
223 spl_debug_get_mb(void) {
224 return (0);
225 }
226
227 static inline int
228 spl_debug_dumplog(int flags)
229 {
230 return (0);
231 }
232
233 static inline void
234 spl_debug_dumpstack(struct task_struct *tsk)
235 {
236 return;
237 }
238
239 static inline void
240 spl_debug_bug(char *file, const char *fn, const int line, int fl)
241 {
242 return;
243 }
244
245 static inline int
246 spl_debug_msg(void *arg, int subsys, int mask, const char *file,
247 const char *fn, const int line, const char *format, ...)
248 {
249 return (0);
250 }
251
252 static inline int
253 spl_debug_clear_buffer(void)
254 {
255 return (0);
256 }
257
258 static inline int
259 spl_debug_mark_buffer(char *text)
260 {
261 return (0);
262 }
263
264 static inline int
265 spl_debug_init(void) {
266 return (0);
267 }
268
269 static inline void
270 spl_debug_fini(void) {
271 return;
272 }
273
274 #endif /* DEBUG_LOG */
275
276 #endif /* SPL_DEBUG_INTERNAL_H */