2 * debugfs interface for sunrpc
4 * (c) 2014 Jeff Layton <jlayton@primarydata.com>
7 #include <linux/debugfs.h>
8 #include <linux/sunrpc/sched.h>
9 #include <linux/sunrpc/clnt.h>
12 static struct dentry
*topdir
;
13 static struct dentry
*rpc_clnt_dir
;
14 static struct dentry
*rpc_xprt_dir
;
16 struct rpc_clnt_iter
{
17 struct rpc_clnt
*clnt
;
22 tasks_show(struct seq_file
*f
, void *v
)
25 struct rpc_task
*task
= v
;
26 struct rpc_clnt
*clnt
= task
->tk_client
;
27 const char *rpc_waitq
= "none";
29 if (RPC_IS_QUEUED(task
))
30 rpc_waitq
= rpc_qname(task
->tk_waitqueue
);
33 xid
= be32_to_cpu(task
->tk_rqstp
->rq_xid
);
35 seq_printf(f
, "%5u %04x %6d 0x%x 0x%x %8ld %ps %sv%u %s a:%ps q:%s\n",
36 task
->tk_pid
, task
->tk_flags
, task
->tk_status
,
37 clnt
->cl_clid
, xid
, task
->tk_timeout
, task
->tk_ops
,
38 clnt
->cl_program
->name
, clnt
->cl_vers
, rpc_proc_name(task
),
39 task
->tk_action
, rpc_waitq
);
44 tasks_start(struct seq_file
*f
, loff_t
*ppos
)
45 __acquires(&clnt
->cl_lock
)
47 struct rpc_clnt_iter
*iter
= f
->private;
49 struct rpc_clnt
*clnt
= iter
->clnt
;
50 struct rpc_task
*task
;
53 spin_lock(&clnt
->cl_lock
);
54 list_for_each_entry(task
, &clnt
->cl_tasks
, tk_task
)
61 tasks_next(struct seq_file
*f
, void *v
, loff_t
*pos
)
63 struct rpc_clnt_iter
*iter
= f
->private;
64 struct rpc_clnt
*clnt
= iter
->clnt
;
65 struct rpc_task
*task
= v
;
66 struct list_head
*next
= task
->tk_task
.next
;
71 /* If there's another task on list, return it */
72 if (next
== &clnt
->cl_tasks
)
74 return list_entry(next
, struct rpc_task
, tk_task
);
78 tasks_stop(struct seq_file
*f
, void *v
)
79 __releases(&clnt
->cl_lock
)
81 struct rpc_clnt_iter
*iter
= f
->private;
82 struct rpc_clnt
*clnt
= iter
->clnt
;
84 spin_unlock(&clnt
->cl_lock
);
87 static const struct seq_operations tasks_seq_operations
= {
94 static int tasks_open(struct inode
*inode
, struct file
*filp
)
96 int ret
= seq_open_private(filp
, &tasks_seq_operations
,
97 sizeof(struct rpc_clnt_iter
));
100 struct seq_file
*seq
= filp
->private_data
;
101 struct rpc_clnt_iter
*iter
= seq
->private;
103 iter
->clnt
= inode
->i_private
;
105 if (!atomic_inc_not_zero(&iter
->clnt
->cl_count
)) {
106 seq_release_private(inode
, filp
);
115 tasks_release(struct inode
*inode
, struct file
*filp
)
117 struct seq_file
*seq
= filp
->private_data
;
118 struct rpc_clnt_iter
*iter
= seq
->private;
120 rpc_release_client(iter
->clnt
);
121 return seq_release_private(inode
, filp
);
124 static const struct file_operations tasks_fops
= {
125 .owner
= THIS_MODULE
,
129 .release
= tasks_release
,
133 rpc_clnt_debugfs_register(struct rpc_clnt
*clnt
)
136 char name
[24]; /* enough for "../../rpc_xprt/ + 8 hex digits + NULL */
137 struct rpc_xprt
*xprt
;
139 /* Already registered? */
140 if (clnt
->cl_debugfs
|| !rpc_clnt_dir
)
143 len
= snprintf(name
, sizeof(name
), "%x", clnt
->cl_clid
);
144 if (len
>= sizeof(name
))
147 /* make the per-client dir */
148 clnt
->cl_debugfs
= debugfs_create_dir(name
, rpc_clnt_dir
);
149 if (!clnt
->cl_debugfs
)
152 /* make tasks file */
153 if (!debugfs_create_file("tasks", S_IFREG
| S_IRUSR
, clnt
->cl_debugfs
,
158 xprt
= rcu_dereference(clnt
->cl_xprt
);
159 /* no "debugfs" dentry? Don't bother with the symlink. */
160 if (!xprt
->debugfs
) {
164 len
= snprintf(name
, sizeof(name
), "../../rpc_xprt/%s",
165 xprt
->debugfs
->d_name
.name
);
168 if (len
>= sizeof(name
))
171 if (!debugfs_create_symlink("xprt", clnt
->cl_debugfs
, name
))
176 debugfs_remove_recursive(clnt
->cl_debugfs
);
177 clnt
->cl_debugfs
= NULL
;
181 rpc_clnt_debugfs_unregister(struct rpc_clnt
*clnt
)
183 debugfs_remove_recursive(clnt
->cl_debugfs
);
184 clnt
->cl_debugfs
= NULL
;
188 xprt_info_show(struct seq_file
*f
, void *v
)
190 struct rpc_xprt
*xprt
= f
->private;
192 seq_printf(f
, "netid: %s\n", xprt
->address_strings
[RPC_DISPLAY_NETID
]);
193 seq_printf(f
, "addr: %s\n", xprt
->address_strings
[RPC_DISPLAY_ADDR
]);
194 seq_printf(f
, "port: %s\n", xprt
->address_strings
[RPC_DISPLAY_PORT
]);
195 seq_printf(f
, "state: 0x%lx\n", xprt
->state
);
200 xprt_info_open(struct inode
*inode
, struct file
*filp
)
203 struct rpc_xprt
*xprt
= inode
->i_private
;
205 ret
= single_open(filp
, xprt_info_show
, xprt
);
208 if (!xprt_get(xprt
)) {
209 single_release(inode
, filp
);
217 xprt_info_release(struct inode
*inode
, struct file
*filp
)
219 struct rpc_xprt
*xprt
= inode
->i_private
;
222 return single_release(inode
, filp
);
225 static const struct file_operations xprt_info_fops
= {
226 .owner
= THIS_MODULE
,
227 .open
= xprt_info_open
,
230 .release
= xprt_info_release
,
234 rpc_xprt_debugfs_register(struct rpc_xprt
*xprt
)
237 static atomic_t cur_id
;
238 char name
[9]; /* 8 hex digits + NULL term */
243 id
= (unsigned int)atomic_inc_return(&cur_id
);
245 len
= snprintf(name
, sizeof(name
), "%x", id
);
246 if (len
>= sizeof(name
))
249 /* make the per-client dir */
250 xprt
->debugfs
= debugfs_create_dir(name
, rpc_xprt_dir
);
254 /* make tasks file */
255 if (!debugfs_create_file("info", S_IFREG
| S_IRUSR
, xprt
->debugfs
,
256 xprt
, &xprt_info_fops
)) {
257 debugfs_remove_recursive(xprt
->debugfs
);
258 xprt
->debugfs
= NULL
;
263 rpc_xprt_debugfs_unregister(struct rpc_xprt
*xprt
)
265 debugfs_remove_recursive(xprt
->debugfs
);
266 xprt
->debugfs
= NULL
;
270 sunrpc_debugfs_exit(void)
272 debugfs_remove_recursive(topdir
);
279 sunrpc_debugfs_init(void)
281 topdir
= debugfs_create_dir("sunrpc", NULL
);
285 rpc_clnt_dir
= debugfs_create_dir("rpc_clnt", topdir
);
289 rpc_xprt_dir
= debugfs_create_dir("rpc_xprt", topdir
);
295 debugfs_remove_recursive(topdir
);