aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ocfs2/cluster
diff options
context:
space:
mode:
authorZach Brown <zach.brown@oracle.com>2005-12-15 17:31:23 -0500
committerJoel Becker <joel.becker@oracle.com>2006-01-03 14:45:45 -0500
commit52fd3d6fea441835fe3a35b7280e5e128bdeca9b (patch)
tree0e3dfdd639ebba904327616375971a37d7aff14f /fs/ocfs2/cluster
parent994fc28c7b1e697ac56befe4aecabf23f0689f46 (diff)
[PATCH] OCFS2: The Second Oracle Cluster Filesystem
Very simple printk wrapper which adds the ability to enable various sets of debug messages at run-time. Signed-off-by: Mark Fasheh <mark.fasheh@oracle.com> Signed-off-by: Kurt Hackel <kurt.hackel@oracle.com>
Diffstat (limited to 'fs/ocfs2/cluster')
-rw-r--r--fs/ocfs2/cluster/masklog.c166
-rw-r--r--fs/ocfs2/cluster/masklog.h275
2 files changed, 441 insertions, 0 deletions
diff --git a/fs/ocfs2/cluster/masklog.c b/fs/ocfs2/cluster/masklog.c
new file mode 100644
index 000000000000..fd741cea5705
--- /dev/null
+++ b/fs/ocfs2/cluster/masklog.c
@@ -0,0 +1,166 @@
1/* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
3 *
4 * Copyright (C) 2004, 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#include <linux/module.h>
23#include <linux/kernel.h>
24#include <linux/proc_fs.h>
25#include <linux/seq_file.h>
26#include <linux/string.h>
27#include <asm/uaccess.h>
28
29#include "masklog.h"
30
31struct mlog_bits mlog_and_bits = MLOG_BITS_RHS(MLOG_INITIAL_AND_MASK);
32EXPORT_SYMBOL_GPL(mlog_and_bits);
33struct mlog_bits mlog_not_bits = MLOG_BITS_RHS(MLOG_INITIAL_NOT_MASK);
34EXPORT_SYMBOL_GPL(mlog_not_bits);
35
36static ssize_t mlog_mask_show(u64 mask, char *buf)
37{
38 char *state;
39
40 if (__mlog_test_u64(mask, mlog_and_bits))
41 state = "allow";
42 else if (__mlog_test_u64(mask, mlog_not_bits))
43 state = "deny";
44 else
45 state = "off";
46
47 return snprintf(buf, PAGE_SIZE, "%s\n", state);
48}
49
50static ssize_t mlog_mask_store(u64 mask, const char *buf, size_t count)
51{
52 if (!strnicmp(buf, "allow", 5)) {
53 __mlog_set_u64(mask, mlog_and_bits);
54 __mlog_clear_u64(mask, mlog_not_bits);
55 } else if (!strnicmp(buf, "deny", 4)) {
56 __mlog_set_u64(mask, mlog_not_bits);
57 __mlog_clear_u64(mask, mlog_and_bits);
58 } else if (!strnicmp(buf, "off", 3)) {
59 __mlog_clear_u64(mask, mlog_not_bits);
60 __mlog_clear_u64(mask, mlog_and_bits);
61 } else
62 return -EINVAL;
63
64 return count;
65}
66
67struct mlog_attribute {
68 struct attribute attr;
69 u64 mask;
70};
71
72#define to_mlog_attr(_attr) container_of(_attr, struct mlog_attribute, attr)
73
74#define define_mask(_name) { \
75 .attr = { \
76 .name = #_name, \
77 .mode = S_IRUGO | S_IWUSR, \
78 }, \
79 .mask = ML_##_name, \
80}
81
82static struct mlog_attribute mlog_attrs[MLOG_MAX_BITS] = {
83 define_mask(ENTRY),
84 define_mask(EXIT),
85 define_mask(TCP),
86 define_mask(MSG),
87 define_mask(SOCKET),
88 define_mask(HEARTBEAT),
89 define_mask(HB_BIO),
90 define_mask(DLMFS),
91 define_mask(DLM),
92 define_mask(DLM_DOMAIN),
93 define_mask(DLM_THREAD),
94 define_mask(DLM_MASTER),
95 define_mask(DLM_RECOVERY),
96 define_mask(AIO),
97 define_mask(JOURNAL),
98 define_mask(DISK_ALLOC),
99 define_mask(SUPER),
100 define_mask(FILE_IO),
101 define_mask(EXTENT_MAP),
102 define_mask(DLM_GLUE),
103 define_mask(BH_IO),
104 define_mask(UPTODATE),
105 define_mask(NAMEI),
106 define_mask(INODE),
107 define_mask(VOTE),
108 define_mask(DCACHE),
109 define_mask(CONN),
110 define_mask(QUORUM),
111 define_mask(EXPORT),
112 define_mask(ERROR),
113 define_mask(NOTICE),
114 define_mask(KTHREAD),
115};
116
117static struct attribute *mlog_attr_ptrs[MLOG_MAX_BITS] = {NULL, };
118
119static ssize_t mlog_show(struct kobject *obj, struct attribute *attr,
120 char *buf)
121{
122 struct mlog_attribute *mlog_attr = to_mlog_attr(attr);
123
124 return mlog_mask_show(mlog_attr->mask, buf);
125}
126
127static ssize_t mlog_store(struct kobject *obj, struct attribute *attr,
128 const char *buf, size_t count)
129{
130 struct mlog_attribute *mlog_attr = to_mlog_attr(attr);
131
132 return mlog_mask_store(mlog_attr->mask, buf, count);
133}
134
135static struct sysfs_ops mlog_attr_ops = {
136 .show = mlog_show,
137 .store = mlog_store,
138};
139
140static struct kobj_type mlog_ktype = {
141 .default_attrs = mlog_attr_ptrs,
142 .sysfs_ops = &mlog_attr_ops,
143};
144
145static struct kset mlog_kset = {
146 .kobj = {.name = "logmask", .ktype = &mlog_ktype},
147};
148
149int mlog_sys_init(struct subsystem *o2cb_subsys)
150{
151 int i = 0;
152
153 while (mlog_attrs[i].attr.mode) {
154 mlog_attr_ptrs[i] = &mlog_attrs[i].attr;
155 i++;
156 }
157 mlog_attr_ptrs[i] = NULL;
158
159 mlog_kset.subsys = o2cb_subsys;
160 return kset_register(&mlog_kset);
161}
162
163void mlog_sys_shutdown(void)
164{
165 kset_unregister(&mlog_kset);
166}
diff --git a/fs/ocfs2/cluster/masklog.h b/fs/ocfs2/cluster/masklog.h
new file mode 100644
index 000000000000..f5ef5ea61a05
--- /dev/null
+++ b/fs/ocfs2/cluster/masklog.h
@@ -0,0 +1,275 @@
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
126#define MLOG_MAX_BITS 64
127
128struct mlog_bits {
129 unsigned long words[MLOG_MAX_BITS / BITS_PER_LONG];
130};
131
132extern struct mlog_bits mlog_and_bits, mlog_not_bits;
133
134#if BITS_PER_LONG == 32
135
136#define __mlog_test_u64(mask, bits) \
137 ( (u32)(mask & 0xffffffff) & bits.words[0] || \
138 ((u64)(mask) >> 32) & bits.words[1] )
139#define __mlog_set_u64(mask, bits) do { \
140 bits.words[0] |= (u32)(mask & 0xffffffff); \
141 bits.words[1] |= (u64)(mask) >> 32; \
142} while (0)
143#define __mlog_clear_u64(mask, bits) do { \
144 bits.words[0] &= ~((u32)(mask & 0xffffffff)); \
145 bits.words[1] &= ~((u64)(mask) >> 32); \
146} while (0)
147#define MLOG_BITS_RHS(mask) { \
148 { \
149 [0] = (u32)(mask & 0xffffffff), \
150 [1] = (u64)(mask) >> 32, \
151 } \
152}
153
154#else /* 32bit long above, 64bit long below */
155
156#define __mlog_test_u64(mask, bits) ((mask) & bits.words[0])
157#define __mlog_set_u64(mask, bits) do { \
158 bits.words[0] |= (mask); \
159} while (0)
160#define __mlog_clear_u64(mask, bits) do { \
161 bits.words[0] &= ~(mask); \
162} while (0)
163#define MLOG_BITS_RHS(mask) { { (mask) } }
164
165#endif
166
167/*
168 * smp_processor_id() "helpfully" screams when called outside preemptible
169 * regions in current kernels. sles doesn't have the variants that don't
170 * scream. just do this instead of trying to guess which we're building
171 * against.. *sigh*.
172 */
173#define __mlog_cpu_guess ({ \
174 unsigned long _cpu = get_cpu(); \
175 put_cpu(); \
176 _cpu; \
177})
178
179/* In the following two macros, the whitespace after the ',' just
180 * before ##args is intentional. Otherwise, gcc 2.95 will eat the
181 * previous token if args expands to nothing.
182 */
183#define __mlog_printk(level, fmt, args...) \
184 printk(level "(%u,%lu):%s:%d " fmt, current->pid, \
185 __mlog_cpu_guess, __PRETTY_FUNCTION__, __LINE__ , \
186 ##args)
187
188#define mlog(mask, fmt, args...) do { \
189 u64 __m = MLOG_MASK_PREFIX | (mask); \
190 if (__mlog_test_u64(__m, mlog_and_bits) && \
191 !__mlog_test_u64(__m, mlog_not_bits)) { \
192 if (__m & ML_ERROR) \
193 __mlog_printk(KERN_ERR, "ERROR: "fmt , ##args); \
194 else if (__m & ML_NOTICE) \
195 __mlog_printk(KERN_NOTICE, fmt , ##args); \
196 else __mlog_printk(KERN_INFO, fmt , ##args); \
197 } \
198} while (0)
199
200#define mlog_errno(st) do { \
201 int _st = (st); \
202 if (_st != -ERESTARTSYS && _st != -EINTR && \
203 _st != AOP_TRUNCATED_PAGE) \
204 mlog(ML_ERROR, "status = %lld\n", (long long)_st); \
205} while (0)
206
207#define mlog_entry(fmt, args...) do { \
208 mlog(ML_ENTRY, "ENTRY:" fmt , ##args); \
209} while (0)
210
211#define mlog_entry_void() do { \
212 mlog(ML_ENTRY, "ENTRY:\n"); \
213} while (0)
214
215/* We disable this for old compilers since they don't have support for
216 * __builtin_types_compatible_p.
217 */
218#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) && \
219 !defined(__CHECKER__)
220#define mlog_exit(st) do { \
221 if (__builtin_types_compatible_p(typeof(st), unsigned long)) \
222 mlog(ML_EXIT, "EXIT: %lu\n", (unsigned long) (st)); \
223 else if (__builtin_types_compatible_p(typeof(st), signed long)) \
224 mlog(ML_EXIT, "EXIT: %ld\n", (signed long) (st)); \
225 else if (__builtin_types_compatible_p(typeof(st), unsigned int) \
226 || __builtin_types_compatible_p(typeof(st), unsigned short) \
227 || __builtin_types_compatible_p(typeof(st), unsigned char)) \
228 mlog(ML_EXIT, "EXIT: %u\n", (unsigned int) (st)); \
229 else if (__builtin_types_compatible_p(typeof(st), signed int) \
230 || __builtin_types_compatible_p(typeof(st), signed short) \
231 || __builtin_types_compatible_p(typeof(st), signed char)) \
232 mlog(ML_EXIT, "EXIT: %d\n", (signed int) (st)); \
233 else if (__builtin_types_compatible_p(typeof(st), long long)) \
234 mlog(ML_EXIT, "EXIT: %lld\n", (long long) (st)); \
235 else \
236 mlog(ML_EXIT, "EXIT: %llu\n", (unsigned long long) (st)); \
237} while (0)
238#else
239#define mlog_exit(st) do { \
240 mlog(ML_EXIT, "EXIT: %lld\n", (long long) (st)); \
241} while (0)
242#endif
243
244#define mlog_exit_ptr(ptr) do { \
245 mlog(ML_EXIT, "EXIT: %p\n", ptr); \
246} while (0)
247
248#define mlog_exit_void() do { \
249 mlog(ML_EXIT, "EXIT\n"); \
250} while (0)
251
252#define mlog_bug_on_msg(cond, fmt, args...) do { \
253 if (cond) { \
254 mlog(ML_ERROR, "bug expression: " #cond "\n"); \
255 mlog(ML_ERROR, fmt, ##args); \
256 BUG(); \
257 } \
258} while (0)
259
260#if (BITS_PER_LONG == 32) || defined(CONFIG_X86_64)
261#define MLFi64 "lld"
262#define MLFu64 "llu"
263#define MLFx64 "llx"
264#else
265#define MLFi64 "ld"
266#define MLFu64 "lu"
267#define MLFx64 "lx"
268#endif
269
270#include <linux/kobject.h>
271#include <linux/sysfs.h>
272int mlog_sys_init(struct subsystem *o2cb_subsys);
273void mlog_sys_shutdown(void);
274
275#endif /* O2CLUSTER_MASKLOG_H */