clean
[linux-2.4.21-pre4.git] / net / sunrpc / stats.c
1 /*
2  * linux/net/sunrpc/stats.c
3  *
4  * procfs-based user access to generic RPC statistics. The stats files
5  * reside in /proc/net/rpc.
6  *
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
10  * limit.
11  *
12  * Copyright (C) 1995, 1996, 1997 Olaf Kirch <okir@monad.swb.de>
13  */
14
15 #define __NO_VERSION__
16 #include <linux/module.h>
17
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>
25
26 #define RPCDBG_FACILITY RPCDBG_MISC
27
28 static struct proc_dir_entry    *proc_net_rpc = NULL;
29
30 /*
31  * Get RPC client stats
32  */
33 int
34 rpc_proc_read(char *buffer, char **start, off_t offset, int count,
35                                 int *eof, void *data)
36 {
37         struct rpc_stat *statp = (struct rpc_stat *) data;
38         struct rpc_program *prog = statp->program;
39         struct rpc_version *vers;
40         int             len, i, j;
41
42         len = sprintf(buffer,
43                 "net %d %d %d %d\n",
44                         statp->netcnt,
45                         statp->netudpcnt,
46                         statp->nettcpcnt,
47                         statp->nettcpconn);
48         len += sprintf(buffer + len,
49                 "rpc %d %d %d\n",
50                         statp->rpccnt,
51                         statp->rpcretrans,
52                         statp->rpcauthrefresh);
53
54         for (i = 0; i < prog->nrvers; i++) {
55                 if (!(vers = prog->version[i]))
56                         continue;
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);
62                 buffer[len++] = '\n';
63         }
64
65         if (offset >= len) {
66                 *start = buffer;
67                 *eof = 1;
68                 return 0;
69         }
70         *start = buffer + offset;
71         if ((len -= offset) > count)
72                 return count;
73         *eof = 1;
74         return len;
75 }
76
77 /*
78  * Get RPC server stats
79  */
80 int
81 svc_proc_read(char *buffer, char **start, off_t offset, int count,
82                                 int *eof, void *data)
83 {
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;
88         int             len, i, j;
89
90         len = sprintf(buffer,
91                 "net %d %d %d %d\n",
92                         statp->netcnt,
93                         statp->netudpcnt,
94                         statp->nettcpcnt,
95                         statp->nettcpconn);
96         len += sprintf(buffer + len,
97                 "rpc %d %d %d %d %d\n",
98                         statp->rpccnt,
99                         statp->rpcbadfmt+statp->rpcbadauth+statp->rpcbadclnt,
100                         statp->rpcbadfmt,
101                         statp->rpcbadauth,
102                         statp->rpcbadclnt);
103
104         for (i = 0; i < prog->pg_nvers; i++) {
105                 if (!(vers = prog->pg_vers[i]) || !(proc = vers->vs_proc))
106                         continue;
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';
111         }
112
113         if (offset >= len) {
114                 *start = buffer;
115                 *eof = 1;
116                 return 0;
117         }
118         *start = buffer + offset;
119         if ((len -= offset) > count)
120                 return count;
121         *eof = 1;
122         return len;
123 }
124
125 /*
126  * Register/unregister RPC proc files
127  */
128 static inline struct proc_dir_entry *
129 do_register(const char *name, void *data, int issvc)
130 {
131         rpc_proc_init();
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,
135                                       data);
136 }
137
138 struct proc_dir_entry *
139 rpc_proc_register(struct rpc_stat *statp)
140 {
141         return do_register(statp->program->name, statp, 0);
142 }
143
144 void
145 rpc_proc_unregister(const char *name)
146 {
147         remove_proc_entry(name, proc_net_rpc);
148 }
149
150 struct proc_dir_entry *
151 svc_proc_register(struct svc_stat *statp)
152 {
153         return do_register(statp->program->pg_name, statp, 1);
154 }
155
156 void
157 svc_proc_unregister(const char *name)
158 {
159         remove_proc_entry(name, proc_net_rpc);
160 }
161
162 void
163 rpc_proc_init(void)
164 {
165         dprintk("RPC: registering /proc/net/rpc\n");
166         if (!proc_net_rpc) {
167                 struct proc_dir_entry *ent;
168                 ent = proc_mkdir("net/rpc", 0);
169                 if (ent) {
170                         ent->owner = THIS_MODULE;
171                         proc_net_rpc = ent;
172                 }
173         }
174 }
175
176 void
177 rpc_proc_exit(void)
178 {
179         dprintk("RPC: unregistering /proc/net/rpc\n");
180         if (proc_net_rpc) {
181                 proc_net_rpc = NULL;
182                 remove_proc_entry("net/rpc", 0);
183         }
184 }
185
186
187 static int __init
188 init_sunrpc(void)
189 {
190 #ifdef RPC_DEBUG
191         rpc_register_sysctl();
192 #endif
193         rpc_proc_init();
194         return 0;
195 }
196
197 static void __exit
198 cleanup_sunrpc(void)
199 {
200 #ifdef RPC_DEBUG
201         rpc_unregister_sysctl();
202 #endif
203         rpc_proc_exit();
204 }
205 MODULE_LICENSE("GPL");
206 module_init(init_sunrpc);
207 module_exit(cleanup_sunrpc);