sysctl.c 3.5 KB

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