sysctl.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 ctl_table debug_table[] = {
  109. {
  110. .ctl_name = CTL_RPCDEBUG,
  111. .procname = "rpc_debug",
  112. .data = &rpc_debug,
  113. .maxlen = sizeof(int),
  114. .mode = 0644,
  115. .proc_handler = &proc_dodebug
  116. },
  117. {
  118. .ctl_name = CTL_NFSDEBUG,
  119. .procname = "nfs_debug",
  120. .data = &nfs_debug,
  121. .maxlen = sizeof(int),
  122. .mode = 0644,
  123. .proc_handler = &proc_dodebug
  124. },
  125. {
  126. .ctl_name = CTL_NFSDDEBUG,
  127. .procname = "nfsd_debug",
  128. .data = &nfsd_debug,
  129. .maxlen = sizeof(int),
  130. .mode = 0644,
  131. .proc_handler = &proc_dodebug
  132. },
  133. {
  134. .ctl_name = CTL_NLMDEBUG,
  135. .procname = "nlm_debug",
  136. .data = &nlm_debug,
  137. .maxlen = sizeof(int),
  138. .mode = 0644,
  139. .proc_handler = &proc_dodebug
  140. },
  141. {
  142. .ctl_name = CTL_SLOTTABLE_UDP,
  143. .procname = "udp_slot_table_entries",
  144. .data = &xprt_udp_slot_table_entries,
  145. .maxlen = sizeof(unsigned int),
  146. .mode = 0644,
  147. .proc_handler = &proc_dointvec_minmax,
  148. .strategy = &sysctl_intvec,
  149. .extra1 = &min_slot_table_size,
  150. .extra2 = &max_slot_table_size
  151. },
  152. {
  153. .ctl_name = CTL_SLOTTABLE_TCP,
  154. .procname = "tcp_slot_table_entries",
  155. .data = &xprt_tcp_slot_table_entries,
  156. .maxlen = sizeof(unsigned int),
  157. .mode = 0644,
  158. .proc_handler = &proc_dointvec_minmax,
  159. .strategy = &sysctl_intvec,
  160. .extra1 = &min_slot_table_size,
  161. .extra2 = &max_slot_table_size
  162. },
  163. { .ctl_name = 0 }
  164. };
  165. static ctl_table sunrpc_table[] = {
  166. {
  167. .ctl_name = CTL_SUNRPC,
  168. .procname = "sunrpc",
  169. .mode = 0555,
  170. .child = debug_table
  171. },
  172. { .ctl_name = 0 }
  173. };
  174. #endif