inotify: fix race
[linux-2.6.22.y-op.git] / net / rxrpc / ar-proc.c
blob1c0be0e77b162949fa74ebd32587773276cdf818
1 /* /proc/net/ support for AF_RXRPC
3 * Copyright (C) 2007 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/module.h>
13 #include <net/sock.h>
14 #include <net/af_rxrpc.h>
15 #include "ar-internal.h"
17 static const char *rxrpc_conn_states[] = {
18 [RXRPC_CONN_UNUSED] = "Unused ",
19 [RXRPC_CONN_CLIENT] = "Client ",
20 [RXRPC_CONN_SERVER_UNSECURED] = "SvUnsec ",
21 [RXRPC_CONN_SERVER_CHALLENGING] = "SvChall ",
22 [RXRPC_CONN_SERVER] = "SvSecure",
23 [RXRPC_CONN_REMOTELY_ABORTED] = "RmtAbort",
24 [RXRPC_CONN_LOCALLY_ABORTED] = "LocAbort",
25 [RXRPC_CONN_NETWORK_ERROR] = "NetError",
29 * generate a list of extant and dead calls in /proc/net/rxrpc_calls
31 static void *rxrpc_call_seq_start(struct seq_file *seq, loff_t *_pos)
33 struct list_head *_p;
34 loff_t pos = *_pos;
36 read_lock(&rxrpc_call_lock);
37 if (!pos)
38 return SEQ_START_TOKEN;
39 pos--;
41 list_for_each(_p, &rxrpc_calls)
42 if (!pos--)
43 break;
45 return _p != &rxrpc_calls ? _p : NULL;
48 static void *rxrpc_call_seq_next(struct seq_file *seq, void *v, loff_t *pos)
50 struct list_head *_p;
52 (*pos)++;
54 _p = v;
55 _p = (v == SEQ_START_TOKEN) ? rxrpc_calls.next : _p->next;
57 return _p != &rxrpc_calls ? _p : NULL;
60 static void rxrpc_call_seq_stop(struct seq_file *seq, void *v)
62 read_unlock(&rxrpc_call_lock);
65 static int rxrpc_call_seq_show(struct seq_file *seq, void *v)
67 struct rxrpc_transport *trans;
68 struct rxrpc_call *call;
69 char lbuff[4 + 4 + 4 + 4 + 5 + 1], rbuff[4 + 4 + 4 + 4 + 5 + 1];
71 if (v == SEQ_START_TOKEN) {
72 seq_puts(seq,
73 "Proto Local Remote "
74 " SvID ConnID CallID End Use State Abort "
75 " UserID\n");
76 return 0;
79 call = list_entry(v, struct rxrpc_call, link);
80 trans = call->conn->trans;
82 sprintf(lbuff, NIPQUAD_FMT":%u",
83 NIPQUAD(trans->local->srx.transport.sin.sin_addr),
84 ntohs(trans->local->srx.transport.sin.sin_port));
86 sprintf(rbuff, NIPQUAD_FMT":%u",
87 NIPQUAD(trans->peer->srx.transport.sin.sin_addr),
88 ntohs(trans->peer->srx.transport.sin.sin_port));
90 seq_printf(seq,
91 "UDP %-22.22s %-22.22s %4x %08x %08x %s %3u"
92 " %-8.8s %08x %lx\n",
93 lbuff,
94 rbuff,
95 ntohs(call->conn->service_id),
96 ntohl(call->conn->cid),
97 ntohl(call->call_id),
98 call->conn->in_clientflag ? "Svc" : "Clt",
99 atomic_read(&call->usage),
100 rxrpc_call_states[call->state],
101 call->abort_code,
102 call->user_call_ID);
104 return 0;
107 static struct seq_operations rxrpc_call_seq_ops = {
108 .start = rxrpc_call_seq_start,
109 .next = rxrpc_call_seq_next,
110 .stop = rxrpc_call_seq_stop,
111 .show = rxrpc_call_seq_show,
114 static int rxrpc_call_seq_open(struct inode *inode, struct file *file)
116 return seq_open(file, &rxrpc_call_seq_ops);
119 struct file_operations rxrpc_call_seq_fops = {
120 .owner = THIS_MODULE,
121 .open = rxrpc_call_seq_open,
122 .read = seq_read,
123 .llseek = seq_lseek,
124 .release = seq_release_private,
128 * generate a list of extant virtual connections in /proc/net/rxrpc_conns
130 static void *rxrpc_connection_seq_start(struct seq_file *seq, loff_t *_pos)
132 struct list_head *_p;
133 loff_t pos = *_pos;
135 read_lock(&rxrpc_connection_lock);
136 if (!pos)
137 return SEQ_START_TOKEN;
138 pos--;
140 list_for_each(_p, &rxrpc_connections)
141 if (!pos--)
142 break;
144 return _p != &rxrpc_connections ? _p : NULL;
147 static void *rxrpc_connection_seq_next(struct seq_file *seq, void *v,
148 loff_t *pos)
150 struct list_head *_p;
152 (*pos)++;
154 _p = v;
155 _p = (v == SEQ_START_TOKEN) ? rxrpc_connections.next : _p->next;
157 return _p != &rxrpc_connections ? _p : NULL;
160 static void rxrpc_connection_seq_stop(struct seq_file *seq, void *v)
162 read_unlock(&rxrpc_connection_lock);
165 static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
167 struct rxrpc_connection *conn;
168 struct rxrpc_transport *trans;
169 char lbuff[4 + 4 + 4 + 4 + 5 + 1], rbuff[4 + 4 + 4 + 4 + 5 + 1];
171 if (v == SEQ_START_TOKEN) {
172 seq_puts(seq,
173 "Proto Local Remote "
174 " SvID ConnID Calls End Use State Key "
175 " Serial ISerial\n"
177 return 0;
180 conn = list_entry(v, struct rxrpc_connection, link);
181 trans = conn->trans;
183 sprintf(lbuff, NIPQUAD_FMT":%u",
184 NIPQUAD(trans->local->srx.transport.sin.sin_addr),
185 ntohs(trans->local->srx.transport.sin.sin_port));
187 sprintf(rbuff, NIPQUAD_FMT":%u",
188 NIPQUAD(trans->peer->srx.transport.sin.sin_addr),
189 ntohs(trans->peer->srx.transport.sin.sin_port));
191 seq_printf(seq,
192 "UDP %-22.22s %-22.22s %4x %08x %08x %s %3u"
193 " %s %08x %08x %08x\n",
194 lbuff,
195 rbuff,
196 ntohs(conn->service_id),
197 ntohl(conn->cid),
198 conn->call_counter,
199 conn->in_clientflag ? "Svc" : "Clt",
200 atomic_read(&conn->usage),
201 rxrpc_conn_states[conn->state],
202 key_serial(conn->key),
203 atomic_read(&conn->serial),
204 atomic_read(&conn->hi_serial));
206 return 0;
209 static struct seq_operations rxrpc_connection_seq_ops = {
210 .start = rxrpc_connection_seq_start,
211 .next = rxrpc_connection_seq_next,
212 .stop = rxrpc_connection_seq_stop,
213 .show = rxrpc_connection_seq_show,
217 static int rxrpc_connection_seq_open(struct inode *inode, struct file *file)
219 return seq_open(file, &rxrpc_connection_seq_ops);
222 struct file_operations rxrpc_connection_seq_fops = {
223 .owner = THIS_MODULE,
224 .open = rxrpc_connection_seq_open,
225 .read = seq_read,
226 .llseek = seq_lseek,
227 .release = seq_release_private,