sysctl.c 3.2 KB

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