xref: /openbmc/linux/fs/jfs/jfs_debug.c (revision 97a32539)
11a59d1b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds  *   Copyright (C) International Business Machines Corp., 2000-2004
41da177e4SLinus Torvalds  *   Portions Copyright (C) Christoph Hellwig, 2001-2002
51da177e4SLinus Torvalds  */
61da177e4SLinus Torvalds 
71da177e4SLinus Torvalds #include <linux/fs.h>
81da177e4SLinus Torvalds #include <linux/ctype.h>
91da177e4SLinus Torvalds #include <linux/module.h>
101da177e4SLinus Torvalds #include <linux/proc_fs.h>
11b2e03ca7SAlexey Dobriyan #include <linux/seq_file.h>
127c0f6ba6SLinus Torvalds #include <linux/uaccess.h>
131da177e4SLinus Torvalds #include "jfs_incore.h"
141da177e4SLinus Torvalds #include "jfs_filsys.h"
151da177e4SLinus Torvalds #include "jfs_debug.h"
161da177e4SLinus Torvalds 
171da177e4SLinus Torvalds #ifdef PROC_FS_JFS /* see jfs_debug.h */
181da177e4SLinus Torvalds 
191da177e4SLinus Torvalds #ifdef CONFIG_JFS_DEBUG
jfs_loglevel_proc_show(struct seq_file * m,void * v)20b2e03ca7SAlexey Dobriyan static int jfs_loglevel_proc_show(struct seq_file *m, void *v)
211da177e4SLinus Torvalds {
22b2e03ca7SAlexey Dobriyan 	seq_printf(m, "%d\n", jfsloglevel);
23b2e03ca7SAlexey Dobriyan 	return 0;
241da177e4SLinus Torvalds }
251da177e4SLinus Torvalds 
jfs_loglevel_proc_open(struct inode * inode,struct file * file)26b2e03ca7SAlexey Dobriyan static int jfs_loglevel_proc_open(struct inode *inode, struct file *file)
27b2e03ca7SAlexey Dobriyan {
28b2e03ca7SAlexey Dobriyan 	return single_open(file, jfs_loglevel_proc_show, NULL);
29b2e03ca7SAlexey Dobriyan }
30b2e03ca7SAlexey Dobriyan 
jfs_loglevel_proc_write(struct file * file,const char __user * buffer,size_t count,loff_t * ppos)31b2e03ca7SAlexey Dobriyan static ssize_t jfs_loglevel_proc_write(struct file *file,
32b2e03ca7SAlexey Dobriyan 		const char __user *buffer, size_t count, loff_t *ppos)
331da177e4SLinus Torvalds {
341da177e4SLinus Torvalds 	char c;
351da177e4SLinus Torvalds 
361da177e4SLinus Torvalds 	if (get_user(c, buffer))
371da177e4SLinus Torvalds 		return -EFAULT;
381da177e4SLinus Torvalds 
391da177e4SLinus Torvalds 	/* yes, I know this is an ASCIIism.  --hch */
401da177e4SLinus Torvalds 	if (c < '0' || c > '9')
411da177e4SLinus Torvalds 		return -EINVAL;
421da177e4SLinus Torvalds 	jfsloglevel = c - '0';
431da177e4SLinus Torvalds 	return count;
441da177e4SLinus Torvalds }
45b2e03ca7SAlexey Dobriyan 
4697a32539SAlexey Dobriyan static const struct proc_ops jfs_loglevel_proc_ops = {
4797a32539SAlexey Dobriyan 	.proc_open	= jfs_loglevel_proc_open,
4897a32539SAlexey Dobriyan 	.proc_read	= seq_read,
4997a32539SAlexey Dobriyan 	.proc_lseek	= seq_lseek,
5097a32539SAlexey Dobriyan 	.proc_release	= single_release,
5197a32539SAlexey Dobriyan 	.proc_write	= jfs_loglevel_proc_write,
52b2e03ca7SAlexey Dobriyan };
531da177e4SLinus Torvalds #endif
541da177e4SLinus Torvalds 
jfs_proc_init(void)551da177e4SLinus Torvalds void jfs_proc_init(void)
561da177e4SLinus Torvalds {
5707a3b8edSChristoph Hellwig 	struct proc_dir_entry *base;
581da177e4SLinus Torvalds 
5907a3b8edSChristoph Hellwig 	base = proc_mkdir("fs/jfs", NULL);
6007a3b8edSChristoph Hellwig 	if (!base)
611da177e4SLinus Torvalds 		return;
621da177e4SLinus Torvalds 
6307a3b8edSChristoph Hellwig #ifdef CONFIG_JFS_STATISTICS
6407a3b8edSChristoph Hellwig 	proc_create_single("lmstats", 0, base, jfs_lmstats_proc_show);
6507a3b8edSChristoph Hellwig 	proc_create_single("txstats", 0, base, jfs_txstats_proc_show);
6607a3b8edSChristoph Hellwig 	proc_create_single("xtstat", 0, base, jfs_xtstat_proc_show);
6707a3b8edSChristoph Hellwig 	proc_create_single("mpstat", 0, base, jfs_mpstat_proc_show);
6807a3b8edSChristoph Hellwig #endif
6907a3b8edSChristoph Hellwig #ifdef CONFIG_JFS_DEBUG
7007a3b8edSChristoph Hellwig 	proc_create_single("TxAnchor", 0, base, jfs_txanchor_proc_show);
7197a32539SAlexey Dobriyan 	proc_create("loglevel", 0, base, &jfs_loglevel_proc_ops);
7207a3b8edSChristoph Hellwig #endif
731da177e4SLinus Torvalds }
741da177e4SLinus Torvalds 
jfs_proc_clean(void)751da177e4SLinus Torvalds void jfs_proc_clean(void)
761da177e4SLinus Torvalds {
7707a3b8edSChristoph Hellwig 	remove_proc_subtree("fs/jfs", NULL);
781da177e4SLinus Torvalds }
791da177e4SLinus Torvalds 
801da177e4SLinus Torvalds #endif /* PROC_FS_JFS */
81