xref: /OK3568_Linux_fs/kernel/fs/jfs/jfs_debug.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-or-later
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  *   Copyright (C) International Business Machines Corp., 2000-2004
4*4882a593Smuzhiyun  *   Portions Copyright (C) Christoph Hellwig, 2001-2002
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun #include <linux/fs.h>
8*4882a593Smuzhiyun #include <linux/ctype.h>
9*4882a593Smuzhiyun #include <linux/module.h>
10*4882a593Smuzhiyun #include <linux/proc_fs.h>
11*4882a593Smuzhiyun #include <linux/seq_file.h>
12*4882a593Smuzhiyun #include <linux/uaccess.h>
13*4882a593Smuzhiyun #include "jfs_incore.h"
14*4882a593Smuzhiyun #include "jfs_filsys.h"
15*4882a593Smuzhiyun #include "jfs_debug.h"
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun #ifdef PROC_FS_JFS /* see jfs_debug.h */
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun #ifdef CONFIG_JFS_DEBUG
jfs_loglevel_proc_show(struct seq_file * m,void * v)20*4882a593Smuzhiyun static int jfs_loglevel_proc_show(struct seq_file *m, void *v)
21*4882a593Smuzhiyun {
22*4882a593Smuzhiyun 	seq_printf(m, "%d\n", jfsloglevel);
23*4882a593Smuzhiyun 	return 0;
24*4882a593Smuzhiyun }
25*4882a593Smuzhiyun 
jfs_loglevel_proc_open(struct inode * inode,struct file * file)26*4882a593Smuzhiyun static int jfs_loglevel_proc_open(struct inode *inode, struct file *file)
27*4882a593Smuzhiyun {
28*4882a593Smuzhiyun 	return single_open(file, jfs_loglevel_proc_show, NULL);
29*4882a593Smuzhiyun }
30*4882a593Smuzhiyun 
jfs_loglevel_proc_write(struct file * file,const char __user * buffer,size_t count,loff_t * ppos)31*4882a593Smuzhiyun static ssize_t jfs_loglevel_proc_write(struct file *file,
32*4882a593Smuzhiyun 		const char __user *buffer, size_t count, loff_t *ppos)
33*4882a593Smuzhiyun {
34*4882a593Smuzhiyun 	char c;
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun 	if (get_user(c, buffer))
37*4882a593Smuzhiyun 		return -EFAULT;
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun 	/* yes, I know this is an ASCIIism.  --hch */
40*4882a593Smuzhiyun 	if (c < '0' || c > '9')
41*4882a593Smuzhiyun 		return -EINVAL;
42*4882a593Smuzhiyun 	jfsloglevel = c - '0';
43*4882a593Smuzhiyun 	return count;
44*4882a593Smuzhiyun }
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun static const struct proc_ops jfs_loglevel_proc_ops = {
47*4882a593Smuzhiyun 	.proc_open	= jfs_loglevel_proc_open,
48*4882a593Smuzhiyun 	.proc_read	= seq_read,
49*4882a593Smuzhiyun 	.proc_lseek	= seq_lseek,
50*4882a593Smuzhiyun 	.proc_release	= single_release,
51*4882a593Smuzhiyun 	.proc_write	= jfs_loglevel_proc_write,
52*4882a593Smuzhiyun };
53*4882a593Smuzhiyun #endif
54*4882a593Smuzhiyun 
jfs_proc_init(void)55*4882a593Smuzhiyun void jfs_proc_init(void)
56*4882a593Smuzhiyun {
57*4882a593Smuzhiyun 	struct proc_dir_entry *base;
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun 	base = proc_mkdir("fs/jfs", NULL);
60*4882a593Smuzhiyun 	if (!base)
61*4882a593Smuzhiyun 		return;
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun #ifdef CONFIG_JFS_STATISTICS
64*4882a593Smuzhiyun 	proc_create_single("lmstats", 0, base, jfs_lmstats_proc_show);
65*4882a593Smuzhiyun 	proc_create_single("txstats", 0, base, jfs_txstats_proc_show);
66*4882a593Smuzhiyun 	proc_create_single("xtstat", 0, base, jfs_xtstat_proc_show);
67*4882a593Smuzhiyun 	proc_create_single("mpstat", 0, base, jfs_mpstat_proc_show);
68*4882a593Smuzhiyun #endif
69*4882a593Smuzhiyun #ifdef CONFIG_JFS_DEBUG
70*4882a593Smuzhiyun 	proc_create_single("TxAnchor", 0, base, jfs_txanchor_proc_show);
71*4882a593Smuzhiyun 	proc_create("loglevel", 0, base, &jfs_loglevel_proc_ops);
72*4882a593Smuzhiyun #endif
73*4882a593Smuzhiyun }
74*4882a593Smuzhiyun 
jfs_proc_clean(void)75*4882a593Smuzhiyun void jfs_proc_clean(void)
76*4882a593Smuzhiyun {
77*4882a593Smuzhiyun 	remove_proc_subtree("fs/jfs", NULL);
78*4882a593Smuzhiyun }
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun #endif /* PROC_FS_JFS */
81