sysctl.c 3.1 KB

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