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