sysctl.c 4.7 KB

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