^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* -*- mode: c; c-basic-offset: 8; -*-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * vim: noexpandtab sw=8 ts=8 sts=0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2004, 2005 Oracle. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "masklog.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) struct mlog_bits mlog_and_bits = MLOG_BITS_RHS(MLOG_INITIAL_AND_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) EXPORT_SYMBOL_GPL(mlog_and_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) struct mlog_bits mlog_not_bits = MLOG_BITS_RHS(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) EXPORT_SYMBOL_GPL(mlog_not_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static ssize_t mlog_mask_show(u64 mask, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) char *state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) if (__mlog_test_u64(mask, mlog_and_bits))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) state = "allow";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) else if (__mlog_test_u64(mask, mlog_not_bits))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) state = "deny";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) state = "off";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) return snprintf(buf, PAGE_SIZE, "%s\n", state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) static ssize_t mlog_mask_store(u64 mask, const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) if (!strncasecmp(buf, "allow", 5)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) __mlog_set_u64(mask, mlog_and_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) __mlog_clear_u64(mask, mlog_not_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) } else if (!strncasecmp(buf, "deny", 4)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) __mlog_set_u64(mask, mlog_not_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) __mlog_clear_u64(mask, mlog_and_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) } else if (!strncasecmp(buf, "off", 3)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) __mlog_clear_u64(mask, mlog_not_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) __mlog_clear_u64(mask, mlog_and_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) void __mlog_printk(const u64 *mask, const char *func, int line,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) struct va_format vaf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) const char *level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) const char *prefix = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) if (!__mlog_test_u64(*mask, mlog_and_bits) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) __mlog_test_u64(*mask, mlog_not_bits))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) if (*mask & ML_ERROR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) level = KERN_ERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) prefix = "ERROR: ";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) } else if (*mask & ML_NOTICE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) level = KERN_NOTICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) level = KERN_INFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) vaf.fmt = fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) vaf.va = &args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) printk("%s(%s,%u,%u):%s:%d %s%pV",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) level, current->comm, task_pid_nr(current),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) raw_smp_processor_id(), func, line, prefix, &vaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) EXPORT_SYMBOL_GPL(__mlog_printk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) struct mlog_attribute {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) struct attribute attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) u64 mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #define to_mlog_attr(_attr) container_of(_attr, struct mlog_attribute, attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) #define define_mask(_name) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) .attr = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) .name = #_name, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) .mode = S_IRUGO | S_IWUSR, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) .mask = ML_##_name, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static struct mlog_attribute mlog_attrs[MLOG_MAX_BITS] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) define_mask(TCP),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) define_mask(MSG),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) define_mask(SOCKET),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) define_mask(HEARTBEAT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) define_mask(HB_BIO),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) define_mask(DLMFS),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) define_mask(DLM),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) define_mask(DLM_DOMAIN),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) define_mask(DLM_THREAD),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) define_mask(DLM_MASTER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) define_mask(DLM_RECOVERY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) define_mask(DLM_GLUE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) define_mask(VOTE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) define_mask(CONN),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) define_mask(QUORUM),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) define_mask(BASTS),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) define_mask(CLUSTER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) define_mask(ERROR),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) define_mask(NOTICE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) define_mask(KTHREAD),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) static struct attribute *mlog_attr_ptrs[MLOG_MAX_BITS] = {NULL, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static ssize_t mlog_show(struct kobject *obj, struct attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) struct mlog_attribute *mlog_attr = to_mlog_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) return mlog_mask_show(mlog_attr->mask, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static ssize_t mlog_store(struct kobject *obj, struct attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct mlog_attribute *mlog_attr = to_mlog_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) return mlog_mask_store(mlog_attr->mask, buf, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static const struct sysfs_ops mlog_attr_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) .show = mlog_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) .store = mlog_store,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static struct kobj_type mlog_ktype = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) .default_attrs = mlog_attr_ptrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) .sysfs_ops = &mlog_attr_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static struct kset mlog_kset = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) .kobj = {.ktype = &mlog_ktype},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) int mlog_sys_init(struct kset *o2cb_kset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) while (mlog_attrs[i].attr.mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) mlog_attr_ptrs[i] = &mlog_attrs[i].attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) mlog_attr_ptrs[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) kobject_set_name(&mlog_kset.kobj, "logmask");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) mlog_kset.kobj.kset = o2cb_kset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) return kset_register(&mlog_kset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) void mlog_sys_shutdown(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) kset_unregister(&mlog_kset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }