at v2.6.12 193 lines 4.1 kB view raw
1/* 2 * linux/net/sunrpc/sysctl.c 3 * 4 * Sysctl interface to sunrpc module. 5 * 6 * I would prefer to register the sunrpc table below sys/net, but that's 7 * impossible at the moment. 8 */ 9 10#include <linux/config.h> 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 18#include <asm/uaccess.h> 19#include <linux/sunrpc/types.h> 20#include <linux/sunrpc/sched.h> 21#include <linux/sunrpc/stats.h> 22#include <linux/sunrpc/xprt.h> 23 24/* 25 * Declare the debug flags here 26 */ 27unsigned int rpc_debug; 28unsigned int nfs_debug; 29unsigned int nfsd_debug; 30unsigned int nlm_debug; 31 32#ifdef RPC_DEBUG 33 34static struct ctl_table_header *sunrpc_table_header; 35static ctl_table sunrpc_table[]; 36 37void 38rpc_register_sysctl(void) 39{ 40 if (!sunrpc_table_header) { 41 sunrpc_table_header = register_sysctl_table(sunrpc_table, 1); 42#ifdef CONFIG_PROC_FS 43 if (sunrpc_table[0].de) 44 sunrpc_table[0].de->owner = THIS_MODULE; 45#endif 46 } 47 48} 49 50void 51rpc_unregister_sysctl(void) 52{ 53 if (sunrpc_table_header) { 54 unregister_sysctl_table(sunrpc_table_header); 55 sunrpc_table_header = NULL; 56 } 57} 58 59static int 60proc_dodebug(ctl_table *table, int write, struct file *file, 61 void __user *buffer, size_t *lenp, loff_t *ppos) 62{ 63 char tmpbuf[20], c, *s; 64 char __user *p; 65 unsigned int value; 66 size_t left, len; 67 68 if ((*ppos && !write) || !*lenp) { 69 *lenp = 0; 70 return 0; 71 } 72 73 left = *lenp; 74 75 if (write) { 76 if (!access_ok(VERIFY_READ, buffer, left)) 77 return -EFAULT; 78 p = buffer; 79 while (left && __get_user(c, p) >= 0 && isspace(c)) 80 left--, p++; 81 if (!left) 82 goto done; 83 84 if (left > sizeof(tmpbuf) - 1) 85 return -EINVAL; 86 if (copy_from_user(tmpbuf, p, left)) 87 return -EFAULT; 88 tmpbuf[left] = '\0'; 89 90 for (s = tmpbuf, value = 0; '0' <= *s && *s <= '9'; s++, left--) 91 value = 10 * value + (*s - '0'); 92 if (*s && !isspace(*s)) 93 return -EINVAL; 94 while (left && isspace(*s)) 95 left--, s++; 96 *(unsigned int *) table->data = value; 97 /* Display the RPC tasks on writing to rpc_debug */ 98 if (table->ctl_name == CTL_RPCDEBUG) { 99 rpc_show_tasks(); 100 } 101 } else { 102 if (!access_ok(VERIFY_WRITE, buffer, left)) 103 return -EFAULT; 104 len = sprintf(tmpbuf, "%d", *(unsigned int *) table->data); 105 if (len > left) 106 len = left; 107 if (__copy_to_user(buffer, tmpbuf, len)) 108 return -EFAULT; 109 if ((left -= len) > 0) { 110 if (put_user('\n', (char __user *)buffer + len)) 111 return -EFAULT; 112 left--; 113 } 114 } 115 116done: 117 *lenp -= left; 118 *ppos += *lenp; 119 return 0; 120} 121 122static unsigned int min_slot_table_size = RPC_MIN_SLOT_TABLE; 123static unsigned int max_slot_table_size = RPC_MAX_SLOT_TABLE; 124 125static ctl_table debug_table[] = { 126 { 127 .ctl_name = CTL_RPCDEBUG, 128 .procname = "rpc_debug", 129 .data = &rpc_debug, 130 .maxlen = sizeof(int), 131 .mode = 0644, 132 .proc_handler = &proc_dodebug 133 }, 134 { 135 .ctl_name = CTL_NFSDEBUG, 136 .procname = "nfs_debug", 137 .data = &nfs_debug, 138 .maxlen = sizeof(int), 139 .mode = 0644, 140 .proc_handler = &proc_dodebug 141 }, 142 { 143 .ctl_name = CTL_NFSDDEBUG, 144 .procname = "nfsd_debug", 145 .data = &nfsd_debug, 146 .maxlen = sizeof(int), 147 .mode = 0644, 148 .proc_handler = &proc_dodebug 149 }, 150 { 151 .ctl_name = CTL_NLMDEBUG, 152 .procname = "nlm_debug", 153 .data = &nlm_debug, 154 .maxlen = sizeof(int), 155 .mode = 0644, 156 .proc_handler = &proc_dodebug 157 }, 158 { 159 .ctl_name = CTL_SLOTTABLE_UDP, 160 .procname = "udp_slot_table_entries", 161 .data = &xprt_udp_slot_table_entries, 162 .maxlen = sizeof(unsigned int), 163 .mode = 0644, 164 .proc_handler = &proc_dointvec_minmax, 165 .strategy = &sysctl_intvec, 166 .extra1 = &min_slot_table_size, 167 .extra2 = &max_slot_table_size 168 }, 169 { 170 .ctl_name = CTL_SLOTTABLE_TCP, 171 .procname = "tcp_slot_table_entries", 172 .data = &xprt_tcp_slot_table_entries, 173 .maxlen = sizeof(unsigned int), 174 .mode = 0644, 175 .proc_handler = &proc_dointvec_minmax, 176 .strategy = &sysctl_intvec, 177 .extra1 = &min_slot_table_size, 178 .extra2 = &max_slot_table_size 179 }, 180 { .ctl_name = 0 } 181}; 182 183static ctl_table sunrpc_table[] = { 184 { 185 .ctl_name = CTL_SUNRPC, 186 .procname = "sunrpc", 187 .mode = 0555, 188 .child = debug_table 189 }, 190 { .ctl_name = 0 } 191}; 192 193#endif