]>
Commit | Line | Data |
---|---|---|
d7e09d03 PT |
1 | /* |
2 | * GPL HEADER START | |
3 | * | |
4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License version 2 only, | |
8 | * as published by the Free Software Foundation. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but | |
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * General Public License version 2 for more details (a copy is included | |
14 | * in the LICENSE file that accompanied this code). | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * version 2 along with this program; If not, see | |
18 | * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf | |
19 | * | |
20 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
21 | * CA 95054 USA or visit www.sun.com if you need additional information or | |
22 | * have any questions. | |
23 | * | |
24 | * GPL HEADER END | |
25 | */ | |
26 | /* | |
27 | * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. | |
28 | * Use is subject to license terms. | |
29 | * | |
30 | * Copyright (c) 2012, Intel Corporation. | |
31 | */ | |
32 | /* | |
33 | * This file is part of Lustre, http://www.lustre.org/ | |
34 | * Lustre is a trademark of Sun Microsystems, Inc. | |
35 | * | |
36 | * libcfs/include/libcfs/libcfs_debug.h | |
37 | * | |
38 | * Debug messages and assertions | |
39 | * | |
40 | */ | |
41 | ||
42 | #ifndef __LIBCFS_DEBUG_H__ | |
43 | #define __LIBCFS_DEBUG_H__ | |
44 | ||
45 | /* | |
46 | * Debugging | |
47 | */ | |
48 | extern unsigned int libcfs_subsystem_debug; | |
49 | extern unsigned int libcfs_stack; | |
50 | extern unsigned int libcfs_debug; | |
51 | extern unsigned int libcfs_printk; | |
52 | extern unsigned int libcfs_console_ratelimit; | |
d7e09d03 PT |
53 | extern unsigned int libcfs_console_max_delay; |
54 | extern unsigned int libcfs_console_min_delay; | |
55 | extern unsigned int libcfs_console_backoff; | |
56 | extern unsigned int libcfs_debug_binary; | |
57 | extern char libcfs_debug_file_path_arr[PATH_MAX]; | |
58 | ||
59 | int libcfs_debug_mask2str(char *str, int size, int mask, int is_subsys); | |
60 | int libcfs_debug_str2mask(int *mask, const char *str, int is_subsys); | |
61 | ||
62 | /* Has there been an LBUG? */ | |
63 | extern unsigned int libcfs_catastrophe; | |
64 | extern unsigned int libcfs_panic_on_lbug; | |
65 | ||
66 | /** | |
67 | * Format for debug message headers | |
68 | */ | |
69 | struct ptldebug_header { | |
70 | __u32 ph_len; | |
71 | __u32 ph_flags; | |
72 | __u32 ph_subsys; | |
73 | __u32 ph_mask; | |
74 | __u16 ph_cpu_id; | |
75 | __u16 ph_type; | |
76 | __u32 ph_sec; | |
77 | __u64 ph_usec; | |
78 | __u32 ph_stack; | |
79 | __u32 ph_pid; | |
80 | __u32 ph_extern_pid; | |
81 | __u32 ph_line_num; | |
fd917652 | 82 | } __packed; |
d7e09d03 | 83 | |
d7e09d03 PT |
84 | #define PH_FLAG_FIRST_RECORD 1 |
85 | ||
86 | /* Debugging subsystems (32 bits, non-overlapping) */ | |
87 | /* keep these in sync with lnet/utils/debug.c and lnet/libcfs/debug.c */ | |
5b50eeff SS |
88 | #define S_UNDEFINED 0x00000001 |
89 | #define S_MDC 0x00000002 | |
90 | #define S_MDS 0x00000004 | |
91 | #define S_OSC 0x00000008 | |
92 | #define S_OST 0x00000010 | |
93 | #define S_CLASS 0x00000020 | |
94 | #define S_LOG 0x00000040 | |
95 | #define S_LLITE 0x00000080 | |
96 | #define S_RPC 0x00000100 | |
97 | #define S_MGMT 0x00000200 | |
98 | #define S_LNET 0x00000400 | |
99 | #define S_LND 0x00000800 /* ALL LNDs */ | |
100 | #define S_PINGER 0x00001000 | |
101 | #define S_FILTER 0x00002000 | |
d7e09d03 | 102 | /* unused */ |
5b50eeff SS |
103 | #define S_ECHO 0x00008000 |
104 | #define S_LDLM 0x00010000 | |
105 | #define S_LOV 0x00020000 | |
106 | #define S_LQUOTA 0x00040000 | |
d7e09d03 PT |
107 | #define S_OSD 0x00080000 |
108 | /* unused */ | |
109 | /* unused */ | |
110 | /* unused */ | |
5b50eeff | 111 | #define S_LMV 0x00800000 /* b_new_cmd */ |
d7e09d03 | 112 | /* unused */ |
5b50eeff SS |
113 | #define S_SEC 0x02000000 /* upcall cache */ |
114 | #define S_GSS 0x04000000 /* b_new_cmd */ | |
d7e09d03 | 115 | /* unused */ |
5b50eeff SS |
116 | #define S_MGC 0x10000000 |
117 | #define S_MGS 0x20000000 | |
118 | #define S_FID 0x40000000 /* b_new_cmd */ | |
119 | #define S_FLD 0x80000000 /* b_new_cmd */ | |
d7e09d03 PT |
120 | /* keep these in sync with lnet/utils/debug.c and lnet/libcfs/debug.c */ |
121 | ||
122 | /* Debugging masks (32 bits, non-overlapping) */ | |
123 | /* keep these in sync with lnet/utils/debug.c and lnet/libcfs/debug.c */ | |
5b50eeff SS |
124 | #define D_TRACE 0x00000001 /* ENTRY/EXIT markers */ |
125 | #define D_INODE 0x00000002 | |
126 | #define D_SUPER 0x00000004 | |
127 | #define D_EXT2 0x00000008 /* anything from ext2_debug */ | |
128 | #define D_MALLOC 0x00000010 /* print malloc, free information */ | |
129 | #define D_CACHE 0x00000020 /* cache-related items */ | |
130 | #define D_INFO 0x00000040 /* general information */ | |
131 | #define D_IOCTL 0x00000080 /* ioctl related information */ | |
132 | #define D_NETERROR 0x00000100 /* network errors */ | |
133 | #define D_NET 0x00000200 /* network communications */ | |
134 | #define D_WARNING 0x00000400 /* CWARN(...) == CDEBUG (D_WARNING, ...) */ | |
135 | #define D_BUFFS 0x00000800 | |
136 | #define D_OTHER 0x00001000 | |
137 | #define D_DENTRY 0x00002000 | |
138 | #define D_NETTRACE 0x00004000 | |
139 | #define D_PAGE 0x00008000 /* bulk page handling */ | |
140 | #define D_DLMTRACE 0x00010000 | |
141 | #define D_ERROR 0x00020000 /* CERROR(...) == CDEBUG (D_ERROR, ...) */ | |
142 | #define D_EMERG 0x00040000 /* CEMERG(...) == CDEBUG (D_EMERG, ...) */ | |
143 | #define D_HA 0x00080000 /* recovery and failover */ | |
144 | #define D_RPCTRACE 0x00100000 /* for distributed debugging */ | |
145 | #define D_VFSTRACE 0x00200000 | |
146 | #define D_READA 0x00400000 /* read-ahead */ | |
147 | #define D_MMAP 0x00800000 | |
148 | #define D_CONFIG 0x01000000 | |
149 | #define D_CONSOLE 0x02000000 | |
150 | #define D_QUOTA 0x04000000 | |
151 | #define D_SEC 0x08000000 | |
152 | #define D_LFSCK 0x10000000 /* For both OI scrub and LFSCK */ | |
d7e09d03 PT |
153 | /* keep these in sync with lnet/{utils,libcfs}/debug.c */ |
154 | ||
155 | #define D_HSM D_TRACE | |
156 | ||
157 | #define D_CANTMASK (D_ERROR | D_EMERG | D_WARNING | D_CONSOLE) | |
158 | ||
159 | #ifndef DEBUG_SUBSYSTEM | |
160 | # define DEBUG_SUBSYSTEM S_UNDEFINED | |
161 | #endif | |
162 | ||
163 | #define CDEBUG_DEFAULT_MAX_DELAY (cfs_time_seconds(600)) /* jiffies */ | |
164 | #define CDEBUG_DEFAULT_MIN_DELAY ((cfs_time_seconds(1) + 1) / 2) /* jiffies */ | |
165 | #define CDEBUG_DEFAULT_BACKOFF 2 | |
a3ea59e0 | 166 | struct cfs_debug_limit_state { |
a649ad1d | 167 | unsigned long cdls_next; |
1c4738c3 | 168 | unsigned int cdls_delay; |
d7e09d03 | 169 | int cdls_count; |
a3ea59e0 | 170 | }; |
d7e09d03 PT |
171 | |
172 | struct libcfs_debug_msg_data { | |
1c4738c3 SS |
173 | const char *msg_file; |
174 | const char *msg_fn; | |
175 | int msg_subsys; | |
176 | int msg_line; | |
177 | int msg_mask; | |
178 | struct cfs_debug_limit_state *msg_cdls; | |
d7e09d03 PT |
179 | }; |
180 | ||
924a9f94 SS |
181 | #define LIBCFS_DEBUG_MSG_DATA_INIT(data, mask, cdls) \ |
182 | do { \ | |
183 | (data)->msg_subsys = DEBUG_SUBSYSTEM; \ | |
184 | (data)->msg_file = __FILE__; \ | |
f9bd9c1a | 185 | (data)->msg_fn = __func__; \ |
924a9f94 SS |
186 | (data)->msg_line = __LINE__; \ |
187 | (data)->msg_cdls = (cdls); \ | |
188 | (data)->msg_mask = (mask); \ | |
d7e09d03 PT |
189 | } while (0) |
190 | ||
924a9f94 SS |
191 | #define LIBCFS_DEBUG_MSG_DATA_DECL(dataname, mask, cdls) \ |
192 | static struct libcfs_debug_msg_data dataname = { \ | |
193 | .msg_subsys = DEBUG_SUBSYSTEM, \ | |
194 | .msg_file = __FILE__, \ | |
f9bd9c1a | 195 | .msg_fn = __func__, \ |
924a9f94 SS |
196 | .msg_line = __LINE__, \ |
197 | .msg_cdls = (cdls) }; \ | |
06133e80 | 198 | dataname.msg_mask = (mask) |
d7e09d03 | 199 | |
d7e09d03 PT |
200 | /** |
201 | * Filters out logging messages based on mask and subsystem. | |
202 | */ | |
203 | static inline int cfs_cdebug_show(unsigned int mask, unsigned int subsystem) | |
204 | { | |
205 | return mask & D_CANTMASK || | |
206 | ((libcfs_debug & mask) && (libcfs_subsystem_debug & subsystem)); | |
207 | } | |
208 | ||
924a9f94 SS |
209 | #define __CDEBUG(cdls, mask, format, ...) \ |
210 | do { \ | |
211 | static struct libcfs_debug_msg_data msgdata; \ | |
d7e09d03 | 212 | \ |
924a9f94 | 213 | CFS_CHECK_STACK(&msgdata, mask, cdls); \ |
d7e09d03 | 214 | \ |
924a9f94 SS |
215 | if (cfs_cdebug_show(mask, DEBUG_SUBSYSTEM)) { \ |
216 | LIBCFS_DEBUG_MSG_DATA_INIT(&msgdata, mask, cdls); \ | |
217 | libcfs_debug_msg(&msgdata, format, ## __VA_ARGS__); \ | |
218 | } \ | |
d7e09d03 PT |
219 | } while (0) |
220 | ||
221 | #define CDEBUG(mask, format, ...) __CDEBUG(NULL, mask, format, ## __VA_ARGS__) | |
222 | ||
924a9f94 SS |
223 | #define CDEBUG_LIMIT(mask, format, ...) \ |
224 | do { \ | |
225 | static struct cfs_debug_limit_state cdls; \ | |
226 | \ | |
227 | __CDEBUG(&cdls, mask, format, ## __VA_ARGS__); \ | |
d7e09d03 PT |
228 | } while (0) |
229 | ||
1c4738c3 SS |
230 | #define CWARN(format, ...) CDEBUG_LIMIT(D_WARNING, format, ## __VA_ARGS__) |
231 | #define CERROR(format, ...) CDEBUG_LIMIT(D_ERROR, format, ## __VA_ARGS__) | |
232 | #define CNETERR(format, a...) CDEBUG_LIMIT(D_NETERROR, format, ## a) | |
233 | #define CEMERG(format, ...) CDEBUG_LIMIT(D_EMERG, format, ## __VA_ARGS__) | |
d7e09d03 PT |
234 | |
235 | #define LCONSOLE(mask, format, ...) CDEBUG(D_CONSOLE | (mask), format, ## __VA_ARGS__) | |
236 | #define LCONSOLE_INFO(format, ...) CDEBUG_LIMIT(D_CONSOLE, format, ## __VA_ARGS__) | |
237 | #define LCONSOLE_WARN(format, ...) CDEBUG_LIMIT(D_CONSOLE | D_WARNING, format, ## __VA_ARGS__) | |
238 | #define LCONSOLE_ERROR_MSG(errnum, format, ...) CDEBUG_LIMIT(D_CONSOLE | D_ERROR, \ | |
239 | "%x-%x: " format, errnum, LERRCHKSUM(errnum), ## __VA_ARGS__) | |
240 | #define LCONSOLE_ERROR(format, ...) LCONSOLE_ERROR_MSG(0x00, format, ## __VA_ARGS__) | |
241 | ||
242 | #define LCONSOLE_EMERG(format, ...) CDEBUG(D_CONSOLE | D_EMERG, format, ## __VA_ARGS__) | |
243 | ||
a393fd54 | 244 | int libcfs_debug_msg(struct libcfs_debug_msg_data *msgdata, |
d7e09d03 | 245 | const char *format1, ...) |
70837c12 | 246 | __printf(2, 3); |
d7e09d03 | 247 | |
a393fd54 | 248 | int libcfs_debug_vmsg2(struct libcfs_debug_msg_data *msgdata, |
d7e09d03 PT |
249 | const char *format1, |
250 | va_list args, const char *format2, ...) | |
70837c12 | 251 | __printf(4, 5); |
d7e09d03 PT |
252 | |
253 | /* other external symbols that tracefile provides: */ | |
a393fd54 | 254 | int cfs_trace_copyin_string(char *knl_buffer, int knl_buffer_nob, |
5a08f067 LC |
255 | const char __user *usr_buffer, int usr_buffer_nob); |
256 | int cfs_trace_copyout_string(char __user *usr_buffer, int usr_buffer_nob, | |
257 | const char *knl_buffer, char *append); | |
d7e09d03 PT |
258 | |
259 | #define LIBCFS_DEBUG_FILE_PATH_DEFAULT "/tmp/lustre-log" | |
260 | ||
261 | #endif /* __LIBCFS_DEBUG_H__ */ |