Use helpers to obtain task pid in printks
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / fs / ocfs2 / cluster / masklog.h
CommitLineData
52fd3d6f
ZB
1/* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
3 *
4 * Copyright (C) 2005 Oracle. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 021110-1307, USA.
20 */
21
22#ifndef O2CLUSTER_MASKLOG_H
23#define O2CLUSTER_MASKLOG_H
24
25/*
26 * For now this is a trivial wrapper around printk() that gives the critical
27 * ability to enable sets of debugging output at run-time. In the future this
28 * will almost certainly be redirected to relayfs so that it can pay a
29 * substantially lower heisenberg tax.
30 *
31 * Callers associate the message with a bitmask and a global bitmask is
32 * maintained with help from /proc. If any of the bits match the message is
33 * output.
34 *
35 * We must have efficient bit tests on i386 and it seems gcc still emits crazy
36 * code for the 64bit compare. It emits very good code for the dual unsigned
37 * long tests, though, completely avoiding tests that can never pass if the
38 * caller gives a constant bitmask that fills one of the longs with all 0s. So
39 * the desire is to have almost all of the calls decided on by comparing just
40 * one of the longs. This leads to having infrequently given bits that are
41 * frequently matched in the high bits.
42 *
43 * _ERROR and _NOTICE are used for messages that always go to the console and
44 * have appropriate KERN_ prefixes. We wrap these in our function instead of
45 * just calling printk() so that this can eventually make its way through
46 * relayfs along with the debugging messages. Everything else gets KERN_DEBUG.
47 * The inline tests and macro dance give GCC the opportunity to quite cleverly
48 * only emit the appropriage printk() when the caller passes in a constant
49 * mask, as is almost always the case.
50 *
51 * All this bitmask nonsense is hidden from the /proc interface so that Joel
52 * doesn't have an aneurism. Reading the file gives a straight forward
53 * indication of which bits are on or off:
54 * ENTRY off
55 * EXIT off
56 * TCP off
57 * MSG off
58 * SOCKET off
59 * ERROR off
60 * NOTICE on
61 *
62 * Writing changes the state of a given bit and requires a strictly formatted
63 * single write() call:
64 *
65 * write(fd, "ENTRY on", 8);
66 *
67 * would turn the entry bit on. "1" is also accepted in the place of "on", and
68 * "off" and "0" behave as expected.
69 *
70 * Some trivial shell can flip all the bits on or off:
71 *
72 * log_mask="/proc/fs/ocfs2_nodemanager/log_mask"
73 * cat $log_mask | (
74 * while read bit status; do
75 * # $1 is "on" or "off", say
76 * echo "$bit $1" > $log_mask
77 * done
78 * )
79 */
80
81/* for task_struct */
82#include <linux/sched.h>
83
84/* bits that are frequently given and infrequently matched in the low word */
85/* NOTE: If you add a flag, you need to also update mlog.c! */
86#define ML_ENTRY 0x0000000000000001ULL /* func call entry */
87#define ML_EXIT 0x0000000000000002ULL /* func call exit */
88#define ML_TCP 0x0000000000000004ULL /* net cluster/tcp.c */
89#define ML_MSG 0x0000000000000008ULL /* net network messages */
90#define ML_SOCKET 0x0000000000000010ULL /* net socket lifetime */
91#define ML_HEARTBEAT 0x0000000000000020ULL /* hb all heartbeat tracking */
92#define ML_HB_BIO 0x0000000000000040ULL /* hb io tracing */
93#define ML_DLMFS 0x0000000000000080ULL /* dlm user dlmfs */
94#define ML_DLM 0x0000000000000100ULL /* dlm general debugging */
95#define ML_DLM_DOMAIN 0x0000000000000200ULL /* dlm domain debugging */
96#define ML_DLM_THREAD 0x0000000000000400ULL /* dlm domain thread */
97#define ML_DLM_MASTER 0x0000000000000800ULL /* dlm master functions */
98#define ML_DLM_RECOVERY 0x0000000000001000ULL /* dlm master functions */
99#define ML_AIO 0x0000000000002000ULL /* ocfs2 aio read and write */
100#define ML_JOURNAL 0x0000000000004000ULL /* ocfs2 journalling functions */
101#define ML_DISK_ALLOC 0x0000000000008000ULL /* ocfs2 disk allocation */
102#define ML_SUPER 0x0000000000010000ULL /* ocfs2 mount / umount */
103#define ML_FILE_IO 0x0000000000020000ULL /* ocfs2 file I/O */
104#define ML_EXTENT_MAP 0x0000000000040000ULL /* ocfs2 extent map caching */
105#define ML_DLM_GLUE 0x0000000000080000ULL /* ocfs2 dlm glue layer */
106#define ML_BH_IO 0x0000000000100000ULL /* ocfs2 buffer I/O */
107#define ML_UPTODATE 0x0000000000200000ULL /* ocfs2 caching sequence #'s */
108#define ML_NAMEI 0x0000000000400000ULL /* ocfs2 directory / namespace */
109#define ML_INODE 0x0000000000800000ULL /* ocfs2 inode manipulation */
110#define ML_VOTE 0x0000000001000000ULL /* ocfs2 node messaging */
111#define ML_DCACHE 0x0000000002000000ULL /* ocfs2 dcache operations */
112#define ML_CONN 0x0000000004000000ULL /* net connection management */
113#define ML_QUORUM 0x0000000008000000ULL /* net connection quorum */
114#define ML_EXPORT 0x0000000010000000ULL /* ocfs2 export operations */
115/* bits that are infrequently given and frequently matched in the high word */
116#define ML_ERROR 0x0000000100000000ULL /* sent to KERN_ERR */
117#define ML_NOTICE 0x0000000200000000ULL /* setn to KERN_NOTICE */
118#define ML_KTHREAD 0x0000000400000000ULL /* kernel thread activity */
119
120#define MLOG_INITIAL_AND_MASK (ML_ERROR|ML_NOTICE)
121#define MLOG_INITIAL_NOT_MASK (ML_ENTRY|ML_EXIT)
122#ifndef MLOG_MASK_PREFIX
123#define MLOG_MASK_PREFIX 0
124#endif
125
2b388c67
JB
126/*
127 * When logging is disabled, force the bit test to 0 for anything other
128 * than errors and notices, allowing gcc to remove the code completely.
129 * When enabled, allow all masks.
130 */
131#if defined(CONFIG_OCFS2_DEBUG_MASKLOG)
132#define ML_ALLOWED_BITS ~0
133#else
134#define ML_ALLOWED_BITS (ML_ERROR|ML_NOTICE)
135#endif
136
52fd3d6f
ZB
137#define MLOG_MAX_BITS 64
138
139struct mlog_bits {
140 unsigned long words[MLOG_MAX_BITS / BITS_PER_LONG];
141};
142
143extern struct mlog_bits mlog_and_bits, mlog_not_bits;
144
145#if BITS_PER_LONG == 32
146
147#define __mlog_test_u64(mask, bits) \
148 ( (u32)(mask & 0xffffffff) & bits.words[0] || \
149 ((u64)(mask) >> 32) & bits.words[1] )
150#define __mlog_set_u64(mask, bits) do { \
151 bits.words[0] |= (u32)(mask & 0xffffffff); \
152 bits.words[1] |= (u64)(mask) >> 32; \
153} while (0)
154#define __mlog_clear_u64(mask, bits) do { \
155 bits.words[0] &= ~((u32)(mask & 0xffffffff)); \
156 bits.words[1] &= ~((u64)(mask) >> 32); \
157} while (0)
158#define MLOG_BITS_RHS(mask) { \
159 { \
160 [0] = (u32)(mask & 0xffffffff), \
161 [1] = (u64)(mask) >> 32, \
162 } \
163}
164
165#else /* 32bit long above, 64bit long below */
166
167#define __mlog_test_u64(mask, bits) ((mask) & bits.words[0])
168#define __mlog_set_u64(mask, bits) do { \
169 bits.words[0] |= (mask); \
170} while (0)
171#define __mlog_clear_u64(mask, bits) do { \
172 bits.words[0] &= ~(mask); \
173} while (0)
174#define MLOG_BITS_RHS(mask) { { (mask) } }
175
176#endif
177
178/*
179 * smp_processor_id() "helpfully" screams when called outside preemptible
180 * regions in current kernels. sles doesn't have the variants that don't
181 * scream. just do this instead of trying to guess which we're building
182 * against.. *sigh*.
183 */
184#define __mlog_cpu_guess ({ \
185 unsigned long _cpu = get_cpu(); \
186 put_cpu(); \
187 _cpu; \
188})
189
190/* In the following two macros, the whitespace after the ',' just
191 * before ##args is intentional. Otherwise, gcc 2.95 will eat the
192 * previous token if args expands to nothing.
193 */
194#define __mlog_printk(level, fmt, args...) \
ba25f9dc 195 printk(level "(%u,%lu):%s:%d " fmt, task_pid_nr(current), \
52fd3d6f
ZB
196 __mlog_cpu_guess, __PRETTY_FUNCTION__, __LINE__ , \
197 ##args)
198
199#define mlog(mask, fmt, args...) do { \
200 u64 __m = MLOG_MASK_PREFIX | (mask); \
2b388c67
JB
201 if ((__m & ML_ALLOWED_BITS) && \
202 __mlog_test_u64(__m, mlog_and_bits) && \
52fd3d6f
ZB
203 !__mlog_test_u64(__m, mlog_not_bits)) { \
204 if (__m & ML_ERROR) \
205 __mlog_printk(KERN_ERR, "ERROR: "fmt , ##args); \
206 else if (__m & ML_NOTICE) \
207 __mlog_printk(KERN_NOTICE, fmt , ##args); \
208 else __mlog_printk(KERN_INFO, fmt , ##args); \
209 } \
210} while (0)
211
212#define mlog_errno(st) do { \
213 int _st = (st); \
214 if (_st != -ERESTARTSYS && _st != -EINTR && \
215 _st != AOP_TRUNCATED_PAGE) \
216 mlog(ML_ERROR, "status = %lld\n", (long long)_st); \
217} while (0)
218
2b388c67 219#if defined(CONFIG_OCFS2_DEBUG_MASKLOG)
52fd3d6f
ZB
220#define mlog_entry(fmt, args...) do { \
221 mlog(ML_ENTRY, "ENTRY:" fmt , ##args); \
222} while (0)
223
224#define mlog_entry_void() do { \
225 mlog(ML_ENTRY, "ENTRY:\n"); \
226} while (0)
227
a1365647
AM
228/*
229 * We disable this for sparse.
52fd3d6f 230 */
a1365647 231#if !defined(__CHECKER__)
52fd3d6f
ZB
232#define mlog_exit(st) do { \
233 if (__builtin_types_compatible_p(typeof(st), unsigned long)) \
234 mlog(ML_EXIT, "EXIT: %lu\n", (unsigned long) (st)); \
235 else if (__builtin_types_compatible_p(typeof(st), signed long)) \
236 mlog(ML_EXIT, "EXIT: %ld\n", (signed long) (st)); \
237 else if (__builtin_types_compatible_p(typeof(st), unsigned int) \
238 || __builtin_types_compatible_p(typeof(st), unsigned short) \
239 || __builtin_types_compatible_p(typeof(st), unsigned char)) \
240 mlog(ML_EXIT, "EXIT: %u\n", (unsigned int) (st)); \
241 else if (__builtin_types_compatible_p(typeof(st), signed int) \
242 || __builtin_types_compatible_p(typeof(st), signed short) \
243 || __builtin_types_compatible_p(typeof(st), signed char)) \
244 mlog(ML_EXIT, "EXIT: %d\n", (signed int) (st)); \
245 else if (__builtin_types_compatible_p(typeof(st), long long)) \
246 mlog(ML_EXIT, "EXIT: %lld\n", (long long) (st)); \
247 else \
248 mlog(ML_EXIT, "EXIT: %llu\n", (unsigned long long) (st)); \
249} while (0)
250#else
251#define mlog_exit(st) do { \
252 mlog(ML_EXIT, "EXIT: %lld\n", (long long) (st)); \
253} while (0)
254#endif
255
256#define mlog_exit_ptr(ptr) do { \
257 mlog(ML_EXIT, "EXIT: %p\n", ptr); \
258} while (0)
259
260#define mlog_exit_void() do { \
261 mlog(ML_EXIT, "EXIT\n"); \
262} while (0)
2b388c67
JB
263#else
264#define mlog_entry(...) do { } while (0)
265#define mlog_entry_void(...) do { } while (0)
266#define mlog_exit(...) do { } while (0)
267#define mlog_exit_ptr(...) do { } while (0)
268#define mlog_exit_void(...) do { } while (0)
269#endif /* defined(CONFIG_OCFS2_DEBUG_MASKLOG) */
52fd3d6f
ZB
270
271#define mlog_bug_on_msg(cond, fmt, args...) do { \
272 if (cond) { \
273 mlog(ML_ERROR, "bug expression: " #cond "\n"); \
274 mlog(ML_ERROR, fmt, ##args); \
275 BUG(); \
276 } \
277} while (0)
278
52fd3d6f
ZB
279#include <linux/kobject.h>
280#include <linux/sysfs.h>
823bccfc 281int mlog_sys_init(struct kset *o2cb_subsys);
52fd3d6f
ZB
282void mlog_sys_shutdown(void);
283
284#endif /* O2CLUSTER_MASKLOG_H */