sysctl.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 <linux/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. #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
  33. static struct ctl_table_header *sunrpc_table_header;
  34. static struct 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(struct 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(struct ctl_table *table, int write,
  63. void __user *buffer, size_t *lenp, loff_t *ppos)
  64. {
  65. char tmpbuf[20], c, *s = NULL;
  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. value = simple_strtol(tmpbuf, &s, 0);
  88. if (s) {
  89. left -= (s - tmpbuf);
  90. if (left && !isspace(*s))
  91. return -EINVAL;
  92. while (left && isspace(*s))
  93. left--, s++;
  94. } else
  95. left = 0;
  96. *(unsigned int *) table->data = value;
  97. /* Display the RPC tasks on writing to rpc_debug */
  98. if (strcmp(table->procname, "rpc_debug") == 0)
  99. rpc_show_tasks(&init_net);
  100. } else {
  101. len = sprintf(tmpbuf, "0x%04x", *(unsigned int *) table->data);
  102. if (len > left)
  103. len = left;
  104. if (copy_to_user(buffer, tmpbuf, len))
  105. return -EFAULT;
  106. if ((left -= len) > 0) {
  107. if (put_user('\n', (char __user *)buffer + len))
  108. return -EFAULT;
  109. left--;
  110. }
  111. }
  112. done:
  113. *lenp -= left;
  114. *ppos += *lenp;
  115. return 0;
  116. }
  117. static struct ctl_table debug_table[] = {
  118. {
  119. .procname = "rpc_debug",
  120. .data = &rpc_debug,
  121. .maxlen = sizeof(int),
  122. .mode = 0644,
  123. .proc_handler = proc_dodebug
  124. },
  125. {
  126. .procname = "nfs_debug",
  127. .data = &nfs_debug,
  128. .maxlen = sizeof(int),
  129. .mode = 0644,
  130. .proc_handler = proc_dodebug
  131. },
  132. {
  133. .procname = "nfsd_debug",
  134. .data = &nfsd_debug,
  135. .maxlen = sizeof(int),
  136. .mode = 0644,
  137. .proc_handler = proc_dodebug
  138. },
  139. {
  140. .procname = "nlm_debug",
  141. .data = &nlm_debug,
  142. .maxlen = sizeof(int),
  143. .mode = 0644,
  144. .proc_handler = proc_dodebug
  145. },
  146. {
  147. .procname = "transports",
  148. .maxlen = 256,
  149. .mode = 0444,
  150. .proc_handler = proc_do_xprt,
  151. },
  152. { }
  153. };
  154. static struct ctl_table sunrpc_table[] = {
  155. {
  156. .procname = "sunrpc",
  157. .mode = 0555,
  158. .child = debug_table
  159. },
  160. { }
  161. };
  162. #endif