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)); 7332927393SChristoph Hellwig return memory_read_from_buffer(buffer, *lenp, ppos, tmpbuf, len); 74dc9a16e4STom Tucker } 75dc9a16e4STom Tucker 761da177e4SLinus Torvalds static int 7732927393SChristoph Hellwig proc_dodebug(struct ctl_table *table, int write, void *buffer, size_t *lenp, 7832927393SChristoph Hellwig loff_t *ppos) 791da177e4SLinus Torvalds { 8032927393SChristoph Hellwig char tmpbuf[20], *s = NULL; 8132927393SChristoph Hellwig char *p; 821da177e4SLinus Torvalds unsigned int value; 831da177e4SLinus Torvalds size_t left, len; 841da177e4SLinus Torvalds 851da177e4SLinus Torvalds if ((*ppos && !write) || !*lenp) { 861da177e4SLinus Torvalds *lenp = 0; 871da177e4SLinus Torvalds return 0; 881da177e4SLinus Torvalds } 891da177e4SLinus Torvalds 901da177e4SLinus Torvalds left = *lenp; 911da177e4SLinus Torvalds 921da177e4SLinus Torvalds if (write) { 931da177e4SLinus Torvalds p = buffer; 9432927393SChristoph Hellwig while (left && isspace(*p)) { 9532927393SChristoph Hellwig left--; 9632927393SChristoph Hellwig p++; 9732927393SChristoph Hellwig } 981da177e4SLinus Torvalds if (!left) 991da177e4SLinus Torvalds goto done; 1001da177e4SLinus Torvalds 1011da177e4SLinus Torvalds if (left > sizeof(tmpbuf) - 1) 1021da177e4SLinus Torvalds return -EINVAL; 10332927393SChristoph Hellwig memcpy(tmpbuf, p, left); 1041da177e4SLinus Torvalds tmpbuf[left] = '\0'; 1051da177e4SLinus Torvalds 106941c3ff3SKinglong Mee value = simple_strtol(tmpbuf, &s, 0); 107941c3ff3SKinglong Mee if (s) { 108941c3ff3SKinglong Mee left -= (s - tmpbuf); 109941c3ff3SKinglong Mee if (left && !isspace(*s)) 1101da177e4SLinus Torvalds return -EINVAL; 111ca65a280SJoe Perches while (left && isspace(*s)) { 112ca65a280SJoe Perches left--; 113ca65a280SJoe Perches s++; 114ca65a280SJoe Perches } 115941c3ff3SKinglong Mee } else 116941c3ff3SKinglong Mee left = 0; 1171da177e4SLinus Torvalds *(unsigned int *) table->data = value; 1181da177e4SLinus Torvalds /* Display the RPC tasks on writing to rpc_debug */ 119bc2a3f86SJ. Bruce Fields if (strcmp(table->procname, "rpc_debug") == 0) 12070abc49bSStanislav Kinsbursky rpc_show_tasks(&init_net); 1211da177e4SLinus Torvalds } else { 122941c3ff3SKinglong Mee len = sprintf(tmpbuf, "0x%04x", *(unsigned int *) table->data); 1231da177e4SLinus Torvalds if (len > left) 1241da177e4SLinus Torvalds len = left; 12532927393SChristoph Hellwig memcpy(buffer, tmpbuf, len); 1261da177e4SLinus Torvalds if ((left -= len) > 0) { 12732927393SChristoph Hellwig *((char *)buffer + len) = '\n'; 1281da177e4SLinus Torvalds left--; 1291da177e4SLinus Torvalds } 1301da177e4SLinus Torvalds } 1311da177e4SLinus Torvalds 1321da177e4SLinus Torvalds done: 1331da177e4SLinus Torvalds *lenp -= left; 1341da177e4SLinus Torvalds *ppos += *lenp; 1351da177e4SLinus Torvalds return 0; 1361da177e4SLinus Torvalds } 1371da177e4SLinus Torvalds 138a246b010SChuck Lever 139fe2c6338SJoe Perches static struct ctl_table debug_table[] = { 1401da177e4SLinus Torvalds { 1411da177e4SLinus Torvalds .procname = "rpc_debug", 1421da177e4SLinus Torvalds .data = &rpc_debug, 1431da177e4SLinus Torvalds .maxlen = sizeof(int), 1441da177e4SLinus Torvalds .mode = 0644, 1456d456111SEric W. Biederman .proc_handler = proc_dodebug 1461da177e4SLinus Torvalds }, 1471da177e4SLinus Torvalds { 1481da177e4SLinus Torvalds .procname = "nfs_debug", 1491da177e4SLinus Torvalds .data = &nfs_debug, 1501da177e4SLinus Torvalds .maxlen = sizeof(int), 1511da177e4SLinus Torvalds .mode = 0644, 1526d456111SEric W. Biederman .proc_handler = proc_dodebug 1531da177e4SLinus Torvalds }, 1541da177e4SLinus Torvalds { 1551da177e4SLinus Torvalds .procname = "nfsd_debug", 1561da177e4SLinus Torvalds .data = &nfsd_debug, 1571da177e4SLinus Torvalds .maxlen = sizeof(int), 1581da177e4SLinus Torvalds .mode = 0644, 1596d456111SEric W. Biederman .proc_handler = proc_dodebug 1601da177e4SLinus Torvalds }, 1611da177e4SLinus Torvalds { 1621da177e4SLinus Torvalds .procname = "nlm_debug", 1631da177e4SLinus Torvalds .data = &nlm_debug, 1641da177e4SLinus Torvalds .maxlen = sizeof(int), 1651da177e4SLinus Torvalds .mode = 0644, 1666d456111SEric W. Biederman .proc_handler = proc_dodebug 1671da177e4SLinus Torvalds }, 168dc9a16e4STom Tucker { 169dc9a16e4STom Tucker .procname = "transports", 170dc9a16e4STom Tucker .maxlen = 256, 171dc9a16e4STom Tucker .mode = 0444, 1726d456111SEric W. Biederman .proc_handler = proc_do_xprt, 173dc9a16e4STom Tucker }, 174f8572d8fSEric W. Biederman { } 1751da177e4SLinus Torvalds }; 1761da177e4SLinus Torvalds 177fe2c6338SJoe Perches static struct ctl_table sunrpc_table[] = { 1781da177e4SLinus Torvalds { 1791da177e4SLinus Torvalds .procname = "sunrpc", 1801da177e4SLinus Torvalds .mode = 0555, 1811da177e4SLinus Torvalds .child = debug_table 1821da177e4SLinus Torvalds }, 183f8572d8fSEric W. Biederman { } 1841da177e4SLinus Torvalds }; 1851da177e4SLinus Torvalds 1861da177e4SLinus Torvalds #endif 187