]> git.proxmox.com Git - mirror_spl.git/blame - include/spl-debug.h
Add atomic_swap_32() and atomic_swap_64()
[mirror_spl.git] / include / spl-debug.h
CommitLineData
55abb092
BB
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.
3d6af2dd 9 * For details, see <http://zfsonlinux.org/>.
55abb092
BB
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 *
b17edc10
BB
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.
55abb092 35 *
b17edc10
BB
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.
55abb092
BB
40 */
41
42#ifndef _SPL_DEBUG_INTERNAL_H
43#define _SPL_DEBUG_INTERNAL_H
44
45#include <linux/limits.h>
4b2220f0 46#include <linux/sched.h>
55abb092 47
b17edc10
BB
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
9fe45dc1 67#define SS_TSD 0x00080000
5c1967eb 68#define SS_ZLIB 0x00100000
b17edc10
BB
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)
55abb092 89
4b2220f0
BB
90/* Debug log support enabled */
91#ifdef DEBUG_LOG
55abb092 92
b17edc10 93#define __SDEBUG(cdls, subsys, mask, format, a...) \
55abb092 94do { \
b17edc10 95 if (((mask) & SD_CANTMASK) != 0 || \
55abb092
BB
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
b17edc10
BB
102#define SDEBUG(mask, format, a...) \
103 __SDEBUG(NULL, SS_DEBUG_SUBSYS, mask, format, ## a)
55abb092 104
b17edc10 105#define __SDEBUG_LIMIT(subsys, mask, format, a...) \
55abb092
BB
106do { \
107 static spl_debug_limit_state_t cdls; \
108 \
b17edc10 109 __SDEBUG(&cdls, subsys, mask, format, ## a); \
55abb092
BB
110} while (0)
111
b17edc10
BB
112#define SDEBUG_LIMIT(mask, format, a...) \
113 __SDEBUG_LIMIT(SS_DEBUG_SUBSYS, mask, format, ## a)
55abb092 114
b17edc10
BB
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)
55abb092 119
b17edc10
BB
120#define SENTRY SDEBUG(SD_TRACE, "Process entered\n")
121#define SEXIT SDEBUG(SD_TRACE, "Process leaving\n")
55abb092 122
b17edc10 123#define SRETURN(rc) \
55abb092
BB
124do { \
125 typeof(rc) RETURN__ret = (rc); \
b17edc10 126 SDEBUG(SD_TRACE, "Process leaving (rc=%lu : %ld : %lx)\n", \
55abb092
BB
127 (long)RETURN__ret, (long)RETURN__ret, (long)RETURN__ret); \
128 return RETURN__ret; \
129} while (0)
130
b17edc10 131#define SGOTO(label, rc) \
55abb092
BB
132do { \
133 long GOTO__ret = (long)(rc); \
b17edc10 134 SDEBUG(SD_TRACE,"Process leaving via %s (rc=%lu : %ld : %lx)\n",\
55abb092
BB
135 #label, (unsigned long)GOTO__ret, (signed long)GOTO__ret, \
136 (signed long)GOTO__ret); \
137 goto label; \
138} while (0)
139
55abb092
BB
140typedef 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 */
147extern unsigned long spl_debug_subsys;
148extern unsigned long spl_debug_mask;
149extern unsigned long spl_debug_printk;
150extern int spl_debug_mb;
151extern unsigned int spl_debug_binary;
152extern unsigned int spl_debug_catastrophe;
153extern unsigned int spl_debug_panic_on_bug;
154extern char spl_debug_file_path[PATH_MAX];
155extern unsigned int spl_console_ratelimit;
156extern long spl_console_max_delay;
157extern long spl_console_min_delay;
158extern unsigned int spl_console_backoff;
159extern unsigned int spl_debug_stack;
160
161/* Exported debug functions */
162extern int spl_debug_mask2str(char *str, int size, unsigned long mask, int ss);
163extern int spl_debug_str2mask(unsigned long *mask, const char *str, int ss);
164extern unsigned long spl_debug_set_mask(unsigned long mask);
165extern unsigned long spl_debug_get_mask(void);
166extern unsigned long spl_debug_set_subsys(unsigned long mask);
167extern unsigned long spl_debug_get_subsys(void);
168extern int spl_debug_set_mb(int mb);
169extern int spl_debug_get_mb(void);
170extern int spl_debug_dumplog(int flags);
171extern void spl_debug_dumpstack(struct task_struct *tsk);
4b2220f0
BB
172extern void spl_debug_bug(char *file, const char *fn, const int line, int fl);
173extern int spl_debug_msg(void *arg, int subsys, int mask, const char *file,
174 const char *fn, const int line, const char *format, ...);
55abb092
BB
175extern int spl_debug_clear_buffer(void);
176extern int spl_debug_mark_buffer(char *text);
177
1114ae6a
BB
178int spl_debug_init(void);
179void spl_debug_fini(void);
55abb092 180
4b2220f0
BB
181/* Debug log support disabled */
182#else /* DEBUG_LOG */
183
feedc436 184#define __SDEBUG(x, y, mask, fmt, a...) ((void)0)
4b2220f0
BB
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
feedc436
BB
197static inline unsigned long
198spl_debug_set_mask(unsigned long mask) {
199 return (0);
200}
201
202static inline unsigned long
203spl_debug_get_mask(void) {
204 return (0);
205}
206
207static inline unsigned long
208spl_debug_set_subsys(unsigned long mask) {
209 return (0);
210}
211
212static inline unsigned long
213spl_debug_get_subsys(void) {
214 return (0);
215}
216
217static inline int
218spl_debug_set_mb(int mb) {
219 return (0);
220}
221
222static inline int
223spl_debug_get_mb(void) {
224 return (0);
225}
226
227static inline int
228spl_debug_dumplog(int flags)
229{
230 return (0);
231}
232
233static inline void
234spl_debug_dumpstack(struct task_struct *tsk)
235{
236 return;
237}
4b2220f0
BB
238
239static inline void
240spl_debug_bug(char *file, const char *fn, const int line, int fl)
241{
242 return;
243}
244
245static inline int
246spl_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
feedc436
BB
252static inline int
253spl_debug_clear_buffer(void)
254{
255 return (0);
256}
257
258static inline int
259spl_debug_mark_buffer(char *text)
260{
261 return (0);
262}
263
264static inline int
265spl_debug_init(void) {
266 return (0);
267}
268
269static inline void
270spl_debug_fini(void) {
271 return;
272}
273
4b2220f0
BB
274#endif /* DEBUG_LOG */
275
55abb092 276#endif /* SPL_DEBUG_INTERNAL_H */