xref: /openbmc/linux/fs/ocfs2/cluster/masklog.c (revision 34980ca8faebfcce31094eba6ffbb0113950361f)
152fd3d6fSZach Brown /* -*- mode: c; c-basic-offset: 8; -*-
252fd3d6fSZach Brown  * vim: noexpandtab sw=8 ts=8 sts=0:
352fd3d6fSZach Brown  *
452fd3d6fSZach Brown  * Copyright (C) 2004, 2005 Oracle.  All rights reserved.
552fd3d6fSZach Brown  *
652fd3d6fSZach Brown  * This program is free software; you can redistribute it and/or
752fd3d6fSZach Brown  * modify it under the terms of the GNU General Public
852fd3d6fSZach Brown  * License as published by the Free Software Foundation; either
952fd3d6fSZach Brown  * version 2 of the License, or (at your option) any later version.
1052fd3d6fSZach Brown  *
1152fd3d6fSZach Brown  * This program is distributed in the hope that it will be useful,
1252fd3d6fSZach Brown  * but WITHOUT ANY WARRANTY; without even the implied warranty of
1352fd3d6fSZach Brown  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1452fd3d6fSZach Brown  * General Public License for more details.
1552fd3d6fSZach Brown  *
1652fd3d6fSZach Brown  * You should have received a copy of the GNU General Public
1752fd3d6fSZach Brown  * License along with this program; if not, write to the
1852fd3d6fSZach Brown  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
1952fd3d6fSZach Brown  * Boston, MA 021110-1307, USA.
2052fd3d6fSZach Brown  */
2152fd3d6fSZach Brown 
2252fd3d6fSZach Brown #include <linux/module.h>
2352fd3d6fSZach Brown #include <linux/kernel.h>
2452fd3d6fSZach Brown #include <linux/proc_fs.h>
2552fd3d6fSZach Brown #include <linux/seq_file.h>
2652fd3d6fSZach Brown #include <linux/string.h>
2752fd3d6fSZach Brown #include <asm/uaccess.h>
2852fd3d6fSZach Brown 
2952fd3d6fSZach Brown #include "masklog.h"
3052fd3d6fSZach Brown 
3152fd3d6fSZach Brown struct mlog_bits mlog_and_bits = MLOG_BITS_RHS(MLOG_INITIAL_AND_MASK);
3252fd3d6fSZach Brown EXPORT_SYMBOL_GPL(mlog_and_bits);
3352fd3d6fSZach Brown struct mlog_bits mlog_not_bits = MLOG_BITS_RHS(MLOG_INITIAL_NOT_MASK);
3452fd3d6fSZach Brown EXPORT_SYMBOL_GPL(mlog_not_bits);
3552fd3d6fSZach Brown 
3652fd3d6fSZach Brown static ssize_t mlog_mask_show(u64 mask, char *buf)
3752fd3d6fSZach Brown {
3852fd3d6fSZach Brown 	char *state;
3952fd3d6fSZach Brown 
4052fd3d6fSZach Brown 	if (__mlog_test_u64(mask, mlog_and_bits))
4152fd3d6fSZach Brown 		state = "allow";
4252fd3d6fSZach Brown 	else if (__mlog_test_u64(mask, mlog_not_bits))
4352fd3d6fSZach Brown 		state = "deny";
4452fd3d6fSZach Brown 	else
4552fd3d6fSZach Brown 		state = "off";
4652fd3d6fSZach Brown 
4752fd3d6fSZach Brown 	return snprintf(buf, PAGE_SIZE, "%s\n", state);
4852fd3d6fSZach Brown }
4952fd3d6fSZach Brown 
5052fd3d6fSZach Brown static ssize_t mlog_mask_store(u64 mask, const char *buf, size_t count)
5152fd3d6fSZach Brown {
5252fd3d6fSZach Brown 	if (!strnicmp(buf, "allow", 5)) {
5352fd3d6fSZach Brown 		__mlog_set_u64(mask, mlog_and_bits);
5452fd3d6fSZach Brown 		__mlog_clear_u64(mask, mlog_not_bits);
5552fd3d6fSZach Brown 	} else if (!strnicmp(buf, "deny", 4)) {
5652fd3d6fSZach Brown 		__mlog_set_u64(mask, mlog_not_bits);
5752fd3d6fSZach Brown 		__mlog_clear_u64(mask, mlog_and_bits);
5852fd3d6fSZach Brown 	} else if (!strnicmp(buf, "off", 3)) {
5952fd3d6fSZach Brown 		__mlog_clear_u64(mask, mlog_not_bits);
6052fd3d6fSZach Brown 		__mlog_clear_u64(mask, mlog_and_bits);
6152fd3d6fSZach Brown 	} else
6252fd3d6fSZach Brown 		return -EINVAL;
6352fd3d6fSZach Brown 
6452fd3d6fSZach Brown 	return count;
6552fd3d6fSZach Brown }
6652fd3d6fSZach Brown 
6752fd3d6fSZach Brown struct mlog_attribute {
6852fd3d6fSZach Brown 	struct attribute attr;
6952fd3d6fSZach Brown 	u64 mask;
7052fd3d6fSZach Brown };
7152fd3d6fSZach Brown 
7252fd3d6fSZach Brown #define to_mlog_attr(_attr) container_of(_attr, struct mlog_attribute, attr)
7352fd3d6fSZach Brown 
7452fd3d6fSZach Brown #define define_mask(_name) {			\
7552fd3d6fSZach Brown 	.attr = {				\
7652fd3d6fSZach Brown 		.name = #_name,			\
7752fd3d6fSZach Brown 		.mode = S_IRUGO | S_IWUSR,	\
7852fd3d6fSZach Brown 	},					\
7952fd3d6fSZach Brown 	.mask = ML_##_name,			\
8052fd3d6fSZach Brown }
8152fd3d6fSZach Brown 
8252fd3d6fSZach Brown static struct mlog_attribute mlog_attrs[MLOG_MAX_BITS] = {
8352fd3d6fSZach Brown 	define_mask(ENTRY),
8452fd3d6fSZach Brown 	define_mask(EXIT),
8552fd3d6fSZach Brown 	define_mask(TCP),
8652fd3d6fSZach Brown 	define_mask(MSG),
8752fd3d6fSZach Brown 	define_mask(SOCKET),
8852fd3d6fSZach Brown 	define_mask(HEARTBEAT),
8952fd3d6fSZach Brown 	define_mask(HB_BIO),
9052fd3d6fSZach Brown 	define_mask(DLMFS),
9152fd3d6fSZach Brown 	define_mask(DLM),
9252fd3d6fSZach Brown 	define_mask(DLM_DOMAIN),
9352fd3d6fSZach Brown 	define_mask(DLM_THREAD),
9452fd3d6fSZach Brown 	define_mask(DLM_MASTER),
9552fd3d6fSZach Brown 	define_mask(DLM_RECOVERY),
9652fd3d6fSZach Brown 	define_mask(AIO),
9752fd3d6fSZach Brown 	define_mask(JOURNAL),
9852fd3d6fSZach Brown 	define_mask(DISK_ALLOC),
9952fd3d6fSZach Brown 	define_mask(SUPER),
10052fd3d6fSZach Brown 	define_mask(FILE_IO),
10152fd3d6fSZach Brown 	define_mask(EXTENT_MAP),
10252fd3d6fSZach Brown 	define_mask(DLM_GLUE),
10352fd3d6fSZach Brown 	define_mask(BH_IO),
10452fd3d6fSZach Brown 	define_mask(UPTODATE),
10552fd3d6fSZach Brown 	define_mask(NAMEI),
10652fd3d6fSZach Brown 	define_mask(INODE),
10752fd3d6fSZach Brown 	define_mask(VOTE),
10852fd3d6fSZach Brown 	define_mask(DCACHE),
10952fd3d6fSZach Brown 	define_mask(CONN),
11052fd3d6fSZach Brown 	define_mask(QUORUM),
11152fd3d6fSZach Brown 	define_mask(EXPORT),
11252fd3d6fSZach Brown 	define_mask(ERROR),
11352fd3d6fSZach Brown 	define_mask(NOTICE),
11452fd3d6fSZach Brown 	define_mask(KTHREAD),
11552fd3d6fSZach Brown };
11652fd3d6fSZach Brown 
11752fd3d6fSZach Brown static struct attribute *mlog_attr_ptrs[MLOG_MAX_BITS] = {NULL, };
11852fd3d6fSZach Brown 
11952fd3d6fSZach Brown static ssize_t mlog_show(struct kobject *obj, struct attribute *attr,
12052fd3d6fSZach Brown 			 char *buf)
12152fd3d6fSZach Brown {
12252fd3d6fSZach Brown 	struct mlog_attribute *mlog_attr = to_mlog_attr(attr);
12352fd3d6fSZach Brown 
12452fd3d6fSZach Brown 	return mlog_mask_show(mlog_attr->mask, buf);
12552fd3d6fSZach Brown }
12652fd3d6fSZach Brown 
12752fd3d6fSZach Brown static ssize_t mlog_store(struct kobject *obj, struct attribute *attr,
12852fd3d6fSZach Brown 			  const char *buf, size_t count)
12952fd3d6fSZach Brown {
13052fd3d6fSZach Brown 	struct mlog_attribute *mlog_attr = to_mlog_attr(attr);
13152fd3d6fSZach Brown 
13252fd3d6fSZach Brown 	return mlog_mask_store(mlog_attr->mask, buf, count);
13352fd3d6fSZach Brown }
13452fd3d6fSZach Brown 
13552fd3d6fSZach Brown static struct sysfs_ops mlog_attr_ops = {
13652fd3d6fSZach Brown 	.show  = mlog_show,
13752fd3d6fSZach Brown 	.store = mlog_store,
13852fd3d6fSZach Brown };
13952fd3d6fSZach Brown 
14052fd3d6fSZach Brown static struct kobj_type mlog_ktype = {
14152fd3d6fSZach Brown 	.default_attrs = mlog_attr_ptrs,
14252fd3d6fSZach Brown 	.sysfs_ops     = &mlog_attr_ops,
14352fd3d6fSZach Brown };
14452fd3d6fSZach Brown 
14552fd3d6fSZach Brown static struct kset mlog_kset = {
146*34980ca8SGreg Kroah-Hartman 	.kobj   = {.ktype = &mlog_ktype},
14752fd3d6fSZach Brown };
14852fd3d6fSZach Brown 
149823bccfcSGreg Kroah-Hartman int mlog_sys_init(struct kset *o2cb_subsys)
15052fd3d6fSZach Brown {
15152fd3d6fSZach Brown 	int i = 0;
15252fd3d6fSZach Brown 
15352fd3d6fSZach Brown 	while (mlog_attrs[i].attr.mode) {
15452fd3d6fSZach Brown 		mlog_attr_ptrs[i] = &mlog_attrs[i].attr;
15552fd3d6fSZach Brown 		i++;
15652fd3d6fSZach Brown 	}
15752fd3d6fSZach Brown 	mlog_attr_ptrs[i] = NULL;
15852fd3d6fSZach Brown 
159*34980ca8SGreg Kroah-Hartman 	kobject_set_name(&mlog_kset.kobj, "logmask");
160c4a7f5ebSRandy Dunlap 	kobj_set_kset_s(&mlog_kset, *o2cb_subsys);
16152fd3d6fSZach Brown 	return kset_register(&mlog_kset);
16252fd3d6fSZach Brown }
16352fd3d6fSZach Brown 
16452fd3d6fSZach Brown void mlog_sys_shutdown(void)
16552fd3d6fSZach Brown {
16652fd3d6fSZach Brown 	kset_unregister(&mlog_kset);
16752fd3d6fSZach Brown }
168