^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * debugfs interface for sunrpc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * (c) 2014 Jeff Layton <jlayton@primarydata.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/sunrpc/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/sunrpc/clnt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "netns.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) static struct dentry *topdir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) static struct dentry *rpc_clnt_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) static struct dentry *rpc_xprt_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) unsigned int rpc_inject_disconnect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) tasks_show(struct seq_file *f, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) u32 xid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct rpc_task *task = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) struct rpc_clnt *clnt = task->tk_client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) const char *rpc_waitq = "none";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) if (RPC_IS_QUEUED(task))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) rpc_waitq = rpc_qname(task->tk_waitqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) if (task->tk_rqstp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) xid = be32_to_cpu(task->tk_rqstp->rq_xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) seq_printf(f, "%5u %04x %6d 0x%x 0x%x %8ld %ps %sv%u %s a:%ps q:%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) task->tk_pid, task->tk_flags, task->tk_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) clnt->cl_clid, xid, rpc_task_timeout(task), task->tk_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) clnt->cl_program->name, clnt->cl_vers, rpc_proc_name(task),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) task->tk_action, rpc_waitq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static void *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) tasks_start(struct seq_file *f, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) __acquires(&clnt->cl_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct rpc_clnt *clnt = f->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) loff_t pos = *ppos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct rpc_task *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) spin_lock(&clnt->cl_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) list_for_each_entry(task, &clnt->cl_tasks, tk_task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) if (pos-- == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) return task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static void *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) tasks_next(struct seq_file *f, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct rpc_clnt *clnt = f->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct rpc_task *task = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct list_head *next = task->tk_task.next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) ++*pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) /* If there's another task on list, return it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (next == &clnt->cl_tasks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) return list_entry(next, struct rpc_task, tk_task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) tasks_stop(struct seq_file *f, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) __releases(&clnt->cl_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct rpc_clnt *clnt = f->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) spin_unlock(&clnt->cl_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) static const struct seq_operations tasks_seq_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) .start = tasks_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) .next = tasks_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) .stop = tasks_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) .show = tasks_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) static int tasks_open(struct inode *inode, struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) int ret = seq_open(filp, &tasks_seq_operations);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct seq_file *seq = filp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) struct rpc_clnt *clnt = seq->private = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (!atomic_inc_not_zero(&clnt->cl_count)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) seq_release(inode, filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) tasks_release(struct inode *inode, struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct seq_file *seq = filp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct rpc_clnt *clnt = seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) rpc_release_client(clnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) return seq_release(inode, filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static const struct file_operations tasks_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) .open = tasks_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) .read = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) .llseek = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) .release = tasks_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) static int do_xprt_debugfs(struct rpc_clnt *clnt, struct rpc_xprt *xprt, void *numv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) char name[24]; /* enough for "../../rpc_xprt/ + 8 hex digits + NULL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) char link[9]; /* enough for 8 hex digits + NULL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) int *nump = numv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) if (IS_ERR_OR_NULL(xprt->debugfs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) len = snprintf(name, sizeof(name), "../../rpc_xprt/%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) xprt->debugfs->d_name.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) if (len >= sizeof(name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (*nump == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) strcpy(link, "xprt");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) len = snprintf(link, sizeof(link), "xprt%d", *nump);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if (len >= sizeof(link))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) debugfs_create_symlink(link, clnt->cl_debugfs, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) (*nump)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) rpc_clnt_debugfs_register(struct rpc_clnt *clnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) char name[9]; /* enough for 8 hex digits + NULL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) int xprtnum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) len = snprintf(name, sizeof(name), "%x", clnt->cl_clid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (len >= sizeof(name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) /* make the per-client dir */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) clnt->cl_debugfs = debugfs_create_dir(name, rpc_clnt_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) /* make tasks file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) debugfs_create_file("tasks", S_IFREG | 0400, clnt->cl_debugfs, clnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) &tasks_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) rpc_clnt_iterate_for_each_xprt(clnt, do_xprt_debugfs, &xprtnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) rpc_clnt_debugfs_unregister(struct rpc_clnt *clnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) debugfs_remove_recursive(clnt->cl_debugfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) clnt->cl_debugfs = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) xprt_info_show(struct seq_file *f, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct rpc_xprt *xprt = f->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) seq_printf(f, "netid: %s\n", xprt->address_strings[RPC_DISPLAY_NETID]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) seq_printf(f, "addr: %s\n", xprt->address_strings[RPC_DISPLAY_ADDR]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) seq_printf(f, "port: %s\n", xprt->address_strings[RPC_DISPLAY_PORT]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) seq_printf(f, "state: 0x%lx\n", xprt->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) xprt_info_open(struct inode *inode, struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) struct rpc_xprt *xprt = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) ret = single_open(filp, xprt_info_show, xprt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) if (!xprt_get(xprt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) single_release(inode, filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) xprt_info_release(struct inode *inode, struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) struct rpc_xprt *xprt = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) xprt_put(xprt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) return single_release(inode, filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) static const struct file_operations xprt_info_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) .open = xprt_info_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) .read = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) .llseek = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) .release = xprt_info_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) rpc_xprt_debugfs_register(struct rpc_xprt *xprt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) int len, id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) static atomic_t cur_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) char name[9]; /* 8 hex digits + NULL term */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) id = (unsigned int)atomic_inc_return(&cur_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) len = snprintf(name, sizeof(name), "%x", id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) if (len >= sizeof(name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) /* make the per-client dir */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) xprt->debugfs = debugfs_create_dir(name, rpc_xprt_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) /* make tasks file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) debugfs_create_file("info", S_IFREG | 0400, xprt->debugfs, xprt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) &xprt_info_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) atomic_set(&xprt->inject_disconnect, rpc_inject_disconnect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) rpc_xprt_debugfs_unregister(struct rpc_xprt *xprt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) debugfs_remove_recursive(xprt->debugfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) xprt->debugfs = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) fault_open(struct inode *inode, struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) filp->private_data = kmalloc(128, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (!filp->private_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) fault_release(struct inode *inode, struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) kfree(filp->private_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) fault_disconnect_read(struct file *filp, char __user *user_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) size_t len, loff_t *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) char *buffer = (char *)filp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) size = sprintf(buffer, "%u\n", rpc_inject_disconnect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) return simple_read_from_buffer(user_buf, len, offset, buffer, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) fault_disconnect_write(struct file *filp, const char __user *user_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) size_t len, loff_t *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) char buffer[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) if (len >= sizeof(buffer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) len = sizeof(buffer) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) if (copy_from_user(buffer, user_buf, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) buffer[len] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) if (kstrtouint(buffer, 10, &rpc_inject_disconnect))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) static const struct file_operations fault_disconnect_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) .open = fault_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) .read = fault_disconnect_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) .write = fault_disconnect_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) .release = fault_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) void __exit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) sunrpc_debugfs_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) debugfs_remove_recursive(topdir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) topdir = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) rpc_clnt_dir = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) rpc_xprt_dir = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) sunrpc_debugfs_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) struct dentry *rpc_fault_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) topdir = debugfs_create_dir("sunrpc", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) rpc_clnt_dir = debugfs_create_dir("rpc_clnt", topdir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) rpc_xprt_dir = debugfs_create_dir("rpc_xprt", topdir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) rpc_fault_dir = debugfs_create_dir("inject_fault", topdir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) debugfs_create_file("disconnect", S_IFREG | 0400, rpc_fault_dir, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) &fault_disconnect_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) }