sysctl.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 int proc_do_xprt(const struct ctl_table *table, int write,
  35. void *buffer, size_t *lenp, loff_t *ppos)
  36. {
  37. char tmpbuf[256];
  38. ssize_t len;
  39. if (write || *ppos) {
  40. *lenp = 0;
  41. return 0;
  42. }
  43. len = svc_print_xprts(tmpbuf, sizeof(tmpbuf));
  44. len = memory_read_from_buffer(buffer, *lenp, ppos, tmpbuf, len);
  45. if (len < 0) {
  46. *lenp = 0;
  47. return -EINVAL;
  48. }
  49. *lenp = len;
  50. return 0;
  51. }
  52. static int
  53. proc_dodebug(const struct ctl_table *table, int write, void *buffer, size_t *lenp,
  54. loff_t *ppos)
  55. {
  56. char tmpbuf[20], *s = NULL;
  57. char *p;
  58. unsigned int value;
  59. size_t left, len;
  60. if ((*ppos && !write) || !*lenp) {
  61. *lenp = 0;
  62. return 0;
  63. }
  64. left = *lenp;
  65. if (write) {
  66. p = buffer;
  67. while (left && isspace(*p)) {
  68. left--;
  69. p++;
  70. }
  71. if (!left)
  72. goto done;
  73. if (left > sizeof(tmpbuf) - 1)
  74. return -EINVAL;
  75. memcpy(tmpbuf, p, left);
  76. tmpbuf[left] = '\0';
  77. value = simple_strtol(tmpbuf, &s, 0);
  78. if (s) {
  79. left -= (s - tmpbuf);
  80. if (left && !isspace(*s))
  81. return -EINVAL;
  82. while (left && isspace(*s)) {
  83. left--;
  84. s++;
  85. }
  86. } else
  87. left = 0;
  88. *(unsigned int *) table->data = value;
  89. /* Display the RPC tasks on writing to rpc_debug */
  90. if (strcmp(table->procname, "rpc_debug") == 0)
  91. rpc_show_tasks(&init_net);
  92. } else {
  93. len = sprintf(tmpbuf, "0x%04x", *(unsigned int *) table->data);
  94. if (len > left)
  95. len = left;
  96. memcpy(buffer, tmpbuf, len);
  97. if ((left -= len) > 0) {
  98. *((char *)buffer + len) = '\n';
  99. left--;
  100. }
  101. }
  102. done:
  103. *lenp -= left;
  104. *ppos += *lenp;
  105. return 0;
  106. }
  107. static struct ctl_table_header *sunrpc_table_header;
  108. static struct ctl_table debug_table[] = {
  109. {
  110. .procname = "rpc_debug",
  111. .data = &rpc_debug,
  112. .maxlen = sizeof(int),
  113. .mode = 0644,
  114. .proc_handler = proc_dodebug
  115. },
  116. {
  117. .procname = "nfs_debug",
  118. .data = &nfs_debug,
  119. .maxlen = sizeof(int),
  120. .mode = 0644,
  121. .proc_handler = proc_dodebug
  122. },
  123. {
  124. .procname = "nfsd_debug",
  125. .data = &nfsd_debug,
  126. .maxlen = sizeof(int),
  127. .mode = 0644,
  128. .proc_handler = proc_dodebug
  129. },
  130. {
  131. .procname = "nlm_debug",
  132. .data = &nlm_debug,
  133. .maxlen = sizeof(int),
  134. .mode = 0644,
  135. .proc_handler = proc_dodebug
  136. },
  137. {
  138. .procname = "transports",
  139. .maxlen = 256,
  140. .mode = 0444,
  141. .proc_handler = proc_do_xprt,
  142. },
  143. };
  144. void
  145. rpc_register_sysctl(void)
  146. {
  147. if (!sunrpc_table_header)
  148. sunrpc_table_header = register_sysctl("sunrpc", debug_table);
  149. }
  150. void
  151. rpc_unregister_sysctl(void)
  152. {
  153. if (sunrpc_table_header) {
  154. unregister_sysctl_table(sunrpc_table_header);
  155. sunrpc_table_header = NULL;
  156. }
  157. }
  158. #endif