1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2004, 2005 Oracle. All rights reserved.
6 #include <linux/module.h>
7 #include <linux/kernel.h>
8 #include <linux/proc_fs.h>
9 #include <linux/seq_file.h>
10 #include <linux/string.h>
11 #include <linux/uaccess.h>
15 struct mlog_bits mlog_and_bits = MLOG_BITS_RHS(MLOG_INITIAL_AND_MASK);
16 EXPORT_SYMBOL_GPL(mlog_and_bits);
17 struct mlog_bits mlog_not_bits = MLOG_BITS_RHS(0);
18 EXPORT_SYMBOL_GPL(mlog_not_bits);
20 static ssize_t mlog_mask_show(u64 mask, char *buf)
24 if (__mlog_test_u64(mask, mlog_and_bits))
26 else if (__mlog_test_u64(mask, mlog_not_bits))
31 return snprintf(buf, PAGE_SIZE, "%s\n", state);
34 static ssize_t mlog_mask_store(u64 mask, const char *buf, size_t count)
36 if (!strncasecmp(buf, "allow", 5)) {
37 __mlog_set_u64(mask, mlog_and_bits);
38 __mlog_clear_u64(mask, mlog_not_bits);
39 } else if (!strncasecmp(buf, "deny", 4)) {
40 __mlog_set_u64(mask, mlog_not_bits);
41 __mlog_clear_u64(mask, mlog_and_bits);
42 } else if (!strncasecmp(buf, "off", 3)) {
43 __mlog_clear_u64(mask, mlog_not_bits);
44 __mlog_clear_u64(mask, mlog_and_bits);
51 void __mlog_printk(const u64 *mask, const char *func, int line,
57 const char *prefix = "";
59 if (!__mlog_test_u64(*mask, mlog_and_bits) ||
60 __mlog_test_u64(*mask, mlog_not_bits))
63 if (*mask & ML_ERROR) {
66 } else if (*mask & ML_NOTICE) {
77 printk("%s(%s,%u,%u):%s:%d %s%pV",
78 level, current->comm, task_pid_nr(current),
79 raw_smp_processor_id(), func, line, prefix, &vaf);
83 EXPORT_SYMBOL_GPL(__mlog_printk);
85 struct mlog_attribute {
86 struct attribute attr;
90 #define to_mlog_attr(_attr) container_of(_attr, struct mlog_attribute, attr)
92 #define define_mask(_name) { \
95 .mode = S_IRUGO | S_IWUSR, \
100 static struct mlog_attribute mlog_attrs[MLOG_MAX_BITS] = {
104 define_mask(HEARTBEAT),
108 define_mask(DLM_DOMAIN),
109 define_mask(DLM_THREAD),
110 define_mask(DLM_MASTER),
111 define_mask(DLM_RECOVERY),
112 define_mask(DLM_GLUE),
117 define_mask(CLUSTER),
120 define_mask(KTHREAD),
123 static struct attribute *mlog_default_attrs[MLOG_MAX_BITS] = {NULL, };
124 ATTRIBUTE_GROUPS(mlog_default);
126 static ssize_t mlog_show(struct kobject *obj, struct attribute *attr,
129 struct mlog_attribute *mlog_attr = to_mlog_attr(attr);
131 return mlog_mask_show(mlog_attr->mask, buf);
134 static ssize_t mlog_store(struct kobject *obj, struct attribute *attr,
135 const char *buf, size_t count)
137 struct mlog_attribute *mlog_attr = to_mlog_attr(attr);
139 return mlog_mask_store(mlog_attr->mask, buf, count);
142 static const struct sysfs_ops mlog_attr_ops = {
147 static struct kobj_type mlog_ktype = {
148 .default_groups = mlog_default_groups,
149 .sysfs_ops = &mlog_attr_ops,
152 static struct kset mlog_kset = {
153 .kobj = {.ktype = &mlog_ktype},
156 int mlog_sys_init(struct kset *o2cb_kset)
160 while (mlog_attrs[i].attr.mode) {
161 mlog_default_attrs[i] = &mlog_attrs[i].attr;
164 mlog_default_attrs[i] = NULL;
166 kobject_set_name(&mlog_kset.kobj, "logmask");
167 mlog_kset.kobj.kset = o2cb_kset;
168 return kset_register(&mlog_kset);
171 void mlog_sys_shutdown(void)
173 kset_unregister(&mlog_kset);