blob: 0fe96c2830c2ab50956e04fd89a5d44fd7d3f6fb [file] [log] [blame]
Zach Brown52fd3d62005-12-15 14:31:23 -08001/* -*- 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 *
Coly Li2b53bc72009-05-05 20:03:28 +080051 * All this bitmask nonsense is managed from the files under
52 * /sys/fs/o2cb/logmask/. Reading the files gives a straightforward
53 * indication of which bits are allowed (allow) or denied (off/deny).
54 * ENTRY deny
55 * EXIT deny
Zach Brown52fd3d62005-12-15 14:31:23 -080056 * TCP off
57 * MSG off
58 * SOCKET off
Coly Li2b53bc72009-05-05 20:03:28 +080059 * ERROR allow
60 * NOTICE allow
Zach Brown52fd3d62005-12-15 14:31:23 -080061 *
62 * Writing changes the state of a given bit and requires a strictly formatted
63 * single write() call:
64 *
Coly Li2b53bc72009-05-05 20:03:28 +080065 * write(fd, "allow", 5);
Zach Brown52fd3d62005-12-15 14:31:23 -080066 *
Coly Li2b53bc72009-05-05 20:03:28 +080067 * Echoing allow/deny/off string into the logmask files can flip the bits
68 * on or off as expected; here is the bash script for example:
Zach Brown52fd3d62005-12-15 14:31:23 -080069 *
Coly Li2b53bc72009-05-05 20:03:28 +080070 * log_mask="/sys/fs/o2cb/log_mask"
71 * for node in ENTRY EXIT TCP MSG SOCKET ERROR NOTICE; do
72 * echo allow >"$log_mask"/"$node"
73 * done
Zach Brown52fd3d62005-12-15 14:31:23 -080074 *
Coly Li2b53bc72009-05-05 20:03:28 +080075 * The debugfs.ocfs2 tool can also flip the bits with the -l option:
76 *
77 * debugfs.ocfs2 -l TCP allow
Zach Brown52fd3d62005-12-15 14:31:23 -080078 */
79
80/* for task_struct */
81#include <linux/sched.h>
82
83/* bits that are frequently given and infrequently matched in the low word */
Sunil Mushran41b41a22010-12-09 18:20:38 -080084/* NOTE: If you add a flag, you need to also update masklog.c! */
Zach Brown52fd3d62005-12-15 14:31:23 -080085#define ML_TCP 0x0000000000000004ULL /* net cluster/tcp.c */
86#define ML_MSG 0x0000000000000008ULL /* net network messages */
87#define ML_SOCKET 0x0000000000000010ULL /* net socket lifetime */
88#define ML_HEARTBEAT 0x0000000000000020ULL /* hb all heartbeat tracking */
89#define ML_HB_BIO 0x0000000000000040ULL /* hb io tracing */
90#define ML_DLMFS 0x0000000000000080ULL /* dlm user dlmfs */
91#define ML_DLM 0x0000000000000100ULL /* dlm general debugging */
92#define ML_DLM_DOMAIN 0x0000000000000200ULL /* dlm domain debugging */
93#define ML_DLM_THREAD 0x0000000000000400ULL /* dlm domain thread */
94#define ML_DLM_MASTER 0x0000000000000800ULL /* dlm master functions */
95#define ML_DLM_RECOVERY 0x0000000000001000ULL /* dlm master functions */
Zach Brown52fd3d62005-12-15 14:31:23 -080096#define ML_DLM_GLUE 0x0000000000080000ULL /* ocfs2 dlm glue layer */
Zach Brown52fd3d62005-12-15 14:31:23 -080097#define ML_VOTE 0x0000000001000000ULL /* ocfs2 node messaging */
Zach Brown52fd3d62005-12-15 14:31:23 -080098#define ML_CONN 0x0000000004000000ULL /* net connection management */
99#define ML_QUORUM 0x0000000008000000ULL /* net connection quorum */
Sunil Mushran41b41a22010-12-09 18:20:38 -0800100#define ML_BASTS 0x0000000100000000ULL /* dlmglue asts and basts */
Sunil Mushran41b41a22010-12-09 18:20:38 -0800101#define ML_CLUSTER 0x0000000400000000ULL /* cluster stack */
102
Zach Brown52fd3d62005-12-15 14:31:23 -0800103/* bits that are infrequently given and frequently matched in the high word */
Sunil Mushran41b41a22010-12-09 18:20:38 -0800104#define ML_ERROR 0x1000000000000000ULL /* sent to KERN_ERR */
105#define ML_NOTICE 0x2000000000000000ULL /* setn to KERN_NOTICE */
106#define ML_KTHREAD 0x4000000000000000ULL /* kernel thread activity */
Zach Brown52fd3d62005-12-15 14:31:23 -0800107
108#define MLOG_INITIAL_AND_MASK (ML_ERROR|ML_NOTICE)
Zach Brown52fd3d62005-12-15 14:31:23 -0800109#ifndef MLOG_MASK_PREFIX
110#define MLOG_MASK_PREFIX 0
111#endif
112
Joel Becker2b388c62006-05-10 18:28:59 -0700113/*
114 * When logging is disabled, force the bit test to 0 for anything other
115 * than errors and notices, allowing gcc to remove the code completely.
116 * When enabled, allow all masks.
117 */
118#if defined(CONFIG_OCFS2_DEBUG_MASKLOG)
119#define ML_ALLOWED_BITS ~0
120#else
121#define ML_ALLOWED_BITS (ML_ERROR|ML_NOTICE)
122#endif
123
Zach Brown52fd3d62005-12-15 14:31:23 -0800124#define MLOG_MAX_BITS 64
125
126struct mlog_bits {
127 unsigned long words[MLOG_MAX_BITS / BITS_PER_LONG];
128};
129
130extern struct mlog_bits mlog_and_bits, mlog_not_bits;
131
132#if BITS_PER_LONG == 32
133
134#define __mlog_test_u64(mask, bits) \
135 ( (u32)(mask & 0xffffffff) & bits.words[0] || \
136 ((u64)(mask) >> 32) & bits.words[1] )
137#define __mlog_set_u64(mask, bits) do { \
138 bits.words[0] |= (u32)(mask & 0xffffffff); \
139 bits.words[1] |= (u64)(mask) >> 32; \
140} while (0)
141#define __mlog_clear_u64(mask, bits) do { \
142 bits.words[0] &= ~((u32)(mask & 0xffffffff)); \
143 bits.words[1] &= ~((u64)(mask) >> 32); \
144} while (0)
145#define MLOG_BITS_RHS(mask) { \
146 { \
147 [0] = (u32)(mask & 0xffffffff), \
148 [1] = (u64)(mask) >> 32, \
149 } \
150}
151
152#else /* 32bit long above, 64bit long below */
153
154#define __mlog_test_u64(mask, bits) ((mask) & bits.words[0])
155#define __mlog_set_u64(mask, bits) do { \
156 bits.words[0] |= (mask); \
157} while (0)
158#define __mlog_clear_u64(mask, bits) do { \
159 bits.words[0] &= ~(mask); \
160} while (0)
161#define MLOG_BITS_RHS(mask) { { (mask) } }
162
163#endif
164
165/*
166 * smp_processor_id() "helpfully" screams when called outside preemptible
167 * regions in current kernels. sles doesn't have the variants that don't
168 * scream. just do this instead of trying to guess which we're building
169 * against.. *sigh*.
170 */
171#define __mlog_cpu_guess ({ \
172 unsigned long _cpu = get_cpu(); \
173 put_cpu(); \
174 _cpu; \
175})
176
177/* In the following two macros, the whitespace after the ',' just
178 * before ##args is intentional. Otherwise, gcc 2.95 will eat the
179 * previous token if args expands to nothing.
180 */
181#define __mlog_printk(level, fmt, args...) \
Sunil Mushran8545e032010-02-12 14:09:06 -0800182 printk(level "(%s,%u,%lu):%s:%d " fmt, current->comm, \
183 task_pid_nr(current), __mlog_cpu_guess, \
184 __PRETTY_FUNCTION__, __LINE__ , ##args)
Zach Brown52fd3d62005-12-15 14:31:23 -0800185
186#define mlog(mask, fmt, args...) do { \
187 u64 __m = MLOG_MASK_PREFIX | (mask); \
Joel Becker2b388c62006-05-10 18:28:59 -0700188 if ((__m & ML_ALLOWED_BITS) && \
189 __mlog_test_u64(__m, mlog_and_bits) && \
Zach Brown52fd3d62005-12-15 14:31:23 -0800190 !__mlog_test_u64(__m, mlog_not_bits)) { \
191 if (__m & ML_ERROR) \
192 __mlog_printk(KERN_ERR, "ERROR: "fmt , ##args); \
193 else if (__m & ML_NOTICE) \
194 __mlog_printk(KERN_NOTICE, fmt , ##args); \
195 else __mlog_printk(KERN_INFO, fmt , ##args); \
196 } \
197} while (0)
198
199#define mlog_errno(st) do { \
200 int _st = (st); \
201 if (_st != -ERESTARTSYS && _st != -EINTR && \
Mark Fashehef9f86c2007-11-19 18:31:17 -0800202 _st != AOP_TRUNCATED_PAGE && _st != -ENOSPC) \
Zach Brown52fd3d62005-12-15 14:31:23 -0800203 mlog(ML_ERROR, "status = %lld\n", (long long)_st); \
204} while (0)
205
Zach Brown52fd3d62005-12-15 14:31:23 -0800206#define mlog_bug_on_msg(cond, fmt, args...) do { \
207 if (cond) { \
208 mlog(ML_ERROR, "bug expression: " #cond "\n"); \
209 mlog(ML_ERROR, fmt, ##args); \
210 BUG(); \
211 } \
212} while (0)
213
Zach Brown52fd3d62005-12-15 14:31:23 -0800214#include <linux/kobject.h>
215#include <linux/sysfs.h>
Greg Kroah-Hartman823bccf2007-04-13 13:15:19 -0700216int mlog_sys_init(struct kset *o2cb_subsys);
Zach Brown52fd3d62005-12-15 14:31:23 -0800217void mlog_sys_shutdown(void);
218
219#endif /* O2CLUSTER_MASKLOG_H */