]> git.proxmox.com Git - mirror_spl-debian.git/blob - include/spl-debug.h
Clear owner after dropping mutex
[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
47 #define SS_UNDEFINED 0x00000001
48 #define SS_ATOMIC 0x00000002
49 #define SS_KOBJ 0x00000004
50 #define SS_VNODE 0x00000008
51 #define SS_TIME 0x00000010
52 #define SS_RWLOCK 0x00000020
53 #define SS_THREAD 0x00000040
54 #define SS_CONDVAR 0x00000080
55 #define SS_MUTEX 0x00000100
56 #define SS_RNG 0x00000200
57 #define SS_TASKQ 0x00000400
58 #define SS_KMEM 0x00000800
59 #define SS_DEBUG 0x00001000
60 #define SS_GENERIC 0x00002000
61 #define SS_PROC 0x00004000
62 #define SS_MODULE 0x00008000
63 #define SS_CRED 0x00010000
64 #define SS_KSTAT 0x00020000
65 #define SS_XDR 0x00040000
66 #define SS_USER1 0x01000000
67 #define SS_USER2 0x02000000
68 #define SS_USER3 0x04000000
69 #define SS_USER4 0x08000000
70 #define SS_USER5 0x10000000
71 #define SS_USER6 0x20000000
72 #define SS_USER7 0x40000000
73 #define SS_USER8 0x80000000
74 #define SS_DEBUG_SUBSYS SS_UNDEFINED
75
76 #define SD_TRACE 0x00000001
77 #define SD_INFO 0x00000002
78 #define SD_WARNING 0x00000004
79 #define SD_ERROR 0x00000008
80 #define SD_EMERG 0x00000010
81 #define SD_CONSOLE 0x00000020
82 #define SD_IOCTL 0x00000040
83 #define SD_DPRINTF 0x00000080
84 #define SD_OTHER 0x00000100
85 #define SD_CANTMASK (SD_ERROR | SD_EMERG | SD_WARNING | SD_CONSOLE)
86
87 #ifdef NDEBUG /* Debugging Disabled */
88
89 #define SDEBUG(mask, fmt, a...) ((void)0)
90 #define SDEBUG_LIMIT(x, y, fmt, a...) ((void)0)
91 #define SWARN(fmt, a...) ((void)0)
92 #define SERROR(fmt, a...) ((void)0)
93 #define SEMERG(fmt, a...) ((void)0)
94 #define SCONSOLE(mask, fmt, a...) ((void)0)
95
96 #define SENTRY ((void)0)
97 #define SEXIT ((void)0)
98 #define SRETURN(x) return (x)
99 #define SGOTO(x, y) { ((void)(y)); goto x; }
100
101 #else /* Debugging Enabled */
102
103 #define __SDEBUG(cdls, subsys, mask, format, a...) \
104 do { \
105 if (((mask) & SD_CANTMASK) != 0 || \
106 ((spl_debug_mask & (mask)) != 0 && \
107 (spl_debug_subsys & (subsys)) != 0)) \
108 spl_debug_msg(cdls, subsys, mask, __FILE__, \
109 __FUNCTION__, __LINE__, format, ## a); \
110 } while (0)
111
112 #define SDEBUG(mask, format, a...) \
113 __SDEBUG(NULL, SS_DEBUG_SUBSYS, mask, format, ## a)
114
115 #define __SDEBUG_LIMIT(subsys, mask, format, a...) \
116 do { \
117 static spl_debug_limit_state_t cdls; \
118 \
119 __SDEBUG(&cdls, subsys, mask, format, ## a); \
120 } while (0)
121
122 #define SDEBUG_LIMIT(mask, format, a...) \
123 __SDEBUG_LIMIT(SS_DEBUG_SUBSYS, mask, format, ## a)
124
125 #define SWARN(fmt, a...) SDEBUG_LIMIT(SD_WARNING, fmt, ## a)
126 #define SERROR(fmt, a...) SDEBUG_LIMIT(SD_ERROR, fmt, ## a)
127 #define SEMERG(fmt, a...) SDEBUG_LIMIT(SD_EMERG, fmt, ## a)
128 #define SCONSOLE(mask, fmt, a...) SDEBUG(SD_CONSOLE | (mask), fmt, ## a)
129
130 #define SENTRY SDEBUG(SD_TRACE, "Process entered\n")
131 #define SEXIT SDEBUG(SD_TRACE, "Process leaving\n")
132
133 #define SRETURN(rc) \
134 do { \
135 typeof(rc) RETURN__ret = (rc); \
136 SDEBUG(SD_TRACE, "Process leaving (rc=%lu : %ld : %lx)\n", \
137 (long)RETURN__ret, (long)RETURN__ret, (long)RETURN__ret); \
138 return RETURN__ret; \
139 } while (0)
140
141 #define SGOTO(label, rc) \
142 do { \
143 long GOTO__ret = (long)(rc); \
144 SDEBUG(SD_TRACE,"Process leaving via %s (rc=%lu : %ld : %lx)\n",\
145 #label, (unsigned long)GOTO__ret, (signed long)GOTO__ret, \
146 (signed long)GOTO__ret); \
147 goto label; \
148 } while (0)
149
150 #endif /* NDEBUG */
151
152 typedef struct {
153 unsigned long cdls_next;
154 int cdls_count;
155 long cdls_delay;
156 } spl_debug_limit_state_t;
157
158 /* Global debug variables */
159 extern unsigned long spl_debug_subsys;
160 extern unsigned long spl_debug_mask;
161 extern unsigned long spl_debug_printk;
162 extern int spl_debug_mb;
163 extern unsigned int spl_debug_binary;
164 extern unsigned int spl_debug_catastrophe;
165 extern unsigned int spl_debug_panic_on_bug;
166 extern char spl_debug_file_path[PATH_MAX];
167 extern unsigned int spl_console_ratelimit;
168 extern long spl_console_max_delay;
169 extern long spl_console_min_delay;
170 extern unsigned int spl_console_backoff;
171 extern unsigned int spl_debug_stack;
172
173 /* Exported debug functions */
174 extern int spl_debug_mask2str(char *str, int size, unsigned long mask, int ss);
175 extern int spl_debug_str2mask(unsigned long *mask, const char *str, int ss);
176 extern unsigned long spl_debug_set_mask(unsigned long mask);
177 extern unsigned long spl_debug_get_mask(void);
178 extern unsigned long spl_debug_set_subsys(unsigned long mask);
179 extern unsigned long spl_debug_get_subsys(void);
180 extern int spl_debug_set_mb(int mb);
181 extern int spl_debug_get_mb(void);
182 extern int spl_debug_dumplog(int flags);
183 extern void spl_debug_dumpstack(struct task_struct *tsk);
184 extern int spl_debug_clear_buffer(void);
185 extern int spl_debug_mark_buffer(char *text);
186
187 int debug_init(void);
188 void debug_fini(void);
189
190 #endif /* SPL_DEBUG_INTERNAL_H */