sysctl.c 4.7 KB

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