1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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(0);
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(TCP),
84 define_mask(MSG),
85 define_mask(SOCKET),
86 define_mask(HEARTBEAT),
87 define_mask(HB_BIO),
88 define_mask(DLMFS),
89 define_mask(DLM),
90 define_mask(DLM_DOMAIN),
91 define_mask(DLM_THREAD),
92 define_mask(DLM_MASTER),
93 define_mask(DLM_RECOVERY),
94 define_mask(DLM_GLUE),
95 define_mask(VOTE),
96 define_mask(CONN),
97 define_mask(QUORUM),
98 define_mask(BASTS),
99 define_mask(CLUSTER),
100 define_mask(ERROR),
101 define_mask(NOTICE),
102 define_mask(KTHREAD),
103};
104
105static struct attribute *mlog_attr_ptrs[MLOG_MAX_BITS] = {NULL, };
106
107static ssize_t mlog_show(struct kobject *obj, struct attribute *attr,
108 char *buf)
109{
110 struct mlog_attribute *mlog_attr = to_mlog_attr(attr);
111
112 return mlog_mask_show(mlog_attr->mask, buf);
113}
114
115static ssize_t mlog_store(struct kobject *obj, struct attribute *attr,
116 const char *buf, size_t count)
117{
118 struct mlog_attribute *mlog_attr = to_mlog_attr(attr);
119
120 return mlog_mask_store(mlog_attr->mask, buf, count);
121}
122
123static const struct sysfs_ops mlog_attr_ops = {
124 .show = mlog_show,
125 .store = mlog_store,
126};
127
128static struct kobj_type mlog_ktype = {
129 .default_attrs = mlog_attr_ptrs,
130 .sysfs_ops = &mlog_attr_ops,
131};
132
133static struct kset mlog_kset = {
134 .kobj = {.ktype = &mlog_ktype},
135};
136
137int mlog_sys_init(struct kset *o2cb_kset)
138{
139 int i = 0;
140
141 while (mlog_attrs[i].attr.mode) {
142 mlog_attr_ptrs[i] = &mlog_attrs[i].attr;
143 i++;
144 }
145 mlog_attr_ptrs[i] = NULL;
146
147 kobject_set_name(&mlog_kset.kobj, "logmask");
148 mlog_kset.kobj.kset = o2cb_kset;
149 return kset_register(&mlog_kset);
150}
151
152void mlog_sys_shutdown(void)
153{
154 kset_unregister(&mlog_kset);
155}
156