Zach Brown | 52fd3d6 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 1 | /* -*- mode: c; c-basic-offset: 8; -*- |
| 2 | * vim: noexpandtab sw=8 ts=8 sts=0: |
| 3 | * |
| 4 | * Copyright (C) 2004, 2005 Oracle. All rights reserved. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public |
| 17 | * License along with this program; if not, write to the |
| 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 19 | * Boston, MA 021110-1307, USA. |
| 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 | |
| 31 | struct mlog_bits mlog_and_bits = MLOG_BITS_RHS(MLOG_INITIAL_AND_MASK); |
| 32 | EXPORT_SYMBOL_GPL(mlog_and_bits); |
Tao Ma | c1e8d35 | 2011-03-07 16:43:21 +0800 | [diff] [blame] | 33 | struct mlog_bits mlog_not_bits = MLOG_BITS_RHS(0); |
Zach Brown | 52fd3d6 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 34 | EXPORT_SYMBOL_GPL(mlog_not_bits); |
| 35 | |
| 36 | static 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 | |
| 50 | static ssize_t mlog_mask_store(u64 mask, const char *buf, size_t count) |
| 51 | { |
Rasmus Villemoes | 2bd6332 | 2014-10-13 15:54:37 -0700 | [diff] [blame] | 52 | if (!strncasecmp(buf, "allow", 5)) { |
Zach Brown | 52fd3d6 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 53 | __mlog_set_u64(mask, mlog_and_bits); |
| 54 | __mlog_clear_u64(mask, mlog_not_bits); |
Rasmus Villemoes | 2bd6332 | 2014-10-13 15:54:37 -0700 | [diff] [blame] | 55 | } else if (!strncasecmp(buf, "deny", 4)) { |
Zach Brown | 52fd3d6 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 56 | __mlog_set_u64(mask, mlog_not_bits); |
| 57 | __mlog_clear_u64(mask, mlog_and_bits); |
Rasmus Villemoes | 2bd6332 | 2014-10-13 15:54:37 -0700 | [diff] [blame] | 58 | } else if (!strncasecmp(buf, "off", 3)) { |
Zach Brown | 52fd3d6 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 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 | |
Joe Perches | 7c2bd2f | 2015-06-24 16:54:53 -0700 | [diff] [blame] | 67 | void __mlog_printk(const u64 *mask, const char *func, int line, |
| 68 | const char *fmt, ...) |
| 69 | { |
| 70 | struct va_format vaf; |
| 71 | va_list args; |
| 72 | const char *level; |
| 73 | const char *prefix = ""; |
| 74 | |
| 75 | if (!__mlog_test_u64(*mask, mlog_and_bits) || |
| 76 | __mlog_test_u64(*mask, mlog_not_bits)) |
| 77 | return; |
| 78 | |
| 79 | if (*mask & ML_ERROR) { |
| 80 | level = KERN_ERR; |
| 81 | prefix = "ERROR: "; |
| 82 | } else if (*mask & ML_NOTICE) { |
| 83 | level = KERN_NOTICE; |
| 84 | } else { |
| 85 | level = KERN_INFO; |
| 86 | } |
| 87 | |
| 88 | va_start(args, fmt); |
| 89 | |
| 90 | vaf.fmt = fmt; |
| 91 | vaf.va = &args; |
| 92 | |
Andrew Morton | e327284 | 2015-06-24 16:54:56 -0700 | [diff] [blame^] | 93 | printk("%s(%s,%u,%u):%s:%d %s%pV", |
| 94 | level, current->comm, task_pid_nr(current), |
| 95 | raw_smp_processor_id(), func, line, prefix, &vaf); |
Joe Perches | 7c2bd2f | 2015-06-24 16:54:53 -0700 | [diff] [blame] | 96 | |
| 97 | va_end(args); |
| 98 | } |
| 99 | EXPORT_SYMBOL_GPL(__mlog_printk); |
| 100 | |
Zach Brown | 52fd3d6 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 101 | struct mlog_attribute { |
| 102 | struct attribute attr; |
| 103 | u64 mask; |
| 104 | }; |
| 105 | |
| 106 | #define to_mlog_attr(_attr) container_of(_attr, struct mlog_attribute, attr) |
| 107 | |
| 108 | #define define_mask(_name) { \ |
| 109 | .attr = { \ |
| 110 | .name = #_name, \ |
Zach Brown | 52fd3d6 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 111 | .mode = S_IRUGO | S_IWUSR, \ |
| 112 | }, \ |
| 113 | .mask = ML_##_name, \ |
| 114 | } |
| 115 | |
| 116 | static struct mlog_attribute mlog_attrs[MLOG_MAX_BITS] = { |
Zach Brown | 52fd3d6 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 117 | define_mask(TCP), |
| 118 | define_mask(MSG), |
| 119 | define_mask(SOCKET), |
| 120 | define_mask(HEARTBEAT), |
| 121 | define_mask(HB_BIO), |
| 122 | define_mask(DLMFS), |
| 123 | define_mask(DLM), |
| 124 | define_mask(DLM_DOMAIN), |
| 125 | define_mask(DLM_THREAD), |
| 126 | define_mask(DLM_MASTER), |
| 127 | define_mask(DLM_RECOVERY), |
Zach Brown | 52fd3d6 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 128 | define_mask(DLM_GLUE), |
Zach Brown | 52fd3d6 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 129 | define_mask(VOTE), |
Zach Brown | 52fd3d6 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 130 | define_mask(CONN), |
| 131 | define_mask(QUORUM), |
Sunil Mushran | 9b91518 | 2010-02-26 19:42:44 -0800 | [diff] [blame] | 132 | define_mask(BASTS), |
Sunil Mushran | 41b41a2 | 2010-12-09 18:20:38 -0800 | [diff] [blame] | 133 | define_mask(CLUSTER), |
Zach Brown | 52fd3d6 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 134 | define_mask(ERROR), |
| 135 | define_mask(NOTICE), |
| 136 | define_mask(KTHREAD), |
| 137 | }; |
| 138 | |
| 139 | static struct attribute *mlog_attr_ptrs[MLOG_MAX_BITS] = {NULL, }; |
| 140 | |
| 141 | static ssize_t mlog_show(struct kobject *obj, struct attribute *attr, |
| 142 | char *buf) |
| 143 | { |
| 144 | struct mlog_attribute *mlog_attr = to_mlog_attr(attr); |
| 145 | |
| 146 | return mlog_mask_show(mlog_attr->mask, buf); |
| 147 | } |
| 148 | |
| 149 | static ssize_t mlog_store(struct kobject *obj, struct attribute *attr, |
| 150 | const char *buf, size_t count) |
| 151 | { |
| 152 | struct mlog_attribute *mlog_attr = to_mlog_attr(attr); |
| 153 | |
| 154 | return mlog_mask_store(mlog_attr->mask, buf, count); |
| 155 | } |
| 156 | |
Emese Revfy | 52cf25d | 2010-01-19 02:58:23 +0100 | [diff] [blame] | 157 | static const struct sysfs_ops mlog_attr_ops = { |
Zach Brown | 52fd3d6 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 158 | .show = mlog_show, |
| 159 | .store = mlog_store, |
| 160 | }; |
| 161 | |
| 162 | static struct kobj_type mlog_ktype = { |
| 163 | .default_attrs = mlog_attr_ptrs, |
| 164 | .sysfs_ops = &mlog_attr_ops, |
| 165 | }; |
| 166 | |
| 167 | static struct kset mlog_kset = { |
Greg Kroah-Hartman | 34980ca | 2007-09-12 15:06:57 -0700 | [diff] [blame] | 168 | .kobj = {.ktype = &mlog_ktype}, |
Zach Brown | 52fd3d6 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 169 | }; |
| 170 | |
Greg Kroah-Hartman | c60b717 | 2007-11-02 16:19:59 -0700 | [diff] [blame] | 171 | int mlog_sys_init(struct kset *o2cb_kset) |
Zach Brown | 52fd3d6 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 172 | { |
| 173 | int i = 0; |
| 174 | |
| 175 | while (mlog_attrs[i].attr.mode) { |
| 176 | mlog_attr_ptrs[i] = &mlog_attrs[i].attr; |
| 177 | i++; |
| 178 | } |
| 179 | mlog_attr_ptrs[i] = NULL; |
| 180 | |
Greg Kroah-Hartman | 34980ca | 2007-09-12 15:06:57 -0700 | [diff] [blame] | 181 | kobject_set_name(&mlog_kset.kobj, "logmask"); |
Greg Kroah-Hartman | c60b717 | 2007-11-02 16:19:59 -0700 | [diff] [blame] | 182 | mlog_kset.kobj.kset = o2cb_kset; |
Zach Brown | 52fd3d6 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 183 | return kset_register(&mlog_kset); |
| 184 | } |
| 185 | |
| 186 | void mlog_sys_shutdown(void) |
| 187 | { |
| 188 | kset_unregister(&mlog_kset); |
| 189 | } |