1328970deSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2fa60ce2cSMasahiro Yamada /*
352fd3d6fSZach Brown * Copyright (C) 2004, 2005 Oracle. All rights reserved.
452fd3d6fSZach Brown */
552fd3d6fSZach Brown
652fd3d6fSZach Brown #include <linux/module.h>
752fd3d6fSZach Brown #include <linux/kernel.h>
852fd3d6fSZach Brown #include <linux/proc_fs.h>
952fd3d6fSZach Brown #include <linux/seq_file.h>
1052fd3d6fSZach Brown #include <linux/string.h>
117c0f6ba6SLinus Torvalds #include <linux/uaccess.h>
1252fd3d6fSZach Brown
1352fd3d6fSZach Brown #include "masklog.h"
1452fd3d6fSZach Brown
1552fd3d6fSZach Brown struct mlog_bits mlog_and_bits = MLOG_BITS_RHS(MLOG_INITIAL_AND_MASK);
1652fd3d6fSZach Brown EXPORT_SYMBOL_GPL(mlog_and_bits);
17c1e8d35eSTao Ma struct mlog_bits mlog_not_bits = MLOG_BITS_RHS(0);
1852fd3d6fSZach Brown EXPORT_SYMBOL_GPL(mlog_not_bits);
1952fd3d6fSZach Brown
mlog_mask_show(u64 mask,char * buf)2052fd3d6fSZach Brown static ssize_t mlog_mask_show(u64 mask, char *buf)
2152fd3d6fSZach Brown {
2252fd3d6fSZach Brown char *state;
2352fd3d6fSZach Brown
2452fd3d6fSZach Brown if (__mlog_test_u64(mask, mlog_and_bits))
2552fd3d6fSZach Brown state = "allow";
2652fd3d6fSZach Brown else if (__mlog_test_u64(mask, mlog_not_bits))
2752fd3d6fSZach Brown state = "deny";
2852fd3d6fSZach Brown else
2952fd3d6fSZach Brown state = "off";
3052fd3d6fSZach Brown
3152fd3d6fSZach Brown return snprintf(buf, PAGE_SIZE, "%s\n", state);
3252fd3d6fSZach Brown }
3352fd3d6fSZach Brown
mlog_mask_store(u64 mask,const char * buf,size_t count)3452fd3d6fSZach Brown static ssize_t mlog_mask_store(u64 mask, const char *buf, size_t count)
3552fd3d6fSZach Brown {
362bd63329SRasmus Villemoes if (!strncasecmp(buf, "allow", 5)) {
3752fd3d6fSZach Brown __mlog_set_u64(mask, mlog_and_bits);
3852fd3d6fSZach Brown __mlog_clear_u64(mask, mlog_not_bits);
392bd63329SRasmus Villemoes } else if (!strncasecmp(buf, "deny", 4)) {
4052fd3d6fSZach Brown __mlog_set_u64(mask, mlog_not_bits);
4152fd3d6fSZach Brown __mlog_clear_u64(mask, mlog_and_bits);
422bd63329SRasmus Villemoes } else if (!strncasecmp(buf, "off", 3)) {
4352fd3d6fSZach Brown __mlog_clear_u64(mask, mlog_not_bits);
4452fd3d6fSZach Brown __mlog_clear_u64(mask, mlog_and_bits);
4552fd3d6fSZach Brown } else
4652fd3d6fSZach Brown return -EINVAL;
4752fd3d6fSZach Brown
4852fd3d6fSZach Brown return count;
4952fd3d6fSZach Brown }
5052fd3d6fSZach Brown
__mlog_printk(const u64 * mask,const char * func,int line,const char * fmt,...)517c2bd2f9SJoe Perches void __mlog_printk(const u64 *mask, const char *func, int line,
527c2bd2f9SJoe Perches const char *fmt, ...)
537c2bd2f9SJoe Perches {
547c2bd2f9SJoe Perches struct va_format vaf;
557c2bd2f9SJoe Perches va_list args;
567c2bd2f9SJoe Perches const char *level;
577c2bd2f9SJoe Perches const char *prefix = "";
587c2bd2f9SJoe Perches
597c2bd2f9SJoe Perches if (!__mlog_test_u64(*mask, mlog_and_bits) ||
607c2bd2f9SJoe Perches __mlog_test_u64(*mask, mlog_not_bits))
617c2bd2f9SJoe Perches return;
627c2bd2f9SJoe Perches
637c2bd2f9SJoe Perches if (*mask & ML_ERROR) {
647c2bd2f9SJoe Perches level = KERN_ERR;
657c2bd2f9SJoe Perches prefix = "ERROR: ";
667c2bd2f9SJoe Perches } else if (*mask & ML_NOTICE) {
677c2bd2f9SJoe Perches level = KERN_NOTICE;
687c2bd2f9SJoe Perches } else {
697c2bd2f9SJoe Perches level = KERN_INFO;
707c2bd2f9SJoe Perches }
717c2bd2f9SJoe Perches
727c2bd2f9SJoe Perches va_start(args, fmt);
737c2bd2f9SJoe Perches
747c2bd2f9SJoe Perches vaf.fmt = fmt;
757c2bd2f9SJoe Perches vaf.va = &args;
767c2bd2f9SJoe Perches
77e327284aSAndrew Morton printk("%s(%s,%u,%u):%s:%d %s%pV",
78e327284aSAndrew Morton level, current->comm, task_pid_nr(current),
79e327284aSAndrew Morton raw_smp_processor_id(), func, line, prefix, &vaf);
807c2bd2f9SJoe Perches
817c2bd2f9SJoe Perches va_end(args);
827c2bd2f9SJoe Perches }
837c2bd2f9SJoe Perches EXPORT_SYMBOL_GPL(__mlog_printk);
847c2bd2f9SJoe Perches
8552fd3d6fSZach Brown struct mlog_attribute {
8652fd3d6fSZach Brown struct attribute attr;
8752fd3d6fSZach Brown u64 mask;
8852fd3d6fSZach Brown };
8952fd3d6fSZach Brown
9052fd3d6fSZach Brown #define to_mlog_attr(_attr) container_of(_attr, struct mlog_attribute, attr)
9152fd3d6fSZach Brown
9252fd3d6fSZach Brown #define define_mask(_name) { \
9352fd3d6fSZach Brown .attr = { \
9452fd3d6fSZach Brown .name = #_name, \
9552fd3d6fSZach Brown .mode = S_IRUGO | S_IWUSR, \
9652fd3d6fSZach Brown }, \
9752fd3d6fSZach Brown .mask = ML_##_name, \
9852fd3d6fSZach Brown }
9952fd3d6fSZach Brown
10052fd3d6fSZach Brown static struct mlog_attribute mlog_attrs[MLOG_MAX_BITS] = {
10152fd3d6fSZach Brown define_mask(TCP),
10252fd3d6fSZach Brown define_mask(MSG),
10352fd3d6fSZach Brown define_mask(SOCKET),
10452fd3d6fSZach Brown define_mask(HEARTBEAT),
10552fd3d6fSZach Brown define_mask(HB_BIO),
10652fd3d6fSZach Brown define_mask(DLMFS),
10752fd3d6fSZach Brown define_mask(DLM),
10852fd3d6fSZach Brown define_mask(DLM_DOMAIN),
10952fd3d6fSZach Brown define_mask(DLM_THREAD),
11052fd3d6fSZach Brown define_mask(DLM_MASTER),
11152fd3d6fSZach Brown define_mask(DLM_RECOVERY),
11252fd3d6fSZach Brown define_mask(DLM_GLUE),
11352fd3d6fSZach Brown define_mask(VOTE),
11452fd3d6fSZach Brown define_mask(CONN),
11552fd3d6fSZach Brown define_mask(QUORUM),
1169b915181SSunil Mushran define_mask(BASTS),
11741b41a26SSunil Mushran define_mask(CLUSTER),
11852fd3d6fSZach Brown define_mask(ERROR),
11952fd3d6fSZach Brown define_mask(NOTICE),
12052fd3d6fSZach Brown define_mask(KTHREAD),
12152fd3d6fSZach Brown };
12252fd3d6fSZach Brown
123*d141b39bSGreg Kroah-Hartman static struct attribute *mlog_default_attrs[MLOG_MAX_BITS] = {NULL, };
124*d141b39bSGreg Kroah-Hartman ATTRIBUTE_GROUPS(mlog_default);
12552fd3d6fSZach Brown
mlog_show(struct kobject * obj,struct attribute * attr,char * buf)12652fd3d6fSZach Brown static ssize_t mlog_show(struct kobject *obj, struct attribute *attr,
12752fd3d6fSZach Brown char *buf)
12852fd3d6fSZach Brown {
12952fd3d6fSZach Brown struct mlog_attribute *mlog_attr = to_mlog_attr(attr);
13052fd3d6fSZach Brown
13152fd3d6fSZach Brown return mlog_mask_show(mlog_attr->mask, buf);
13252fd3d6fSZach Brown }
13352fd3d6fSZach Brown
mlog_store(struct kobject * obj,struct attribute * attr,const char * buf,size_t count)13452fd3d6fSZach Brown static ssize_t mlog_store(struct kobject *obj, struct attribute *attr,
13552fd3d6fSZach Brown const char *buf, size_t count)
13652fd3d6fSZach Brown {
13752fd3d6fSZach Brown struct mlog_attribute *mlog_attr = to_mlog_attr(attr);
13852fd3d6fSZach Brown
13952fd3d6fSZach Brown return mlog_mask_store(mlog_attr->mask, buf, count);
14052fd3d6fSZach Brown }
14152fd3d6fSZach Brown
14252cf25d0SEmese Revfy static const struct sysfs_ops mlog_attr_ops = {
14352fd3d6fSZach Brown .show = mlog_show,
14452fd3d6fSZach Brown .store = mlog_store,
14552fd3d6fSZach Brown };
14652fd3d6fSZach Brown
14752fd3d6fSZach Brown static struct kobj_type mlog_ktype = {
148*d141b39bSGreg Kroah-Hartman .default_groups = mlog_default_groups,
14952fd3d6fSZach Brown .sysfs_ops = &mlog_attr_ops,
15052fd3d6fSZach Brown };
15152fd3d6fSZach Brown
15252fd3d6fSZach Brown static struct kset mlog_kset = {
15334980ca8SGreg Kroah-Hartman .kobj = {.ktype = &mlog_ktype},
15452fd3d6fSZach Brown };
15552fd3d6fSZach Brown
mlog_sys_init(struct kset * o2cb_kset)156c60b7178SGreg Kroah-Hartman int mlog_sys_init(struct kset *o2cb_kset)
15752fd3d6fSZach Brown {
15852fd3d6fSZach Brown int i = 0;
15952fd3d6fSZach Brown
16052fd3d6fSZach Brown while (mlog_attrs[i].attr.mode) {
161*d141b39bSGreg Kroah-Hartman mlog_default_attrs[i] = &mlog_attrs[i].attr;
16252fd3d6fSZach Brown i++;
16352fd3d6fSZach Brown }
164*d141b39bSGreg Kroah-Hartman mlog_default_attrs[i] = NULL;
16552fd3d6fSZach Brown
16634980ca8SGreg Kroah-Hartman kobject_set_name(&mlog_kset.kobj, "logmask");
167c60b7178SGreg Kroah-Hartman mlog_kset.kobj.kset = o2cb_kset;
16852fd3d6fSZach Brown return kset_register(&mlog_kset);
16952fd3d6fSZach Brown }
17052fd3d6fSZach Brown
mlog_sys_shutdown(void)17152fd3d6fSZach Brown void mlog_sys_shutdown(void)
17252fd3d6fSZach Brown {
17352fd3d6fSZach Brown kset_unregister(&mlog_kset);
17452fd3d6fSZach Brown }
175