sysctl.c 3.1 KB

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