sysctl.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * linux/net/sunrpc/sysctl.c
  4. *
  5. * Sysctl interface to sunrpc module.
  6. *
  7. * I would prefer to register the sunrpc table below sys/net, but that's
  8. * impossible at the moment.
  9. */
  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 <linux/uaccess.h>
  17. #include <linux/sunrpc/types.h>
  18. #include <linux/sunrpc/sched.h>
  19. #include <linux/sunrpc/stats.h>
  20. #include <linux/sunrpc/svc_xprt.h>
  21. #include "netns.h"
  22. /*
  23. * Declare the debug flags here
  24. */
  25. unsigned int rpc_debug;
  26. EXPORT_SYMBOL_GPL(rpc_debug);
  27. unsigned int nfs_debug;
  28. EXPORT_SYMBOL_GPL(nfs_debug);
  29. unsigned int nfsd_debug;
  30. EXPORT_SYMBOL_GPL(nfsd_debug);
  31. unsigned int nlm_debug;
  32. EXPORT_SYMBOL_GPL(nlm_debug);
  33. #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
  34. static struct ctl_table_header *sunrpc_table_header;
  35. static struct ctl_table sunrpc_table[];
  36. void
  37. rpc_register_sysctl(void)
  38. {
  39. if (!sunrpc_table_header)
  40. sunrpc_table_header = register_sysctl_table(sunrpc_table);
  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 proc_do_xprt(struct ctl_table *table, int write,
  51. void *buffer, size_t *lenp, loff_t *ppos)
  52. {
  53. char tmpbuf[256];
  54. ssize_t len;
  55. if (write || *ppos) {
  56. *lenp = 0;
  57. return 0;
  58. }
  59. len = svc_print_xprts(tmpbuf, sizeof(tmpbuf));
  60. len = memory_read_from_buffer(buffer, *lenp, ppos, tmpbuf, len);
  61. if (len < 0) {
  62. *lenp = 0;
  63. return -EINVAL;
  64. }
  65. *lenp = len;
  66. return 0;
  67. }
  68. static int
  69. proc_dodebug(struct ctl_table *table, int write, void *buffer, size_t *lenp,
  70. loff_t *ppos)
  71. {
  72. char tmpbuf[20], *s = NULL;
  73. char *p;
  74. unsigned int value;
  75. size_t left, len;
  76. if ((*ppos && !write) || !*lenp) {
  77. *lenp = 0;
  78. return 0;
  79. }
  80. left = *lenp;
  81. if (write) {
  82. p = buffer;
  83. while (left && isspace(*p)) {
  84. left--;
  85. p++;
  86. }
  87. if (!left)
  88. goto done;
  89. if (left > sizeof(tmpbuf) - 1)
  90. return -EINVAL;
  91. memcpy(tmpbuf, p, left);
  92. tmpbuf[left] = '\0';
  93. value = simple_strtol(tmpbuf, &s, 0);
  94. if (s) {
  95. left -= (s - tmpbuf);
  96. if (left && !isspace(*s))
  97. return -EINVAL;
  98. while (left && isspace(*s)) {
  99. left--;
  100. s++;
  101. }
  102. } else
  103. left = 0;
  104. *(unsigned int *) table->data = value;
  105. /* Display the RPC tasks on writing to rpc_debug */
  106. if (strcmp(table->procname, "rpc_debug") == 0)
  107. rpc_show_tasks(&init_net);
  108. } else {
  109. len = sprintf(tmpbuf, "0x%04x", *(unsigned int *) table->data);
  110. if (len > left)
  111. len = left;
  112. memcpy(buffer, tmpbuf, len);
  113. if ((left -= len) > 0) {
  114. *((char *)buffer + len) = '\n';
  115. left--;
  116. }
  117. }
  118. done:
  119. *lenp -= left;
  120. *ppos += *lenp;
  121. return 0;
  122. }
  123. static struct ctl_table debug_table[] = {
  124. {
  125. .procname = "rpc_debug",
  126. .data = &rpc_debug,
  127. .maxlen = sizeof(int),
  128. .mode = 0644,
  129. .proc_handler = proc_dodebug
  130. },
  131. {
  132. .procname = "nfs_debug",
  133. .data = &nfs_debug,
  134. .maxlen = sizeof(int),
  135. .mode = 0644,
  136. .proc_handler = proc_dodebug
  137. },
  138. {
  139. .procname = "nfsd_debug",
  140. .data = &nfsd_debug,
  141. .maxlen = sizeof(int),
  142. .mode = 0644,
  143. .proc_handler = proc_dodebug
  144. },
  145. {
  146. .procname = "nlm_debug",
  147. .data = &nlm_debug,
  148. .maxlen = sizeof(int),
  149. .mode = 0644,
  150. .proc_handler = proc_dodebug
  151. },
  152. {
  153. .procname = "transports",
  154. .maxlen = 256,
  155. .mode = 0444,
  156. .proc_handler = proc_do_xprt,
  157. },
  158. { }
  159. };
  160. static struct ctl_table sunrpc_table[] = {
  161. {
  162. .procname = "sunrpc",
  163. .mode = 0555,
  164. .child = debug_table
  165. },
  166. { }
  167. };
  168. #endif