2 * linux/net/sunrpc/stats.c
4 * procfs-based user access to generic RPC statistics. The stats files
5 * reside in /proc/net/rpc.
7 * The read routines assume that the buffer passed in is just big enough.
8 * If you implement an RPC service that has its own stats routine which
9 * appends the generic RPC stats, make sure you don't exceed the PAGE_SIZE
12 * Copyright (C) 1995, 1996, 1997 Olaf Kirch <okir@monad.swb.de>
15 #define __NO_VERSION__
16 #include <linux/module.h>
18 #include <linux/init.h>
19 #include <linux/kernel.h>
20 #include <linux/sched.h>
21 #include <linux/proc_fs.h>
22 #include <linux/sunrpc/clnt.h>
23 #include <linux/sunrpc/svcsock.h>
24 #include <linux/init.h>
26 #define RPCDBG_FACILITY RPCDBG_MISC
28 static struct proc_dir_entry *proc_net_rpc = NULL;
31 * Get RPC client stats
34 rpc_proc_read(char *buffer, char **start, off_t offset, int count,
37 struct rpc_stat *statp = (struct rpc_stat *) data;
38 struct rpc_program *prog = statp->program;
39 struct rpc_version *vers;
48 len += sprintf(buffer + len,
52 statp->rpcauthrefresh);
54 for (i = 0; i < prog->nrvers; i++) {
55 if (!(vers = prog->version[i]))
57 len += sprintf(buffer + len, "proc%d %d",
58 vers->number, vers->nrprocs);
59 for (j = 0; j < vers->nrprocs; j++)
60 len += sprintf(buffer + len, " %d",
61 vers->procs[j].p_count);
70 *start = buffer + offset;
71 if ((len -= offset) > count)
78 * Get RPC server stats
81 svc_proc_read(char *buffer, char **start, off_t offset, int count,
84 struct svc_stat *statp = (struct svc_stat *) data;
85 struct svc_program *prog = statp->program;
86 struct svc_procedure *proc;
87 struct svc_version *vers;
96 len += sprintf(buffer + len,
97 "rpc %d %d %d %d %d\n",
99 statp->rpcbadfmt+statp->rpcbadauth+statp->rpcbadclnt,
104 for (i = 0; i < prog->pg_nvers; i++) {
105 if (!(vers = prog->pg_vers[i]) || !(proc = vers->vs_proc))
107 len += sprintf(buffer + len, "proc%d %d", i, vers->vs_nproc);
108 for (j = 0; j < vers->vs_nproc; j++, proc++)
109 len += sprintf(buffer + len, " %d", proc->pc_count);
110 buffer[len++] = '\n';
118 *start = buffer + offset;
119 if ((len -= offset) > count)
126 * Register/unregister RPC proc files
128 static inline struct proc_dir_entry *
129 do_register(const char *name, void *data, int issvc)
132 dprintk("RPC: registering /proc/net/rpc/%s\n", name);
133 return create_proc_read_entry(name, 0, proc_net_rpc,
134 issvc? svc_proc_read : rpc_proc_read,
138 struct proc_dir_entry *
139 rpc_proc_register(struct rpc_stat *statp)
141 return do_register(statp->program->name, statp, 0);
145 rpc_proc_unregister(const char *name)
147 remove_proc_entry(name, proc_net_rpc);
150 struct proc_dir_entry *
151 svc_proc_register(struct svc_stat *statp)
153 return do_register(statp->program->pg_name, statp, 1);
157 svc_proc_unregister(const char *name)
159 remove_proc_entry(name, proc_net_rpc);
165 dprintk("RPC: registering /proc/net/rpc\n");
167 struct proc_dir_entry *ent;
168 ent = proc_mkdir("net/rpc", 0);
170 ent->owner = THIS_MODULE;
179 dprintk("RPC: unregistering /proc/net/rpc\n");
182 remove_proc_entry("net/rpc", 0);
191 rpc_register_sysctl();
201 rpc_unregister_sysctl();
205 MODULE_LICENSE("GPL");
206 module_init(init_sunrpc);
207 module_exit(cleanup_sunrpc);