Thomas Gleixner | 457c899 | 2019-05-19 13:08:55 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * linux/net/sunrpc/sysctl.c |
| 4 | * |
| 5 | * Sysctl interface to sunrpc module. |
| 6 | * |
| 7 | * I would prefer to register the sunrpc table below sys/net, but that's |
| 8 | * impossible at the moment. |
| 9 | */ |
| 10 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/types.h> |
| 12 | #include <linux/linkage.h> |
| 13 | #include <linux/ctype.h> |
| 14 | #include <linux/fs.h> |
| 15 | #include <linux/sysctl.h> |
| 16 | #include <linux/module.h> |
| 17 | |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 18 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/sunrpc/types.h> |
| 20 | #include <linux/sunrpc/sched.h> |
| 21 | #include <linux/sunrpc/stats.h> |
Tom Tucker | dc9a16e | 2007-12-30 21:08:31 -0600 | [diff] [blame] | 22 | #include <linux/sunrpc/svc_xprt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
Stanislav Kinsbursky | 70abc49 | 2012-01-12 22:07:51 +0400 | [diff] [blame] | 24 | #include "netns.h" |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | /* |
| 27 | * Declare the debug flags here |
| 28 | */ |
| 29 | unsigned int rpc_debug; |
Trond Myklebust | e8914c6 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 30 | EXPORT_SYMBOL_GPL(rpc_debug); |
Trond Myklebust | a6eaf8b | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 31 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | unsigned int nfs_debug; |
Trond Myklebust | e8914c6 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 33 | EXPORT_SYMBOL_GPL(nfs_debug); |
Trond Myklebust | a6eaf8b | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | unsigned int nfsd_debug; |
Trond Myklebust | e8914c6 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 36 | EXPORT_SYMBOL_GPL(nfsd_debug); |
Trond Myklebust | a6eaf8b | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 37 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | unsigned int nlm_debug; |
Trond Myklebust | e8914c6 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 39 | EXPORT_SYMBOL_GPL(nlm_debug); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Jeff Layton | f895b25 | 2014-11-17 16:58:04 -0500 | [diff] [blame] | 41 | #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
| 43 | static struct ctl_table_header *sunrpc_table_header; |
Joe Perches | fe2c633 | 2013-06-11 23:04:25 -0700 | [diff] [blame] | 44 | static struct ctl_table sunrpc_table[]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | void |
| 47 | rpc_register_sysctl(void) |
| 48 | { |
Eric W. Biederman | 2b1bec5 | 2007-02-14 00:33:24 -0800 | [diff] [blame] | 49 | if (!sunrpc_table_header) |
Eric W. Biederman | 0b4d414 | 2007-02-14 00:34:09 -0800 | [diff] [blame] | 50 | sunrpc_table_header = register_sysctl_table(sunrpc_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | void |
| 54 | rpc_unregister_sysctl(void) |
| 55 | { |
| 56 | if (sunrpc_table_header) { |
| 57 | unregister_sysctl_table(sunrpc_table_header); |
| 58 | sunrpc_table_header = NULL; |
| 59 | } |
| 60 | } |
| 61 | |
Joe Perches | fe2c633 | 2013-06-11 23:04:25 -0700 | [diff] [blame] | 62 | static int proc_do_xprt(struct ctl_table *table, int write, |
Christoph Hellwig | 3292739 | 2020-04-24 08:43:38 +0200 | [diff] [blame] | 63 | void *buffer, size_t *lenp, loff_t *ppos) |
Tom Tucker | dc9a16e | 2007-12-30 21:08:31 -0600 | [diff] [blame] | 64 | { |
| 65 | char tmpbuf[256]; |
Dan Carpenter | ae29750 | 2020-11-06 15:50:39 -0500 | [diff] [blame] | 66 | ssize_t len; |
Cyrill Gorcunov | 27df6f2 | 2008-08-31 19:25:49 +0400 | [diff] [blame] | 67 | |
Dan Carpenter | d435c05 | 2020-11-06 15:39:50 -0500 | [diff] [blame] | 68 | if (write || *ppos) { |
Tom Tucker | dc9a16e | 2007-12-30 21:08:31 -0600 | [diff] [blame] | 69 | *lenp = 0; |
| 70 | return 0; |
| 71 | } |
Cyrill Gorcunov | 27df6f2 | 2008-08-31 19:25:49 +0400 | [diff] [blame] | 72 | len = svc_print_xprts(tmpbuf, sizeof(tmpbuf)); |
Dan Carpenter | ae29750 | 2020-11-06 15:50:39 -0500 | [diff] [blame] | 73 | len = memory_read_from_buffer(buffer, *lenp, ppos, tmpbuf, len); |
Artur Molchanov | c09f56b | 2020-10-12 01:00:45 +0300 | [diff] [blame] | 74 | |
Dan Carpenter | ae29750 | 2020-11-06 15:50:39 -0500 | [diff] [blame] | 75 | if (len < 0) { |
Artur Molchanov | c09f56b | 2020-10-12 01:00:45 +0300 | [diff] [blame] | 76 | *lenp = 0; |
| 77 | return -EINVAL; |
| 78 | } |
Dan Carpenter | ae29750 | 2020-11-06 15:50:39 -0500 | [diff] [blame] | 79 | *lenp = len; |
Artur Molchanov | c09f56b | 2020-10-12 01:00:45 +0300 | [diff] [blame] | 80 | return 0; |
Tom Tucker | dc9a16e | 2007-12-30 21:08:31 -0600 | [diff] [blame] | 81 | } |
| 82 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | static int |
Christoph Hellwig | 3292739 | 2020-04-24 08:43:38 +0200 | [diff] [blame] | 84 | proc_dodebug(struct ctl_table *table, int write, void *buffer, size_t *lenp, |
| 85 | loff_t *ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | { |
Christoph Hellwig | 3292739 | 2020-04-24 08:43:38 +0200 | [diff] [blame] | 87 | char tmpbuf[20], *s = NULL; |
| 88 | char *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | unsigned int value; |
| 90 | size_t left, len; |
| 91 | |
| 92 | if ((*ppos && !write) || !*lenp) { |
| 93 | *lenp = 0; |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | left = *lenp; |
| 98 | |
| 99 | if (write) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | p = buffer; |
Christoph Hellwig | 3292739 | 2020-04-24 08:43:38 +0200 | [diff] [blame] | 101 | while (left && isspace(*p)) { |
| 102 | left--; |
| 103 | p++; |
| 104 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | if (!left) |
| 106 | goto done; |
| 107 | |
| 108 | if (left > sizeof(tmpbuf) - 1) |
| 109 | return -EINVAL; |
Christoph Hellwig | 3292739 | 2020-04-24 08:43:38 +0200 | [diff] [blame] | 110 | memcpy(tmpbuf, p, left); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | tmpbuf[left] = '\0'; |
| 112 | |
Kinglong Mee | 941c3ff | 2015-09-12 09:37:18 +0800 | [diff] [blame] | 113 | value = simple_strtol(tmpbuf, &s, 0); |
| 114 | if (s) { |
| 115 | left -= (s - tmpbuf); |
| 116 | if (left && !isspace(*s)) |
| 117 | return -EINVAL; |
Joe Perches | ca65a28 | 2020-08-24 21:56:25 -0700 | [diff] [blame] | 118 | while (left && isspace(*s)) { |
| 119 | left--; |
| 120 | s++; |
| 121 | } |
Kinglong Mee | 941c3ff | 2015-09-12 09:37:18 +0800 | [diff] [blame] | 122 | } else |
| 123 | left = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | *(unsigned int *) table->data = value; |
| 125 | /* Display the RPC tasks on writing to rpc_debug */ |
J. Bruce Fields | bc2a3f8 | 2007-10-29 14:37:18 -0700 | [diff] [blame] | 126 | if (strcmp(table->procname, "rpc_debug") == 0) |
Stanislav Kinsbursky | 70abc49 | 2012-01-12 22:07:51 +0400 | [diff] [blame] | 127 | rpc_show_tasks(&init_net); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | } else { |
Kinglong Mee | 941c3ff | 2015-09-12 09:37:18 +0800 | [diff] [blame] | 129 | len = sprintf(tmpbuf, "0x%04x", *(unsigned int *) table->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | if (len > left) |
| 131 | len = left; |
Christoph Hellwig | 3292739 | 2020-04-24 08:43:38 +0200 | [diff] [blame] | 132 | memcpy(buffer, tmpbuf, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | if ((left -= len) > 0) { |
Christoph Hellwig | 3292739 | 2020-04-24 08:43:38 +0200 | [diff] [blame] | 134 | *((char *)buffer + len) = '\n'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | left--; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | done: |
| 140 | *lenp -= left; |
| 141 | *ppos += *lenp; |
| 142 | return 0; |
| 143 | } |
| 144 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 145 | |
Joe Perches | fe2c633 | 2013-06-11 23:04:25 -0700 | [diff] [blame] | 146 | static struct ctl_table debug_table[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | .procname = "rpc_debug", |
| 149 | .data = &rpc_debug, |
| 150 | .maxlen = sizeof(int), |
| 151 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 152 | .proc_handler = proc_dodebug |
YOSHIFUJI Hideaki | cca5172 | 2007-02-09 15:38:13 -0800 | [diff] [blame] | 153 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | .procname = "nfs_debug", |
| 156 | .data = &nfs_debug, |
| 157 | .maxlen = sizeof(int), |
| 158 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 159 | .proc_handler = proc_dodebug |
YOSHIFUJI Hideaki | cca5172 | 2007-02-09 15:38:13 -0800 | [diff] [blame] | 160 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | .procname = "nfsd_debug", |
| 163 | .data = &nfsd_debug, |
| 164 | .maxlen = sizeof(int), |
| 165 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 166 | .proc_handler = proc_dodebug |
YOSHIFUJI Hideaki | cca5172 | 2007-02-09 15:38:13 -0800 | [diff] [blame] | 167 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | .procname = "nlm_debug", |
| 170 | .data = &nlm_debug, |
| 171 | .maxlen = sizeof(int), |
| 172 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 173 | .proc_handler = proc_dodebug |
YOSHIFUJI Hideaki | cca5172 | 2007-02-09 15:38:13 -0800 | [diff] [blame] | 174 | }, |
Tom Tucker | dc9a16e | 2007-12-30 21:08:31 -0600 | [diff] [blame] | 175 | { |
| 176 | .procname = "transports", |
| 177 | .maxlen = 256, |
| 178 | .mode = 0444, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 179 | .proc_handler = proc_do_xprt, |
Tom Tucker | dc9a16e | 2007-12-30 21:08:31 -0600 | [diff] [blame] | 180 | }, |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 181 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | }; |
| 183 | |
Joe Perches | fe2c633 | 2013-06-11 23:04:25 -0700 | [diff] [blame] | 184 | static struct ctl_table sunrpc_table[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | .procname = "sunrpc", |
| 187 | .mode = 0555, |
| 188 | .child = debug_table |
| 189 | }, |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 190 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | }; |
| 192 | |
| 193 | #endif |