1 // SPDX-License-Identifier: GPL-2.0
3 * debugfs interface for sunrpc
5 * (c) 2014 Jeff Layton <jlayton@primarydata.com>
8 #include <linux/debugfs.h>
9 #include <linux/sunrpc/sched.h>
10 #include <linux/sunrpc/clnt.h>
15 static struct dentry *topdir;
16 static struct dentry *rpc_clnt_dir;
17 static struct dentry *rpc_xprt_dir;
20 tasks_show(struct seq_file *f, void *v)
23 struct rpc_task *task = v;
24 struct rpc_clnt *clnt = task->tk_client;
25 const char *rpc_waitq = "none";
27 if (RPC_IS_QUEUED(task))
28 rpc_waitq = rpc_qname(task->tk_waitqueue);
31 xid = be32_to_cpu(task->tk_rqstp->rq_xid);
33 seq_printf(f, "%5u %04x %6d 0x%x 0x%x %8ld %ps %sv%u %s a:%ps q:%s\n",
34 task->tk_pid, task->tk_flags, task->tk_status,
35 clnt->cl_clid, xid, rpc_task_timeout(task), task->tk_ops,
36 clnt->cl_program->name, clnt->cl_vers, rpc_proc_name(task),
37 task->tk_action, rpc_waitq);
42 tasks_start(struct seq_file *f, loff_t *ppos)
43 __acquires(&clnt->cl_lock)
45 struct rpc_clnt *clnt = f->private;
47 struct rpc_task *task;
49 spin_lock(&clnt->cl_lock);
50 list_for_each_entry(task, &clnt->cl_tasks, tk_task)
57 tasks_next(struct seq_file *f, void *v, loff_t *pos)
59 struct rpc_clnt *clnt = f->private;
60 struct rpc_task *task = v;
61 struct list_head *next = task->tk_task.next;
65 /* If there's another task on list, return it */
66 if (next == &clnt->cl_tasks)
68 return list_entry(next, struct rpc_task, tk_task);
72 tasks_stop(struct seq_file *f, void *v)
73 __releases(&clnt->cl_lock)
75 struct rpc_clnt *clnt = f->private;
76 spin_unlock(&clnt->cl_lock);
79 static const struct seq_operations tasks_seq_operations = {
86 static int tasks_open(struct inode *inode, struct file *filp)
88 int ret = seq_open(filp, &tasks_seq_operations);
90 struct seq_file *seq = filp->private_data;
91 struct rpc_clnt *clnt = seq->private = inode->i_private;
93 if (!refcount_inc_not_zero(&clnt->cl_count)) {
94 seq_release(inode, filp);
103 tasks_release(struct inode *inode, struct file *filp)
105 struct seq_file *seq = filp->private_data;
106 struct rpc_clnt *clnt = seq->private;
108 rpc_release_client(clnt);
109 return seq_release(inode, filp);
112 static const struct file_operations tasks_fops = {
113 .owner = THIS_MODULE,
117 .release = tasks_release,
120 static int do_xprt_debugfs(struct rpc_clnt *clnt, struct rpc_xprt *xprt, void *numv)
123 char name[24]; /* enough for "../../rpc_xprt/ + 8 hex digits + NULL */
124 char link[9]; /* enough for 8 hex digits + NULL */
127 if (IS_ERR_OR_NULL(xprt->debugfs))
129 len = snprintf(name, sizeof(name), "../../rpc_xprt/%s",
130 xprt->debugfs->d_name.name);
131 if (len >= sizeof(name))
134 strcpy(link, "xprt");
136 len = snprintf(link, sizeof(link), "xprt%d", *nump);
137 if (len >= sizeof(link))
140 debugfs_create_symlink(link, clnt->cl_debugfs, name);
146 rpc_clnt_debugfs_register(struct rpc_clnt *clnt)
149 char name[9]; /* enough for 8 hex digits + NULL */
152 len = snprintf(name, sizeof(name), "%x", clnt->cl_clid);
153 if (len >= sizeof(name))
156 /* make the per-client dir */
157 clnt->cl_debugfs = debugfs_create_dir(name, rpc_clnt_dir);
159 /* make tasks file */
160 debugfs_create_file("tasks", S_IFREG | 0400, clnt->cl_debugfs, clnt,
163 rpc_clnt_iterate_for_each_xprt(clnt, do_xprt_debugfs, &xprtnum);
167 rpc_clnt_debugfs_unregister(struct rpc_clnt *clnt)
169 debugfs_remove_recursive(clnt->cl_debugfs);
170 clnt->cl_debugfs = NULL;
174 xprt_info_show(struct seq_file *f, void *v)
176 struct rpc_xprt *xprt = f->private;
178 seq_printf(f, "netid: %s\n", xprt->address_strings[RPC_DISPLAY_NETID]);
179 seq_printf(f, "addr: %s\n", xprt->address_strings[RPC_DISPLAY_ADDR]);
180 seq_printf(f, "port: %s\n", xprt->address_strings[RPC_DISPLAY_PORT]);
181 seq_printf(f, "state: 0x%lx\n", xprt->state);
186 xprt_info_open(struct inode *inode, struct file *filp)
189 struct rpc_xprt *xprt = inode->i_private;
191 ret = single_open(filp, xprt_info_show, xprt);
194 if (!xprt_get(xprt)) {
195 single_release(inode, filp);
203 xprt_info_release(struct inode *inode, struct file *filp)
205 struct rpc_xprt *xprt = inode->i_private;
208 return single_release(inode, filp);
211 static const struct file_operations xprt_info_fops = {
212 .owner = THIS_MODULE,
213 .open = xprt_info_open,
216 .release = xprt_info_release,
220 rpc_xprt_debugfs_register(struct rpc_xprt *xprt)
223 static atomic_t cur_id;
224 char name[9]; /* 8 hex digits + NULL term */
226 id = (unsigned int)atomic_inc_return(&cur_id);
228 len = snprintf(name, sizeof(name), "%x", id);
229 if (len >= sizeof(name))
232 /* make the per-client dir */
233 xprt->debugfs = debugfs_create_dir(name, rpc_xprt_dir);
235 /* make tasks file */
236 debugfs_create_file("info", S_IFREG | 0400, xprt->debugfs, xprt,
241 rpc_xprt_debugfs_unregister(struct rpc_xprt *xprt)
243 debugfs_remove_recursive(xprt->debugfs);
244 xprt->debugfs = NULL;
247 #if IS_ENABLED(CONFIG_FAIL_SUNRPC)
248 struct fail_sunrpc_attr fail_sunrpc = {
249 .attr = FAULT_ATTR_INITIALIZER,
251 EXPORT_SYMBOL_GPL(fail_sunrpc);
253 static void fail_sunrpc_init(void)
257 dir = fault_create_debugfs_attr("fail_sunrpc", NULL,
260 debugfs_create_bool("ignore-client-disconnect", S_IFREG | 0600, dir,
261 &fail_sunrpc.ignore_client_disconnect);
263 debugfs_create_bool("ignore-server-disconnect", S_IFREG | 0600, dir,
264 &fail_sunrpc.ignore_server_disconnect);
266 debugfs_create_bool("ignore-cache-wait", S_IFREG | 0600, dir,
267 &fail_sunrpc.ignore_cache_wait);
270 static void fail_sunrpc_init(void)
276 sunrpc_debugfs_exit(void)
278 debugfs_remove_recursive(topdir);
285 sunrpc_debugfs_init(void)
287 topdir = debugfs_create_dir("sunrpc", NULL);
289 rpc_clnt_dir = debugfs_create_dir("rpc_clnt", topdir);
291 rpc_xprt_dir = debugfs_create_dir("rpc_xprt", topdir);