Linux-2.6.12-rc2
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / rxrpc / proc.c
blob3b5ecd8e2401f85c9d2f14a64ec33d3ef38db14e
1 /* proc.c: /proc interface for RxRPC
3 * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #include <linux/sched.h>
13 #include <linux/slab.h>
14 #include <linux/module.h>
15 #include <linux/proc_fs.h>
16 #include <linux/seq_file.h>
17 #include <rxrpc/rxrpc.h>
18 #include <rxrpc/transport.h>
19 #include <rxrpc/peer.h>
20 #include <rxrpc/connection.h>
21 #include <rxrpc/call.h>
22 #include <rxrpc/message.h>
23 #include "internal.h"
25 static struct proc_dir_entry *proc_rxrpc;
27 static int rxrpc_proc_transports_open(struct inode *inode, struct file *file);
28 static void *rxrpc_proc_transports_start(struct seq_file *p, loff_t *pos);
29 static void *rxrpc_proc_transports_next(struct seq_file *p, void *v, loff_t *pos);
30 static void rxrpc_proc_transports_stop(struct seq_file *p, void *v);
31 static int rxrpc_proc_transports_show(struct seq_file *m, void *v);
33 static struct seq_operations rxrpc_proc_transports_ops = {
34 .start = rxrpc_proc_transports_start,
35 .next = rxrpc_proc_transports_next,
36 .stop = rxrpc_proc_transports_stop,
37 .show = rxrpc_proc_transports_show,
40 static struct file_operations rxrpc_proc_transports_fops = {
41 .open = rxrpc_proc_transports_open,
42 .read = seq_read,
43 .llseek = seq_lseek,
44 .release = seq_release,
47 static int rxrpc_proc_peers_open(struct inode *inode, struct file *file);
48 static void *rxrpc_proc_peers_start(struct seq_file *p, loff_t *pos);
49 static void *rxrpc_proc_peers_next(struct seq_file *p, void *v, loff_t *pos);
50 static void rxrpc_proc_peers_stop(struct seq_file *p, void *v);
51 static int rxrpc_proc_peers_show(struct seq_file *m, void *v);
53 static struct seq_operations rxrpc_proc_peers_ops = {
54 .start = rxrpc_proc_peers_start,
55 .next = rxrpc_proc_peers_next,
56 .stop = rxrpc_proc_peers_stop,
57 .show = rxrpc_proc_peers_show,
60 static struct file_operations rxrpc_proc_peers_fops = {
61 .open = rxrpc_proc_peers_open,
62 .read = seq_read,
63 .llseek = seq_lseek,
64 .release = seq_release,
67 static int rxrpc_proc_conns_open(struct inode *inode, struct file *file);
68 static void *rxrpc_proc_conns_start(struct seq_file *p, loff_t *pos);
69 static void *rxrpc_proc_conns_next(struct seq_file *p, void *v, loff_t *pos);
70 static void rxrpc_proc_conns_stop(struct seq_file *p, void *v);
71 static int rxrpc_proc_conns_show(struct seq_file *m, void *v);
73 static struct seq_operations rxrpc_proc_conns_ops = {
74 .start = rxrpc_proc_conns_start,
75 .next = rxrpc_proc_conns_next,
76 .stop = rxrpc_proc_conns_stop,
77 .show = rxrpc_proc_conns_show,
80 static struct file_operations rxrpc_proc_conns_fops = {
81 .open = rxrpc_proc_conns_open,
82 .read = seq_read,
83 .llseek = seq_lseek,
84 .release = seq_release,
87 static int rxrpc_proc_calls_open(struct inode *inode, struct file *file);
88 static void *rxrpc_proc_calls_start(struct seq_file *p, loff_t *pos);
89 static void *rxrpc_proc_calls_next(struct seq_file *p, void *v, loff_t *pos);
90 static void rxrpc_proc_calls_stop(struct seq_file *p, void *v);
91 static int rxrpc_proc_calls_show(struct seq_file *m, void *v);
93 static struct seq_operations rxrpc_proc_calls_ops = {
94 .start = rxrpc_proc_calls_start,
95 .next = rxrpc_proc_calls_next,
96 .stop = rxrpc_proc_calls_stop,
97 .show = rxrpc_proc_calls_show,
100 static struct file_operations rxrpc_proc_calls_fops = {
101 .open = rxrpc_proc_calls_open,
102 .read = seq_read,
103 .llseek = seq_lseek,
104 .release = seq_release,
107 static const char *rxrpc_call_states7[] = {
108 "complet",
109 "error ",
110 "rcv_op ",
111 "rcv_arg",
112 "got_arg",
113 "snd_rpl",
114 "fin_ack",
115 "snd_arg",
116 "rcv_rpl",
117 "got_rpl"
120 static const char *rxrpc_call_error_states7[] = {
121 "no_err ",
122 "loc_abt",
123 "rmt_abt",
124 "loc_err",
125 "rmt_err"
128 /*****************************************************************************/
130 * initialise the /proc/net/rxrpc/ directory
132 int rxrpc_proc_init(void)
134 struct proc_dir_entry *p;
136 proc_rxrpc = proc_mkdir("rxrpc", proc_net);
137 if (!proc_rxrpc)
138 goto error;
139 proc_rxrpc->owner = THIS_MODULE;
141 p = create_proc_entry("calls", 0, proc_rxrpc);
142 if (!p)
143 goto error_proc;
144 p->proc_fops = &rxrpc_proc_calls_fops;
145 p->owner = THIS_MODULE;
147 p = create_proc_entry("connections", 0, proc_rxrpc);
148 if (!p)
149 goto error_calls;
150 p->proc_fops = &rxrpc_proc_conns_fops;
151 p->owner = THIS_MODULE;
153 p = create_proc_entry("peers", 0, proc_rxrpc);
154 if (!p)
155 goto error_calls;
156 p->proc_fops = &rxrpc_proc_peers_fops;
157 p->owner = THIS_MODULE;
159 p = create_proc_entry("transports", 0, proc_rxrpc);
160 if (!p)
161 goto error_conns;
162 p->proc_fops = &rxrpc_proc_transports_fops;
163 p->owner = THIS_MODULE;
165 return 0;
167 error_conns:
168 remove_proc_entry("connections", proc_rxrpc);
169 error_calls:
170 remove_proc_entry("calls", proc_rxrpc);
171 error_proc:
172 remove_proc_entry("rxrpc", proc_net);
173 error:
174 return -ENOMEM;
175 } /* end rxrpc_proc_init() */
177 /*****************************************************************************/
179 * clean up the /proc/net/rxrpc/ directory
181 void rxrpc_proc_cleanup(void)
183 remove_proc_entry("transports", proc_rxrpc);
184 remove_proc_entry("peers", proc_rxrpc);
185 remove_proc_entry("connections", proc_rxrpc);
186 remove_proc_entry("calls", proc_rxrpc);
188 remove_proc_entry("rxrpc", proc_net);
190 } /* end rxrpc_proc_cleanup() */
192 /*****************************************************************************/
194 * open "/proc/net/rxrpc/transports" which provides a summary of extant transports
196 static int rxrpc_proc_transports_open(struct inode *inode, struct file *file)
198 struct seq_file *m;
199 int ret;
201 ret = seq_open(file, &rxrpc_proc_transports_ops);
202 if (ret < 0)
203 return ret;
205 m = file->private_data;
206 m->private = PDE(inode)->data;
208 return 0;
209 } /* end rxrpc_proc_transports_open() */
211 /*****************************************************************************/
213 * set up the iterator to start reading from the transports list and return the first item
215 static void *rxrpc_proc_transports_start(struct seq_file *m, loff_t *_pos)
217 struct list_head *_p;
218 loff_t pos = *_pos;
220 /* lock the list against modification */
221 down_read(&rxrpc_proc_transports_sem);
223 /* allow for the header line */
224 if (!pos)
225 return SEQ_START_TOKEN;
226 pos--;
228 /* find the n'th element in the list */
229 list_for_each(_p, &rxrpc_proc_transports)
230 if (!pos--)
231 break;
233 return _p != &rxrpc_proc_transports ? _p : NULL;
234 } /* end rxrpc_proc_transports_start() */
236 /*****************************************************************************/
238 * move to next call in transports list
240 static void *rxrpc_proc_transports_next(struct seq_file *p, void *v, loff_t *pos)
242 struct list_head *_p;
244 (*pos)++;
246 _p = v;
247 _p = (v == SEQ_START_TOKEN) ? rxrpc_proc_transports.next : _p->next;
249 return _p != &rxrpc_proc_transports ? _p : NULL;
250 } /* end rxrpc_proc_transports_next() */
252 /*****************************************************************************/
254 * clean up after reading from the transports list
256 static void rxrpc_proc_transports_stop(struct seq_file *p, void *v)
258 up_read(&rxrpc_proc_transports_sem);
260 } /* end rxrpc_proc_transports_stop() */
262 /*****************************************************************************/
264 * display a header line followed by a load of call lines
266 static int rxrpc_proc_transports_show(struct seq_file *m, void *v)
268 struct rxrpc_transport *trans =
269 list_entry(v, struct rxrpc_transport, proc_link);
271 /* display header on line 1 */
272 if (v == SEQ_START_TOKEN) {
273 seq_puts(m, "LOCAL USE\n");
274 return 0;
277 /* display one transport per line on subsequent lines */
278 seq_printf(m, "%5hu %3d\n",
279 trans->port,
280 atomic_read(&trans->usage)
283 return 0;
284 } /* end rxrpc_proc_transports_show() */
286 /*****************************************************************************/
288 * open "/proc/net/rxrpc/peers" which provides a summary of extant peers
290 static int rxrpc_proc_peers_open(struct inode *inode, struct file *file)
292 struct seq_file *m;
293 int ret;
295 ret = seq_open(file, &rxrpc_proc_peers_ops);
296 if (ret < 0)
297 return ret;
299 m = file->private_data;
300 m->private = PDE(inode)->data;
302 return 0;
303 } /* end rxrpc_proc_peers_open() */
305 /*****************************************************************************/
307 * set up the iterator to start reading from the peers list and return the
308 * first item
310 static void *rxrpc_proc_peers_start(struct seq_file *m, loff_t *_pos)
312 struct list_head *_p;
313 loff_t pos = *_pos;
315 /* lock the list against modification */
316 down_read(&rxrpc_peers_sem);
318 /* allow for the header line */
319 if (!pos)
320 return SEQ_START_TOKEN;
321 pos--;
323 /* find the n'th element in the list */
324 list_for_each(_p, &rxrpc_peers)
325 if (!pos--)
326 break;
328 return _p != &rxrpc_peers ? _p : NULL;
329 } /* end rxrpc_proc_peers_start() */
331 /*****************************************************************************/
333 * move to next conn in peers list
335 static void *rxrpc_proc_peers_next(struct seq_file *p, void *v, loff_t *pos)
337 struct list_head *_p;
339 (*pos)++;
341 _p = v;
342 _p = (v == SEQ_START_TOKEN) ? rxrpc_peers.next : _p->next;
344 return _p != &rxrpc_peers ? _p : NULL;
345 } /* end rxrpc_proc_peers_next() */
347 /*****************************************************************************/
349 * clean up after reading from the peers list
351 static void rxrpc_proc_peers_stop(struct seq_file *p, void *v)
353 up_read(&rxrpc_peers_sem);
355 } /* end rxrpc_proc_peers_stop() */
357 /*****************************************************************************/
359 * display a header line followed by a load of conn lines
361 static int rxrpc_proc_peers_show(struct seq_file *m, void *v)
363 struct rxrpc_peer *peer = list_entry(v, struct rxrpc_peer, proc_link);
364 signed long timeout;
366 /* display header on line 1 */
367 if (v == SEQ_START_TOKEN) {
368 seq_puts(m, "LOCAL REMOTE USAGE CONNS TIMEOUT"
369 " MTU RTT(uS)\n");
370 return 0;
373 /* display one peer per line on subsequent lines */
374 timeout = 0;
375 if (!list_empty(&peer->timeout.link))
376 timeout = (signed long) peer->timeout.timo_jif -
377 (signed long) jiffies;
379 seq_printf(m, "%5hu %08x %5d %5d %8ld %5Zu %7lu\n",
380 peer->trans->port,
381 ntohl(peer->addr.s_addr),
382 atomic_read(&peer->usage),
383 atomic_read(&peer->conn_count),
384 timeout,
385 peer->if_mtu,
386 (long) peer->rtt
389 return 0;
390 } /* end rxrpc_proc_peers_show() */
392 /*****************************************************************************/
394 * open "/proc/net/rxrpc/connections" which provides a summary of extant
395 * connections
397 static int rxrpc_proc_conns_open(struct inode *inode, struct file *file)
399 struct seq_file *m;
400 int ret;
402 ret = seq_open(file, &rxrpc_proc_conns_ops);
403 if (ret < 0)
404 return ret;
406 m = file->private_data;
407 m->private = PDE(inode)->data;
409 return 0;
410 } /* end rxrpc_proc_conns_open() */
412 /*****************************************************************************/
414 * set up the iterator to start reading from the conns list and return the
415 * first item
417 static void *rxrpc_proc_conns_start(struct seq_file *m, loff_t *_pos)
419 struct list_head *_p;
420 loff_t pos = *_pos;
422 /* lock the list against modification */
423 down_read(&rxrpc_conns_sem);
425 /* allow for the header line */
426 if (!pos)
427 return SEQ_START_TOKEN;
428 pos--;
430 /* find the n'th element in the list */
431 list_for_each(_p, &rxrpc_conns)
432 if (!pos--)
433 break;
435 return _p != &rxrpc_conns ? _p : NULL;
436 } /* end rxrpc_proc_conns_start() */
438 /*****************************************************************************/
440 * move to next conn in conns list
442 static void *rxrpc_proc_conns_next(struct seq_file *p, void *v, loff_t *pos)
444 struct list_head *_p;
446 (*pos)++;
448 _p = v;
449 _p = (v == SEQ_START_TOKEN) ? rxrpc_conns.next : _p->next;
451 return _p != &rxrpc_conns ? _p : NULL;
452 } /* end rxrpc_proc_conns_next() */
454 /*****************************************************************************/
456 * clean up after reading from the conns list
458 static void rxrpc_proc_conns_stop(struct seq_file *p, void *v)
460 up_read(&rxrpc_conns_sem);
462 } /* end rxrpc_proc_conns_stop() */
464 /*****************************************************************************/
466 * display a header line followed by a load of conn lines
468 static int rxrpc_proc_conns_show(struct seq_file *m, void *v)
470 struct rxrpc_connection *conn;
471 signed long timeout;
473 conn = list_entry(v, struct rxrpc_connection, proc_link);
475 /* display header on line 1 */
476 if (v == SEQ_START_TOKEN) {
477 seq_puts(m,
478 "LOCAL REMOTE RPORT SRVC CONN END SERIALNO "
479 "CALLNO MTU TIMEOUT"
480 "\n");
481 return 0;
484 /* display one conn per line on subsequent lines */
485 timeout = 0;
486 if (!list_empty(&conn->timeout.link))
487 timeout = (signed long) conn->timeout.timo_jif -
488 (signed long) jiffies;
490 seq_printf(m,
491 "%5hu %08x %5hu %04hx %08x %-3.3s %08x %08x %5Zu %8ld\n",
492 conn->trans->port,
493 ntohl(conn->addr.sin_addr.s_addr),
494 ntohs(conn->addr.sin_port),
495 ntohs(conn->service_id),
496 ntohl(conn->conn_id),
497 conn->out_clientflag ? "CLT" : "SRV",
498 conn->serial_counter,
499 conn->call_counter,
500 conn->mtu_size,
501 timeout
504 return 0;
505 } /* end rxrpc_proc_conns_show() */
507 /*****************************************************************************/
509 * open "/proc/net/rxrpc/calls" which provides a summary of extant calls
511 static int rxrpc_proc_calls_open(struct inode *inode, struct file *file)
513 struct seq_file *m;
514 int ret;
516 ret = seq_open(file, &rxrpc_proc_calls_ops);
517 if (ret < 0)
518 return ret;
520 m = file->private_data;
521 m->private = PDE(inode)->data;
523 return 0;
524 } /* end rxrpc_proc_calls_open() */
526 /*****************************************************************************/
528 * set up the iterator to start reading from the calls list and return the
529 * first item
531 static void *rxrpc_proc_calls_start(struct seq_file *m, loff_t *_pos)
533 struct list_head *_p;
534 loff_t pos = *_pos;
536 /* lock the list against modification */
537 down_read(&rxrpc_calls_sem);
539 /* allow for the header line */
540 if (!pos)
541 return SEQ_START_TOKEN;
542 pos--;
544 /* find the n'th element in the list */
545 list_for_each(_p, &rxrpc_calls)
546 if (!pos--)
547 break;
549 return _p != &rxrpc_calls ? _p : NULL;
550 } /* end rxrpc_proc_calls_start() */
552 /*****************************************************************************/
554 * move to next call in calls list
556 static void *rxrpc_proc_calls_next(struct seq_file *p, void *v, loff_t *pos)
558 struct list_head *_p;
560 (*pos)++;
562 _p = v;
563 _p = (v == SEQ_START_TOKEN) ? rxrpc_calls.next : _p->next;
565 return _p != &rxrpc_calls ? _p : NULL;
566 } /* end rxrpc_proc_calls_next() */
568 /*****************************************************************************/
570 * clean up after reading from the calls list
572 static void rxrpc_proc_calls_stop(struct seq_file *p, void *v)
574 up_read(&rxrpc_calls_sem);
576 } /* end rxrpc_proc_calls_stop() */
578 /*****************************************************************************/
580 * display a header line followed by a load of call lines
582 static int rxrpc_proc_calls_show(struct seq_file *m, void *v)
584 struct rxrpc_call *call = list_entry(v, struct rxrpc_call, call_link);
586 /* display header on line 1 */
587 if (v == SEQ_START_TOKEN) {
588 seq_puts(m,
589 "LOCAL REMOT SRVC CONN CALL DIR USE "
590 " L STATE OPCODE ABORT ERRNO\n"
592 return 0;
595 /* display one call per line on subsequent lines */
596 seq_printf(m,
597 "%5hu %5hu %04hx %08x %08x %s %3u%c"
598 " %c %-7.7s %6d %08x %5d\n",
599 call->conn->trans->port,
600 ntohs(call->conn->addr.sin_port),
601 ntohs(call->conn->service_id),
602 ntohl(call->conn->conn_id),
603 ntohl(call->call_id),
604 call->conn->service ? "SVC" : "CLT",
605 atomic_read(&call->usage),
606 waitqueue_active(&call->waitq) ? 'w' : ' ',
607 call->app_last_rcv ? 'Y' : '-',
608 (call->app_call_state!=RXRPC_CSTATE_ERROR ?
609 rxrpc_call_states7[call->app_call_state] :
610 rxrpc_call_error_states7[call->app_err_state]),
611 call->app_opcode,
612 call->app_abort_code,
613 call->app_errno
616 return 0;
617 } /* end rxrpc_proc_calls_show() */