1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* -*- mode: c; c-basic-offset: 8; -*-
3 * vim: noexpandtab sw=8 ts=8 sts=0:
5 * Copyright (C) 2004, 2005 Oracle. All rights reserved.
8 #include <linux/module.h>
9 #include <linux/kernel.h>
10 #include <linux/proc_fs.h>
11 #include <linux/seq_file.h>
12 #include <linux/string.h>
13 #include <linux/uaccess.h>
17 struct mlog_bits mlog_and_bits = MLOG_BITS_RHS(MLOG_INITIAL_AND_MASK);
18 EXPORT_SYMBOL_GPL(mlog_and_bits);
19 struct mlog_bits mlog_not_bits = MLOG_BITS_RHS(0);
20 EXPORT_SYMBOL_GPL(mlog_not_bits);
22 static ssize_t mlog_mask_show(u64 mask, char *buf)
26 if (__mlog_test_u64(mask, mlog_and_bits))
28 else if (__mlog_test_u64(mask, mlog_not_bits))
33 return snprintf(buf, PAGE_SIZE, "%s\n", state);
36 static ssize_t mlog_mask_store(u64 mask, const char *buf, size_t count)
38 if (!strncasecmp(buf, "allow", 5)) {
39 __mlog_set_u64(mask, mlog_and_bits);
40 __mlog_clear_u64(mask, mlog_not_bits);
41 } else if (!strncasecmp(buf, "deny", 4)) {
42 __mlog_set_u64(mask, mlog_not_bits);
43 __mlog_clear_u64(mask, mlog_and_bits);
44 } else if (!strncasecmp(buf, "off", 3)) {
45 __mlog_clear_u64(mask, mlog_not_bits);
46 __mlog_clear_u64(mask, mlog_and_bits);
53 void __mlog_printk(const u64 *mask, const char *func, int line,
59 const char *prefix = "";
61 if (!__mlog_test_u64(*mask, mlog_and_bits) ||
62 __mlog_test_u64(*mask, mlog_not_bits))
65 if (*mask & ML_ERROR) {
68 } else if (*mask & ML_NOTICE) {
79 printk("%s(%s,%u,%u):%s:%d %s%pV",
80 level, current->comm, task_pid_nr(current),
81 raw_smp_processor_id(), func, line, prefix, &vaf);
85 EXPORT_SYMBOL_GPL(__mlog_printk);
87 struct mlog_attribute {
88 struct attribute attr;
92 #define to_mlog_attr(_attr) container_of(_attr, struct mlog_attribute, attr)
94 #define define_mask(_name) { \
97 .mode = S_IRUGO | S_IWUSR, \
102 static struct mlog_attribute mlog_attrs[MLOG_MAX_BITS] = {
106 define_mask(HEARTBEAT),
110 define_mask(DLM_DOMAIN),
111 define_mask(DLM_THREAD),
112 define_mask(DLM_MASTER),
113 define_mask(DLM_RECOVERY),
114 define_mask(DLM_GLUE),
119 define_mask(CLUSTER),
122 define_mask(KTHREAD),
125 static struct attribute *mlog_attr_ptrs[MLOG_MAX_BITS] = {NULL, };
127 static ssize_t mlog_show(struct kobject *obj, struct attribute *attr,
130 struct mlog_attribute *mlog_attr = to_mlog_attr(attr);
132 return mlog_mask_show(mlog_attr->mask, buf);
135 static ssize_t mlog_store(struct kobject *obj, struct attribute *attr,
136 const char *buf, size_t count)
138 struct mlog_attribute *mlog_attr = to_mlog_attr(attr);
140 return mlog_mask_store(mlog_attr->mask, buf, count);
143 static const struct sysfs_ops mlog_attr_ops = {
148 static struct kobj_type mlog_ktype = {
149 .default_attrs = mlog_attr_ptrs,
150 .sysfs_ops = &mlog_attr_ops,
153 static struct kset mlog_kset = {
154 .kobj = {.ktype = &mlog_ktype},
157 int mlog_sys_init(struct kset *o2cb_kset)
161 while (mlog_attrs[i].attr.mode) {
162 mlog_attr_ptrs[i] = &mlog_attrs[i].attr;
165 mlog_attr_ptrs[i] = NULL;
167 kobject_set_name(&mlog_kset.kobj, "logmask");
168 mlog_kset.kobj.kset = o2cb_kset;
169 return kset_register(&mlog_kset);
172 void mlog_sys_shutdown(void)
174 kset_unregister(&mlog_kset);