Skip to content

Commit b4b9d2c

Browse files
Jeff Laytontrondmypd
authored andcommitted
sunrpc: add debugfs file for displaying client rpc_task queue
It's possible to get a dump of the RPC task queue by writing a value to /proc/sys/sunrpc/rpc_debug. If you write any value to that file, you get a dump of the RPC client task list into the log buffer. This is a rather inconvenient interface however, and makes it hard to get immediate info about the task queue. Add a new directory hierarchy under debugfs: sunrpc/ rpc_clnt/ <clientid>/ Within each clientid directory we create a new "tasks" file that will dump info similar to what shows up in the log buffer, but with a few small differences -- we avoid printing raw kernel addresses in favor of symbolic names and the XID is also displayed. Signed-off-by: Jeff Layton <jlayton@primarydata.com> Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
1 parent ea52641 commit b4b9d2c

7 files changed

Lines changed: 245 additions & 1 deletion

File tree

‎include/linux/sunrpc/clnt.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ struct rpc_clnt {
6363
struct rpc_rtt cl_rtt_default;
6464
struct rpc_timeout cl_timeout_default;
6565
const struct rpc_program *cl_program;
66+
#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
67+
struct dentry *cl_debugfs; /* debugfs directory */
68+
#endif
6669
};
6770

6871
/*
@@ -176,5 +179,6 @@ size_t rpc_peeraddr(struct rpc_clnt *, struct sockaddr *, size_t);
176179
const char *rpc_peeraddr2str(struct rpc_clnt *, enum rpc_display_format_t);
177180
int rpc_localaddr(struct rpc_clnt *, struct sockaddr *, size_t);
178181

182+
const char *rpc_proc_name(const struct rpc_task *task);
179183
#endif /* __KERNEL__ */
180184
#endif /* _LINUX_SUNRPC_CLNT_H */

‎include/linux/sunrpc/debug.h‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,40 @@ extern unsigned int nlm_debug;
5353
/*
5454
* Sysctl interface for RPC debugging
5555
*/
56+
57+
struct rpc_clnt;
58+
5659
#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
5760
void rpc_register_sysctl(void);
5861
void rpc_unregister_sysctl(void);
62+
int sunrpc_debugfs_init(void);
63+
void sunrpc_debugfs_exit(void);
64+
int rpc_clnt_debugfs_register(struct rpc_clnt *);
65+
void rpc_clnt_debugfs_unregister(struct rpc_clnt *);
66+
#else
67+
static inline int
68+
sunrpc_debugfs_init(void)
69+
{
70+
return 0;
71+
}
72+
73+
static inline void
74+
sunrpc_debugfs_exit(void)
75+
{
76+
return;
77+
}
78+
79+
static inline int
80+
rpc_clnt_debugfs_register(struct rpc_clnt *clnt)
81+
{
82+
return 0;
83+
}
84+
85+
static inline void
86+
rpc_clnt_debugfs_unregister(struct rpc_clnt *clnt)
87+
{
88+
return;
89+
}
5990
#endif
6091

6192
#endif /* _LINUX_SUNRPC_DEBUG_H_ */

‎net/sunrpc/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ config RPCSEC_GSS_KRB5
3535
config SUNRPC_DEBUG
3636
bool "RPC: Enable dprintk debugging"
3737
depends on SUNRPC && SYSCTL
38+
select DEBUG_FS
3839
help
3940
This option enables a sysctl-based debugging interface
4041
that is be used by the 'rpcdebug' utility to turn on or off

‎net/sunrpc/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ sunrpc-y := clnt.o xprt.o socklib.o xprtsock.o sched.o \
1414
addr.o rpcb_clnt.o timer.o xdr.o \
1515
sunrpc_syms.o cache.o rpc_pipe.o \
1616
svc_xprt.o
17+
sunrpc-$(CONFIG_SUNRPC_DEBUG) += debugfs.o
1718
sunrpc-$(CONFIG_SUNRPC_BACKCHANNEL) += backchannel_rqst.o bc_svc.o
1819
sunrpc-$(CONFIG_PROC_FS) += stats.o
1920
sunrpc-$(CONFIG_SYSCTL) += sysctl.o

