debugfs.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/debugfs.h>
  3. #include "nfsd.h"
  4. static struct dentry *nfsd_top_dir __read_mostly;
  5. /*
  6. * /sys/kernel/debug/nfsd/disable-splice-read
  7. *
  8. * Contents:
  9. * %0: NFS READ is allowed to use page splicing
  10. * %1: NFS READ uses only iov iter read
  11. *
  12. * The default value of this setting is zero (page splicing is
  13. * allowed). This setting takes immediate effect for all NFS
  14. * versions, all exports, and in all NFSD net namespaces.
  15. */
  16. static int nfsd_dsr_get(void *data, u64 *val)
  17. {
  18. *val = nfsd_disable_splice_read ? 1 : 0;
  19. return 0;
  20. }
  21. static int nfsd_dsr_set(void *data, u64 val)
  22. {
  23. nfsd_disable_splice_read = (val > 0);
  24. if (!nfsd_disable_splice_read) {
  25. /*
  26. * Must use buffered I/O if splice_read is enabled.
  27. */
  28. nfsd_io_cache_read = NFSD_IO_BUFFERED;
  29. }
  30. return 0;
  31. }
  32. DEFINE_DEBUGFS_ATTRIBUTE(nfsd_dsr_fops, nfsd_dsr_get, nfsd_dsr_set, "%llu\n");
  33. /*
  34. * /sys/kernel/debug/nfsd/io_cache_read
  35. *
  36. * Contents:
  37. * %0: NFS READ will use buffered IO
  38. * %1: NFS READ will use dontcache (buffered IO w/ dropbehind)
  39. * %2: NFS READ will use direct IO
  40. *
  41. * This setting takes immediate effect for all NFS versions,
  42. * all exports, and in all NFSD net namespaces.
  43. */
  44. static int nfsd_io_cache_read_get(void *data, u64 *val)
  45. {
  46. *val = nfsd_io_cache_read;
  47. return 0;
  48. }
  49. static int nfsd_io_cache_read_set(void *data, u64 val)
  50. {
  51. int ret = 0;
  52. switch (val) {
  53. case NFSD_IO_BUFFERED:
  54. nfsd_io_cache_read = NFSD_IO_BUFFERED;
  55. break;
  56. case NFSD_IO_DONTCACHE:
  57. case NFSD_IO_DIRECT:
  58. /*
  59. * Must disable splice_read when enabling
  60. * NFSD_IO_DONTCACHE.
  61. */
  62. nfsd_disable_splice_read = true;
  63. nfsd_io_cache_read = val;
  64. break;
  65. default:
  66. ret = -EINVAL;
  67. break;
  68. }
  69. return ret;
  70. }
  71. DEFINE_DEBUGFS_ATTRIBUTE(nfsd_io_cache_read_fops, nfsd_io_cache_read_get,
  72. nfsd_io_cache_read_set, "%llu\n");
  73. /*
  74. * /sys/kernel/debug/nfsd/io_cache_write
  75. *
  76. * Contents:
  77. * %0: NFS WRITE will use buffered IO
  78. * %1: NFS WRITE will use dontcache (buffered IO w/ dropbehind)
  79. *
  80. * This setting takes immediate effect for all NFS versions,
  81. * all exports, and in all NFSD net namespaces.
  82. */
  83. static int nfsd_io_cache_write_get(void *data, u64 *val)
  84. {
  85. *val = nfsd_io_cache_write;
  86. return 0;
  87. }
  88. static int nfsd_io_cache_write_set(void *data, u64 val)
  89. {
  90. int ret = 0;
  91. switch (val) {
  92. case NFSD_IO_BUFFERED:
  93. case NFSD_IO_DONTCACHE:
  94. case NFSD_IO_DIRECT:
  95. nfsd_io_cache_write = val;
  96. break;
  97. default:
  98. ret = -EINVAL;
  99. break;
  100. }
  101. return ret;
  102. }
  103. DEFINE_DEBUGFS_ATTRIBUTE(nfsd_io_cache_write_fops, nfsd_io_cache_write_get,
  104. nfsd_io_cache_write_set, "%llu\n");
  105. void nfsd_debugfs_exit(void)
  106. {
  107. debugfs_remove_recursive(nfsd_top_dir);
  108. nfsd_top_dir = NULL;
  109. }
  110. void nfsd_debugfs_init(void)
  111. {
  112. nfsd_top_dir = debugfs_create_dir("nfsd", NULL);
  113. debugfs_create_file("disable-splice-read", S_IWUSR | S_IRUGO,
  114. nfsd_top_dir, NULL, &nfsd_dsr_fops);
  115. debugfs_create_file("io_cache_read", 0644, nfsd_top_dir, NULL,
  116. &nfsd_io_cache_read_fops);
  117. debugfs_create_file("io_cache_write", 0644, nfsd_top_dir, NULL,
  118. &nfsd_io_cache_write_fops);
  119. }