1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42#ifndef __LIBCFS_DEBUG_H__
43#define __LIBCFS_DEBUG_H__
44
45
46
47
48extern unsigned int libcfs_subsystem_debug;
49extern unsigned int libcfs_stack;
50extern unsigned int libcfs_debug;
51extern unsigned int libcfs_printk;
52extern unsigned int libcfs_console_ratelimit;
53extern unsigned int libcfs_watchdog_ratelimit;
54extern unsigned int libcfs_console_max_delay;
55extern unsigned int libcfs_console_min_delay;
56extern unsigned int libcfs_console_backoff;
57extern unsigned int libcfs_debug_binary;
58extern char libcfs_debug_file_path_arr[PATH_MAX];
59
60int libcfs_debug_mask2str(char *str, int size, int mask, int is_subsys);
61int libcfs_debug_str2mask(int *mask, const char *str, int is_subsys);
62
63
64extern unsigned int libcfs_catastrophe;
65extern unsigned int libcfs_panic_on_lbug;
66
67
68
69
70struct ptldebug_header {
71 __u32 ph_len;
72 __u32 ph_flags;
73 __u32 ph_subsys;
74 __u32 ph_mask;
75 __u16 ph_cpu_id;
76 __u16 ph_type;
77 __u32 ph_sec;
78 __u64 ph_usec;
79 __u32 ph_stack;
80 __u32 ph_pid;
81 __u32 ph_extern_pid;
82 __u32 ph_line_num;
83} __packed;
84
85#define PH_FLAG_FIRST_RECORD 1
86
87
88
89#define S_UNDEFINED 0x00000001
90#define S_MDC 0x00000002
91#define S_MDS 0x00000004
92#define S_OSC 0x00000008
93#define S_OST 0x00000010
94#define S_CLASS 0x00000020
95#define S_LOG 0x00000040
96#define S_LLITE 0x00000080
97#define S_RPC 0x00000100
98#define S_MGMT 0x00000200
99#define S_LNET 0x00000400
100#define S_LND 0x00000800
101#define S_PINGER 0x00001000
102#define S_FILTER 0x00002000
103
104#define S_ECHO 0x00008000
105#define S_LDLM 0x00010000
106#define S_LOV 0x00020000
107#define S_LQUOTA 0x00040000
108#define S_OSD 0x00080000
109
110
111
112#define S_LMV 0x00800000
113
114#define S_SEC 0x02000000
115#define S_GSS 0x04000000
116
117#define S_MGC 0x10000000
118#define S_MGS 0x20000000
119#define S_FID 0x40000000
120#define S_FLD 0x80000000
121
122
123
124
125#define D_TRACE 0x00000001
126#define D_INODE 0x00000002
127#define D_SUPER 0x00000004
128#define D_EXT2 0x00000008
129#define D_MALLOC 0x00000010
130#define D_CACHE 0x00000020
131#define D_INFO 0x00000040
132#define D_IOCTL 0x00000080
133#define D_NETERROR 0x00000100
134#define D_NET 0x00000200
135#define D_WARNING 0x00000400
136#define D_BUFFS 0x00000800
137#define D_OTHER 0x00001000
138#define D_DENTRY 0x00002000
139#define D_NETTRACE 0x00004000
140#define D_PAGE 0x00008000
141#define D_DLMTRACE 0x00010000
142#define D_ERROR 0x00020000
143#define D_EMERG 0x00040000
144#define D_HA 0x00080000
145#define D_RPCTRACE 0x00100000
146#define D_VFSTRACE 0x00200000
147#define D_READA 0x00400000
148#define D_MMAP 0x00800000
149#define D_CONFIG 0x01000000
150#define D_CONSOLE 0x02000000
151#define D_QUOTA 0x04000000
152#define D_SEC 0x08000000
153#define D_LFSCK 0x10000000
154
155
156#define D_HSM D_TRACE
157
158#define D_CANTMASK (D_ERROR | D_EMERG | D_WARNING | D_CONSOLE)
159
160#ifndef DEBUG_SUBSYSTEM
161# define DEBUG_SUBSYSTEM S_UNDEFINED
162#endif
163
164#define CDEBUG_DEFAULT_MAX_DELAY (cfs_time_seconds(600))
165#define CDEBUG_DEFAULT_MIN_DELAY ((cfs_time_seconds(1) + 1) / 2)
166#define CDEBUG_DEFAULT_BACKOFF 2
167struct cfs_debug_limit_state {
168 unsigned long cdls_next;
169 unsigned int cdls_delay;
170 int cdls_count;
171};
172
173struct libcfs_debug_msg_data {
174 const char *msg_file;
175 const char *msg_fn;
176 int msg_subsys;
177 int msg_line;
178 int msg_mask;
179 struct cfs_debug_limit_state *msg_cdls;
180};
181
182#define LIBCFS_DEBUG_MSG_DATA_INIT(data, mask, cdls) \
183do { \
184 (data)->msg_subsys = DEBUG_SUBSYSTEM; \
185 (data)->msg_file = __FILE__; \
186 (data)->msg_fn = __func__; \
187 (data)->msg_line = __LINE__; \
188 (data)->msg_cdls = (cdls); \
189 (data)->msg_mask = (mask); \
190} while (0)
191
192#define LIBCFS_DEBUG_MSG_DATA_DECL(dataname, mask, cdls) \
193 static struct libcfs_debug_msg_data dataname = { \
194 .msg_subsys = DEBUG_SUBSYSTEM, \
195 .msg_file = __FILE__, \
196 .msg_fn = __func__, \
197 .msg_line = __LINE__, \
198 .msg_cdls = (cdls) }; \
199 dataname.msg_mask = (mask)
200
201
202
203
204static inline int cfs_cdebug_show(unsigned int mask, unsigned int subsystem)
205{
206 return mask & D_CANTMASK ||
207 ((libcfs_debug & mask) && (libcfs_subsystem_debug & subsystem));
208}
209
210#define __CDEBUG(cdls, mask, format, ...) \
211do { \
212 static struct libcfs_debug_msg_data msgdata; \
213 \
214 CFS_CHECK_STACK(&msgdata, mask, cdls); \
215 \
216 if (cfs_cdebug_show(mask, DEBUG_SUBSYSTEM)) { \
217 LIBCFS_DEBUG_MSG_DATA_INIT(&msgdata, mask, cdls); \
218 libcfs_debug_msg(&msgdata, format, ## __VA_ARGS__); \
219 } \
220} while (0)
221
222#define CDEBUG(mask, format, ...) __CDEBUG(NULL, mask, format, ## __VA_ARGS__)
223
224#define CDEBUG_LIMIT(mask, format, ...) \
225do { \
226 static struct cfs_debug_limit_state cdls; \
227 \
228 __CDEBUG(&cdls, mask, format, ## __VA_ARGS__); \
229} while (0)
230
231#define CWARN(format, ...) CDEBUG_LIMIT(D_WARNING, format, ## __VA_ARGS__)
232#define CERROR(format, ...) CDEBUG_LIMIT(D_ERROR, format, ## __VA_ARGS__)
233#define CNETERR(format, a...) CDEBUG_LIMIT(D_NETERROR, format, ## a)
234#define CEMERG(format, ...) CDEBUG_LIMIT(D_EMERG, format, ## __VA_ARGS__)
235
236#define LCONSOLE(mask, format, ...) CDEBUG(D_CONSOLE | (mask), format, ## __VA_ARGS__)
237#define LCONSOLE_INFO(format, ...) CDEBUG_LIMIT(D_CONSOLE, format, ## __VA_ARGS__)
238#define LCONSOLE_WARN(format, ...) CDEBUG_LIMIT(D_CONSOLE | D_WARNING, format, ## __VA_ARGS__)
239#define LCONSOLE_ERROR_MSG(errnum, format, ...) CDEBUG_LIMIT(D_CONSOLE | D_ERROR, \
240 "%x-%x: " format, errnum, LERRCHKSUM(errnum), ## __VA_ARGS__)
241#define LCONSOLE_ERROR(format, ...) LCONSOLE_ERROR_MSG(0x00, format, ## __VA_ARGS__)
242
243#define LCONSOLE_EMERG(format, ...) CDEBUG(D_CONSOLE | D_EMERG, format, ## __VA_ARGS__)
244
245int libcfs_debug_msg(struct libcfs_debug_msg_data *msgdata,
246 const char *format1, ...)
247 __printf(2, 3);
248
249int libcfs_debug_vmsg2(struct libcfs_debug_msg_data *msgdata,
250 const char *format1,
251 va_list args, const char *format2, ...)
252 __printf(4, 5);
253
254
255int cfs_trace_copyin_string(char *knl_buffer, int knl_buffer_nob,
256 const char __user *usr_buffer, int usr_buffer_nob);
257int cfs_trace_copyout_string(char __user *usr_buffer, int usr_buffer_nob,
258 const char *knl_buffer, char *append);
259
260#define LIBCFS_DEBUG_FILE_PATH_DEFAULT "/tmp/lustre-log"
261
262#endif
263