‎net/sunrpc/clnt.c‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,10 @@ static int rpc_client_register(struct rpc_clnt *clnt,
305305
struct super_block *pipefs_sb;
306306
int err;
307307

308+
err = rpc_clnt_debugfs_register(clnt);
309+
if (err)
310+
return err;
311+
308312
pipefs_sb = rpc_get_sb_net(net);
309313
if (pipefs_sb) {
310314
err = rpc_setup_pipedir(pipefs_sb, clnt);
@@ -331,6 +335,7 @@ static int rpc_client_register(struct rpc_clnt *clnt,
331335
out:
332336
if (pipefs_sb)
333337
rpc_put_sb_net(net);
338+
rpc_clnt_debugfs_unregister(clnt);
334339
return err;
335340
}
336341

@@ -670,6 +675,7 @@ int rpc_switch_client_transport(struct rpc_clnt *clnt,
670675

671676
rpc_unregister_client(clnt);
672677
__rpc_clnt_remove_pipedir(clnt);
678+
rpc_clnt_debugfs_unregister(clnt);
673679

674680
/*
675681
* A new transport was created. "clnt" therefore
@@ -771,6 +777,7 @@ rpc_free_client(struct rpc_clnt *clnt)
771777
rcu_dereference(clnt->cl_xprt)->servername);
772778
if (clnt->cl_parent != clnt)
773779
parent = clnt->cl_parent;
780+
rpc_clnt_debugfs_unregister(clnt);
774781
rpc_clnt_remove_pipedir(clnt);
775782
rpc_unregister_client(clnt);
776783
rpc_free_iostats(clnt->cl_metrics);
@@ -1397,7 +1404,8 @@ rpc_restart_call(struct rpc_task *task)
13971404
EXPORT_SYMBOL_GPL(rpc_restart_call);
13981405

13991406
#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
1400-
static const char *rpc_proc_name(const struct rpc_task *task)
1407+
const char
1408+
*rpc_proc_name(const struct rpc_task *task)
14011409
{
14021410
const struct rpc_procinfo *proc = task->tk_msg.rpc_proc;
14031411

‎net/sunrpc/debugfs.c‎

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
/**
2+
* debugfs interface for sunrpc
3+
*
4+
* (c) 2014 Jeff Layton <jlayton@primarydata.com>
5+
*/
6+
7+
#include <linux/debugfs.h>
8+
#include <linux/sunrpc/sched.h>
9+
#include <linux/sunrpc/clnt.h>
10+
#include "netns.h"
11+
12+
static struct dentry *topdir;
13+
static struct dentry *rpc_clnt_dir;
14+
15+
struct rpc_clnt_iter {
16+
struct rpc_clnt *clnt;
17+
loff_t pos;
18+
};
19+
20+
static int
21+
tasks_show(struct seq_file *f, void *v)
22+
{
23+
u32 xid = 0;
24+
struct rpc_task *task = v;
25+
struct rpc_clnt *clnt = task->tk_client;
26+
const char *rpc_waitq = "none";
27+
28+
if (RPC_IS_QUEUED(task))
29+
rpc_waitq = rpc_qname(task->tk_waitqueue);
30+
31+
if (task->tk_rqstp)
32+
xid = be32_to_cpu(task->tk_rqstp->rq_xid);
33+
34+
seq_printf(f, "%5u %04x %6d 0x%x 0x%x %8ld %ps %sv%u %s a:%ps q:%s\n",
35+
task->tk_pid, task->tk_flags, task->tk_status,
36+
clnt->cl_clid, xid, task->tk_timeout, task->tk_ops,
37+
clnt->cl_program->name, clnt->cl_vers, rpc_proc_name(task),
38+
task->tk_action, rpc_waitq);
39+
return 0;
40+
}
41+
42+
static void *
43+
tasks_start(struct seq_file *f, loff_t *ppos)
44+
__acquires(&clnt->cl_lock)
45+
{
46+
struct rpc_clnt_iter *iter = f->private;
47+
loff_t pos = *ppos;
48+
struct rpc_clnt *clnt = iter->clnt;
49+
struct rpc_task *task;
50+
51+
iter->pos = pos + 1;
52+
spin_lock(&clnt->cl_lock);
53+
list_for_each_entry(task, &clnt->cl_tasks, tk_task)
54+
if (pos-- == 0)
55+
return task;
56+
return NULL;
57+
}
58+
59+
static void *
60+
tasks_next(struct seq_file *f, void *v, loff_t *pos)
61+
{
62+
struct rpc_clnt_iter *iter = f->private;
63+
struct rpc_clnt *clnt = iter->clnt;
64+
struct rpc_task *task = v;
65+
struct list_head *next = task->tk_task.next;
66+
67+
++iter->pos;
68+
++*pos;
69+
70+
/* If there's another task on list, return it */
71+
if (next == &clnt->cl_tasks)
72+
return NULL;
73+
return list_entry(next, struct rpc_task, tk_task);
74+
}
75+
76+
static void
77+
tasks_stop(struct seq_file *f, void *v)
78+
__releases(&clnt->cl_lock)
79+
{
80+
struct rpc_clnt_iter *iter = f->private;
81+
struct rpc_clnt *clnt = iter->clnt;
82+
83+
spin_unlock(&clnt->cl_lock);
84+
}
85+
86+
static const struct seq_operations tasks_seq_operations = {
87+
.start = tasks_start,
88+
.next = tasks_next,
89+
.stop = tasks_stop,
90+
.show = tasks_show,
91+
};
92+
93+
static int tasks_open(struct inode *inode, struct file *filp)
94+
{
95+
int ret = seq_open_private(filp, &tasks_seq_operations,
96+
sizeof(struct rpc_clnt_iter));
97+
98+
if (!ret) {
99+
struct seq_file *seq = filp->private_data;
100+
struct rpc_clnt_iter *iter = seq->private;
101+
102+
iter->clnt = inode->i_private;
103+
104+
if (!atomic_inc_not_zero(&iter->clnt->cl_count)) {
105+
seq_release_private(inode, filp);
106+
ret = -EINVAL;
107+
}
108+
}
109+
110+
return ret;
111+
}
112+
113+
static int
114+
tasks_release(struct inode *inode, struct file *filp)
115+
{
116+
struct seq_file *seq = filp->private_data;
117+
struct rpc_clnt_iter *iter = seq->private;
118+
119+
rpc_release_client(iter->clnt);
120+
return seq_release_private(inode, filp);
121+
}
122+
123+
static const struct file_operations tasks_fops = {
124+
.owner = THIS_MODULE,
125+
.open = tasks_open,
126+
.read = seq_read,
127+
.llseek = seq_lseek,
128+
.release = tasks_release,
129+
};
130+
131+
int
132+
rpc_clnt_debugfs_register(struct rpc_clnt *clnt)
133+
{
134+
int len;
135+
char name[9]; /* 8 for hex digits + NULL terminator */
136+
137+
/* Already registered? */
138+
if (clnt->cl_debugfs)
139+
return 0;
140+
141+
len = snprintf(name, sizeof(name), "%x", clnt->cl_clid);
142+
if (len >= sizeof(name))
143+
return -EINVAL;
144+
145+
/* make the per-client dir */
146+
clnt->cl_debugfs = debugfs_create_dir(name, rpc_clnt_dir);
147+
if (!clnt->cl_debugfs)
148+
return -ENOMEM;
149+
150+
/* make tasks file */
151+
if (!debugfs_create_file("tasks", S_IFREG | S_IRUSR, clnt->cl_debugfs,
152+
clnt, &tasks_fops)) {
153+
debugfs_remove_recursive(clnt->cl_debugfs);
154+
clnt->cl_debugfs = NULL;
155+
return -ENOMEM;
156+
}
157+
158+
return 0;
159+
}
160+
161+
void
162+
rpc_clnt_debugfs_unregister(struct rpc_clnt *clnt)
163+
{
164+
debugfs_remove_recursive(clnt->cl_debugfs);
165+
clnt->cl_debugfs = NULL;
166+
}
167+
168+
void __exit
169+
sunrpc_debugfs_exit(void)
170+
{
171+
debugfs_remove_recursive(topdir);
172+
}
173+
174+
int __init
175+
sunrpc_debugfs_init(void)
176+
{
177+
topdir = debugfs_create_dir("sunrpc", NULL);
178+
if (!topdir)
179+
goto out;
180+
181+
rpc_clnt_dir = debugfs_create_dir("rpc_clnt", topdir);
182+
if (!rpc_clnt_dir)
183+
goto out_remove;
184+
185+
return 0;
186+
out_remove:
187+
debugfs_remove_recursive(topdir);
188+
topdir = NULL;
189+
out:
190+
return -ENOMEM;
191+
}

‎net/sunrpc/sunrpc_syms.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,20 @@ init_sunrpc(void)
9797
err = register_rpc_pipefs();
9898
if (err)
9999
goto out4;
100+
101+
err = sunrpc_debugfs_init();
102+
if (err)
103+
goto out5;
104+
100105
#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
101106
rpc_register_sysctl();
102107
#endif
103108
svc_init_xprt_sock(); /* svc sock transport */
104109
init_socket_xprt(); /* clnt sock transport */
105110
return 0;
106111

112+
out5:
113+
unregister_rpc_pipefs();
107114
out4:
108115
unregister_pernet_subsys(&sunrpc_net_ops);
109116
out3:
@@ -120,6 +127,7 @@ cleanup_sunrpc(void)
120127
rpcauth_remove_module();
121128
cleanup_socket_xprt();
122129
svc_cleanup_xprt_sock();
130+
sunrpc_debugfs_exit();
123131
unregister_rpc_pipefs();
124132
rpc_destroy_mempool();
125133
unregister_pernet_subsys(&sunrpc_net_ops);

0 commit comments

Comments
 (0)