blob: fdc302ddafe8228165126c17b132e495fcf537f3 [file] [log] [blame]
Zach Brown52fd3d62005-12-15 14:31:23 -08001/* -*- 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
31struct mlog_bits mlog_and_bits = MLOG_BITS_RHS(MLOG_INITIAL_AND_MASK);
32EXPORT_SYMBOL_GPL(mlog_and_bits);
Tao Mac1e8d352011-03-07 16:43:21 +080033struct mlog_bits mlog_not_bits = MLOG_BITS_RHS(0);
Zach Brown52fd3d62005-12-15 14:31:23 -080034EXPORT_SYMBOL_GPL(mlog_not_bits);
35
36static 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
50static ssize_t mlog_mask_store(u64 mask, const char *buf, size_t count)
51{
52 if (!strnicmp(buf, "allow", 5)) {
53 __mlog_set_u64(mask, mlog_and_bits);
54 __mlog_clear_u64(mask, mlog_not_bits);
55 } else if (!strnicmp(buf, "deny", 4)) {
56 __mlog_set_u64(mask, mlog_not_bits);
57 __mlog_clear_u64(mask, mlog_and_bits);
58 } else if (!strnicmp(buf, "off", 3)) {
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
67struct mlog_attribute {
68 struct attribute attr;
69 u64 mask;
70};
71
72#define to_mlog_attr(_attr) container_of(_attr, struct mlog_attribute, attr)
73
74#define define_mask(_name) { \
75 .attr = { \
76 .name = #_name, \
Zach Brown52fd3d62005-12-15 14:31:23 -080077 .mode = S_IRUGO | S_IWUSR, \
78 }, \
79 .mask = ML_##_name, \
80}
81
82static struct mlog_attribute mlog_attrs[MLOG_MAX_BITS] = {
Zach Brown52fd3d62005-12-15 14:31:23 -080083 define_mask(TCP),
84 define_mask(MSG),
85 define_mask(SOCKET),
86 define_mask(HEARTBEAT),
87 define_mask(HB_BIO),
88 define_mask(DLMFS),
89 define_mask(DLM),
90 define_mask(DLM_DOMAIN),
91 define_mask(DLM_THREAD),
92 define_mask(DLM_MASTER),
93 define_mask(DLM_RECOVERY),
94 define_mask(AIO),
95 define_mask(JOURNAL),
96 define_mask(DISK_ALLOC),
97 define_mask(SUPER),
98 define_mask(FILE_IO),
99 define_mask(EXTENT_MAP),
100 define_mask(DLM_GLUE),
101 define_mask(BH_IO),
102 define_mask(UPTODATE),
103 define_mask(NAMEI),
104 define_mask(INODE),
105 define_mask(VOTE),
106 define_mask(DCACHE),
107 define_mask(CONN),
108 define_mask(QUORUM),
109 define_mask(EXPORT),
Tao Maf56654c2008-08-18 17:38:48 +0800110 define_mask(XATTR),
Tao Ma754938c2008-12-15 06:03:41 +0800111 define_mask(QUOTA),
Tao Maf2c870e2009-08-18 11:19:26 +0800112 define_mask(REFCOUNT),
Sunil Mushran9b915182010-02-26 19:42:44 -0800113 define_mask(BASTS),
Sunil Mushran41b41a22010-12-09 18:20:38 -0800114 define_mask(RESERVATIONS),
115 define_mask(CLUSTER),
Zach Brown52fd3d62005-12-15 14:31:23 -0800116 define_mask(ERROR),
117 define_mask(NOTICE),
118 define_mask(KTHREAD),
119};
120
121static struct attribute *mlog_attr_ptrs[MLOG_MAX_BITS] = {NULL, };
122
123static ssize_t mlog_show(struct kobject *obj, struct attribute *attr,
124 char *buf)
125{
126 struct mlog_attribute *mlog_attr = to_mlog_attr(attr);
127
128 return mlog_mask_show(mlog_attr->mask, buf);
129}
130
131static ssize_t mlog_store(struct kobject *obj, struct attribute *attr,
132 const char *buf, size_t count)
133{
134 struct mlog_attribute *mlog_attr = to_mlog_attr(attr);
135
136 return mlog_mask_store(mlog_attr->mask, buf, count);
137}
138
Emese Revfy52cf25d2010-01-19 02:58:23 +0100139static const struct sysfs_ops mlog_attr_ops = {
Zach Brown52fd3d62005-12-15 14:31:23 -0800140 .show = mlog_show,
141 .store = mlog_store,
142};
143
144static struct kobj_type mlog_ktype = {
145 .default_attrs = mlog_attr_ptrs,
146 .sysfs_ops = &mlog_attr_ops,
147};
148
149static struct kset mlog_kset = {
Greg Kroah-Hartman34980ca2007-09-12 15:06:57 -0700150 .kobj = {.ktype = &mlog_ktype},
Zach Brown52fd3d62005-12-15 14:31:23 -0800151};
152
Greg Kroah-Hartmanc60b7172007-11-02 16:19:59 -0700153int mlog_sys_init(struct kset *o2cb_kset)
Zach Brown52fd3d62005-12-15 14:31:23 -0800154{
155 int i = 0;
156
157 while (mlog_attrs[i].attr.mode) {
158 mlog_attr_ptrs[i] = &mlog_attrs[i].attr;
159 i++;
160 }
161 mlog_attr_ptrs[i] = NULL;
162
Greg Kroah-Hartman34980ca2007-09-12 15:06:57 -0700163 kobject_set_name(&mlog_kset.kobj, "logmask");
Greg Kroah-Hartmanc60b7172007-11-02 16:19:59 -0700164 mlog_kset.kobj.kset = o2cb_kset;
Zach Brown52fd3d62005-12-15 14:31:23 -0800165 return kset_register(&mlog_kset);
166}
167
168void mlog_sys_shutdown(void)
169{
170 kset_unregister(&mlog_kset);
171}