blob: fd8217404162ecd8136554e3de567d98bbbf80b2 [file] [log] [blame]
Andy Grover639b3212009-02-24 15:30:18 +00001/*
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/module.h>
34#include <linux/errno.h>
35#include <linux/kernel.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090036#include <linux/gfp.h>
Andy Grover639b3212009-02-24 15:30:18 +000037#include <linux/in.h>
38#include <linux/poll.h>
Andy Grover639b3212009-02-24 15:30:18 +000039#include <net/sock.h>
40
41#include "rds.h"
Andy Grover639b3212009-02-24 15:30:18 +000042
43/* this is just used for stats gathering :/ */
44static DEFINE_SPINLOCK(rds_sock_lock);
45static unsigned long rds_sock_count;
46static LIST_HEAD(rds_sock_list);
47DECLARE_WAIT_QUEUE_HEAD(rds_poll_waitq);
48
49/*
50 * This is called as the final descriptor referencing this socket is closed.
51 * We have to unbind the socket so that another socket can be bound to the
52 * address it was using.
53 *
54 * We have to be careful about racing with the incoming path. sock_orphan()
55 * sets SOCK_DEAD and we use that as an indicator to the rx path that new
56 * messages shouldn't be queued.
57 */
58static int rds_release(struct socket *sock)
59{
60 struct sock *sk = sock->sk;
61 struct rds_sock *rs;
Andy Grover639b3212009-02-24 15:30:18 +000062
Andy Grover8690bfa2010-01-12 11:56:44 -080063 if (!sk)
Andy Grover639b3212009-02-24 15:30:18 +000064 goto out;
65
66 rs = rds_sk_to_rs(sk);
67
68 sock_orphan(sk);
69 /* Note - rds_clear_recv_queue grabs rs_recv_lock, so
70 * that ensures the recv path has completed messing
71 * with the socket. */
72 rds_clear_recv_queue(rs);
73 rds_cong_remove_socket(rs);
Chris Mason38a4e5e2010-05-11 15:09:45 -070074
Andy Grover639b3212009-02-24 15:30:18 +000075 rds_remove_bound(rs);
Chris Mason38a4e5e2010-05-11 15:09:45 -070076
Andy Grover639b3212009-02-24 15:30:18 +000077 rds_send_drop_to(rs, NULL);
78 rds_rdma_drop_keys(rs);
79 rds_notify_queue_get(rs, NULL);
80
David S. Millerefc3dbc2012-01-24 17:03:44 -050081 spin_lock_bh(&rds_sock_lock);
Andy Grover639b3212009-02-24 15:30:18 +000082 list_del_init(&rs->rs_item);
83 rds_sock_count--;
David S. Millerefc3dbc2012-01-24 17:03:44 -050084 spin_unlock_bh(&rds_sock_lock);
Andy Grover639b3212009-02-24 15:30:18 +000085
Zach Brown5adb5bc2010-07-23 10:32:31 -070086 rds_trans_put(rs->rs_transport);
87
Andy Grover639b3212009-02-24 15:30:18 +000088 sock->sk = NULL;
89 sock_put(sk);
90out:
91 return 0;
92}
93
94/*
95 * Careful not to race with rds_release -> sock_orphan which clears sk_sleep.
96 * _bh() isn't OK here, we're called from interrupt handlers. It's probably OK
97 * to wake the waitqueue after sk_sleep is clear as we hold a sock ref, but
98 * this seems more conservative.
99 * NB - normally, one would use sk_callback_lock for this, but we can
100 * get here from interrupts, whereas the network code grabs sk_callback_lock
101 * with _lock_bh only - so relying on sk_callback_lock introduces livelocks.
102 */
103void rds_wake_sk_sleep(struct rds_sock *rs)
104{
105 unsigned long flags;
106
107 read_lock_irqsave(&rs->rs_recv_lock, flags);
108 __rds_wake_sk_sleep(rds_rs_to_sk(rs));
109 read_unlock_irqrestore(&rs->rs_recv_lock, flags);
110}
111
112static int rds_getname(struct socket *sock, struct sockaddr *uaddr,
113 int *uaddr_len, int peer)
114{
115 struct sockaddr_in *sin = (struct sockaddr_in *)uaddr;
116 struct rds_sock *rs = rds_sk_to_rs(sock->sk);
117
118 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
119
120 /* racey, don't care */
121 if (peer) {
122 if (!rs->rs_conn_addr)
123 return -ENOTCONN;
124
125 sin->sin_port = rs->rs_conn_port;
126 sin->sin_addr.s_addr = rs->rs_conn_addr;
127 } else {
128 sin->sin_port = rs->rs_bound_port;
129 sin->sin_addr.s_addr = rs->rs_bound_addr;
130 }
131
132 sin->sin_family = AF_INET;
133
134 *uaddr_len = sizeof(*sin);
135 return 0;
136}
137
138/*
139 * RDS' poll is without a doubt the least intuitive part of the interface,
140 * as POLLIN and POLLOUT do not behave entirely as you would expect from
141 * a network protocol.
142 *
143 * POLLIN is asserted if
144 * - there is data on the receive queue.
145 * - to signal that a previously congested destination may have become
146 * uncongested
147 * - A notification has been queued to the socket (this can be a congestion
148 * update, or a RDMA completion).
149 *
150 * POLLOUT is asserted if there is room on the send queue. This does not mean
151 * however, that the next sendmsg() call will succeed. If the application tries
152 * to send to a congested destination, the system call may still fail (and
153 * return ENOBUFS).
154 */
155static unsigned int rds_poll(struct file *file, struct socket *sock,
156 poll_table *wait)
157{
158 struct sock *sk = sock->sk;
159 struct rds_sock *rs = rds_sk_to_rs(sk);
160 unsigned int mask = 0;
161 unsigned long flags;
162
Eric Dumazetaa395142010-04-20 13:03:51 +0000163 poll_wait(file, sk_sleep(sk), wait);
Andy Grover639b3212009-02-24 15:30:18 +0000164
Andy Groverb98ba522010-03-11 13:50:04 +0000165 if (rs->rs_seen_congestion)
166 poll_wait(file, &rds_poll_waitq, wait);
Andy Grover639b3212009-02-24 15:30:18 +0000167
168 read_lock_irqsave(&rs->rs_recv_lock, flags);
169 if (!rs->rs_cong_monitor) {
170 /* When a congestion map was updated, we signal POLLIN for
171 * "historical" reasons. Applications can also poll for
172 * WRBAND instead. */
173 if (rds_cong_updated_since(&rs->rs_cong_track))
174 mask |= (POLLIN | POLLRDNORM | POLLWRBAND);
175 } else {
176 spin_lock(&rs->rs_lock);
177 if (rs->rs_cong_notify)
178 mask |= (POLLIN | POLLRDNORM);
179 spin_unlock(&rs->rs_lock);
180 }
Joe Perchesf64f9e72009-11-29 16:55:45 -0800181 if (!list_empty(&rs->rs_recv_queue) ||
182 !list_empty(&rs->rs_notify_queue))
Andy Grover639b3212009-02-24 15:30:18 +0000183 mask |= (POLLIN | POLLRDNORM);
184 if (rs->rs_snd_bytes < rds_sk_sndbuf(rs))
185 mask |= (POLLOUT | POLLWRNORM);
186 read_unlock_irqrestore(&rs->rs_recv_lock, flags);
187
Andy Groverb98ba522010-03-11 13:50:04 +0000188 /* clear state any time we wake a seen-congested socket */
189 if (mask)
190 rs->rs_seen_congestion = 0;
191
Andy Grover639b3212009-02-24 15:30:18 +0000192 return mask;
193}
194
195static int rds_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
196{
197 return -ENOIOCTLCMD;
198}
199
200static int rds_cancel_sent_to(struct rds_sock *rs, char __user *optval,
201 int len)
202{
203 struct sockaddr_in sin;
204 int ret = 0;
205
206 /* racing with another thread binding seems ok here */
207 if (rs->rs_bound_addr == 0) {
208 ret = -ENOTCONN; /* XXX not a great errno */
209 goto out;
210 }
211
212 if (len < sizeof(struct sockaddr_in)) {
213 ret = -EINVAL;
214 goto out;
215 }
216
217 if (copy_from_user(&sin, optval, sizeof(sin))) {
218 ret = -EFAULT;
219 goto out;
220 }
221
222 rds_send_drop_to(rs, &sin);
223out:
224 return ret;
225}
226
227static int rds_set_bool_option(unsigned char *optvar, char __user *optval,
228 int optlen)
229{
230 int value;
231
232 if (optlen < sizeof(int))
233 return -EINVAL;
234 if (get_user(value, (int __user *) optval))
235 return -EFAULT;
236 *optvar = !!value;
237 return 0;
238}
239
240static int rds_cong_monitor(struct rds_sock *rs, char __user *optval,
241 int optlen)
242{
243 int ret;
244
245 ret = rds_set_bool_option(&rs->rs_cong_monitor, optval, optlen);
246 if (ret == 0) {
247 if (rs->rs_cong_monitor) {
248 rds_cong_add_socket(rs);
249 } else {
250 rds_cong_remove_socket(rs);
251 rs->rs_cong_mask = 0;
252 rs->rs_cong_notify = 0;
253 }
254 }
255 return ret;
256}
257
Sowmini Varadhand97dac52015-05-29 17:28:08 -0400258static int rds_set_transport(struct rds_sock *rs, char __user *optval,
259 int optlen)
260{
261 int t_type;
262
263 if (rs->rs_transport)
264 return -EOPNOTSUPP; /* previously attached to transport */
265
266 if (optlen != sizeof(int))
267 return -EINVAL;
268
269 if (copy_from_user(&t_type, (int __user *)optval, sizeof(t_type)))
270 return -EFAULT;
271
272 if (t_type < 0 || t_type >= RDS_TRANS_COUNT)
273 return -EINVAL;
274
275 rs->rs_transport = rds_trans_get(t_type);
276
277 return rs->rs_transport ? 0 : -ENOPROTOOPT;
278}
279
santosh.shilimkar@oracle.com5711f8b2016-03-01 15:20:43 -0800280static int rds_enable_recvtstamp(struct sock *sk, char __user *optval,
281 int optlen)
282{
283 int val, valbool;
284
285 if (optlen != sizeof(int))
286 return -EFAULT;
287
288 if (get_user(val, (int __user *)optval))
289 return -EFAULT;
290
291 valbool = val ? 1 : 0;
292
293 if (valbool)
294 sock_set_flag(sk, SOCK_RCVTSTAMP);
295 else
296 sock_reset_flag(sk, SOCK_RCVTSTAMP);
297
298 return 0;
299}
300
Santosh Shilimkar32890252016-07-04 22:35:15 -0700301static int rds_recv_track_latency(struct rds_sock *rs, char __user *optval,
302 int optlen)
303{
304 struct rds_rx_trace_so trace;
305 int i;
306
307 if (optlen != sizeof(struct rds_rx_trace_so))
308 return -EFAULT;
309
310 if (copy_from_user(&trace, optval, sizeof(trace)))
311 return -EFAULT;
312
313 rs->rs_rx_traces = trace.rx_traces;
314 for (i = 0; i < rs->rs_rx_traces; i++) {
315 if (trace.rx_trace_pos[i] > RDS_MSG_RX_DGRAM_TRACE_MAX) {
316 rs->rs_rx_traces = 0;
317 return -EFAULT;
318 }
319 rs->rs_rx_trace[i] = trace.rx_trace_pos[i];
320 }
321
322 return 0;
323}
324
Andy Grover639b3212009-02-24 15:30:18 +0000325static int rds_setsockopt(struct socket *sock, int level, int optname,
David S. Millerb7058842009-09-30 16:12:20 -0700326 char __user *optval, unsigned int optlen)
Andy Grover639b3212009-02-24 15:30:18 +0000327{
328 struct rds_sock *rs = rds_sk_to_rs(sock->sk);
329 int ret;
330
331 if (level != SOL_RDS) {
332 ret = -ENOPROTOOPT;
333 goto out;
334 }
335
336 switch (optname) {
337 case RDS_CANCEL_SENT_TO:
338 ret = rds_cancel_sent_to(rs, optval, optlen);
339 break;
340 case RDS_GET_MR:
341 ret = rds_get_mr(rs, optval, optlen);
342 break;
Andy Grover244546f2009-10-30 08:54:53 +0000343 case RDS_GET_MR_FOR_DEST:
344 ret = rds_get_mr_for_dest(rs, optval, optlen);
345 break;
Andy Grover639b3212009-02-24 15:30:18 +0000346 case RDS_FREE_MR:
347 ret = rds_free_mr(rs, optval, optlen);
348 break;
349 case RDS_RECVERR:
350 ret = rds_set_bool_option(&rs->rs_recverr, optval, optlen);
351 break;
352 case RDS_CONG_MONITOR:
353 ret = rds_cong_monitor(rs, optval, optlen);
354 break;
Sowmini Varadhand97dac52015-05-29 17:28:08 -0400355 case SO_RDS_TRANSPORT:
356 lock_sock(sock->sk);
357 ret = rds_set_transport(rs, optval, optlen);
358 release_sock(sock->sk);
359 break;
santosh.shilimkar@oracle.com5711f8b2016-03-01 15:20:43 -0800360 case SO_TIMESTAMP:
361 lock_sock(sock->sk);
362 ret = rds_enable_recvtstamp(sock->sk, optval, optlen);
363 release_sock(sock->sk);
364 break;
Santosh Shilimkar32890252016-07-04 22:35:15 -0700365 case SO_RDS_MSG_RXPATH_LATENCY:
366 ret = rds_recv_track_latency(rs, optval, optlen);
367 break;
Andy Grover639b3212009-02-24 15:30:18 +0000368 default:
369 ret = -ENOPROTOOPT;
370 }
371out:
372 return ret;
373}
374
375static int rds_getsockopt(struct socket *sock, int level, int optname,
376 char __user *optval, int __user *optlen)
377{
378 struct rds_sock *rs = rds_sk_to_rs(sock->sk);
379 int ret = -ENOPROTOOPT, len;
Sowmini Varadhan8ba38462015-05-29 17:28:09 -0400380 int trans;
Andy Grover639b3212009-02-24 15:30:18 +0000381
382 if (level != SOL_RDS)
383 goto out;
384
385 if (get_user(len, optlen)) {
386 ret = -EFAULT;
387 goto out;
388 }
389
390 switch (optname) {
391 case RDS_INFO_FIRST ... RDS_INFO_LAST:
392 ret = rds_info_getsockopt(sock, optname, optval,
393 optlen);
394 break;
395
396 case RDS_RECVERR:
397 if (len < sizeof(int))
398 ret = -EINVAL;
399 else
Joe Perchesf64f9e72009-11-29 16:55:45 -0800400 if (put_user(rs->rs_recverr, (int __user *) optval) ||
401 put_user(sizeof(int), optlen))
Andy Grover639b3212009-02-24 15:30:18 +0000402 ret = -EFAULT;
403 else
404 ret = 0;
405 break;
Sowmini Varadhan8ba38462015-05-29 17:28:09 -0400406 case SO_RDS_TRANSPORT:
407 if (len < sizeof(int)) {
408 ret = -EINVAL;
409 break;
410 }
411 trans = (rs->rs_transport ? rs->rs_transport->t_type :
412 RDS_TRANS_NONE); /* unbound */
413 if (put_user(trans, (int __user *)optval) ||
414 put_user(sizeof(int), optlen))
415 ret = -EFAULT;
416 else
417 ret = 0;
418 break;
Andy Grover639b3212009-02-24 15:30:18 +0000419 default:
420 break;
421 }
422
423out:
424 return ret;
425
426}
427
428static int rds_connect(struct socket *sock, struct sockaddr *uaddr,
429 int addr_len, int flags)
430{
431 struct sock *sk = sock->sk;
432 struct sockaddr_in *sin = (struct sockaddr_in *)uaddr;
433 struct rds_sock *rs = rds_sk_to_rs(sk);
434 int ret = 0;
435
436 lock_sock(sk);
437
438 if (addr_len != sizeof(struct sockaddr_in)) {
439 ret = -EINVAL;
440 goto out;
441 }
442
443 if (sin->sin_family != AF_INET) {
444 ret = -EAFNOSUPPORT;
445 goto out;
446 }
447
448 if (sin->sin_addr.s_addr == htonl(INADDR_ANY)) {
449 ret = -EDESTADDRREQ;
450 goto out;
451 }
452
453 rs->rs_conn_addr = sin->sin_addr.s_addr;
454 rs->rs_conn_port = sin->sin_port;
455
456out:
457 release_sock(sk);
458 return ret;
459}
460
461static struct proto rds_proto = {
462 .name = "RDS",
463 .owner = THIS_MODULE,
464 .obj_size = sizeof(struct rds_sock),
465};
466
Alexey Dobriyan5708e862009-09-14 12:23:23 +0000467static const struct proto_ops rds_proto_ops = {
Andy Grover639b3212009-02-24 15:30:18 +0000468 .family = AF_RDS,
469 .owner = THIS_MODULE,
470 .release = rds_release,
471 .bind = rds_bind,
472 .connect = rds_connect,
473 .socketpair = sock_no_socketpair,
474 .accept = sock_no_accept,
475 .getname = rds_getname,
476 .poll = rds_poll,
477 .ioctl = rds_ioctl,
478 .listen = sock_no_listen,
479 .shutdown = sock_no_shutdown,
480 .setsockopt = rds_setsockopt,
481 .getsockopt = rds_getsockopt,
482 .sendmsg = rds_sendmsg,
483 .recvmsg = rds_recvmsg,
484 .mmap = sock_no_mmap,
485 .sendpage = sock_no_sendpage,
486};
487
santosh.shilimkar@oracle.com0df5f9a62015-08-22 15:45:28 -0700488static void rds_sock_destruct(struct sock *sk)
489{
490 struct rds_sock *rs = rds_sk_to_rs(sk);
491
492 WARN_ON((&rs->rs_item != rs->rs_item.next ||
493 &rs->rs_item != rs->rs_item.prev));
494}
495
Andy Grover639b3212009-02-24 15:30:18 +0000496static int __rds_create(struct socket *sock, struct sock *sk, int protocol)
497{
Andy Grover639b3212009-02-24 15:30:18 +0000498 struct rds_sock *rs;
499
500 sock_init_data(sock, sk);
501 sock->ops = &rds_proto_ops;
502 sk->sk_protocol = protocol;
santosh.shilimkar@oracle.com0df5f9a62015-08-22 15:45:28 -0700503 sk->sk_destruct = rds_sock_destruct;
Andy Grover639b3212009-02-24 15:30:18 +0000504
505 rs = rds_sk_to_rs(sk);
506 spin_lock_init(&rs->rs_lock);
507 rwlock_init(&rs->rs_recv_lock);
508 INIT_LIST_HEAD(&rs->rs_send_queue);
509 INIT_LIST_HEAD(&rs->rs_recv_queue);
510 INIT_LIST_HEAD(&rs->rs_notify_queue);
511 INIT_LIST_HEAD(&rs->rs_cong_list);
512 spin_lock_init(&rs->rs_rdma_lock);
513 rs->rs_rdma_keys = RB_ROOT;
Santosh Shilimkar32890252016-07-04 22:35:15 -0700514 rs->rs_rx_traces = 0;
Andy Grover639b3212009-02-24 15:30:18 +0000515
David S. Millerefc3dbc2012-01-24 17:03:44 -0500516 spin_lock_bh(&rds_sock_lock);
Andy Grover639b3212009-02-24 15:30:18 +0000517 list_add_tail(&rs->rs_item, &rds_sock_list);
518 rds_sock_count++;
David S. Millerefc3dbc2012-01-24 17:03:44 -0500519 spin_unlock_bh(&rds_sock_lock);
Andy Grover639b3212009-02-24 15:30:18 +0000520
521 return 0;
522}
523
Eric Paris3f378b62009-11-05 22:18:14 -0800524static int rds_create(struct net *net, struct socket *sock, int protocol,
525 int kern)
Andy Grover639b3212009-02-24 15:30:18 +0000526{
527 struct sock *sk;
528
529 if (sock->type != SOCK_SEQPACKET || protocol)
530 return -ESOCKTNOSUPPORT;
531
Eric W. Biederman11aa9c22015-05-08 21:09:13 -0500532 sk = sk_alloc(net, AF_RDS, GFP_ATOMIC, &rds_proto, kern);
Andy Grover639b3212009-02-24 15:30:18 +0000533 if (!sk)
534 return -ENOMEM;
535
536 return __rds_create(sock, sk, protocol);
537}
538
539void rds_sock_addref(struct rds_sock *rs)
540{
541 sock_hold(rds_rs_to_sk(rs));
542}
543
544void rds_sock_put(struct rds_sock *rs)
545{
546 sock_put(rds_rs_to_sk(rs));
547}
548
Stephen Hemmingerec1b4cf2009-10-05 05:58:39 +0000549static const struct net_proto_family rds_family_ops = {
Andy Grover639b3212009-02-24 15:30:18 +0000550 .family = AF_RDS,
551 .create = rds_create,
552 .owner = THIS_MODULE,
553};
554
555static void rds_sock_inc_info(struct socket *sock, unsigned int len,
556 struct rds_info_iterator *iter,
557 struct rds_info_lengths *lens)
558{
559 struct rds_sock *rs;
Andy Grover639b3212009-02-24 15:30:18 +0000560 struct rds_incoming *inc;
Andy Grover639b3212009-02-24 15:30:18 +0000561 unsigned int total = 0;
562
563 len /= sizeof(struct rds_info_message);
564
David S. Millerefc3dbc2012-01-24 17:03:44 -0500565 spin_lock_bh(&rds_sock_lock);
Andy Grover639b3212009-02-24 15:30:18 +0000566
567 list_for_each_entry(rs, &rds_sock_list, rs_item) {
Andy Grover639b3212009-02-24 15:30:18 +0000568 read_lock(&rs->rs_recv_lock);
569
570 /* XXX too lazy to maintain counts.. */
571 list_for_each_entry(inc, &rs->rs_recv_queue, i_item) {
572 total++;
573 if (total <= len)
574 rds_inc_info_copy(inc, iter, inc->i_saddr,
575 rs->rs_bound_addr, 1);
576 }
577
578 read_unlock(&rs->rs_recv_lock);
579 }
580
David S. Millerefc3dbc2012-01-24 17:03:44 -0500581 spin_unlock_bh(&rds_sock_lock);
Andy Grover639b3212009-02-24 15:30:18 +0000582
583 lens->nr = total;
584 lens->each = sizeof(struct rds_info_message);
585}
586
587static void rds_sock_info(struct socket *sock, unsigned int len,
588 struct rds_info_iterator *iter,
589 struct rds_info_lengths *lens)
590{
591 struct rds_info_socket sinfo;
592 struct rds_sock *rs;
Andy Grover639b3212009-02-24 15:30:18 +0000593
594 len /= sizeof(struct rds_info_socket);
595
David S. Millerefc3dbc2012-01-24 17:03:44 -0500596 spin_lock_bh(&rds_sock_lock);
Andy Grover639b3212009-02-24 15:30:18 +0000597
598 if (len < rds_sock_count)
599 goto out;
600
601 list_for_each_entry(rs, &rds_sock_list, rs_item) {
602 sinfo.sndbuf = rds_sk_sndbuf(rs);
603 sinfo.rcvbuf = rds_sk_rcvbuf(rs);
604 sinfo.bound_addr = rs->rs_bound_addr;
605 sinfo.connected_addr = rs->rs_conn_addr;
606 sinfo.bound_port = rs->rs_bound_port;
607 sinfo.connected_port = rs->rs_conn_port;
608 sinfo.inum = sock_i_ino(rds_rs_to_sk(rs));
609
610 rds_info_copy(iter, &sinfo, sizeof(sinfo));
611 }
612
613out:
614 lens->nr = rds_sock_count;
615 lens->each = sizeof(struct rds_info_socket);
616
David S. Millerefc3dbc2012-01-24 17:03:44 -0500617 spin_unlock_bh(&rds_sock_lock);
Andy Grover639b3212009-02-24 15:30:18 +0000618}
619
Zach Brownef87b7e2010-07-09 12:26:20 -0700620static void rds_exit(void)
Andy Grover639b3212009-02-24 15:30:18 +0000621{
Andy Grover639b3212009-02-24 15:30:18 +0000622 sock_unregister(rds_family_ops.family);
623 proto_unregister(&rds_proto);
624 rds_conn_exit();
625 rds_cong_exit();
626 rds_sysctl_exit();
627 rds_threads_exit();
628 rds_stats_exit();
629 rds_page_exit();
santosh.shilimkar@oracle.com7b565432015-10-30 08:49:10 -0700630 rds_bind_lock_destroy();
Andy Grover639b3212009-02-24 15:30:18 +0000631 rds_info_deregister_func(RDS_INFO_SOCKETS, rds_sock_info);
632 rds_info_deregister_func(RDS_INFO_RECV_MESSAGES, rds_sock_inc_info);
633}
634module_exit(rds_exit);
635
Sowmini Varadhan905dd412016-11-16 13:29:49 -0800636u32 rds_gen_num;
637
Zach Brownef87b7e2010-07-09 12:26:20 -0700638static int rds_init(void)
Andy Grover639b3212009-02-24 15:30:18 +0000639{
640 int ret;
641
Sowmini Varadhan905dd412016-11-16 13:29:49 -0800642 net_get_random_once(&rds_gen_num, sizeof(rds_gen_num));
643
santosh.shilimkar@oracle.com7b565432015-10-30 08:49:10 -0700644 ret = rds_bind_lock_init();
645 if (ret)
646 goto out;
Santosh Shilimkar9b9acde2014-02-11 19:34:25 -0800647
Andy Grover639b3212009-02-24 15:30:18 +0000648 ret = rds_conn_init();
649 if (ret)
santosh.shilimkar@oracle.com7b565432015-10-30 08:49:10 -0700650 goto out_bind;
651
Andy Grover639b3212009-02-24 15:30:18 +0000652 ret = rds_threads_init();
653 if (ret)
654 goto out_conn;
655 ret = rds_sysctl_init();
656 if (ret)
657 goto out_threads;
658 ret = rds_stats_init();
659 if (ret)
660 goto out_sysctl;
661 ret = proto_register(&rds_proto, 1);
662 if (ret)
663 goto out_stats;
664 ret = sock_register(&rds_family_ops);
665 if (ret)
666 goto out_proto;
667
668 rds_info_register_func(RDS_INFO_SOCKETS, rds_sock_info);
669 rds_info_register_func(RDS_INFO_RECV_MESSAGES, rds_sock_inc_info);
670
Andy Grover639b3212009-02-24 15:30:18 +0000671 goto out;
672
Andy Grover639b3212009-02-24 15:30:18 +0000673out_proto:
674 proto_unregister(&rds_proto);
675out_stats:
676 rds_stats_exit();
677out_sysctl:
678 rds_sysctl_exit();
679out_threads:
680 rds_threads_exit();
681out_conn:
682 rds_conn_exit();
683 rds_cong_exit();
684 rds_page_exit();
santosh.shilimkar@oracle.com7b565432015-10-30 08:49:10 -0700685out_bind:
686 rds_bind_lock_destroy();
Andy Grover639b3212009-02-24 15:30:18 +0000687out:
688 return ret;
689}
690module_init(rds_init);
691
692#define DRV_VERSION "4.0"
693#define DRV_RELDATE "Feb 12, 2009"
694
695MODULE_AUTHOR("Oracle Corporation <rds-devel@oss.oracle.com>");
696MODULE_DESCRIPTION("RDS: Reliable Datagram Sockets"
697 " v" DRV_VERSION " (" DRV_RELDATE ")");
698MODULE_VERSION(DRV_VERSION);
699MODULE_LICENSE("Dual BSD/GPL");
700MODULE_ALIAS_NETPROTO(PF_RDS);