Andy Grover | 639b321 | 2009-02-24 15:30:18 +0000 | [diff] [blame] | 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/module.h> |
| 34 | #include <linux/errno.h> |
| 35 | #include <linux/kernel.h> |
| 36 | #include <linux/in.h> |
| 37 | #include <linux/poll.h> |
Andy Grover | 639b321 | 2009-02-24 15:30:18 +0000 | [diff] [blame] | 38 | #include <net/sock.h> |
| 39 | |
| 40 | #include "rds.h" |
| 41 | #include "rdma.h" |
Andy Grover | 639b321 | 2009-02-24 15:30:18 +0000 | [diff] [blame] | 42 | |
| 43 | /* this is just used for stats gathering :/ */ |
| 44 | static DEFINE_SPINLOCK(rds_sock_lock); |
| 45 | static unsigned long rds_sock_count; |
| 46 | static LIST_HEAD(rds_sock_list); |
| 47 | DECLARE_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 | */ |
| 58 | static int rds_release(struct socket *sock) |
| 59 | { |
| 60 | struct sock *sk = sock->sk; |
| 61 | struct rds_sock *rs; |
| 62 | unsigned long flags; |
| 63 | |
| 64 | if (sk == NULL) |
| 65 | goto out; |
| 66 | |
| 67 | rs = rds_sk_to_rs(sk); |
| 68 | |
| 69 | sock_orphan(sk); |
| 70 | /* Note - rds_clear_recv_queue grabs rs_recv_lock, so |
| 71 | * that ensures the recv path has completed messing |
| 72 | * with the socket. */ |
| 73 | rds_clear_recv_queue(rs); |
| 74 | rds_cong_remove_socket(rs); |
| 75 | rds_remove_bound(rs); |
| 76 | rds_send_drop_to(rs, NULL); |
| 77 | rds_rdma_drop_keys(rs); |
| 78 | rds_notify_queue_get(rs, NULL); |
| 79 | |
| 80 | spin_lock_irqsave(&rds_sock_lock, flags); |
| 81 | list_del_init(&rs->rs_item); |
| 82 | rds_sock_count--; |
| 83 | spin_unlock_irqrestore(&rds_sock_lock, flags); |
| 84 | |
| 85 | sock->sk = NULL; |
| 86 | sock_put(sk); |
| 87 | out: |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | /* |
| 92 | * Careful not to race with rds_release -> sock_orphan which clears sk_sleep. |
| 93 | * _bh() isn't OK here, we're called from interrupt handlers. It's probably OK |
| 94 | * to wake the waitqueue after sk_sleep is clear as we hold a sock ref, but |
| 95 | * this seems more conservative. |
| 96 | * NB - normally, one would use sk_callback_lock for this, but we can |
| 97 | * get here from interrupts, whereas the network code grabs sk_callback_lock |
| 98 | * with _lock_bh only - so relying on sk_callback_lock introduces livelocks. |
| 99 | */ |
| 100 | void rds_wake_sk_sleep(struct rds_sock *rs) |
| 101 | { |
| 102 | unsigned long flags; |
| 103 | |
| 104 | read_lock_irqsave(&rs->rs_recv_lock, flags); |
| 105 | __rds_wake_sk_sleep(rds_rs_to_sk(rs)); |
| 106 | read_unlock_irqrestore(&rs->rs_recv_lock, flags); |
| 107 | } |
| 108 | |
| 109 | static int rds_getname(struct socket *sock, struct sockaddr *uaddr, |
| 110 | int *uaddr_len, int peer) |
| 111 | { |
| 112 | struct sockaddr_in *sin = (struct sockaddr_in *)uaddr; |
| 113 | struct rds_sock *rs = rds_sk_to_rs(sock->sk); |
| 114 | |
| 115 | memset(sin->sin_zero, 0, sizeof(sin->sin_zero)); |
| 116 | |
| 117 | /* racey, don't care */ |
| 118 | if (peer) { |
| 119 | if (!rs->rs_conn_addr) |
| 120 | return -ENOTCONN; |
| 121 | |
| 122 | sin->sin_port = rs->rs_conn_port; |
| 123 | sin->sin_addr.s_addr = rs->rs_conn_addr; |
| 124 | } else { |
| 125 | sin->sin_port = rs->rs_bound_port; |
| 126 | sin->sin_addr.s_addr = rs->rs_bound_addr; |
| 127 | } |
| 128 | |
| 129 | sin->sin_family = AF_INET; |
| 130 | |
| 131 | *uaddr_len = sizeof(*sin); |
| 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | /* |
| 136 | * RDS' poll is without a doubt the least intuitive part of the interface, |
| 137 | * as POLLIN and POLLOUT do not behave entirely as you would expect from |
| 138 | * a network protocol. |
| 139 | * |
| 140 | * POLLIN is asserted if |
| 141 | * - there is data on the receive queue. |
| 142 | * - to signal that a previously congested destination may have become |
| 143 | * uncongested |
| 144 | * - A notification has been queued to the socket (this can be a congestion |
| 145 | * update, or a RDMA completion). |
| 146 | * |
| 147 | * POLLOUT is asserted if there is room on the send queue. This does not mean |
| 148 | * however, that the next sendmsg() call will succeed. If the application tries |
| 149 | * to send to a congested destination, the system call may still fail (and |
| 150 | * return ENOBUFS). |
| 151 | */ |
| 152 | static unsigned int rds_poll(struct file *file, struct socket *sock, |
| 153 | poll_table *wait) |
| 154 | { |
| 155 | struct sock *sk = sock->sk; |
| 156 | struct rds_sock *rs = rds_sk_to_rs(sk); |
| 157 | unsigned int mask = 0; |
| 158 | unsigned long flags; |
| 159 | |
| 160 | poll_wait(file, sk->sk_sleep, wait); |
| 161 | |
| 162 | poll_wait(file, &rds_poll_waitq, wait); |
| 163 | |
| 164 | read_lock_irqsave(&rs->rs_recv_lock, flags); |
| 165 | if (!rs->rs_cong_monitor) { |
| 166 | /* When a congestion map was updated, we signal POLLIN for |
| 167 | * "historical" reasons. Applications can also poll for |
| 168 | * WRBAND instead. */ |
| 169 | if (rds_cong_updated_since(&rs->rs_cong_track)) |
| 170 | mask |= (POLLIN | POLLRDNORM | POLLWRBAND); |
| 171 | } else { |
| 172 | spin_lock(&rs->rs_lock); |
| 173 | if (rs->rs_cong_notify) |
| 174 | mask |= (POLLIN | POLLRDNORM); |
| 175 | spin_unlock(&rs->rs_lock); |
| 176 | } |
Joe Perches | f64f9e7 | 2009-11-29 16:55:45 -0800 | [diff] [blame^] | 177 | if (!list_empty(&rs->rs_recv_queue) || |
| 178 | !list_empty(&rs->rs_notify_queue)) |
Andy Grover | 639b321 | 2009-02-24 15:30:18 +0000 | [diff] [blame] | 179 | mask |= (POLLIN | POLLRDNORM); |
| 180 | if (rs->rs_snd_bytes < rds_sk_sndbuf(rs)) |
| 181 | mask |= (POLLOUT | POLLWRNORM); |
| 182 | read_unlock_irqrestore(&rs->rs_recv_lock, flags); |
| 183 | |
| 184 | return mask; |
| 185 | } |
| 186 | |
| 187 | static int rds_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) |
| 188 | { |
| 189 | return -ENOIOCTLCMD; |
| 190 | } |
| 191 | |
| 192 | static int rds_cancel_sent_to(struct rds_sock *rs, char __user *optval, |
| 193 | int len) |
| 194 | { |
| 195 | struct sockaddr_in sin; |
| 196 | int ret = 0; |
| 197 | |
| 198 | /* racing with another thread binding seems ok here */ |
| 199 | if (rs->rs_bound_addr == 0) { |
| 200 | ret = -ENOTCONN; /* XXX not a great errno */ |
| 201 | goto out; |
| 202 | } |
| 203 | |
| 204 | if (len < sizeof(struct sockaddr_in)) { |
| 205 | ret = -EINVAL; |
| 206 | goto out; |
| 207 | } |
| 208 | |
| 209 | if (copy_from_user(&sin, optval, sizeof(sin))) { |
| 210 | ret = -EFAULT; |
| 211 | goto out; |
| 212 | } |
| 213 | |
| 214 | rds_send_drop_to(rs, &sin); |
| 215 | out: |
| 216 | return ret; |
| 217 | } |
| 218 | |
| 219 | static int rds_set_bool_option(unsigned char *optvar, char __user *optval, |
| 220 | int optlen) |
| 221 | { |
| 222 | int value; |
| 223 | |
| 224 | if (optlen < sizeof(int)) |
| 225 | return -EINVAL; |
| 226 | if (get_user(value, (int __user *) optval)) |
| 227 | return -EFAULT; |
| 228 | *optvar = !!value; |
| 229 | return 0; |
| 230 | } |
| 231 | |
| 232 | static int rds_cong_monitor(struct rds_sock *rs, char __user *optval, |
| 233 | int optlen) |
| 234 | { |
| 235 | int ret; |
| 236 | |
| 237 | ret = rds_set_bool_option(&rs->rs_cong_monitor, optval, optlen); |
| 238 | if (ret == 0) { |
| 239 | if (rs->rs_cong_monitor) { |
| 240 | rds_cong_add_socket(rs); |
| 241 | } else { |
| 242 | rds_cong_remove_socket(rs); |
| 243 | rs->rs_cong_mask = 0; |
| 244 | rs->rs_cong_notify = 0; |
| 245 | } |
| 246 | } |
| 247 | return ret; |
| 248 | } |
| 249 | |
| 250 | static int rds_setsockopt(struct socket *sock, int level, int optname, |
David S. Miller | b705884 | 2009-09-30 16:12:20 -0700 | [diff] [blame] | 251 | char __user *optval, unsigned int optlen) |
Andy Grover | 639b321 | 2009-02-24 15:30:18 +0000 | [diff] [blame] | 252 | { |
| 253 | struct rds_sock *rs = rds_sk_to_rs(sock->sk); |
| 254 | int ret; |
| 255 | |
| 256 | if (level != SOL_RDS) { |
| 257 | ret = -ENOPROTOOPT; |
| 258 | goto out; |
| 259 | } |
| 260 | |
| 261 | switch (optname) { |
| 262 | case RDS_CANCEL_SENT_TO: |
| 263 | ret = rds_cancel_sent_to(rs, optval, optlen); |
| 264 | break; |
| 265 | case RDS_GET_MR: |
| 266 | ret = rds_get_mr(rs, optval, optlen); |
| 267 | break; |
Andy Grover | 244546f | 2009-10-30 08:54:53 +0000 | [diff] [blame] | 268 | case RDS_GET_MR_FOR_DEST: |
| 269 | ret = rds_get_mr_for_dest(rs, optval, optlen); |
| 270 | break; |
Andy Grover | 639b321 | 2009-02-24 15:30:18 +0000 | [diff] [blame] | 271 | case RDS_FREE_MR: |
| 272 | ret = rds_free_mr(rs, optval, optlen); |
| 273 | break; |
| 274 | case RDS_RECVERR: |
| 275 | ret = rds_set_bool_option(&rs->rs_recverr, optval, optlen); |
| 276 | break; |
| 277 | case RDS_CONG_MONITOR: |
| 278 | ret = rds_cong_monitor(rs, optval, optlen); |
| 279 | break; |
| 280 | default: |
| 281 | ret = -ENOPROTOOPT; |
| 282 | } |
| 283 | out: |
| 284 | return ret; |
| 285 | } |
| 286 | |
| 287 | static int rds_getsockopt(struct socket *sock, int level, int optname, |
| 288 | char __user *optval, int __user *optlen) |
| 289 | { |
| 290 | struct rds_sock *rs = rds_sk_to_rs(sock->sk); |
| 291 | int ret = -ENOPROTOOPT, len; |
| 292 | |
| 293 | if (level != SOL_RDS) |
| 294 | goto out; |
| 295 | |
| 296 | if (get_user(len, optlen)) { |
| 297 | ret = -EFAULT; |
| 298 | goto out; |
| 299 | } |
| 300 | |
| 301 | switch (optname) { |
| 302 | case RDS_INFO_FIRST ... RDS_INFO_LAST: |
| 303 | ret = rds_info_getsockopt(sock, optname, optval, |
| 304 | optlen); |
| 305 | break; |
| 306 | |
| 307 | case RDS_RECVERR: |
| 308 | if (len < sizeof(int)) |
| 309 | ret = -EINVAL; |
| 310 | else |
Joe Perches | f64f9e7 | 2009-11-29 16:55:45 -0800 | [diff] [blame^] | 311 | if (put_user(rs->rs_recverr, (int __user *) optval) || |
| 312 | put_user(sizeof(int), optlen)) |
Andy Grover | 639b321 | 2009-02-24 15:30:18 +0000 | [diff] [blame] | 313 | ret = -EFAULT; |
| 314 | else |
| 315 | ret = 0; |
| 316 | break; |
| 317 | default: |
| 318 | break; |
| 319 | } |
| 320 | |
| 321 | out: |
| 322 | return ret; |
| 323 | |
| 324 | } |
| 325 | |
| 326 | static int rds_connect(struct socket *sock, struct sockaddr *uaddr, |
| 327 | int addr_len, int flags) |
| 328 | { |
| 329 | struct sock *sk = sock->sk; |
| 330 | struct sockaddr_in *sin = (struct sockaddr_in *)uaddr; |
| 331 | struct rds_sock *rs = rds_sk_to_rs(sk); |
| 332 | int ret = 0; |
| 333 | |
| 334 | lock_sock(sk); |
| 335 | |
| 336 | if (addr_len != sizeof(struct sockaddr_in)) { |
| 337 | ret = -EINVAL; |
| 338 | goto out; |
| 339 | } |
| 340 | |
| 341 | if (sin->sin_family != AF_INET) { |
| 342 | ret = -EAFNOSUPPORT; |
| 343 | goto out; |
| 344 | } |
| 345 | |
| 346 | if (sin->sin_addr.s_addr == htonl(INADDR_ANY)) { |
| 347 | ret = -EDESTADDRREQ; |
| 348 | goto out; |
| 349 | } |
| 350 | |
| 351 | rs->rs_conn_addr = sin->sin_addr.s_addr; |
| 352 | rs->rs_conn_port = sin->sin_port; |
| 353 | |
| 354 | out: |
| 355 | release_sock(sk); |
| 356 | return ret; |
| 357 | } |
| 358 | |
| 359 | static struct proto rds_proto = { |
| 360 | .name = "RDS", |
| 361 | .owner = THIS_MODULE, |
| 362 | .obj_size = sizeof(struct rds_sock), |
| 363 | }; |
| 364 | |
Alexey Dobriyan | 5708e86 | 2009-09-14 12:23:23 +0000 | [diff] [blame] | 365 | static const struct proto_ops rds_proto_ops = { |
Andy Grover | 639b321 | 2009-02-24 15:30:18 +0000 | [diff] [blame] | 366 | .family = AF_RDS, |
| 367 | .owner = THIS_MODULE, |
| 368 | .release = rds_release, |
| 369 | .bind = rds_bind, |
| 370 | .connect = rds_connect, |
| 371 | .socketpair = sock_no_socketpair, |
| 372 | .accept = sock_no_accept, |
| 373 | .getname = rds_getname, |
| 374 | .poll = rds_poll, |
| 375 | .ioctl = rds_ioctl, |
| 376 | .listen = sock_no_listen, |
| 377 | .shutdown = sock_no_shutdown, |
| 378 | .setsockopt = rds_setsockopt, |
| 379 | .getsockopt = rds_getsockopt, |
| 380 | .sendmsg = rds_sendmsg, |
| 381 | .recvmsg = rds_recvmsg, |
| 382 | .mmap = sock_no_mmap, |
| 383 | .sendpage = sock_no_sendpage, |
| 384 | }; |
| 385 | |
| 386 | static int __rds_create(struct socket *sock, struct sock *sk, int protocol) |
| 387 | { |
| 388 | unsigned long flags; |
| 389 | struct rds_sock *rs; |
| 390 | |
| 391 | sock_init_data(sock, sk); |
| 392 | sock->ops = &rds_proto_ops; |
| 393 | sk->sk_protocol = protocol; |
| 394 | |
| 395 | rs = rds_sk_to_rs(sk); |
| 396 | spin_lock_init(&rs->rs_lock); |
| 397 | rwlock_init(&rs->rs_recv_lock); |
| 398 | INIT_LIST_HEAD(&rs->rs_send_queue); |
| 399 | INIT_LIST_HEAD(&rs->rs_recv_queue); |
| 400 | INIT_LIST_HEAD(&rs->rs_notify_queue); |
| 401 | INIT_LIST_HEAD(&rs->rs_cong_list); |
| 402 | spin_lock_init(&rs->rs_rdma_lock); |
| 403 | rs->rs_rdma_keys = RB_ROOT; |
| 404 | |
| 405 | spin_lock_irqsave(&rds_sock_lock, flags); |
| 406 | list_add_tail(&rs->rs_item, &rds_sock_list); |
| 407 | rds_sock_count++; |
| 408 | spin_unlock_irqrestore(&rds_sock_lock, flags); |
| 409 | |
| 410 | return 0; |
| 411 | } |
| 412 | |
Eric Paris | 3f378b6 | 2009-11-05 22:18:14 -0800 | [diff] [blame] | 413 | static int rds_create(struct net *net, struct socket *sock, int protocol, |
| 414 | int kern) |
Andy Grover | 639b321 | 2009-02-24 15:30:18 +0000 | [diff] [blame] | 415 | { |
| 416 | struct sock *sk; |
| 417 | |
| 418 | if (sock->type != SOCK_SEQPACKET || protocol) |
| 419 | return -ESOCKTNOSUPPORT; |
| 420 | |
| 421 | sk = sk_alloc(net, AF_RDS, GFP_ATOMIC, &rds_proto); |
| 422 | if (!sk) |
| 423 | return -ENOMEM; |
| 424 | |
| 425 | return __rds_create(sock, sk, protocol); |
| 426 | } |
| 427 | |
| 428 | void rds_sock_addref(struct rds_sock *rs) |
| 429 | { |
| 430 | sock_hold(rds_rs_to_sk(rs)); |
| 431 | } |
| 432 | |
| 433 | void rds_sock_put(struct rds_sock *rs) |
| 434 | { |
| 435 | sock_put(rds_rs_to_sk(rs)); |
| 436 | } |
| 437 | |
Stephen Hemminger | ec1b4cf | 2009-10-05 05:58:39 +0000 | [diff] [blame] | 438 | static const struct net_proto_family rds_family_ops = { |
Andy Grover | 639b321 | 2009-02-24 15:30:18 +0000 | [diff] [blame] | 439 | .family = AF_RDS, |
| 440 | .create = rds_create, |
| 441 | .owner = THIS_MODULE, |
| 442 | }; |
| 443 | |
| 444 | static void rds_sock_inc_info(struct socket *sock, unsigned int len, |
| 445 | struct rds_info_iterator *iter, |
| 446 | struct rds_info_lengths *lens) |
| 447 | { |
| 448 | struct rds_sock *rs; |
| 449 | struct sock *sk; |
| 450 | struct rds_incoming *inc; |
| 451 | unsigned long flags; |
| 452 | unsigned int total = 0; |
| 453 | |
| 454 | len /= sizeof(struct rds_info_message); |
| 455 | |
| 456 | spin_lock_irqsave(&rds_sock_lock, flags); |
| 457 | |
| 458 | list_for_each_entry(rs, &rds_sock_list, rs_item) { |
| 459 | sk = rds_rs_to_sk(rs); |
| 460 | read_lock(&rs->rs_recv_lock); |
| 461 | |
| 462 | /* XXX too lazy to maintain counts.. */ |
| 463 | list_for_each_entry(inc, &rs->rs_recv_queue, i_item) { |
| 464 | total++; |
| 465 | if (total <= len) |
| 466 | rds_inc_info_copy(inc, iter, inc->i_saddr, |
| 467 | rs->rs_bound_addr, 1); |
| 468 | } |
| 469 | |
| 470 | read_unlock(&rs->rs_recv_lock); |
| 471 | } |
| 472 | |
| 473 | spin_unlock_irqrestore(&rds_sock_lock, flags); |
| 474 | |
| 475 | lens->nr = total; |
| 476 | lens->each = sizeof(struct rds_info_message); |
| 477 | } |
| 478 | |
| 479 | static void rds_sock_info(struct socket *sock, unsigned int len, |
| 480 | struct rds_info_iterator *iter, |
| 481 | struct rds_info_lengths *lens) |
| 482 | { |
| 483 | struct rds_info_socket sinfo; |
| 484 | struct rds_sock *rs; |
| 485 | unsigned long flags; |
| 486 | |
| 487 | len /= sizeof(struct rds_info_socket); |
| 488 | |
| 489 | spin_lock_irqsave(&rds_sock_lock, flags); |
| 490 | |
| 491 | if (len < rds_sock_count) |
| 492 | goto out; |
| 493 | |
| 494 | list_for_each_entry(rs, &rds_sock_list, rs_item) { |
| 495 | sinfo.sndbuf = rds_sk_sndbuf(rs); |
| 496 | sinfo.rcvbuf = rds_sk_rcvbuf(rs); |
| 497 | sinfo.bound_addr = rs->rs_bound_addr; |
| 498 | sinfo.connected_addr = rs->rs_conn_addr; |
| 499 | sinfo.bound_port = rs->rs_bound_port; |
| 500 | sinfo.connected_port = rs->rs_conn_port; |
| 501 | sinfo.inum = sock_i_ino(rds_rs_to_sk(rs)); |
| 502 | |
| 503 | rds_info_copy(iter, &sinfo, sizeof(sinfo)); |
| 504 | } |
| 505 | |
| 506 | out: |
| 507 | lens->nr = rds_sock_count; |
| 508 | lens->each = sizeof(struct rds_info_socket); |
| 509 | |
| 510 | spin_unlock_irqrestore(&rds_sock_lock, flags); |
| 511 | } |
| 512 | |
| 513 | static void __exit rds_exit(void) |
| 514 | { |
Andy Grover | 639b321 | 2009-02-24 15:30:18 +0000 | [diff] [blame] | 515 | sock_unregister(rds_family_ops.family); |
| 516 | proto_unregister(&rds_proto); |
| 517 | rds_conn_exit(); |
| 518 | rds_cong_exit(); |
| 519 | rds_sysctl_exit(); |
| 520 | rds_threads_exit(); |
| 521 | rds_stats_exit(); |
| 522 | rds_page_exit(); |
| 523 | rds_info_deregister_func(RDS_INFO_SOCKETS, rds_sock_info); |
| 524 | rds_info_deregister_func(RDS_INFO_RECV_MESSAGES, rds_sock_inc_info); |
| 525 | } |
| 526 | module_exit(rds_exit); |
| 527 | |
| 528 | static int __init rds_init(void) |
| 529 | { |
| 530 | int ret; |
| 531 | |
| 532 | ret = rds_conn_init(); |
| 533 | if (ret) |
| 534 | goto out; |
| 535 | ret = rds_threads_init(); |
| 536 | if (ret) |
| 537 | goto out_conn; |
| 538 | ret = rds_sysctl_init(); |
| 539 | if (ret) |
| 540 | goto out_threads; |
| 541 | ret = rds_stats_init(); |
| 542 | if (ret) |
| 543 | goto out_sysctl; |
| 544 | ret = proto_register(&rds_proto, 1); |
| 545 | if (ret) |
| 546 | goto out_stats; |
| 547 | ret = sock_register(&rds_family_ops); |
| 548 | if (ret) |
| 549 | goto out_proto; |
| 550 | |
| 551 | rds_info_register_func(RDS_INFO_SOCKETS, rds_sock_info); |
| 552 | rds_info_register_func(RDS_INFO_RECV_MESSAGES, rds_sock_inc_info); |
| 553 | |
Andy Grover | 639b321 | 2009-02-24 15:30:18 +0000 | [diff] [blame] | 554 | goto out; |
| 555 | |
Andy Grover | 639b321 | 2009-02-24 15:30:18 +0000 | [diff] [blame] | 556 | out_proto: |
| 557 | proto_unregister(&rds_proto); |
| 558 | out_stats: |
| 559 | rds_stats_exit(); |
| 560 | out_sysctl: |
| 561 | rds_sysctl_exit(); |
| 562 | out_threads: |
| 563 | rds_threads_exit(); |
| 564 | out_conn: |
| 565 | rds_conn_exit(); |
| 566 | rds_cong_exit(); |
| 567 | rds_page_exit(); |
| 568 | out: |
| 569 | return ret; |
| 570 | } |
| 571 | module_init(rds_init); |
| 572 | |
| 573 | #define DRV_VERSION "4.0" |
| 574 | #define DRV_RELDATE "Feb 12, 2009" |
| 575 | |
| 576 | MODULE_AUTHOR("Oracle Corporation <rds-devel@oss.oracle.com>"); |
| 577 | MODULE_DESCRIPTION("RDS: Reliable Datagram Sockets" |
| 578 | " v" DRV_VERSION " (" DRV_RELDATE ")"); |
| 579 | MODULE_VERSION(DRV_VERSION); |
| 580 | MODULE_LICENSE("Dual BSD/GPL"); |
| 581 | MODULE_ALIAS_NETPROTO(PF_RDS); |