Commit | Line | Data |
---|---|---|
70041088 AG |
1 | /* |
2 | * Copyright (c) 2006 Oracle. All rights reserved. | |
3 | * | |
4 | * This software is available to you under a choice of one of two | |
5 | * licenses. You may choose to be licensed under the terms of the GNU | |
6 | * General Public License (GPL) Version 2, available from the file | |
7 | * COPYING in the main directory of this source tree, or the | |
8 | * OpenIB.org BSD license below: | |
9 | * | |
10 | * Redistribution and use in source and binary forms, with or | |
11 | * without modification, are permitted provided that the following | |
12 | * conditions are met: | |
13 | * | |
14 | * - Redistributions of source code must retain the above | |
15 | * copyright notice, this list of conditions and the following | |
16 | * disclaimer. | |
17 | * | |
18 | * - Redistributions in binary form must reproduce the above | |
19 | * copyright notice, this list of conditions and the following | |
20 | * disclaimer in the documentation and/or other materials | |
21 | * provided with the distribution. | |
22 | * | |
23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
24 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
25 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
26 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | |
27 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | |
28 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |
29 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
30 | * SOFTWARE. | |
31 | * | |
32 | */ | |
33 | #include <linux/kernel.h> | |
5a0e3ad6 | 34 | #include <linux/slab.h> |
70041088 | 35 | #include <linux/in.h> |
3a9a231d | 36 | #include <linux/module.h> |
70041088 | 37 | #include <net/tcp.h> |
467fa153 SV |
38 | #include <net/net_namespace.h> |
39 | #include <net/netns/generic.h> | |
70041088 AG |
40 | |
41 | #include "rds.h" | |
42 | #include "tcp.h" | |
43 | ||
44 | /* only for info exporting */ | |
45 | static DEFINE_SPINLOCK(rds_tcp_tc_list_lock); | |
46 | static LIST_HEAD(rds_tcp_tc_list); | |
ff51bf84 | 47 | static unsigned int rds_tcp_tc_count; |
70041088 AG |
48 | |
49 | /* Track rds_tcp_connection structs so they can be cleaned up */ | |
50 | static DEFINE_SPINLOCK(rds_tcp_conn_lock); | |
51 | static LIST_HEAD(rds_tcp_conn_list); | |
52 | ||
53 | static struct kmem_cache *rds_tcp_conn_slab; | |
54 | ||
c6a58ffe SV |
55 | static int rds_tcp_skbuf_handler(struct ctl_table *ctl, int write, |
56 | void __user *buffer, size_t *lenp, | |
57 | loff_t *fpos); | |
58 | ||
59 | int rds_tcp_min_sndbuf = SOCK_MIN_SNDBUF; | |
60 | int rds_tcp_min_rcvbuf = SOCK_MIN_RCVBUF; | |
61 | ||
62 | static struct ctl_table rds_tcp_sysctl_table[] = { | |
63 | #define RDS_TCP_SNDBUF 0 | |
64 | { | |
65 | .procname = "rds_tcp_sndbuf", | |
66 | /* data is per-net pointer */ | |
67 | .maxlen = sizeof(int), | |
68 | .mode = 0644, | |
69 | .proc_handler = rds_tcp_skbuf_handler, | |
70 | .extra1 = &rds_tcp_min_sndbuf, | |
71 | }, | |
72 | #define RDS_TCP_RCVBUF 1 | |
73 | { | |
74 | .procname = "rds_tcp_rcvbuf", | |
75 | /* data is per-net pointer */ | |
76 | .maxlen = sizeof(int), | |
77 | .mode = 0644, | |
78 | .proc_handler = rds_tcp_skbuf_handler, | |
79 | .extra1 = &rds_tcp_min_rcvbuf, | |
80 | }, | |
81 | { } | |
82 | }; | |
83 | ||
70041088 AG |
84 | /* doing it this way avoids calling tcp_sk() */ |
85 | void rds_tcp_nonagle(struct socket *sock) | |
86 | { | |
87 | mm_segment_t oldfs = get_fs(); | |
88 | int val = 1; | |
89 | ||
90 | set_fs(KERNEL_DS); | |
91 | sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val, | |
92 | sizeof(val)); | |
93 | set_fs(oldfs); | |
94 | } | |
95 | ||
70041088 AG |
96 | u32 rds_tcp_snd_nxt(struct rds_tcp_connection *tc) |
97 | { | |
98 | return tcp_sk(tc->t_sock->sk)->snd_nxt; | |
99 | } | |
100 | ||
101 | u32 rds_tcp_snd_una(struct rds_tcp_connection *tc) | |
102 | { | |
103 | return tcp_sk(tc->t_sock->sk)->snd_una; | |
104 | } | |
105 | ||
106 | void rds_tcp_restore_callbacks(struct socket *sock, | |
107 | struct rds_tcp_connection *tc) | |
108 | { | |
109 | rdsdebug("restoring sock %p callbacks from tc %p\n", sock, tc); | |
110 | write_lock_bh(&sock->sk->sk_callback_lock); | |
111 | ||
112 | /* done under the callback_lock to serialize with write_space */ | |
113 | spin_lock(&rds_tcp_tc_list_lock); | |
114 | list_del_init(&tc->t_list_item); | |
115 | rds_tcp_tc_count--; | |
116 | spin_unlock(&rds_tcp_tc_list_lock); | |
117 | ||
118 | tc->t_sock = NULL; | |
119 | ||
120 | sock->sk->sk_write_space = tc->t_orig_write_space; | |
121 | sock->sk->sk_data_ready = tc->t_orig_data_ready; | |
122 | sock->sk->sk_state_change = tc->t_orig_state_change; | |
123 | sock->sk->sk_user_data = NULL; | |
124 | ||
125 | write_unlock_bh(&sock->sk->sk_callback_lock); | |
126 | } | |
127 | ||
128 | /* | |
129 | * This is the only path that sets tc->t_sock. Send and receive trust that | |
eb192840 | 130 | * it is set. The RDS_CONN_UP bit protects those paths from being |
70041088 AG |
131 | * called while it isn't set. |
132 | */ | |
133 | void rds_tcp_set_callbacks(struct socket *sock, struct rds_connection *conn) | |
134 | { | |
135 | struct rds_tcp_connection *tc = conn->c_transport_data; | |
136 | ||
137 | rdsdebug("setting sock %p callbacks to tc %p\n", sock, tc); | |
138 | write_lock_bh(&sock->sk->sk_callback_lock); | |
139 | ||
140 | /* done under the callback_lock to serialize with write_space */ | |
141 | spin_lock(&rds_tcp_tc_list_lock); | |
142 | list_add_tail(&tc->t_list_item, &rds_tcp_tc_list); | |
143 | rds_tcp_tc_count++; | |
144 | spin_unlock(&rds_tcp_tc_list_lock); | |
145 | ||
146 | /* accepted sockets need our listen data ready undone */ | |
147 | if (sock->sk->sk_data_ready == rds_tcp_listen_data_ready) | |
148 | sock->sk->sk_data_ready = sock->sk->sk_user_data; | |
149 | ||
150 | tc->t_sock = sock; | |
151 | tc->conn = conn; | |
152 | tc->t_orig_data_ready = sock->sk->sk_data_ready; | |
153 | tc->t_orig_write_space = sock->sk->sk_write_space; | |
154 | tc->t_orig_state_change = sock->sk->sk_state_change; | |
155 | ||
156 | sock->sk->sk_user_data = conn; | |
157 | sock->sk->sk_data_ready = rds_tcp_data_ready; | |
158 | sock->sk->sk_write_space = rds_tcp_write_space; | |
159 | sock->sk->sk_state_change = rds_tcp_state_change; | |
160 | ||
161 | write_unlock_bh(&sock->sk->sk_callback_lock); | |
162 | } | |
163 | ||
164 | static void rds_tcp_tc_info(struct socket *sock, unsigned int len, | |
165 | struct rds_info_iterator *iter, | |
166 | struct rds_info_lengths *lens) | |
167 | { | |
168 | struct rds_info_tcp_socket tsinfo; | |
169 | struct rds_tcp_connection *tc; | |
170 | unsigned long flags; | |
171 | struct sockaddr_in sin; | |
172 | int sinlen; | |
173 | ||
174 | spin_lock_irqsave(&rds_tcp_tc_list_lock, flags); | |
175 | ||
176 | if (len / sizeof(tsinfo) < rds_tcp_tc_count) | |
177 | goto out; | |
178 | ||
179 | list_for_each_entry(tc, &rds_tcp_tc_list, t_list_item) { | |
180 | ||
181 | sock->ops->getname(sock, (struct sockaddr *)&sin, &sinlen, 0); | |
182 | tsinfo.local_addr = sin.sin_addr.s_addr; | |
183 | tsinfo.local_port = sin.sin_port; | |
184 | sock->ops->getname(sock, (struct sockaddr *)&sin, &sinlen, 1); | |
185 | tsinfo.peer_addr = sin.sin_addr.s_addr; | |
186 | tsinfo.peer_port = sin.sin_port; | |
187 | ||
188 | tsinfo.hdr_rem = tc->t_tinc_hdr_rem; | |
189 | tsinfo.data_rem = tc->t_tinc_data_rem; | |
190 | tsinfo.last_sent_nxt = tc->t_last_sent_nxt; | |
191 | tsinfo.last_expected_una = tc->t_last_expected_una; | |
192 | tsinfo.last_seen_una = tc->t_last_seen_una; | |
193 | ||
194 | rds_info_copy(iter, &tsinfo, sizeof(tsinfo)); | |
195 | } | |
196 | ||
197 | out: | |
198 | lens->nr = rds_tcp_tc_count; | |
199 | lens->each = sizeof(tsinfo); | |
200 | ||
201 | spin_unlock_irqrestore(&rds_tcp_tc_list_lock, flags); | |
202 | } | |
203 | ||
d5a8ac28 | 204 | static int rds_tcp_laddr_check(struct net *net, __be32 addr) |
70041088 | 205 | { |
d5a8ac28 | 206 | if (inet_addr_type(net, addr) == RTN_LOCAL) |
70041088 AG |
207 | return 0; |
208 | return -EADDRNOTAVAIL; | |
209 | } | |
210 | ||
211 | static int rds_tcp_conn_alloc(struct rds_connection *conn, gfp_t gfp) | |
212 | { | |
213 | struct rds_tcp_connection *tc; | |
214 | ||
215 | tc = kmem_cache_alloc(rds_tcp_conn_slab, gfp); | |
8690bfa1 | 216 | if (!tc) |
70041088 AG |
217 | return -ENOMEM; |
218 | ||
219 | tc->t_sock = NULL; | |
220 | tc->t_tinc = NULL; | |
221 | tc->t_tinc_hdr_rem = sizeof(struct rds_header); | |
222 | tc->t_tinc_data_rem = 0; | |
223 | ||
224 | conn->c_transport_data = tc; | |
225 | ||
226 | spin_lock_irq(&rds_tcp_conn_lock); | |
227 | list_add_tail(&tc->t_tcp_node, &rds_tcp_conn_list); | |
228 | spin_unlock_irq(&rds_tcp_conn_lock); | |
229 | ||
230 | rdsdebug("alloced tc %p\n", conn->c_transport_data); | |
231 | return 0; | |
232 | } | |
233 | ||
234 | static void rds_tcp_conn_free(void *arg) | |
235 | { | |
236 | struct rds_tcp_connection *tc = arg; | |
8200a59f | 237 | unsigned long flags; |
70041088 | 238 | rdsdebug("freeing tc %p\n", tc); |
8200a59f PE |
239 | |
240 | spin_lock_irqsave(&rds_tcp_conn_lock, flags); | |
241 | list_del(&tc->t_tcp_node); | |
242 | spin_unlock_irqrestore(&rds_tcp_conn_lock, flags); | |
243 | ||
70041088 AG |
244 | kmem_cache_free(rds_tcp_conn_slab, tc); |
245 | } | |
246 | ||
247 | static void rds_tcp_destroy_conns(void) | |
248 | { | |
249 | struct rds_tcp_connection *tc, *_tc; | |
250 | LIST_HEAD(tmp_list); | |
251 | ||
252 | /* avoid calling conn_destroy with irqs off */ | |
253 | spin_lock_irq(&rds_tcp_conn_lock); | |
254 | list_splice(&rds_tcp_conn_list, &tmp_list); | |
255 | INIT_LIST_HEAD(&rds_tcp_conn_list); | |
256 | spin_unlock_irq(&rds_tcp_conn_lock); | |
257 | ||
258 | list_for_each_entry_safe(tc, _tc, &tmp_list, t_tcp_node) { | |
259 | if (tc->conn->c_passive) | |
260 | rds_conn_destroy(tc->conn->c_passive); | |
261 | rds_conn_destroy(tc->conn); | |
262 | } | |
263 | } | |
264 | ||
467fa153 | 265 | static void rds_tcp_exit(void); |
70041088 AG |
266 | |
267 | struct rds_transport rds_tcp_transport = { | |
268 | .laddr_check = rds_tcp_laddr_check, | |
269 | .xmit_prepare = rds_tcp_xmit_prepare, | |
270 | .xmit_complete = rds_tcp_xmit_complete, | |
70041088 AG |
271 | .xmit = rds_tcp_xmit, |
272 | .recv = rds_tcp_recv, | |
273 | .conn_alloc = rds_tcp_conn_alloc, | |
274 | .conn_free = rds_tcp_conn_free, | |
275 | .conn_connect = rds_tcp_conn_connect, | |
276 | .conn_shutdown = rds_tcp_conn_shutdown, | |
277 | .inc_copy_to_user = rds_tcp_inc_copy_to_user, | |
70041088 AG |
278 | .inc_free = rds_tcp_inc_free, |
279 | .stats_info_copy = rds_tcp_stats_info_copy, | |
280 | .exit = rds_tcp_exit, | |
281 | .t_owner = THIS_MODULE, | |
282 | .t_name = "tcp", | |
335776bd | 283 | .t_type = RDS_TRANS_TCP, |
70041088 AG |
284 | .t_prefer_loopback = 1, |
285 | }; | |
286 | ||
467fa153 SV |
287 | static int rds_tcp_netid; |
288 | ||
289 | /* per-network namespace private data for this module */ | |
290 | struct rds_tcp_net { | |
291 | struct socket *rds_tcp_listen_sock; | |
292 | struct work_struct rds_tcp_accept_w; | |
c6a58ffe SV |
293 | struct ctl_table_header *rds_tcp_sysctl; |
294 | struct ctl_table *ctl_table; | |
295 | int sndbuf_size; | |
296 | int rcvbuf_size; | |
467fa153 SV |
297 | }; |
298 | ||
c6a58ffe SV |
299 | /* All module specific customizations to the RDS-TCP socket should be done in |
300 | * rds_tcp_tune() and applied after socket creation. | |
301 | */ | |
302 | void rds_tcp_tune(struct socket *sock) | |
303 | { | |
304 | struct sock *sk = sock->sk; | |
305 | struct net *net = sock_net(sk); | |
306 | struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid); | |
307 | ||
308 | rds_tcp_nonagle(sock); | |
309 | lock_sock(sk); | |
310 | if (rtn->sndbuf_size > 0) { | |
311 | sk->sk_sndbuf = rtn->sndbuf_size; | |
312 | sk->sk_userlocks |= SOCK_SNDBUF_LOCK; | |
313 | } | |
314 | if (rtn->rcvbuf_size > 0) { | |
315 | sk->sk_sndbuf = rtn->rcvbuf_size; | |
316 | sk->sk_userlocks |= SOCK_RCVBUF_LOCK; | |
317 | } | |
318 | release_sock(sk); | |
319 | } | |
320 | ||
467fa153 SV |
321 | static void rds_tcp_accept_worker(struct work_struct *work) |
322 | { | |
323 | struct rds_tcp_net *rtn = container_of(work, | |
324 | struct rds_tcp_net, | |
325 | rds_tcp_accept_w); | |
326 | ||
327 | while (rds_tcp_accept_one(rtn->rds_tcp_listen_sock) == 0) | |
328 | cond_resched(); | |
329 | } | |
330 | ||
331 | void rds_tcp_accept_work(struct sock *sk) | |
332 | { | |
333 | struct net *net = sock_net(sk); | |
334 | struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid); | |
335 | ||
336 | queue_work(rds_wq, &rtn->rds_tcp_accept_w); | |
337 | } | |
338 | ||
339 | static __net_init int rds_tcp_init_net(struct net *net) | |
340 | { | |
341 | struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid); | |
c6a58ffe SV |
342 | struct ctl_table *tbl; |
343 | int err = 0; | |
467fa153 | 344 | |
c6a58ffe SV |
345 | memset(rtn, 0, sizeof(*rtn)); |
346 | ||
347 | /* {snd, rcv}buf_size default to 0, which implies we let the | |
348 | * stack pick the value, and permit auto-tuning of buffer size. | |
349 | */ | |
350 | if (net == &init_net) { | |
351 | tbl = rds_tcp_sysctl_table; | |
352 | } else { | |
353 | tbl = kmemdup(rds_tcp_sysctl_table, | |
354 | sizeof(rds_tcp_sysctl_table), GFP_KERNEL); | |
355 | if (!tbl) { | |
356 | pr_warn("could not set allocate syctl table\n"); | |
357 | return -ENOMEM; | |
358 | } | |
359 | rtn->ctl_table = tbl; | |
360 | } | |
361 | tbl[RDS_TCP_SNDBUF].data = &rtn->sndbuf_size; | |
362 | tbl[RDS_TCP_RCVBUF].data = &rtn->rcvbuf_size; | |
363 | rtn->rds_tcp_sysctl = register_net_sysctl(net, "net/rds/tcp", tbl); | |
364 | if (!rtn->rds_tcp_sysctl) { | |
365 | pr_warn("could not register sysctl\n"); | |
366 | err = -ENOMEM; | |
367 | goto fail; | |
368 | } | |
467fa153 SV |
369 | rtn->rds_tcp_listen_sock = rds_tcp_listen_init(net); |
370 | if (!rtn->rds_tcp_listen_sock) { | |
371 | pr_warn("could not set up listen sock\n"); | |
c6a58ffe SV |
372 | unregister_net_sysctl_table(rtn->rds_tcp_sysctl); |
373 | rtn->rds_tcp_sysctl = NULL; | |
374 | err = -EAFNOSUPPORT; | |
375 | goto fail; | |
467fa153 SV |
376 | } |
377 | INIT_WORK(&rtn->rds_tcp_accept_w, rds_tcp_accept_worker); | |
378 | return 0; | |
c6a58ffe SV |
379 | |
380 | fail: | |
381 | if (net != &init_net) | |
382 | kfree(tbl); | |
383 | return err; | |
467fa153 SV |
384 | } |
385 | ||
386 | static void __net_exit rds_tcp_exit_net(struct net *net) | |
387 | { | |
388 | struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid); | |
389 | ||
c6a58ffe SV |
390 | if (rtn->rds_tcp_sysctl) |
391 | unregister_net_sysctl_table(rtn->rds_tcp_sysctl); | |
392 | ||
393 | if (net != &init_net && rtn->ctl_table) | |
394 | kfree(rtn->ctl_table); | |
395 | ||
467fa153 SV |
396 | /* If rds_tcp_exit_net() is called as a result of netns deletion, |
397 | * the rds_tcp_kill_sock() device notifier would already have cleaned | |
398 | * up the listen socket, thus there is no work to do in this function. | |
399 | * | |
400 | * If rds_tcp_exit_net() is called as a result of module unload, | |
401 | * i.e., due to rds_tcp_exit() -> unregister_pernet_subsys(), then | |
402 | * we do need to clean up the listen socket here. | |
403 | */ | |
404 | if (rtn->rds_tcp_listen_sock) { | |
405 | rds_tcp_listen_stop(rtn->rds_tcp_listen_sock); | |
406 | rtn->rds_tcp_listen_sock = NULL; | |
407 | flush_work(&rtn->rds_tcp_accept_w); | |
408 | } | |
409 | } | |
410 | ||
411 | static struct pernet_operations rds_tcp_net_ops = { | |
412 | .init = rds_tcp_init_net, | |
413 | .exit = rds_tcp_exit_net, | |
414 | .id = &rds_tcp_netid, | |
415 | .size = sizeof(struct rds_tcp_net), | |
416 | }; | |
417 | ||
418 | static void rds_tcp_kill_sock(struct net *net) | |
419 | { | |
420 | struct rds_tcp_connection *tc, *_tc; | |
421 | struct sock *sk; | |
422 | LIST_HEAD(tmp_list); | |
423 | struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid); | |
424 | ||
425 | rds_tcp_listen_stop(rtn->rds_tcp_listen_sock); | |
426 | rtn->rds_tcp_listen_sock = NULL; | |
427 | flush_work(&rtn->rds_tcp_accept_w); | |
428 | spin_lock_irq(&rds_tcp_conn_lock); | |
429 | list_for_each_entry_safe(tc, _tc, &rds_tcp_conn_list, t_tcp_node) { | |
430 | struct net *c_net = read_pnet(&tc->conn->c_net); | |
431 | ||
432 | if (net != c_net || !tc->t_sock) | |
433 | continue; | |
434 | list_move_tail(&tc->t_tcp_node, &tmp_list); | |
435 | } | |
436 | spin_unlock_irq(&rds_tcp_conn_lock); | |
437 | list_for_each_entry_safe(tc, _tc, &tmp_list, t_tcp_node) { | |
438 | sk = tc->t_sock->sk; | |
439 | sk->sk_prot->disconnect(sk, 0); | |
440 | tcp_done(sk); | |
441 | if (tc->conn->c_passive) | |
442 | rds_conn_destroy(tc->conn->c_passive); | |
443 | rds_conn_destroy(tc->conn); | |
444 | } | |
445 | } | |
446 | ||
447 | static int rds_tcp_dev_event(struct notifier_block *this, | |
448 | unsigned long event, void *ptr) | |
449 | { | |
450 | struct net_device *dev = netdev_notifier_info_to_dev(ptr); | |
451 | ||
452 | /* rds-tcp registers as a pernet subys, so the ->exit will only | |
453 | * get invoked after network acitivity has quiesced. We need to | |
454 | * clean up all sockets to quiesce network activity, and use | |
455 | * the unregistration of the per-net loopback device as a trigger | |
456 | * to start that cleanup. | |
457 | */ | |
458 | if (event == NETDEV_UNREGISTER_FINAL && | |
459 | dev->ifindex == LOOPBACK_IFINDEX) | |
460 | rds_tcp_kill_sock(dev_net(dev)); | |
461 | ||
462 | return NOTIFY_DONE; | |
463 | } | |
464 | ||
465 | static struct notifier_block rds_tcp_dev_notifier = { | |
466 | .notifier_call = rds_tcp_dev_event, | |
467 | .priority = -10, /* must be called after other network notifiers */ | |
468 | }; | |
469 | ||
c6a58ffe SV |
470 | /* when sysctl is used to modify some kernel socket parameters,this |
471 | * function resets the RDS connections in that netns so that we can | |
472 | * restart with new parameters. The assumption is that such reset | |
473 | * events are few and far-between. | |
474 | */ | |
475 | static void rds_tcp_sysctl_reset(struct net *net) | |
476 | { | |
477 | struct rds_tcp_connection *tc, *_tc; | |
478 | ||
479 | spin_lock_irq(&rds_tcp_conn_lock); | |
480 | list_for_each_entry_safe(tc, _tc, &rds_tcp_conn_list, t_tcp_node) { | |
481 | struct net *c_net = read_pnet(&tc->conn->c_net); | |
482 | ||
483 | if (net != c_net || !tc->t_sock) | |
484 | continue; | |
485 | ||
486 | rds_conn_drop(tc->conn); /* reconnect with new parameters */ | |
487 | } | |
488 | spin_unlock_irq(&rds_tcp_conn_lock); | |
489 | } | |
490 | ||
491 | static int rds_tcp_skbuf_handler(struct ctl_table *ctl, int write, | |
492 | void __user *buffer, size_t *lenp, | |
493 | loff_t *fpos) | |
494 | { | |
495 | struct net *net = current->nsproxy->net_ns; | |
496 | int err; | |
497 | ||
498 | err = proc_dointvec_minmax(ctl, write, buffer, lenp, fpos); | |
499 | if (err < 0) { | |
500 | pr_warn("Invalid input. Must be >= %d\n", | |
501 | *(int *)(ctl->extra1)); | |
502 | return err; | |
503 | } | |
504 | if (write) | |
505 | rds_tcp_sysctl_reset(net); | |
506 | return 0; | |
507 | } | |
508 | ||
467fa153 SV |
509 | static void rds_tcp_exit(void) |
510 | { | |
511 | rds_info_deregister_func(RDS_INFO_TCP_SOCKETS, rds_tcp_tc_info); | |
512 | unregister_pernet_subsys(&rds_tcp_net_ops); | |
513 | if (unregister_netdevice_notifier(&rds_tcp_dev_notifier)) | |
514 | pr_warn("could not unregister rds_tcp_dev_notifier\n"); | |
515 | rds_tcp_destroy_conns(); | |
516 | rds_trans_unregister(&rds_tcp_transport); | |
517 | rds_tcp_recv_exit(); | |
518 | kmem_cache_destroy(rds_tcp_conn_slab); | |
519 | } | |
520 | module_exit(rds_tcp_exit); | |
521 | ||
ff51bf84 | 522 | static int rds_tcp_init(void) |
70041088 AG |
523 | { |
524 | int ret; | |
525 | ||
526 | rds_tcp_conn_slab = kmem_cache_create("rds_tcp_connection", | |
527 | sizeof(struct rds_tcp_connection), | |
528 | 0, 0, NULL); | |
8690bfa1 | 529 | if (!rds_tcp_conn_slab) { |
70041088 AG |
530 | ret = -ENOMEM; |
531 | goto out; | |
532 | } | |
533 | ||
467fa153 SV |
534 | ret = register_netdevice_notifier(&rds_tcp_dev_notifier); |
535 | if (ret) { | |
536 | pr_warn("could not register rds_tcp_dev_notifier\n"); | |
537 | goto out; | |
538 | } | |
539 | ||
540 | ret = register_pernet_subsys(&rds_tcp_net_ops); | |
541 | if (ret) | |
542 | goto out_slab; | |
543 | ||
70041088 AG |
544 | ret = rds_tcp_recv_init(); |
545 | if (ret) | |
546 | goto out_slab; | |
547 | ||
548 | ret = rds_trans_register(&rds_tcp_transport); | |
549 | if (ret) | |
550 | goto out_recv; | |
551 | ||
70041088 AG |
552 | rds_info_register_func(RDS_INFO_TCP_SOCKETS, rds_tcp_tc_info); |
553 | ||
554 | goto out; | |
555 | ||
70041088 AG |
556 | out_recv: |
557 | rds_tcp_recv_exit(); | |
558 | out_slab: | |
467fa153 | 559 | unregister_pernet_subsys(&rds_tcp_net_ops); |
70041088 AG |
560 | kmem_cache_destroy(rds_tcp_conn_slab); |
561 | out: | |
562 | return ret; | |
563 | } | |
564 | module_init(rds_tcp_init); | |
565 | ||
566 | MODULE_AUTHOR("Oracle Corporation <rds-devel@oss.oracle.com>"); | |
567 | MODULE_DESCRIPTION("RDS: TCP transport"); | |
568 | MODULE_LICENSE("Dual BSD/GPL"); | |
569 |