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