sysctl.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 (strcmp(table->procname, "rpc_debug") == 0)
  78. rpc_show_tasks();
  79. } else {
  80. if (!access_ok(VERIFY_WRITE, buffer, left))
  81. return -EFAULT;
  82. len = sprintf(tmpbuf, "%d", *(unsigned int *) table->data);
  83. if (len > left)
  84. len = left;
  85. if (__copy_to_user(buffer, tmpbuf, len))
  86. return -EFAULT;
  87. if ((left -= len) > 0) {
  88. if (put_user('\n', (char __user *)buffer + len))
  89. return -EFAULT;
  90. left--;
  91. }
  92. }
  93. done:
  94. *lenp -= left;
  95. *ppos += *lenp;
  96. return 0;
  97. }
  98. static ctl_table debug_table[] = {
  99. {
  100. .procname = "rpc_debug",
  101. .data = &rpc_debug,
  102. .maxlen = sizeof(int),
  103. .mode = 0644,
  104. .proc_handler = &proc_dodebug
  105. },
  106. {
  107. .procname = "nfs_debug",
  108. .data = &nfs_debug,
  109. .maxlen = sizeof(int),
  110. .mode = 0644,
  111. .proc_handler = &proc_dodebug
  112. },
  113. {
  114. .procname = "nfsd_debug",
  115. .data = &nfsd_debug,
  116. .maxlen = sizeof(int),
  117. .mode = 0644,
  118. .proc_handler = &proc_dodebug
  119. },
  120. {
  121. .procname = "nlm_debug",
  122. .data = &nlm_debug,
  123. .maxlen = sizeof(int),
  124. .mode = 0644,
  125. .proc_handler = &proc_dodebug
  126. },
  127. { .ctl_name = 0 }
  128. };
  129. static ctl_table sunrpc_table[] = {
  130. {
  131. .ctl_name = CTL_SUNRPC,
  132. .procname = "sunrpc",
  133. .mode = 0555,
  134. .child = debug_table
  135. },
  136. { .ctl_name = 0 }
  137. };
  138. #endif