1457c8996SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 21da177e4SLinus Torvalds /* 31da177e4SLinus Torvalds * linux/net/sunrpc/sysctl.c 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * Sysctl interface to sunrpc module. 61da177e4SLinus Torvalds * 71da177e4SLinus Torvalds * I would prefer to register the sunrpc table below sys/net, but that's 81da177e4SLinus Torvalds * impossible at the moment. 91da177e4SLinus Torvalds */ 101da177e4SLinus Torvalds 111da177e4SLinus Torvalds #include <linux/types.h> 121da177e4SLinus Torvalds #include <linux/linkage.h> 131da177e4SLinus Torvalds #include <linux/ctype.h> 141da177e4SLinus Torvalds #include <linux/fs.h> 151da177e4SLinus Torvalds #include <linux/sysctl.h> 161da177e4SLinus Torvalds #include <linux/module.h> 171da177e4SLinus Torvalds 187c0f6ba6SLinus Torvalds #include <linux/uaccess.h> 191da177e4SLinus Torvalds #include <linux/sunrpc/types.h> 201da177e4SLinus Torvalds #include <linux/sunrpc/sched.h> 211da177e4SLinus Torvalds #include <linux/sunrpc/stats.h> 22dc9a16e4STom Tucker #include <linux/sunrpc/svc_xprt.h> 231da177e4SLinus Torvalds 2470abc49bSStanislav Kinsbursky #include "netns.h" 2570abc49bSStanislav Kinsbursky 261da177e4SLinus Torvalds /* 271da177e4SLinus Torvalds * Declare the debug flags here 281da177e4SLinus Torvalds */ 291da177e4SLinus Torvalds unsigned int rpc_debug; 30e8914c65STrond Myklebust EXPORT_SYMBOL_GPL(rpc_debug); 31a6eaf8bdSTrond Myklebust 321da177e4SLinus Torvalds unsigned int nfs_debug; 33e8914c65STrond Myklebust EXPORT_SYMBOL_GPL(nfs_debug); 34a6eaf8bdSTrond Myklebust 351da177e4SLinus Torvalds unsigned int nfsd_debug; 36e8914c65STrond Myklebust EXPORT_SYMBOL_GPL(nfsd_debug); 37a6eaf8bdSTrond Myklebust 381da177e4SLinus Torvalds unsigned int nlm_debug; 39e8914c65STrond Myklebust EXPORT_SYMBOL_GPL(nlm_debug); 401da177e4SLinus Torvalds 41f895b252SJeff Layton #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) 421da177e4SLinus Torvalds 431da177e4SLinus Torvalds static struct ctl_table_header *sunrpc_table_header; 44fe2c6338SJoe Perches static struct ctl_table sunrpc_table[]; 451da177e4SLinus Torvalds 461da177e4SLinus Torvalds void 471da177e4SLinus Torvalds rpc_register_sysctl(void) 481da177e4SLinus Torvalds { 492b1bec5fSEric W. Biederman if (!sunrpc_table_header) 500b4d4147SEric W. Biederman sunrpc_table_header = register_sysctl_table(sunrpc_table); 511da177e4SLinus Torvalds } 521da177e4SLinus Torvalds 531da177e4SLinus Torvalds void 541da177e4SLinus Torvalds rpc_unregister_sysctl(void) 551da177e4SLinus Torvalds { 561da177e4SLinus Torvalds if (sunrpc_table_header) { 571da177e4SLinus Torvalds unregister_sysctl_table(sunrpc_table_header); 581da177e4SLinus Torvalds sunrpc_table_header = NULL; 591da177e4SLinus Torvalds } 601da177e4SLinus Torvalds } 611da177e4SLinus Torvalds 62fe2c6338SJoe Perches static int proc_do_xprt(struct ctl_table *table, int write, 6332927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 64dc9a16e4STom Tucker { 65dc9a16e4STom Tucker char tmpbuf[256]; 6627df6f25SCyrill Gorcunov size_t len; 6727df6f25SCyrill Gorcunov 68dc9a16e4STom Tucker if ((*ppos && !write) || !*lenp) { 69dc9a16e4STom Tucker *lenp = 0; 70dc9a16e4STom Tucker return 0; 71dc9a16e4STom Tucker } 72dc9a16e4STom Tucker len = svc_print_xprts(tmpbuf, sizeof(tmpbuf)); 73c09f56b8SArtur Molchanov *lenp = memory_read_from_buffer(buffer, *lenp, ppos, tmpbuf, len); 74c09f56b8SArtur Molchanov 75c09f56b8SArtur Molchanov if (*lenp < 0) { 76c09f56b8SArtur Molchanov *lenp = 0; 77c09f56b8SArtur Molchanov return -EINVAL; 78c09f56b8SArtur Molchanov } 79c09f56b8SArtur Molchanov return 0; 80dc9a16e4STom Tucker } 81dc9a16e4STom Tucker 821da177e4SLinus Torvalds static int 8332927393SChristoph Hellwig proc_dodebug(struct ctl_table *table, int write, void *buffer, size_t *lenp, 8432927393SChristoph Hellwig loff_t *ppos) 851da177e4SLinus Torvalds { 8632927393SChristoph Hellwig char tmpbuf[20], *s = NULL; 8732927393SChristoph Hellwig char *p; 881da177e4SLinus Torvalds unsigned int value; 891da177e4SLinus Torvalds size_t left, len; 901da177e4SLinus Torvalds 911da177e4SLinus Torvalds if ((*ppos && !write) || !*lenp) { 921da177e4SLinus Torvalds *lenp = 0; 931da177e4SLinus Torvalds return 0; 941da177e4SLinus Torvalds } 951da177e4SLinus Torvalds 961da177e4SLinus Torvalds left = *lenp; 971da177e4SLinus Torvalds 981da177e4SLinus Torvalds if (write) { 991da177e4SLinus Torvalds p = buffer; 10032927393SChristoph Hellwig while (left && isspace(*p)) { 10132927393SChristoph Hellwig left--; 10232927393SChristoph Hellwig p++; 10332927393SChristoph Hellwig } 1041da177e4SLinus Torvalds if (!left) 1051da177e4SLinus Torvalds goto done; 1061da177e4SLinus Torvalds 1071da177e4SLinus Torvalds if (left > sizeof(tmpbuf) - 1) 1081da177e4SLinus Torvalds return -EINVAL; 10932927393SChristoph Hellwig memcpy(tmpbuf, p, left); 1101da177e4SLinus Torvalds tmpbuf[left] = '\0'; 1111da177e4SLinus Torvalds 112941c3ff3SKinglong Mee value = simple_strtol(tmpbuf, &s, 0); 113941c3ff3SKinglong Mee if (s) { 114941c3ff3SKinglong Mee left -= (s - tmpbuf); 115941c3ff3SKinglong Mee if (left && !isspace(*s)) 1161da177e4SLinus Torvalds return -EINVAL; 1171da177e4SLinus Torvalds while (left && isspace(*s)) 1181da177e4SLinus Torvalds left--, s++; 119941c3ff3SKinglong Mee } else 120941c3ff3SKinglong Mee left = 0; 1211da177e4SLinus Torvalds *(unsigned int *) table->data = value; 1221da177e4SLinus Torvalds /* Display the RPC tasks on writing to rpc_debug */ 123bc2a3f86SJ. Bruce Fields if (strcmp(table->procname, "rpc_debug") == 0) 12470abc49bSStanislav Kinsbursky rpc_show_tasks(&init_net); 1251da177e4SLinus Torvalds } else { 126941c3ff3SKinglong Mee len = sprintf(tmpbuf, "0x%04x", *(unsigned int *) table->data); 1271da177e4SLinus Torvalds if (len > left) 1281da177e4SLinus Torvalds len = left; 12932927393SChristoph Hellwig memcpy(buffer, tmpbuf, len); 1301da177e4SLinus Torvalds if ((left -= len) > 0) { 13132927393SChristoph Hellwig *((char *)buffer + len) = '\n'; 1321da177e4SLinus Torvalds left--; 1331da177e4SLinus Torvalds } 1341da177e4SLinus Torvalds } 1351da177e4SLinus Torvalds 1361da177e4SLinus Torvalds done: 1371da177e4SLinus Torvalds *lenp -= left; 1381da177e4SLinus Torvalds *ppos += *lenp; 1391da177e4SLinus Torvalds return 0; 1401da177e4SLinus Torvalds } 1411da177e4SLinus Torvalds 142a246b010SChuck Lever 143fe2c6338SJoe Perches static struct ctl_table debug_table[] = { 1441da177e4SLinus Torvalds { 1451da177e4SLinus Torvalds .procname = "rpc_debug", 1461da177e4SLinus Torvalds .data = &rpc_debug, 1471da177e4SLinus Torvalds .maxlen = sizeof(int), 1481da177e4SLinus Torvalds .mode = 0644, 1496d456111SEric W. Biederman .proc_handler = proc_dodebug 1501da177e4SLinus Torvalds }, 1511da177e4SLinus Torvalds { 1521da177e4SLinus Torvalds .procname = "nfs_debug", 1531da177e4SLinus Torvalds .data = &nfs_debug, 1541da177e4SLinus Torvalds .maxlen = sizeof(int), 1551da177e4SLinus Torvalds .mode = 0644, 1566d456111SEric W. Biederman .proc_handler = proc_dodebug 1571da177e4SLinus Torvalds }, 1581da177e4SLinus Torvalds { 1591da177e4SLinus Torvalds .procname = "nfsd_debug", 1601da177e4SLinus Torvalds .data = &nfsd_debug, 1611da177e4SLinus Torvalds .maxlen = sizeof(int), 1621da177e4SLinus Torvalds .mode = 0644, 1636d456111SEric W. Biederman .proc_handler = proc_dodebug 1641da177e4SLinus Torvalds }, 1651da177e4SLinus Torvalds { 1661da177e4SLinus Torvalds .procname = "nlm_debug", 1671da177e4SLinus Torvalds .data = &nlm_debug, 1681da177e4SLinus Torvalds .maxlen = sizeof(int), 1691da177e4SLinus Torvalds .mode = 0644, 1706d456111SEric W. Biederman .proc_handler = proc_dodebug 1711da177e4SLinus Torvalds }, 172dc9a16e4STom Tucker { 173dc9a16e4STom Tucker .procname = "transports", 174dc9a16e4STom Tucker .maxlen = 256, 175dc9a16e4STom Tucker .mode = 0444, 1766d456111SEric W. Biederman .proc_handler = proc_do_xprt, 177dc9a16e4STom Tucker }, 178f8572d8fSEric W. Biederman { } 1791da177e4SLinus Torvalds }; 1801da177e4SLinus Torvalds 181fe2c6338SJoe Perches static struct ctl_table sunrpc_table[] = { 1821da177e4SLinus Torvalds { 1831da177e4SLinus Torvalds .procname = "sunrpc", 1841da177e4SLinus Torvalds .mode = 0555, 1851da177e4SLinus Torvalds .child = debug_table 1861da177e4SLinus Torvalds }, 187f8572d8fSEric W. Biederman { } 1881da177e4SLinus Torvalds }; 1891da177e4SLinus Torvalds 1901da177e4SLinus Torvalds #endif 191