sysctl.c 3.8 KB

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