sysctl.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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/svc_xprt.h>
  20. #include "netns.h"
  21. /*
  22. * Declare the debug flags here
  23. */
  24. unsigned int rpc_debug;
  25. EXPORT_SYMBOL_GPL(rpc_debug);
  26. unsigned int nfs_debug;
  27. EXPORT_SYMBOL_GPL(nfs_debug);
  28. unsigned int nfsd_debug;
  29. EXPORT_SYMBOL_GPL(nfsd_debug);
  30. unsigned int nlm_debug;
  31. EXPORT_SYMBOL_GPL(nlm_debug);
  32. #ifdef RPC_DEBUG
  33. static struct ctl_table_header *sunrpc_table_header;
  34. static ctl_table sunrpc_table[];
  35. void
  36. rpc_register_sysctl(void)
  37. {
  38. if (!sunrpc_table_header)
  39. sunrpc_table_header = register_sysctl_table(sunrpc_table);
  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 proc_do_xprt(ctl_table *table, int write,
  50. void __user *buffer, size_t *lenp, loff_t *ppos)
  51. {
  52. char tmpbuf[256];
  53. size_t len;
  54. if ((*ppos && !write) || !*lenp) {
  55. *lenp = 0;
  56. return 0;
  57. }
  58. len = svc_print_xprts(tmpbuf, sizeof(tmpbuf));
  59. return simple_read_from_buffer(buffer, *lenp, ppos, tmpbuf, len);
  60. }
  61. static int
  62. proc_dodebug(ctl_table *table, int write,
  63. void __user *buffer, size_t *lenp, loff_t *ppos)
  64. {
  65. char tmpbuf[20], c, *s;
  66. char __user *p;
  67. unsigned int value;
  68. size_t left, len;
  69. if ((*ppos && !write) || !*lenp) {
  70. *lenp = 0;
  71. return 0;
  72. }
  73. left = *lenp;
  74. if (write) {
  75. if (!access_ok(VERIFY_READ, buffer, left))
  76. return -EFAULT;
  77. p = buffer;
  78. while (left && __get_user(c, p) >= 0 && isspace(c))
  79. left--, p++;
  80. if (!left)
  81. goto done;
  82. if (left > sizeof(tmpbuf) - 1)
  83. return -EINVAL;
  84. if (copy_from_user(tmpbuf, p, left))
  85. return -EFAULT;
  86. tmpbuf[left] = '\0';
  87. for (s = tmpbuf, value = 0; '0' <= *s && *s <= '9'; s++, left--)
  88. value = 10 * value + (*s - '0');
  89. if (*s && !isspace(*s))
  90. return -EINVAL;
  91. while (left && isspace(*s))
  92. left--, s++;
  93. *(unsigned int *) table->data = value;
  94. /* Display the RPC tasks on writing to rpc_debug */
  95. if (strcmp(table->procname, "rpc_debug") == 0)
  96. rpc_show_tasks(&init_net);
  97. } else {
  98. if (!access_ok(VERIFY_WRITE, buffer, left))
  99. return -EFAULT;
  100. len = sprintf(tmpbuf, "%d", *(unsigned int *) table->data);
  101. if (len > left)
  102. len = left;
  103. if (__copy_to_user(buffer, tmpbuf, len))
  104. return -EFAULT;
  105. if ((left -= len) > 0) {
  106. if (put_user('\n', (char __user *)buffer + len))
  107. return -EFAULT;
  108. left--;
  109. }
  110. }
  111. done:
  112. *lenp -= left;
  113. *ppos += *lenp;
  114. return 0;
  115. }
  116. static ctl_table debug_table[] = {
  117. {
  118. .procname = "rpc_debug",
  119. .data = &rpc_debug,
  120. .maxlen = sizeof(int),
  121. .mode = 0644,
  122. .proc_handler = proc_dodebug
  123. },
  124. {
  125. .procname = "nfs_debug",
  126. .data = &nfs_debug,
  127. .maxlen = sizeof(int),
  128. .mode = 0644,
  129. .proc_handler = proc_dodebug
  130. },
  131. {
  132. .procname = "nfsd_debug",
  133. .data = &nfsd_debug,
  134. .maxlen = sizeof(int),
  135. .mode = 0644,
  136. .proc_handler = proc_dodebug
  137. },
  138. {
  139. .procname = "nlm_debug",
  140. .data = &nlm_debug,
  141. .maxlen = sizeof(int),
  142. .mode = 0644,
  143. .proc_handler = proc_dodebug
  144. },
  145. {
  146. .procname = "transports",
  147. .maxlen = 256,
  148. .mode = 0444,
  149. .proc_handler = proc_do_xprt,
  150. },
  151. { }
  152. };
  153. static ctl_table sunrpc_table[] = {
  154. {
  155. .procname = "sunrpc",
  156. .mode = 0555,
  157. .child = debug_table
  158. },
  159. { }
  160. };
  161. #endif