blob: 9bfe7fb721e6ae0609bb0827caf4f4aa7eb2e51c [file] [log] [blame]
Patrick Caulfieldfdda3872006-11-02 11:19:21 -05001/******************************************************************************
2*******************************************************************************
3**
4** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
Patrick Caulfielda34fbc62007-02-01 16:46:33 +00005** Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
Patrick Caulfieldfdda3872006-11-02 11:19:21 -05006**
7** This copyrighted material is made available to anyone wishing to use,
8** modify, copy, or redistribute it subject to the terms and conditions
9** of the GNU General Public License v.2.
10**
11*******************************************************************************
12******************************************************************************/
13
14/*
15 * lowcomms.c
16 *
17 * This is the "low-level" comms layer.
18 *
19 * It is responsible for sending/receiving messages
20 * from other nodes in the cluster.
21 *
22 * Cluster nodes are referred to by their nodeids. nodeids are
23 * simply 32 bit numbers to the locking module - if they need to
24 * be expanded for the cluster infrastructure then that is it's
25 * responsibility. It is this layer's
26 * responsibility to resolve these into IP address or
27 * whatever it needs for inter-node communication.
28 *
29 * The comms level is two kernel threads that deal mainly with
30 * the receiving of messages from other nodes and passing them
31 * up to the mid-level comms layer (which understands the
32 * message format) for execution by the locking core, and
33 * a send thread which does all the setting up of connections
34 * to remote nodes and the sending of data. Threads are not allowed
35 * to send their own data because it may cause them to wait in times
36 * of high load. Also, this way, the sending thread can collect together
37 * messages bound for one node and send them in one block.
38 *
39 * I don't see any problem with the recv thread executing the locking
40 * code on behalf of remote processes as the locking code is
41 * short, efficient and never waits.
42 *
43 */
44
45
46#include <asm/ioctls.h>
47#include <net/sock.h>
48#include <net/tcp.h>
49#include <linux/pagemap.h>
50
51#include "dlm_internal.h"
52#include "lowcomms.h"
53#include "midcomms.h"
54#include "config.h"
55
56struct cbuf {
Patrick Caulfieldac33d072006-12-06 15:10:37 +000057 unsigned int base;
58 unsigned int len;
59 unsigned int mask;
Patrick Caulfieldfdda3872006-11-02 11:19:21 -050060};
61
Patrick Caulfieldfdda3872006-11-02 11:19:21 -050062#define NODE_INCREMENT 32
Patrick Caulfieldac33d072006-12-06 15:10:37 +000063static void cbuf_add(struct cbuf *cb, int n)
64{
65 cb->len += n;
66}
Patrick Caulfieldfdda3872006-11-02 11:19:21 -050067
Patrick Caulfieldac33d072006-12-06 15:10:37 +000068static int cbuf_data(struct cbuf *cb)
69{
70 return ((cb->base + cb->len) & cb->mask);
71}
72
73static void cbuf_init(struct cbuf *cb, int size)
74{
75 cb->base = cb->len = 0;
76 cb->mask = size-1;
77}
78
79static void cbuf_eat(struct cbuf *cb, int n)
80{
81 cb->len -= n;
82 cb->base += n;
83 cb->base &= cb->mask;
84}
85
86static bool cbuf_empty(struct cbuf *cb)
87{
88 return cb->len == 0;
89}
Patrick Caulfieldfdda3872006-11-02 11:19:21 -050090
91/* Maximum number of incoming messages to process before
Patrick Caulfieldac33d072006-12-06 15:10:37 +000092 doing a cond_resched()
Patrick Caulfieldfdda3872006-11-02 11:19:21 -050093*/
94#define MAX_RX_MSG_COUNT 25
95
96struct connection {
97 struct socket *sock; /* NULL if not connected */
98 uint32_t nodeid; /* So we know who we are in the list */
Patrick Caulfieldf1f1c1c2007-01-24 11:17:59 +000099 struct mutex sock_mutex;
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500100 unsigned long flags; /* bit 1,2 = We are on the read/write lists */
101#define CF_READ_PENDING 1
102#define CF_WRITE_PENDING 2
103#define CF_CONNECT_PENDING 3
104#define CF_IS_OTHERCON 4
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000105 struct list_head writequeue; /* List of outgoing writequeue_entries */
106 struct list_head listenlist; /* List of allocated listening sockets */
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500107 spinlock_t writequeue_lock;
108 int (*rx_action) (struct connection *); /* What to do when active */
109 struct page *rx_page;
110 struct cbuf cb;
111 int retries;
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500112#define MAX_CONNECT_RETRIES 3
113 struct connection *othercon;
Patrick Caulfield1d6e8132007-01-15 14:33:34 +0000114 struct work_struct rwork; /* Receive workqueue */
115 struct work_struct swork; /* Send workqueue */
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500116};
117#define sock2con(x) ((struct connection *)(x)->sk_user_data)
118
119/* An entry waiting to be sent */
120struct writequeue_entry {
121 struct list_head list;
122 struct page *page;
123 int offset;
124 int len;
125 int end;
126 int users;
127 struct connection *con;
128};
129
130static struct sockaddr_storage dlm_local_addr;
131
Patrick Caulfield1d6e8132007-01-15 14:33:34 +0000132/* Work queues */
133static struct workqueue_struct *recv_workqueue;
134static struct workqueue_struct *send_workqueue;
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500135
136/* An array of pointers to connections, indexed by NODEID */
137static struct connection **connections;
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000138static DECLARE_MUTEX(connections_lock);
Patrick Caulfieldc80e7c82006-12-08 14:31:12 -0500139static struct kmem_cache *con_cache;
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500140static int conn_array_size;
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500141
Patrick Caulfield1d6e8132007-01-15 14:33:34 +0000142static void process_recv_sockets(struct work_struct *work);
143static void process_send_sockets(struct work_struct *work);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500144
145static struct connection *nodeid2con(int nodeid, gfp_t allocation)
146{
147 struct connection *con = NULL;
148
149 down(&connections_lock);
150 if (nodeid >= conn_array_size) {
151 int new_size = nodeid + NODE_INCREMENT;
152 struct connection **new_conns;
153
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000154 new_conns = kzalloc(sizeof(struct connection *) *
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500155 new_size, allocation);
156 if (!new_conns)
157 goto finish;
158
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500159 memcpy(new_conns, connections, sizeof(struct connection *) * conn_array_size);
160 conn_array_size = new_size;
161 kfree(connections);
162 connections = new_conns;
163
164 }
165
166 con = connections[nodeid];
167 if (con == NULL && allocation) {
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000168 con = kmem_cache_zalloc(con_cache, allocation);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500169 if (!con)
170 goto finish;
171
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500172 con->nodeid = nodeid;
Patrick Caulfieldf1f1c1c2007-01-24 11:17:59 +0000173 mutex_init(&con->sock_mutex);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500174 INIT_LIST_HEAD(&con->writequeue);
175 spin_lock_init(&con->writequeue_lock);
Patrick Caulfield1d6e8132007-01-15 14:33:34 +0000176 INIT_WORK(&con->swork, process_send_sockets);
177 INIT_WORK(&con->rwork, process_recv_sockets);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500178
179 connections[nodeid] = con;
180 }
181
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000182finish:
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500183 up(&connections_lock);
184 return con;
185}
186
187/* Data available on socket or listen socket received a connect */
188static void lowcomms_data_ready(struct sock *sk, int count_unused)
189{
190 struct connection *con = sock2con(sk);
191
Patrick Caulfield1d6e8132007-01-15 14:33:34 +0000192 if (!test_and_set_bit(CF_READ_PENDING, &con->flags))
193 queue_work(recv_workqueue, &con->rwork);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500194}
195
196static void lowcomms_write_space(struct sock *sk)
197{
198 struct connection *con = sock2con(sk);
199
Patrick Caulfield1d6e8132007-01-15 14:33:34 +0000200 if (!test_and_set_bit(CF_WRITE_PENDING, &con->flags))
201 queue_work(send_workqueue, &con->swork);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500202}
203
204static inline void lowcomms_connect_sock(struct connection *con)
205{
Patrick Caulfield1d6e8132007-01-15 14:33:34 +0000206 if (!test_and_set_bit(CF_CONNECT_PENDING, &con->flags))
207 queue_work(send_workqueue, &con->swork);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500208}
209
210static void lowcomms_state_change(struct sock *sk)
211{
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000212 if (sk->sk_state == TCP_ESTABLISHED)
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500213 lowcomms_write_space(sk);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500214}
215
216/* Make a socket active */
217static int add_sock(struct socket *sock, struct connection *con)
218{
219 con->sock = sock;
220
221 /* Install a data_ready callback */
222 con->sock->sk->sk_data_ready = lowcomms_data_ready;
223 con->sock->sk->sk_write_space = lowcomms_write_space;
224 con->sock->sk->sk_state_change = lowcomms_state_change;
225
226 return 0;
227}
228
229/* Add the port number to an IP6 or 4 sockaddr and return the address
230 length */
231static void make_sockaddr(struct sockaddr_storage *saddr, uint16_t port,
232 int *addr_len)
233{
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000234 saddr->ss_family = dlm_local_addr.ss_family;
235 if (saddr->ss_family == AF_INET) {
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500236 struct sockaddr_in *in4_addr = (struct sockaddr_in *)saddr;
237 in4_addr->sin_port = cpu_to_be16(port);
238 *addr_len = sizeof(struct sockaddr_in);
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000239 } else {
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500240 struct sockaddr_in6 *in6_addr = (struct sockaddr_in6 *)saddr;
241 in6_addr->sin6_port = cpu_to_be16(port);
242 *addr_len = sizeof(struct sockaddr_in6);
243 }
244}
245
246/* Close a remote connection and tidy up */
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000247static void close_connection(struct connection *con, bool and_other)
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500248{
Patrick Caulfieldf1f1c1c2007-01-24 11:17:59 +0000249 mutex_lock(&con->sock_mutex);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500250
251 if (con->sock) {
252 sock_release(con->sock);
253 con->sock = NULL;
254 }
255 if (con->othercon && and_other) {
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000256 /* Will only re-enter once. */
257 close_connection(con->othercon, false);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500258 }
259 if (con->rx_page) {
260 __free_page(con->rx_page);
261 con->rx_page = NULL;
262 }
263 con->retries = 0;
Patrick Caulfieldf1f1c1c2007-01-24 11:17:59 +0000264 mutex_unlock(&con->sock_mutex);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500265}
266
267/* Data received from remote end */
268static int receive_from_sock(struct connection *con)
269{
270 int ret = 0;
Al Viro58addbf2007-02-09 16:38:45 +0000271 struct msghdr msg = {};
272 struct kvec iov[2];
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500273 unsigned len;
274 int r;
275 int call_again_soon = 0;
Al Viro58addbf2007-02-09 16:38:45 +0000276 int nvec;
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500277
Patrick Caulfieldf1f1c1c2007-01-24 11:17:59 +0000278 mutex_lock(&con->sock_mutex);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500279
Patrick Caulfielda34fbc62007-02-01 16:46:33 +0000280 if (con->sock == NULL) {
281 ret = -EAGAIN;
282 goto out_close;
283 }
284
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500285 if (con->rx_page == NULL) {
286 /*
287 * This doesn't need to be atomic, but I think it should
288 * improve performance if it is.
289 */
290 con->rx_page = alloc_page(GFP_ATOMIC);
291 if (con->rx_page == NULL)
292 goto out_resched;
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000293 cbuf_init(&con->cb, PAGE_CACHE_SIZE);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500294 }
295
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500296 /*
297 * iov[0] is the bit of the circular buffer between the current end
298 * point (cb.base + cb.len) and the end of the buffer.
299 */
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000300 iov[0].iov_len = con->cb.base - cbuf_data(&con->cb);
301 iov[0].iov_base = page_address(con->rx_page) + cbuf_data(&con->cb);
Patrick Caulfield89adc932007-03-13 17:08:45 +0000302 iov[1].iov_len = 0;
Al Viro58addbf2007-02-09 16:38:45 +0000303 nvec = 1;
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500304
305 /*
306 * iov[1] is the bit of the circular buffer between the start of the
307 * buffer and the start of the currently used section (cb.base)
308 */
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000309 if (cbuf_data(&con->cb) >= con->cb.base) {
310 iov[0].iov_len = PAGE_CACHE_SIZE - cbuf_data(&con->cb);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500311 iov[1].iov_len = con->cb.base;
312 iov[1].iov_base = page_address(con->rx_page);
Al Viro58addbf2007-02-09 16:38:45 +0000313 nvec = 2;
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500314 }
315 len = iov[0].iov_len + iov[1].iov_len;
316
Al Viro58addbf2007-02-09 16:38:45 +0000317 r = ret = kernel_recvmsg(con->sock, &msg, iov, nvec, len,
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500318 MSG_DONTWAIT | MSG_NOSIGNAL);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500319
320 if (ret <= 0)
321 goto out_close;
Patrick Caulfieldbd44e2b2007-01-22 14:51:33 +0000322 if (ret == -EAGAIN)
323 goto out_resched;
324
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500325 if (ret == len)
326 call_again_soon = 1;
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000327 cbuf_add(&con->cb, ret);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500328 ret = dlm_process_incoming_buffer(con->nodeid,
329 page_address(con->rx_page),
330 con->cb.base, con->cb.len,
331 PAGE_CACHE_SIZE);
332 if (ret == -EBADMSG) {
333 printk(KERN_INFO "dlm: lowcomms: addr=%p, base=%u, len=%u, "
334 "iov_len=%u, iov_base[0]=%p, read=%d\n",
335 page_address(con->rx_page), con->cb.base, con->cb.len,
336 len, iov[0].iov_base, r);
337 }
338 if (ret < 0)
339 goto out_close;
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000340 cbuf_eat(&con->cb, ret);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500341
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000342 if (cbuf_empty(&con->cb) && !call_again_soon) {
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500343 __free_page(con->rx_page);
344 con->rx_page = NULL;
345 }
346
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500347 if (call_again_soon)
348 goto out_resched;
Patrick Caulfieldf1f1c1c2007-01-24 11:17:59 +0000349 mutex_unlock(&con->sock_mutex);
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000350 return 0;
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500351
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000352out_resched:
Patrick Caulfield1d6e8132007-01-15 14:33:34 +0000353 if (!test_and_set_bit(CF_READ_PENDING, &con->flags))
354 queue_work(recv_workqueue, &con->rwork);
Patrick Caulfieldf1f1c1c2007-01-24 11:17:59 +0000355 mutex_unlock(&con->sock_mutex);
Patrick Caulfieldbd44e2b2007-01-22 14:51:33 +0000356 return -EAGAIN;
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500357
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000358out_close:
Patrick Caulfieldf1f1c1c2007-01-24 11:17:59 +0000359 mutex_unlock(&con->sock_mutex);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500360 if (ret != -EAGAIN && !test_bit(CF_IS_OTHERCON, &con->flags)) {
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000361 close_connection(con, false);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500362 /* Reconnect when there is something to send */
363 }
Patrick Caulfielda34fbc62007-02-01 16:46:33 +0000364 /* Don't return success if we really got EOF */
365 if (ret == 0)
366 ret = -EAGAIN;
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500367
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500368 return ret;
369}
370
371/* Listening socket is busy, accept a connection */
372static int accept_from_sock(struct connection *con)
373{
374 int result;
375 struct sockaddr_storage peeraddr;
376 struct socket *newsock;
377 int len;
378 int nodeid;
379 struct connection *newcon;
Patrick Caulfieldbd44e2b2007-01-22 14:51:33 +0000380 struct connection *addcon;
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500381
382 memset(&peeraddr, 0, sizeof(peeraddr));
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000383 result = sock_create_kern(dlm_local_addr.ss_family, SOCK_STREAM,
384 IPPROTO_TCP, &newsock);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500385 if (result < 0)
386 return -ENOMEM;
387
Patrick Caulfieldf1f1c1c2007-01-24 11:17:59 +0000388 mutex_lock_nested(&con->sock_mutex, 0);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500389
390 result = -ENOTCONN;
391 if (con->sock == NULL)
392 goto accept_err;
393
394 newsock->type = con->sock->type;
395 newsock->ops = con->sock->ops;
396
397 result = con->sock->ops->accept(con->sock, newsock, O_NONBLOCK);
398 if (result < 0)
399 goto accept_err;
400
401 /* Get the connected socket's peer */
402 memset(&peeraddr, 0, sizeof(peeraddr));
403 if (newsock->ops->getname(newsock, (struct sockaddr *)&peeraddr,
404 &len, 2)) {
405 result = -ECONNABORTED;
406 goto accept_err;
407 }
408
409 /* Get the new node's NODEID */
410 make_sockaddr(&peeraddr, 0, &len);
411 if (dlm_addr_to_nodeid(&peeraddr, &nodeid)) {
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000412 printk("dlm: connect from non cluster node\n");
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500413 sock_release(newsock);
Patrick Caulfieldf1f1c1c2007-01-24 11:17:59 +0000414 mutex_unlock(&con->sock_mutex);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500415 return -1;
416 }
417
418 log_print("got connection from %d", nodeid);
419
420 /* Check to see if we already have a connection to this node. This
421 * could happen if the two nodes initiate a connection at roughly
422 * the same time and the connections cross on the wire.
423 * TEMPORARY FIX:
424 * In this case we store the incoming one in "othercon"
425 */
426 newcon = nodeid2con(nodeid, GFP_KERNEL);
427 if (!newcon) {
428 result = -ENOMEM;
429 goto accept_err;
430 }
Patrick Caulfieldf1f1c1c2007-01-24 11:17:59 +0000431 mutex_lock_nested(&newcon->sock_mutex, 1);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500432 if (newcon->sock) {
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000433 struct connection *othercon = newcon->othercon;
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500434
435 if (!othercon) {
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000436 othercon = kmem_cache_zalloc(con_cache, GFP_KERNEL);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500437 if (!othercon) {
438 printk("dlm: failed to allocate incoming socket\n");
Patrick Caulfieldf1f1c1c2007-01-24 11:17:59 +0000439 mutex_unlock(&newcon->sock_mutex);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500440 result = -ENOMEM;
441 goto accept_err;
442 }
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500443 othercon->nodeid = nodeid;
444 othercon->rx_action = receive_from_sock;
Patrick Caulfieldf1f1c1c2007-01-24 11:17:59 +0000445 mutex_init(&othercon->sock_mutex);
Patrick Caulfield1d6e8132007-01-15 14:33:34 +0000446 INIT_WORK(&othercon->swork, process_send_sockets);
447 INIT_WORK(&othercon->rwork, process_recv_sockets);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500448 set_bit(CF_IS_OTHERCON, &othercon->flags);
449 newcon->othercon = othercon;
450 }
451 othercon->sock = newsock;
452 newsock->sk->sk_user_data = othercon;
453 add_sock(newsock, othercon);
Patrick Caulfieldbd44e2b2007-01-22 14:51:33 +0000454 addcon = othercon;
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500455 }
456 else {
457 newsock->sk->sk_user_data = newcon;
458 newcon->rx_action = receive_from_sock;
459 add_sock(newsock, newcon);
Patrick Caulfieldbd44e2b2007-01-22 14:51:33 +0000460 addcon = newcon;
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500461 }
462
Patrick Caulfieldf1f1c1c2007-01-24 11:17:59 +0000463 mutex_unlock(&newcon->sock_mutex);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500464
465 /*
466 * Add it to the active queue in case we got data
467 * beween processing the accept adding the socket
468 * to the read_sockets list
469 */
Patrick Caulfieldbd44e2b2007-01-22 14:51:33 +0000470 if (!test_and_set_bit(CF_READ_PENDING, &addcon->flags))
471 queue_work(recv_workqueue, &addcon->rwork);
Patrick Caulfieldf1f1c1c2007-01-24 11:17:59 +0000472 mutex_unlock(&con->sock_mutex);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500473
474 return 0;
475
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000476accept_err:
Patrick Caulfieldf1f1c1c2007-01-24 11:17:59 +0000477 mutex_unlock(&con->sock_mutex);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500478 sock_release(newsock);
479
480 if (result != -EAGAIN)
481 printk("dlm: error accepting connection from node: %d\n", result);
482 return result;
483}
484
485/* Connect a new socket to its peer */
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000486static void connect_to_sock(struct connection *con)
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500487{
488 int result = -EHOSTUNREACH;
489 struct sockaddr_storage saddr;
490 int addr_len;
491 struct socket *sock;
492
493 if (con->nodeid == 0) {
494 log_print("attempt to connect sock 0 foiled");
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000495 return;
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500496 }
497
Patrick Caulfieldf1f1c1c2007-01-24 11:17:59 +0000498 mutex_lock(&con->sock_mutex);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500499 if (con->retries++ > MAX_CONNECT_RETRIES)
500 goto out;
501
502 /* Some odd races can cause double-connects, ignore them */
503 if (con->sock) {
504 result = 0;
505 goto out;
506 }
507
508 /* Create a socket to communicate with */
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000509 result = sock_create_kern(dlm_local_addr.ss_family, SOCK_STREAM,
510 IPPROTO_TCP, &sock);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500511 if (result < 0)
512 goto out_err;
513
514 memset(&saddr, 0, sizeof(saddr));
515 if (dlm_nodeid_to_addr(con->nodeid, &saddr))
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000516 goto out_err;
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500517
518 sock->sk->sk_user_data = con;
519 con->rx_action = receive_from_sock;
520
David Teigland68c817a2007-01-09 09:41:48 -0600521 make_sockaddr(&saddr, dlm_config.ci_tcp_port, &addr_len);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500522
523 add_sock(sock, con);
524
525 log_print("connecting to %d", con->nodeid);
526 result =
527 sock->ops->connect(sock, (struct sockaddr *)&saddr, addr_len,
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000528 O_NONBLOCK);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500529 if (result == -EINPROGRESS)
530 result = 0;
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000531 if (result == 0)
532 goto out;
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500533
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000534out_err:
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500535 if (con->sock) {
536 sock_release(con->sock);
537 con->sock = NULL;
538 }
539 /*
540 * Some errors are fatal and this list might need adjusting. For other
541 * errors we try again until the max number of retries is reached.
542 */
543 if (result != -EHOSTUNREACH && result != -ENETUNREACH &&
544 result != -ENETDOWN && result != EINVAL
545 && result != -EPROTONOSUPPORT) {
546 lowcomms_connect_sock(con);
547 result = 0;
548 }
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000549out:
Patrick Caulfieldf1f1c1c2007-01-24 11:17:59 +0000550 mutex_unlock(&con->sock_mutex);
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000551 return;
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500552}
553
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000554static struct socket *create_listen_sock(struct connection *con,
555 struct sockaddr_storage *saddr)
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500556{
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000557 struct socket *sock = NULL;
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500558 mm_segment_t fs;
559 int result = 0;
560 int one = 1;
561 int addr_len;
562
563 if (dlm_local_addr.ss_family == AF_INET)
564 addr_len = sizeof(struct sockaddr_in);
565 else
566 addr_len = sizeof(struct sockaddr_in6);
567
568 /* Create a socket to communicate with */
569 result = sock_create_kern(dlm_local_addr.ss_family, SOCK_STREAM, IPPROTO_TCP, &sock);
570 if (result < 0) {
571 printk("dlm: Can't create listening comms socket\n");
572 goto create_out;
573 }
574
575 fs = get_fs();
576 set_fs(get_ds());
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000577 result = sock_setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
578 (char *)&one, sizeof(one));
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500579 set_fs(fs);
580 if (result < 0) {
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000581 printk("dlm: Failed to set SO_REUSEADDR on socket: result=%d\n",
582 result);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500583 }
584 sock->sk->sk_user_data = con;
585 con->rx_action = accept_from_sock;
586 con->sock = sock;
587
588 /* Bind to our port */
David Teigland68c817a2007-01-09 09:41:48 -0600589 make_sockaddr(saddr, dlm_config.ci_tcp_port, &addr_len);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500590 result = sock->ops->bind(sock, (struct sockaddr *) saddr, addr_len);
591 if (result < 0) {
David Teigland68c817a2007-01-09 09:41:48 -0600592 printk("dlm: Can't bind to port %d\n", dlm_config.ci_tcp_port);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500593 sock_release(sock);
594 sock = NULL;
595 con->sock = NULL;
596 goto create_out;
597 }
598
599 fs = get_fs();
600 set_fs(get_ds());
601
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000602 result = sock_setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE,
603 (char *)&one, sizeof(one));
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500604 set_fs(fs);
605 if (result < 0) {
606 printk("dlm: Set keepalive failed: %d\n", result);
607 }
608
609 result = sock->ops->listen(sock, 5);
610 if (result < 0) {
Patrick Caulfieldbd44e2b2007-01-22 14:51:33 +0000611 printk("dlm: Can't listen on port %d\n", dlm_config.ci_tcp_port);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500612 sock_release(sock);
613 sock = NULL;
614 goto create_out;
615 }
616
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000617create_out:
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500618 return sock;
619}
620
621
622/* Listen on all interfaces */
623static int listen_for_all(void)
624{
625 struct socket *sock = NULL;
626 struct connection *con = nodeid2con(0, GFP_KERNEL);
627 int result = -EINVAL;
628
629 /* We don't support multi-homed hosts */
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500630 set_bit(CF_IS_OTHERCON, &con->flags);
631
632 sock = create_listen_sock(con, &dlm_local_addr);
633 if (sock) {
634 add_sock(sock, con);
635 result = 0;
636 }
637 else {
638 result = -EADDRINUSE;
639 }
640
641 return result;
642}
643
644
645
646static struct writequeue_entry *new_writequeue_entry(struct connection *con,
647 gfp_t allocation)
648{
649 struct writequeue_entry *entry;
650
651 entry = kmalloc(sizeof(struct writequeue_entry), allocation);
652 if (!entry)
653 return NULL;
654
655 entry->page = alloc_page(allocation);
656 if (!entry->page) {
657 kfree(entry);
658 return NULL;
659 }
660
661 entry->offset = 0;
662 entry->len = 0;
663 entry->end = 0;
664 entry->users = 0;
665 entry->con = con;
666
667 return entry;
668}
669
670void *dlm_lowcomms_get_buffer(int nodeid, int len,
671 gfp_t allocation, char **ppc)
672{
673 struct connection *con;
674 struct writequeue_entry *e;
675 int offset = 0;
676 int users = 0;
677
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500678 con = nodeid2con(nodeid, allocation);
679 if (!con)
680 return NULL;
681
Patrick Caulfield4edde742007-01-02 17:08:54 +0000682 spin_lock(&con->writequeue_lock);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500683 e = list_entry(con->writequeue.prev, struct writequeue_entry, list);
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000684 if ((&e->list == &con->writequeue) ||
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500685 (PAGE_CACHE_SIZE - e->end < len)) {
686 e = NULL;
687 } else {
688 offset = e->end;
689 e->end += len;
690 users = e->users++;
691 }
692 spin_unlock(&con->writequeue_lock);
693
694 if (e) {
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000695 got_one:
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500696 if (users == 0)
697 kmap(e->page);
698 *ppc = page_address(e->page) + offset;
699 return e;
700 }
701
702 e = new_writequeue_entry(con, allocation);
703 if (e) {
704 spin_lock(&con->writequeue_lock);
705 offset = e->end;
706 e->end += len;
707 users = e->users++;
708 list_add_tail(&e->list, &con->writequeue);
709 spin_unlock(&con->writequeue_lock);
710 goto got_one;
711 }
712 return NULL;
713}
714
715void dlm_lowcomms_commit_buffer(void *mh)
716{
717 struct writequeue_entry *e = (struct writequeue_entry *)mh;
718 struct connection *con = e->con;
719 int users;
720
Patrick Caulfield4edde742007-01-02 17:08:54 +0000721 spin_lock(&con->writequeue_lock);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500722 users = --e->users;
723 if (users)
724 goto out;
725 e->len = e->end - e->offset;
726 kunmap(e->page);
727 spin_unlock(&con->writequeue_lock);
728
Patrick Caulfield1d6e8132007-01-15 14:33:34 +0000729 if (!test_and_set_bit(CF_WRITE_PENDING, &con->flags)) {
730 queue_work(send_workqueue, &con->swork);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500731 }
732 return;
733
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000734out:
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500735 spin_unlock(&con->writequeue_lock);
736 return;
737}
738
739static void free_entry(struct writequeue_entry *e)
740{
741 __free_page(e->page);
742 kfree(e);
743}
744
745/* Send a message */
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000746static void send_to_sock(struct connection *con)
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500747{
748 int ret = 0;
749 ssize_t(*sendpage) (struct socket *, struct page *, int, size_t, int);
750 const int msg_flags = MSG_DONTWAIT | MSG_NOSIGNAL;
751 struct writequeue_entry *e;
752 int len, offset;
753
Patrick Caulfieldf1f1c1c2007-01-24 11:17:59 +0000754 mutex_lock(&con->sock_mutex);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500755 if (con->sock == NULL)
756 goto out_connect;
757
758 sendpage = con->sock->ops->sendpage;
759
760 spin_lock(&con->writequeue_lock);
761 for (;;) {
762 e = list_entry(con->writequeue.next, struct writequeue_entry,
763 list);
764 if ((struct list_head *) e == &con->writequeue)
765 break;
766
767 len = e->len;
768 offset = e->offset;
769 BUG_ON(len == 0 && e->users == 0);
770 spin_unlock(&con->writequeue_lock);
Patrick Caulfield1d6e8132007-01-15 14:33:34 +0000771 kmap(e->page);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500772
773 ret = 0;
774 if (len) {
775 ret = sendpage(con->sock, e->page, offset, len,
776 msg_flags);
777 if (ret == -EAGAIN || ret == 0)
778 goto out;
779 if (ret <= 0)
780 goto send_error;
781 }
782 else {
783 /* Don't starve people filling buffers */
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000784 cond_resched();
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500785 }
786
787 spin_lock(&con->writequeue_lock);
788 e->offset += ret;
789 e->len -= ret;
790
791 if (e->len == 0 && e->users == 0) {
792 list_del(&e->list);
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000793 kunmap(e->page);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500794 free_entry(e);
795 continue;
796 }
797 }
798 spin_unlock(&con->writequeue_lock);
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000799out:
Patrick Caulfieldf1f1c1c2007-01-24 11:17:59 +0000800 mutex_unlock(&con->sock_mutex);
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000801 return;
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500802
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000803send_error:
Patrick Caulfieldf1f1c1c2007-01-24 11:17:59 +0000804 mutex_unlock(&con->sock_mutex);
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000805 close_connection(con, false);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500806 lowcomms_connect_sock(con);
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000807 return;
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500808
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000809out_connect:
Patrick Caulfieldf1f1c1c2007-01-24 11:17:59 +0000810 mutex_unlock(&con->sock_mutex);
Patrick Caulfieldbd44e2b2007-01-22 14:51:33 +0000811 connect_to_sock(con);
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000812 return;
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500813}
814
815static void clean_one_writequeue(struct connection *con)
816{
817 struct list_head *list;
818 struct list_head *temp;
819
820 spin_lock(&con->writequeue_lock);
821 list_for_each_safe(list, temp, &con->writequeue) {
822 struct writequeue_entry *e =
823 list_entry(list, struct writequeue_entry, list);
824 list_del(&e->list);
825 free_entry(e);
826 }
827 spin_unlock(&con->writequeue_lock);
828}
829
830/* Called from recovery when it knows that a node has
831 left the cluster */
832int dlm_lowcomms_close(int nodeid)
833{
834 struct connection *con;
835
836 if (!connections)
837 goto out;
838
839 log_print("closing connection to node %d", nodeid);
840 con = nodeid2con(nodeid, 0);
841 if (con) {
842 clean_one_writequeue(con);
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000843 close_connection(con, true);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500844 }
845 return 0;
846
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000847out:
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500848 return -1;
849}
850
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500851/* Look for activity on active sockets */
Patrick Caulfield1d6e8132007-01-15 14:33:34 +0000852static void process_recv_sockets(struct work_struct *work)
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500853{
Patrick Caulfield1d6e8132007-01-15 14:33:34 +0000854 struct connection *con = container_of(work, struct connection, rwork);
855 int err;
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500856
Patrick Caulfield1d6e8132007-01-15 14:33:34 +0000857 clear_bit(CF_READ_PENDING, &con->flags);
858 do {
859 err = con->rx_action(con);
860 } while (!err);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500861}
862
Patrick Caulfield1d6e8132007-01-15 14:33:34 +0000863
864static void process_send_sockets(struct work_struct *work)
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500865{
Patrick Caulfield1d6e8132007-01-15 14:33:34 +0000866 struct connection *con = container_of(work, struct connection, swork);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500867
Patrick Caulfield1d6e8132007-01-15 14:33:34 +0000868 if (test_and_clear_bit(CF_CONNECT_PENDING, &con->flags)) {
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000869 connect_to_sock(con);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500870 }
Patrick Caulfield1d6e8132007-01-15 14:33:34 +0000871
Patrick Caulfieldbd44e2b2007-01-22 14:51:33 +0000872 clear_bit(CF_WRITE_PENDING, &con->flags);
873 send_to_sock(con);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500874}
875
876
877/* Discard all entries on the write queues */
878static void clean_writequeues(void)
879{
880 int nodeid;
881
882 for (nodeid = 1; nodeid < conn_array_size; nodeid++) {
883 struct connection *con = nodeid2con(nodeid, 0);
884
885 if (con)
886 clean_one_writequeue(con);
887 }
888}
889
Patrick Caulfield1d6e8132007-01-15 14:33:34 +0000890static void work_stop(void)
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500891{
Patrick Caulfield1d6e8132007-01-15 14:33:34 +0000892 destroy_workqueue(recv_workqueue);
893 destroy_workqueue(send_workqueue);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500894}
895
Patrick Caulfield1d6e8132007-01-15 14:33:34 +0000896static int work_start(void)
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500897{
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500898 int error;
Patrick Caulfield1d6e8132007-01-15 14:33:34 +0000899 recv_workqueue = create_workqueue("dlm_recv");
900 error = IS_ERR(recv_workqueue);
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000901 if (error) {
Patrick Caulfield1d6e8132007-01-15 14:33:34 +0000902 log_print("can't start dlm_recv %d", error);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500903 return error;
904 }
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500905
Patrick Caulfield1d6e8132007-01-15 14:33:34 +0000906 send_workqueue = create_singlethread_workqueue("dlm_send");
907 error = IS_ERR(send_workqueue);
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000908 if (error) {
Patrick Caulfield1d6e8132007-01-15 14:33:34 +0000909 log_print("can't start dlm_send %d", error);
910 destroy_workqueue(recv_workqueue);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500911 return error;
912 }
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500913
914 return 0;
915}
916
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500917void dlm_lowcomms_stop(void)
918{
919 int i;
920
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000921 /* Set all the flags to prevent any
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500922 socket activity.
923 */
924 for (i = 0; i < conn_array_size; i++) {
925 if (connections[i])
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000926 connections[i]->flags |= 0xFF;
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500927 }
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000928
Patrick Caulfield1d6e8132007-01-15 14:33:34 +0000929 work_stop();
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500930 clean_writequeues();
931
932 for (i = 0; i < conn_array_size; i++) {
933 if (connections[i]) {
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000934 close_connection(connections[i], true);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500935 if (connections[i]->othercon)
936 kmem_cache_free(con_cache, connections[i]->othercon);
937 kmem_cache_free(con_cache, connections[i]);
938 }
939 }
940
941 kfree(connections);
942 connections = NULL;
943
944 kmem_cache_destroy(con_cache);
945}
946
947/* This is quite likely to sleep... */
948int dlm_lowcomms_start(void)
949{
950 int error = 0;
951
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500952 error = -ENOMEM;
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000953 connections = kzalloc(sizeof(struct connection *) *
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500954 NODE_INCREMENT, GFP_KERNEL);
955 if (!connections)
956 goto out;
957
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500958 conn_array_size = NODE_INCREMENT;
959
960 if (dlm_our_addr(&dlm_local_addr, 0)) {
961 log_print("no local IP address has been set");
962 goto fail_free_conn;
963 }
964 if (!dlm_our_addr(&dlm_local_addr, 1)) {
965 log_print("This dlm comms module does not support multi-homed clustering");
966 goto fail_free_conn;
967 }
968
969 con_cache = kmem_cache_create("dlm_conn", sizeof(struct connection),
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000970 __alignof__(struct connection), 0,
971 NULL, NULL);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500972 if (!con_cache)
973 goto fail_free_conn;
974
975
976 /* Start listening */
977 error = listen_for_all();
978 if (error)
979 goto fail_unlisten;
980
Patrick Caulfield1d6e8132007-01-15 14:33:34 +0000981 error = work_start();
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500982 if (error)
983 goto fail_unlisten;
984
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500985 return 0;
986
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000987fail_unlisten:
988 close_connection(connections[0], false);
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500989 kmem_cache_free(con_cache, connections[0]);
990 kmem_cache_destroy(con_cache);
991
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000992fail_free_conn:
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500993 kfree(connections);
994
Patrick Caulfieldac33d072006-12-06 15:10:37 +0000995out:
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500996 return error;
997}
998
Patrick Caulfieldfdda3872006-11-02 11:19:21 -0500999/*
1000 * Overrides for Emacs so that we follow Linus's tabbing style.
1001 * Emacs will notice this stuff at the end of the file and automatically
1002 * adjust the settings for this buffer only. This must remain at the end
1003 * of the file.
1004 * ---------------------------------------------------------------------------
1005 * Local variables:
1006 * c-file-style: "linux"
1007 * End:
1008 */