4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lnet/klnds/socklnd/socklnd.c
34 * Author: Zach Brown <zab@zabbo.net>
35 * Author: Peter J. Braam <braam@clusterfs.com>
36 * Author: Phil Schwan <phil@clusterfs.com>
37 * Author: Eric Barton <eric@bartonsoftware.com>
40 #include <linux/inetdevice.h>
42 #include <linux/sunrpc/addr.h>
44 static const struct lnet_lnd the_ksocklnd;
45 struct ksock_nal_data ksocknal_data;
47 static struct ksock_interface *
48 ksocknal_ip2iface(struct lnet_ni *ni, struct sockaddr *addr)
50 struct ksock_net *net = ni->ni_data;
51 struct ksock_interface *iface;
53 iface = &net->ksnn_interface;
55 if (rpc_cmp_addr((struct sockaddr *)&iface->ksni_addr, addr))
61 static struct ksock_interface *
62 ksocknal_index2iface(struct lnet_ni *ni, int index)
64 struct ksock_net *net = ni->ni_data;
65 struct ksock_interface *iface;
67 iface = &net->ksnn_interface;
69 if (iface->ksni_index == index)
75 static int ksocknal_ip2index(struct sockaddr *addr, struct lnet_ni *ni)
77 struct net_device *dev;
79 DECLARE_CONST_IN_IFADDR(ifa);
81 if (addr->sa_family != AF_INET)
82 /* No IPv6 support yet */
86 for_each_netdev(ni->ni_net_ns, dev) {
87 int flags = dev_get_flags(dev);
88 struct in_device *in_dev;
90 if (flags & IFF_LOOPBACK) /* skip the loopback IF */
93 if (!(flags & IFF_UP))
96 in_dev = __in_dev_get_rcu(dev);
100 in_dev_for_each_ifa_rcu(ifa, in_dev) {
101 if (ifa->ifa_local ==
102 ((struct sockaddr_in *)addr)->sin_addr.s_addr)
114 static struct ksock_route *
115 ksocknal_create_route(struct sockaddr *addr)
117 struct ksock_route *route;
119 LIBCFS_ALLOC (route, sizeof (*route));
123 refcount_set(&route->ksnr_refcount, 1);
124 route->ksnr_peer = NULL;
125 route->ksnr_retry_interval = 0; /* OK to connect at any time */
126 rpc_copy_addr((struct sockaddr *)&route->ksnr_addr, addr);
127 rpc_set_port((struct sockaddr *)&route->ksnr_addr, rpc_get_port(addr));
128 route->ksnr_myiface = -1;
129 route->ksnr_scheduled = 0;
130 route->ksnr_connecting = 0;
131 route->ksnr_connected = 0;
132 route->ksnr_deleted = 0;
133 route->ksnr_conn_count = 0;
134 route->ksnr_share_count = 0;
140 ksocknal_destroy_route(struct ksock_route *route)
142 LASSERT(refcount_read(&route->ksnr_refcount) == 0);
144 if (route->ksnr_peer != NULL)
145 ksocknal_peer_decref(route->ksnr_peer);
147 LIBCFS_FREE (route, sizeof (*route));
150 static struct ksock_peer_ni *
151 ksocknal_create_peer(struct lnet_ni *ni, struct lnet_process_id id)
153 int cpt = lnet_cpt_of_nid(id.nid, ni);
154 struct ksock_net *net = ni->ni_data;
155 struct ksock_peer_ni *peer_ni;
157 LASSERT(id.nid != LNET_NID_ANY);
158 LASSERT(id.pid != LNET_PID_ANY);
159 LASSERT(!in_interrupt());
161 if (!atomic_inc_unless_negative(&net->ksnn_npeers)) {
162 CERROR("Can't create peer_ni: network shutdown\n");
163 return ERR_PTR(-ESHUTDOWN);
166 LIBCFS_CPT_ALLOC(peer_ni, lnet_cpt_table(), cpt, sizeof(*peer_ni));
168 atomic_dec(&net->ksnn_npeers);
169 return ERR_PTR(-ENOMEM);
172 peer_ni->ksnp_ni = ni;
173 peer_ni->ksnp_id = id;
174 refcount_set(&peer_ni->ksnp_refcount, 1); /* 1 ref for caller */
175 peer_ni->ksnp_closing = 0;
176 peer_ni->ksnp_accepting = 0;
177 peer_ni->ksnp_proto = NULL;
178 peer_ni->ksnp_last_alive = 0;
179 peer_ni->ksnp_zc_next_cookie = SOCKNAL_KEEPALIVE_PING + 1;
181 INIT_LIST_HEAD(&peer_ni->ksnp_conns);
182 INIT_LIST_HEAD(&peer_ni->ksnp_routes);
183 INIT_LIST_HEAD(&peer_ni->ksnp_tx_queue);
184 INIT_LIST_HEAD(&peer_ni->ksnp_zc_req_list);
185 spin_lock_init(&peer_ni->ksnp_lock);
191 ksocknal_destroy_peer(struct ksock_peer_ni *peer_ni)
193 struct ksock_net *net = peer_ni->ksnp_ni->ni_data;
195 CDEBUG (D_NET, "peer_ni %s %p deleted\n",
196 libcfs_id2str(peer_ni->ksnp_id), peer_ni);
198 LASSERT(refcount_read(&peer_ni->ksnp_refcount) == 0);
199 LASSERT(peer_ni->ksnp_accepting == 0);
200 LASSERT(list_empty(&peer_ni->ksnp_conns));
201 LASSERT(list_empty(&peer_ni->ksnp_routes));
202 LASSERT(list_empty(&peer_ni->ksnp_tx_queue));
203 LASSERT(list_empty(&peer_ni->ksnp_zc_req_list));
205 LIBCFS_FREE(peer_ni, sizeof(*peer_ni));
207 /* NB a peer_ni's connections and routes keep a reference on their
208 * peer_ni until they are destroyed, so we can be assured that _all_
209 * state to do with this peer_ni has been cleaned up when its refcount
212 if (atomic_dec_and_test(&net->ksnn_npeers))
213 wake_up_var(&net->ksnn_npeers);
216 struct ksock_peer_ni *
217 ksocknal_find_peer_locked(struct lnet_ni *ni, struct lnet_process_id id)
219 struct ksock_peer_ni *peer_ni;
221 hash_for_each_possible(ksocknal_data.ksnd_peers, peer_ni,
223 LASSERT(!peer_ni->ksnp_closing);
225 if (peer_ni->ksnp_ni != ni)
228 if (peer_ni->ksnp_id.nid != id.nid ||
229 peer_ni->ksnp_id.pid != id.pid)
232 CDEBUG(D_NET, "got peer_ni [%p] -> %s (%d)\n",
233 peer_ni, libcfs_id2str(id),
234 refcount_read(&peer_ni->ksnp_refcount));
240 struct ksock_peer_ni *
241 ksocknal_find_peer(struct lnet_ni *ni, struct lnet_process_id id)
243 struct ksock_peer_ni *peer_ni;
245 read_lock(&ksocknal_data.ksnd_global_lock);
246 peer_ni = ksocknal_find_peer_locked(ni, id);
247 if (peer_ni != NULL) /* +1 ref for caller? */
248 ksocknal_peer_addref(peer_ni);
249 read_unlock(&ksocknal_data.ksnd_global_lock);
255 ksocknal_unlink_peer_locked(struct ksock_peer_ni *peer_ni)
258 struct ksock_interface *iface;
260 for (i = 0; i < peer_ni->ksnp_n_passive_ips; i++) {
261 struct sockaddr_in sa = { .sin_family = AF_INET };
262 LASSERT(i < LNET_INTERFACES_NUM);
263 sa.sin_addr.s_addr = htonl(peer_ni->ksnp_passive_ips[i]);
265 iface = ksocknal_ip2iface(peer_ni->ksnp_ni,
266 (struct sockaddr *)&sa);
268 * All IPs in peer_ni->ksnp_passive_ips[] come from the
269 * interface list, therefore the call must succeed.
271 LASSERT(iface != NULL);
273 CDEBUG(D_NET, "peer_ni=%p iface=%p ksni_nroutes=%d\n",
274 peer_ni, iface, iface->ksni_nroutes);
275 iface->ksni_npeers--;
278 LASSERT(list_empty(&peer_ni->ksnp_conns));
279 LASSERT(list_empty(&peer_ni->ksnp_routes));
280 LASSERT(!peer_ni->ksnp_closing);
281 peer_ni->ksnp_closing = 1;
282 hlist_del(&peer_ni->ksnp_list);
283 /* lose peerlist's ref */
284 ksocknal_peer_decref(peer_ni);
288 ksocknal_get_peer_info(struct lnet_ni *ni, int index,
289 struct lnet_process_id *id, __u32 *myip, __u32 *peer_ip,
290 int *port, int *conn_count, int *share_count)
292 struct ksock_peer_ni *peer_ni;
293 struct ksock_route *route;
294 struct list_head *rtmp;
299 read_lock(&ksocknal_data.ksnd_global_lock);
301 hash_for_each(ksocknal_data.ksnd_peers, i, peer_ni, ksnp_list) {
303 if (peer_ni->ksnp_ni != ni)
306 if (peer_ni->ksnp_n_passive_ips == 0 &&
307 list_empty(&peer_ni->ksnp_routes)) {
311 *id = peer_ni->ksnp_id;
321 for (j = 0; j < peer_ni->ksnp_n_passive_ips; j++) {
325 *id = peer_ni->ksnp_id;
326 *myip = peer_ni->ksnp_passive_ips[j];
335 list_for_each(rtmp, &peer_ni->ksnp_routes) {
339 route = list_entry(rtmp, struct ksock_route,
342 *id = peer_ni->ksnp_id;
343 if (route->ksnr_addr.ss_family == AF_INET) {
344 struct sockaddr_in *sa =
345 (void *)&route->ksnr_addr;
346 rc = choose_ipv4_src(
349 ntohl(sa->sin_addr.s_addr),
351 *peer_ip = ntohl(sa->sin_addr.s_addr);
352 *port = ntohs(sa->sin_port);
355 *peer_ip = 0xFFFFFFFF;
359 *conn_count = route->ksnr_conn_count;
360 *share_count = route->ksnr_share_count;
365 read_unlock(&ksocknal_data.ksnd_global_lock);
370 ksocknal_associate_route_conn_locked(struct ksock_route *route,
371 struct ksock_conn *conn)
373 struct ksock_peer_ni *peer_ni = route->ksnr_peer;
374 int type = conn->ksnc_type;
375 struct ksock_interface *iface;
377 ksocknal_ip2index((struct sockaddr *)&conn->ksnc_myaddr,
378 route->ksnr_peer->ksnp_ni);
380 conn->ksnc_route = route;
381 ksocknal_route_addref(route);
383 if (route->ksnr_myiface != conn_iface) {
384 if (route->ksnr_myiface < 0) {
385 /* route wasn't bound locally yet (the initial route) */
386 CDEBUG(D_NET, "Binding %s %pIS to interface %d\n",
387 libcfs_id2str(peer_ni->ksnp_id),
392 "Rebinding %s %pIS from interface %d to %d\n",
393 libcfs_id2str(peer_ni->ksnp_id),
398 iface = ksocknal_index2iface(route->ksnr_peer->ksnp_ni,
399 route->ksnr_myiface);
401 iface->ksni_nroutes--;
403 route->ksnr_myiface = conn_iface;
404 iface = ksocknal_index2iface(route->ksnr_peer->ksnp_ni,
405 route->ksnr_myiface);
407 iface->ksni_nroutes++;
410 route->ksnr_connected |= (1<<type);
411 route->ksnr_conn_count++;
413 /* Successful connection => further attempts can
414 * proceed immediately
416 route->ksnr_retry_interval = 0;
420 ksocknal_add_route_locked(struct ksock_peer_ni *peer_ni, struct ksock_route *route)
422 struct list_head *tmp;
423 struct ksock_conn *conn;
424 struct ksock_route *route2;
425 struct ksock_net *net = peer_ni->ksnp_ni->ni_data;
427 LASSERT(!peer_ni->ksnp_closing);
428 LASSERT(route->ksnr_peer == NULL);
429 LASSERT(!route->ksnr_scheduled);
430 LASSERT(!route->ksnr_connecting);
431 LASSERT(route->ksnr_connected == 0);
433 /* LASSERT(unique) */
434 list_for_each(tmp, &peer_ni->ksnp_routes) {
435 route2 = list_entry(tmp, struct ksock_route, ksnr_list);
437 if (rpc_cmp_addr((struct sockaddr *)&route2->ksnr_addr,
438 (struct sockaddr *)&route->ksnr_addr)) {
439 CERROR("Duplicate route %s %pI4h\n",
440 libcfs_id2str(peer_ni->ksnp_id),
446 route->ksnr_peer = peer_ni;
447 ksocknal_peer_addref(peer_ni);
449 /* set the route's interface to the current net's interface */
450 route->ksnr_myiface = net->ksnn_interface.ksni_index;
451 net->ksnn_interface.ksni_nroutes++;
453 /* peer_ni's routelist takes over my ref on 'route' */
454 list_add_tail(&route->ksnr_list, &peer_ni->ksnp_routes);
456 list_for_each(tmp, &peer_ni->ksnp_conns) {
457 conn = list_entry(tmp, struct ksock_conn, ksnc_list);
459 if (!rpc_cmp_addr((struct sockaddr *)&conn->ksnc_peeraddr,
460 (struct sockaddr *)&route->ksnr_addr))
463 ksocknal_associate_route_conn_locked(route, conn);
464 /* keep going (typed routes) */
469 ksocknal_del_route_locked(struct ksock_route *route)
471 struct ksock_peer_ni *peer_ni = route->ksnr_peer;
472 struct ksock_interface *iface;
473 struct ksock_conn *conn;
474 struct ksock_conn *cnxt;
476 LASSERT(!route->ksnr_deleted);
478 /* Close associated conns */
479 list_for_each_entry_safe(conn, cnxt, &peer_ni->ksnp_conns, ksnc_list) {
480 if (conn->ksnc_route != route)
483 ksocknal_close_conn_locked(conn, 0);
486 if (route->ksnr_myiface >= 0) {
487 iface = ksocknal_index2iface(route->ksnr_peer->ksnp_ni,
488 route->ksnr_myiface);
490 iface->ksni_nroutes--;
493 route->ksnr_deleted = 1;
494 list_del(&route->ksnr_list);
495 ksocknal_route_decref(route); /* drop peer_ni's ref */
497 if (list_empty(&peer_ni->ksnp_routes) &&
498 list_empty(&peer_ni->ksnp_conns)) {
499 /* I've just removed the last route to a peer_ni with no active
501 ksocknal_unlink_peer_locked(peer_ni);
506 ksocknal_add_peer(struct lnet_ni *ni, struct lnet_process_id id,
507 struct sockaddr *addr)
509 struct list_head *tmp;
510 struct ksock_peer_ni *peer_ni;
511 struct ksock_peer_ni *peer2;
512 struct ksock_route *route;
513 struct ksock_route *route2;
515 if (id.nid == LNET_NID_ANY ||
516 id.pid == LNET_PID_ANY)
519 /* Have a brand new peer_ni ready... */
520 peer_ni = ksocknal_create_peer(ni, id);
522 return PTR_ERR(peer_ni);
524 route = ksocknal_create_route(addr);
526 ksocknal_peer_decref(peer_ni);
530 write_lock_bh(&ksocknal_data.ksnd_global_lock);
532 /* always called with a ref on ni, so shutdown can't have started */
533 LASSERT(atomic_read(&((struct ksock_net *)ni->ni_data)->ksnn_npeers)
536 peer2 = ksocknal_find_peer_locked(ni, id);
538 ksocknal_peer_decref(peer_ni);
541 /* peer_ni table takes my ref on peer_ni */
542 hash_add(ksocknal_data.ksnd_peers, &peer_ni->ksnp_list, id.nid);
546 list_for_each(tmp, &peer_ni->ksnp_routes) {
547 route2 = list_entry(tmp, struct ksock_route, ksnr_list);
549 if (rpc_cmp_addr(addr, (struct sockaddr *)&route2->ksnr_addr))
554 if (route2 == NULL) {
555 ksocknal_add_route_locked(peer_ni, route);
556 route->ksnr_share_count++;
558 ksocknal_route_decref(route);
559 route2->ksnr_share_count++;
562 write_unlock_bh(&ksocknal_data.ksnd_global_lock);
568 ksocknal_del_peer_locked(struct ksock_peer_ni *peer_ni, __u32 ip)
570 struct ksock_conn *conn;
571 struct ksock_conn *cnxt;
572 struct ksock_route *route;
573 struct ksock_route *rnxt;
576 LASSERT(!peer_ni->ksnp_closing);
578 /* Extra ref prevents peer_ni disappearing until I'm done with it */
579 ksocknal_peer_addref(peer_ni);
581 list_for_each_entry_safe(route, rnxt, &peer_ni->ksnp_routes,
585 if (route->ksnr_addr.ss_family != AF_INET)
587 if (((struct sockaddr_in *)&route->ksnr_addr)
588 ->sin_addr.s_addr != htonl(ip))
592 route->ksnr_share_count = 0;
593 /* This deletes associated conns too */
594 ksocknal_del_route_locked(route);
598 list_for_each_entry(route, &peer_ni->ksnp_routes, ksnr_list)
599 nshared += route->ksnr_share_count;
602 /* remove everything else if there are no explicit entries
605 list_for_each_entry_safe(route, rnxt, &peer_ni->ksnp_routes,
607 /* we should only be removing auto-entries */
608 LASSERT(route->ksnr_share_count == 0);
609 ksocknal_del_route_locked(route);
612 list_for_each_entry_safe(conn, cnxt, &peer_ni->ksnp_conns,
614 ksocknal_close_conn_locked(conn, 0);
617 ksocknal_peer_decref(peer_ni);
618 /* NB peer_ni unlinks itself when last conn/route is removed */
622 ksocknal_del_peer(struct lnet_ni *ni, struct lnet_process_id id, __u32 ip)
625 struct hlist_node *pnxt;
626 struct ksock_peer_ni *peer_ni;
632 write_lock_bh(&ksocknal_data.ksnd_global_lock);
634 if (id.nid != LNET_NID_ANY) {
635 lo = hash_min(id.nid, HASH_BITS(ksocknal_data.ksnd_peers));
639 hi = HASH_SIZE(ksocknal_data.ksnd_peers) - 1;
642 for (i = lo; i <= hi; i++) {
643 hlist_for_each_entry_safe(peer_ni, pnxt,
644 &ksocknal_data.ksnd_peers[i],
646 if (peer_ni->ksnp_ni != ni)
649 if (!((id.nid == LNET_NID_ANY ||
650 peer_ni->ksnp_id.nid == id.nid) &&
651 (id.pid == LNET_PID_ANY ||
652 peer_ni->ksnp_id.pid == id.pid)))
655 ksocknal_peer_addref(peer_ni); /* a ref for me... */
657 ksocknal_del_peer_locked(peer_ni, ip);
659 if (peer_ni->ksnp_closing &&
660 !list_empty(&peer_ni->ksnp_tx_queue)) {
661 LASSERT(list_empty(&peer_ni->ksnp_conns));
662 LASSERT(list_empty(&peer_ni->ksnp_routes));
664 list_splice_init(&peer_ni->ksnp_tx_queue,
668 ksocknal_peer_decref(peer_ni); /* ...till here */
670 rc = 0; /* matched! */
674 write_unlock_bh(&ksocknal_data.ksnd_global_lock);
676 ksocknal_txlist_done(ni, &zombies, -ENETDOWN);
681 static struct ksock_conn *
682 ksocknal_get_conn_by_idx(struct lnet_ni *ni, int index)
684 struct ksock_peer_ni *peer_ni;
685 struct ksock_conn *conn;
686 struct list_head *ctmp;
689 read_lock(&ksocknal_data.ksnd_global_lock);
691 hash_for_each(ksocknal_data.ksnd_peers, i, peer_ni, ksnp_list) {
692 LASSERT(!peer_ni->ksnp_closing);
694 if (peer_ni->ksnp_ni != ni)
697 list_for_each(ctmp, &peer_ni->ksnp_conns) {
701 conn = list_entry(ctmp, struct ksock_conn,
703 ksocknal_conn_addref(conn);
704 read_unlock(&ksocknal_data.ksnd_global_lock);
709 read_unlock(&ksocknal_data.ksnd_global_lock);
713 static struct ksock_sched *
714 ksocknal_choose_scheduler_locked(unsigned int cpt)
716 struct ksock_sched *sched = ksocknal_data.ksnd_schedulers[cpt];
719 if (sched->kss_nthreads == 0) {
720 cfs_percpt_for_each(sched, i, ksocknal_data.ksnd_schedulers) {
721 if (sched->kss_nthreads > 0) {
722 CDEBUG(D_NET, "scheduler[%d] has no threads. selected scheduler[%d]\n",
723 cpt, sched->kss_cpt);
734 ksocknal_accept(struct lnet_ni *ni, struct socket *sock)
736 struct ksock_connreq *cr;
738 struct sockaddr_storage peer;
740 rc = lnet_sock_getaddr(sock, true, &peer);
741 LASSERT(rc == 0); /* we succeeded before */
743 LIBCFS_ALLOC(cr, sizeof(*cr));
745 LCONSOLE_ERROR_MSG(0x12f,
746 "Dropping connection request from %pIS: memory exhausted\n",
753 cr->ksncr_sock = sock;
755 spin_lock_bh(&ksocknal_data.ksnd_connd_lock);
757 list_add_tail(&cr->ksncr_list, &ksocknal_data.ksnd_connd_connreqs);
758 wake_up(&ksocknal_data.ksnd_connd_waitq);
760 spin_unlock_bh(&ksocknal_data.ksnd_connd_lock);
765 ksocknal_connecting(struct ksock_peer_ni *peer_ni, struct sockaddr *sa)
767 struct ksock_route *route;
769 list_for_each_entry(route, &peer_ni->ksnp_routes, ksnr_list) {
770 if (rpc_cmp_addr((struct sockaddr *)&route->ksnr_addr, sa))
771 return route->ksnr_connecting;
777 ksocknal_create_conn(struct lnet_ni *ni, struct ksock_route *route,
778 struct socket *sock, int type)
780 rwlock_t *global_lock = &ksocknal_data.ksnd_global_lock;
782 struct lnet_process_id peerid;
783 struct list_head *tmp;
785 struct ksock_conn *conn;
786 struct ksock_conn *conn2;
787 struct ksock_peer_ni *peer_ni = NULL;
788 struct ksock_peer_ni *peer2;
789 struct ksock_sched *sched;
790 struct ksock_hello_msg *hello;
793 struct ksock_tx *txtmp;
799 active = (route != NULL);
801 LASSERT (active == (type != SOCKLND_CONN_NONE));
803 LIBCFS_ALLOC(conn, sizeof(*conn));
809 conn->ksnc_peer = NULL;
810 conn->ksnc_route = NULL;
811 conn->ksnc_sock = sock;
812 /* 2 ref, 1 for conn, another extra ref prevents socket
813 * being closed before establishment of connection */
814 refcount_set(&conn->ksnc_sock_refcount, 2);
815 conn->ksnc_type = type;
816 ksocknal_lib_save_callback(sock, conn);
817 refcount_set(&conn->ksnc_conn_refcount, 1); /* 1 ref for me */
819 conn->ksnc_rx_ready = 0;
820 conn->ksnc_rx_scheduled = 0;
822 INIT_LIST_HEAD(&conn->ksnc_tx_queue);
823 conn->ksnc_tx_ready = 0;
824 conn->ksnc_tx_scheduled = 0;
825 conn->ksnc_tx_carrier = NULL;
826 atomic_set (&conn->ksnc_tx_nob, 0);
828 LIBCFS_ALLOC(hello, offsetof(struct ksock_hello_msg,
829 kshm_ips[LNET_INTERFACES_NUM]));
835 /* stash conn's local and remote addrs */
836 rc = ksocknal_lib_get_conn_addrs (conn);
840 /* Find out/confirm peer_ni's NID and connection type and get the
841 * vector of interfaces she's willing to let me connect to.
842 * Passive connections use the listener timeout since the peer_ni sends
846 peer_ni = route->ksnr_peer;
847 LASSERT(ni == peer_ni->ksnp_ni);
849 /* Active connection sends HELLO eagerly */
850 hello->kshm_nips = 0;
851 peerid = peer_ni->ksnp_id;
853 write_lock_bh(global_lock);
854 conn->ksnc_proto = peer_ni->ksnp_proto;
855 write_unlock_bh(global_lock);
857 if (conn->ksnc_proto == NULL) {
858 conn->ksnc_proto = &ksocknal_protocol_v3x;
859 #if SOCKNAL_VERSION_DEBUG
860 if (*ksocknal_tunables.ksnd_protocol == 2)
861 conn->ksnc_proto = &ksocknal_protocol_v2x;
862 else if (*ksocknal_tunables.ksnd_protocol == 1)
863 conn->ksnc_proto = &ksocknal_protocol_v1x;
867 rc = ksocknal_send_hello (ni, conn, peerid.nid, hello);
871 peerid.nid = LNET_NID_ANY;
872 peerid.pid = LNET_PID_ANY;
874 /* Passive, get protocol from peer_ni */
875 conn->ksnc_proto = NULL;
878 rc = ksocknal_recv_hello(ni, conn, hello, &peerid, &incarnation);
882 LASSERT(rc == 0 || active);
883 LASSERT(conn->ksnc_proto != NULL);
884 LASSERT(peerid.nid != LNET_NID_ANY);
886 cpt = lnet_cpt_of_nid(peerid.nid, ni);
889 ksocknal_peer_addref(peer_ni);
890 write_lock_bh(global_lock);
892 peer_ni = ksocknal_create_peer(ni, peerid);
893 if (IS_ERR(peer_ni)) {
894 rc = PTR_ERR(peer_ni);
898 write_lock_bh(global_lock);
900 /* called with a ref on ni, so shutdown can't have started */
901 LASSERT(atomic_read(&((struct ksock_net *)ni->ni_data)->ksnn_npeers) >= 0);
903 peer2 = ksocknal_find_peer_locked(ni, peerid);
905 /* NB this puts an "empty" peer_ni in the peer_ni
906 * table (which takes my ref) */
907 hash_add(ksocknal_data.ksnd_peers,
908 &peer_ni->ksnp_list, peerid.nid);
910 ksocknal_peer_decref(peer_ni);
915 ksocknal_peer_addref(peer_ni);
916 peer_ni->ksnp_accepting++;
918 /* Am I already connecting to this guy? Resolve in
919 * favour of higher NID...
921 if (peerid.nid < ni->ni_nid &&
922 ksocknal_connecting(peer_ni, ((struct sockaddr *)
923 &conn->ksnc_peeraddr))) {
925 warn = "connection race resolution";
930 if (peer_ni->ksnp_closing ||
931 (active && route->ksnr_deleted)) {
932 /* peer_ni/route got closed under me */
934 warn = "peer_ni/route removed";
938 if (peer_ni->ksnp_proto == NULL) {
939 /* Never connected before.
940 * NB recv_hello may have returned EPROTO to signal my peer_ni
941 * wants a different protocol than the one I asked for.
943 LASSERT(list_empty(&peer_ni->ksnp_conns));
945 peer_ni->ksnp_proto = conn->ksnc_proto;
946 peer_ni->ksnp_incarnation = incarnation;
949 if (peer_ni->ksnp_proto != conn->ksnc_proto ||
950 peer_ni->ksnp_incarnation != incarnation) {
951 /* peer_ni rebooted or I've got the wrong protocol version */
952 ksocknal_close_peer_conns_locked(peer_ni, NULL, 0);
954 peer_ni->ksnp_proto = NULL;
956 warn = peer_ni->ksnp_incarnation != incarnation ?
958 "wrong proto version";
968 warn = "lost conn race";
971 warn = "retry with different protocol version";
975 /* Refuse to duplicate an existing connection, unless this is a
976 * loopback connection */
977 if (!rpc_cmp_addr((struct sockaddr *)&conn->ksnc_peeraddr,
978 (struct sockaddr *)&conn->ksnc_myaddr)) {
979 list_for_each(tmp, &peer_ni->ksnp_conns) {
980 conn2 = list_entry(tmp, struct ksock_conn, ksnc_list);
983 (struct sockaddr *)&conn2->ksnc_peeraddr,
984 (struct sockaddr *)&conn->ksnc_peeraddr) ||
986 (struct sockaddr *)&conn2->ksnc_myaddr,
987 (struct sockaddr *)&conn->ksnc_myaddr) ||
988 conn2->ksnc_type != conn->ksnc_type)
991 /* Reply on a passive connection attempt so the peer_ni
992 * realises we're connected. */
1002 /* If the connection created by this route didn't bind to the IP
1003 * address the route connected to, the connection/route matching
1004 * code below probably isn't going to work. */
1006 !rpc_cmp_addr((struct sockaddr *)&route->ksnr_addr,
1007 (struct sockaddr *)&conn->ksnc_peeraddr)) {
1008 CERROR("Route %s %pIS connected to %pIS\n",
1009 libcfs_id2str(peer_ni->ksnp_id),
1011 &conn->ksnc_peeraddr);
1014 /* Search for a route corresponding to the new connection and
1015 * create an association. This allows incoming connections created
1016 * by routes in my peer_ni to match my own route entries so I don't
1017 * continually create duplicate routes. */
1018 list_for_each(tmp, &peer_ni->ksnp_routes) {
1019 route = list_entry(tmp, struct ksock_route, ksnr_list);
1021 if (!rpc_cmp_addr((struct sockaddr *)&route->ksnr_addr,
1022 (struct sockaddr *)&conn->ksnc_peeraddr))
1025 ksocknal_associate_route_conn_locked(route, conn);
1029 conn->ksnc_peer = peer_ni; /* conn takes my ref on peer_ni */
1030 peer_ni->ksnp_last_alive = ktime_get_seconds();
1031 peer_ni->ksnp_send_keepalive = 0;
1032 peer_ni->ksnp_error = 0;
1034 sched = ksocknal_choose_scheduler_locked(cpt);
1036 CERROR("no schedulers available. node is unhealthy\n");
1040 * The cpt might have changed if we ended up selecting a non cpt
1041 * native scheduler. So use the scheduler's cpt instead.
1043 cpt = sched->kss_cpt;
1044 sched->kss_nconns++;
1045 conn->ksnc_scheduler = sched;
1047 conn->ksnc_tx_last_post = ktime_get_seconds();
1048 /* Set the deadline for the outgoing HELLO to drain */
1049 conn->ksnc_tx_bufnob = sock->sk->sk_wmem_queued;
1050 conn->ksnc_tx_deadline = ktime_get_seconds() +
1052 smp_mb(); /* order with adding to peer_ni's conn list */
1054 list_add(&conn->ksnc_list, &peer_ni->ksnp_conns);
1055 ksocknal_conn_addref(conn);
1057 ksocknal_new_packet(conn, 0);
1059 conn->ksnc_zc_capable = ksocknal_lib_zc_capable(conn);
1061 /* Take packets blocking for this connection. */
1062 list_for_each_entry_safe(tx, txtmp, &peer_ni->ksnp_tx_queue, tx_list) {
1063 if (conn->ksnc_proto->pro_match_tx(conn, tx, tx->tx_nonblk) ==
1067 list_del(&tx->tx_list);
1068 ksocknal_queue_tx_locked(tx, conn);
1071 write_unlock_bh(global_lock);
1073 /* We've now got a new connection. Any errors from here on are just
1074 * like "normal" comms errors and we close the connection normally.
1075 * NB (a) we still have to send the reply HELLO for passive
1077 * (b) normal I/O on the conn is blocked until I setup and call the
1081 CDEBUG(D_NET, "New conn %s p %d.x %pIS -> %pISp"
1082 " incarnation:%lld sched[%d]\n",
1083 libcfs_id2str(peerid), conn->ksnc_proto->pro_version,
1084 &conn->ksnc_myaddr, &conn->ksnc_peeraddr,
1088 hello->kshm_nips = 0;
1089 rc = ksocknal_send_hello(ni, conn, peerid.nid, hello);
1092 LIBCFS_FREE(hello, offsetof(struct ksock_hello_msg,
1093 kshm_ips[LNET_INTERFACES_NUM]));
1095 /* setup the socket AFTER I've received hello (it disables
1096 * SO_LINGER). I might call back to the acceptor who may want
1097 * to send a protocol version response and then close the
1098 * socket; this ensures the socket only tears down after the
1099 * response has been sent. */
1101 rc = ksocknal_lib_setup_sock(sock);
1103 write_lock_bh(global_lock);
1105 /* NB my callbacks block while I hold ksnd_global_lock */
1106 ksocknal_lib_set_callback(sock, conn);
1109 peer_ni->ksnp_accepting--;
1111 write_unlock_bh(global_lock);
1114 write_lock_bh(global_lock);
1115 if (!conn->ksnc_closing) {
1116 /* could be closed by another thread */
1117 ksocknal_close_conn_locked(conn, rc);
1119 write_unlock_bh(global_lock);
1120 } else if (ksocknal_connsock_addref(conn) == 0) {
1121 /* Allow I/O to proceed. */
1122 ksocknal_read_callback(conn);
1123 ksocknal_write_callback(conn);
1124 ksocknal_connsock_decref(conn);
1127 ksocknal_connsock_decref(conn);
1128 ksocknal_conn_decref(conn);
1132 if (!peer_ni->ksnp_closing &&
1133 list_empty(&peer_ni->ksnp_conns) &&
1134 list_empty(&peer_ni->ksnp_routes)) {
1135 list_splice_init(&peer_ni->ksnp_tx_queue, &zombies);
1136 ksocknal_unlink_peer_locked(peer_ni);
1139 write_unlock_bh(global_lock);
1143 CERROR("Not creating conn %s type %d: %s\n",
1144 libcfs_id2str(peerid), conn->ksnc_type, warn);
1146 CDEBUG(D_NET, "Not creating conn %s type %d: %s\n",
1147 libcfs_id2str(peerid), conn->ksnc_type, warn);
1152 /* Request retry by replying with CONN_NONE
1153 * ksnc_proto has been set already */
1154 conn->ksnc_type = SOCKLND_CONN_NONE;
1155 hello->kshm_nips = 0;
1156 ksocknal_send_hello(ni, conn, peerid.nid, hello);
1159 write_lock_bh(global_lock);
1160 peer_ni->ksnp_accepting--;
1161 write_unlock_bh(global_lock);
1165 * If we get here without an error code, just use -EALREADY.
1166 * Depending on how we got here, the error may be positive
1167 * or negative. Normalize the value for ksocknal_txlist_done().
1169 rc2 = (rc == 0 ? -EALREADY : (rc > 0 ? -rc : rc));
1170 ksocknal_txlist_done(ni, &zombies, rc2);
1171 ksocknal_peer_decref(peer_ni);
1175 LIBCFS_FREE(hello, offsetof(struct ksock_hello_msg,
1176 kshm_ips[LNET_INTERFACES_NUM]));
1178 LIBCFS_FREE(conn, sizeof(*conn));
1186 ksocknal_close_conn_locked(struct ksock_conn *conn, int error)
1188 /* This just does the immmediate housekeeping, and queues the
1189 * connection for the reaper to terminate.
1190 * Caller holds ksnd_global_lock exclusively in irq context */
1191 struct ksock_peer_ni *peer_ni = conn->ksnc_peer;
1192 struct ksock_route *route;
1193 struct ksock_conn *conn2;
1194 struct list_head *tmp;
1196 LASSERT(peer_ni->ksnp_error == 0);
1197 LASSERT(!conn->ksnc_closing);
1198 conn->ksnc_closing = 1;
1200 /* ksnd_deathrow_conns takes over peer_ni's ref */
1201 list_del(&conn->ksnc_list);
1203 route = conn->ksnc_route;
1204 if (route != NULL) {
1205 /* dissociate conn from route... */
1206 LASSERT(!route->ksnr_deleted);
1207 LASSERT((route->ksnr_connected & BIT(conn->ksnc_type)) != 0);
1210 list_for_each(tmp, &peer_ni->ksnp_conns) {
1211 conn2 = list_entry(tmp, struct ksock_conn, ksnc_list);
1213 if (conn2->ksnc_route == route &&
1214 conn2->ksnc_type == conn->ksnc_type)
1220 route->ksnr_connected &= ~BIT(conn->ksnc_type);
1222 conn->ksnc_route = NULL;
1224 ksocknal_route_decref(route); /* drop conn's ref on route */
1227 if (list_empty(&peer_ni->ksnp_conns)) {
1228 /* No more connections to this peer_ni */
1230 if (!list_empty(&peer_ni->ksnp_tx_queue)) {
1231 struct ksock_tx *tx;
1233 LASSERT(conn->ksnc_proto == &ksocknal_protocol_v3x);
1235 /* throw them to the last connection...,
1236 * these TXs will be send to /dev/null by scheduler */
1237 list_for_each_entry(tx, &peer_ni->ksnp_tx_queue,
1239 ksocknal_tx_prep(conn, tx);
1241 spin_lock_bh(&conn->ksnc_scheduler->kss_lock);
1242 list_splice_init(&peer_ni->ksnp_tx_queue,
1243 &conn->ksnc_tx_queue);
1244 spin_unlock_bh(&conn->ksnc_scheduler->kss_lock);
1247 /* renegotiate protocol version */
1248 peer_ni->ksnp_proto = NULL;
1249 /* stash last conn close reason */
1250 peer_ni->ksnp_error = error;
1252 if (list_empty(&peer_ni->ksnp_routes)) {
1253 /* I've just closed last conn belonging to a
1254 * peer_ni with no routes to it */
1255 ksocknal_unlink_peer_locked(peer_ni);
1259 spin_lock_bh(&ksocknal_data.ksnd_reaper_lock);
1261 list_add_tail(&conn->ksnc_list, &ksocknal_data.ksnd_deathrow_conns);
1262 wake_up(&ksocknal_data.ksnd_reaper_waitq);
1264 spin_unlock_bh(&ksocknal_data.ksnd_reaper_lock);
1268 ksocknal_peer_failed(struct ksock_peer_ni *peer_ni)
1270 bool notify = false;
1271 time64_t last_alive = 0;
1273 /* There has been a connection failure or comms error; but I'll only
1274 * tell LNET I think the peer_ni is dead if it's to another kernel and
1275 * there are no connections or connection attempts in existence. */
1277 read_lock(&ksocknal_data.ksnd_global_lock);
1279 if ((peer_ni->ksnp_id.pid & LNET_PID_USERFLAG) == 0 &&
1280 list_empty(&peer_ni->ksnp_conns) &&
1281 peer_ni->ksnp_accepting == 0 &&
1282 ksocknal_find_connecting_route_locked(peer_ni) == NULL) {
1284 last_alive = peer_ni->ksnp_last_alive;
1287 read_unlock(&ksocknal_data.ksnd_global_lock);
1290 lnet_notify(peer_ni->ksnp_ni, peer_ni->ksnp_id.nid,
1291 false, false, last_alive);
1295 ksocknal_finalize_zcreq(struct ksock_conn *conn)
1297 struct ksock_peer_ni *peer_ni = conn->ksnc_peer;
1298 struct ksock_tx *tx;
1299 struct ksock_tx *tmp;
1302 /* NB safe to finalize TXs because closing of socket will
1303 * abort all buffered data */
1304 LASSERT(conn->ksnc_sock == NULL);
1306 spin_lock(&peer_ni->ksnp_lock);
1308 list_for_each_entry_safe(tx, tmp, &peer_ni->ksnp_zc_req_list, tx_zc_list) {
1309 if (tx->tx_conn != conn)
1312 LASSERT(tx->tx_msg.ksm_zc_cookies[0] != 0);
1314 tx->tx_msg.ksm_zc_cookies[0] = 0;
1315 tx->tx_zc_aborted = 1; /* mark it as not-acked */
1316 list_move(&tx->tx_zc_list, &zlist);
1319 spin_unlock(&peer_ni->ksnp_lock);
1321 while (!list_empty(&zlist)) {
1322 tx = list_entry(zlist.next, struct ksock_tx, tx_zc_list);
1324 list_del(&tx->tx_zc_list);
1325 ksocknal_tx_decref(tx);
1330 ksocknal_terminate_conn(struct ksock_conn *conn)
1332 /* This gets called by the reaper (guaranteed thread context) to
1333 * disengage the socket from its callbacks and close it.
1334 * ksnc_refcount will eventually hit zero, and then the reaper will
1337 struct ksock_peer_ni *peer_ni = conn->ksnc_peer;
1338 struct ksock_sched *sched = conn->ksnc_scheduler;
1339 bool failed = false;
1341 LASSERT(conn->ksnc_closing);
1343 /* wake up the scheduler to "send" all remaining packets to /dev/null */
1344 spin_lock_bh(&sched->kss_lock);
1346 /* a closing conn is always ready to tx */
1347 conn->ksnc_tx_ready = 1;
1349 if (!conn->ksnc_tx_scheduled &&
1350 !list_empty(&conn->ksnc_tx_queue)) {
1351 list_add_tail(&conn->ksnc_tx_list,
1352 &sched->kss_tx_conns);
1353 conn->ksnc_tx_scheduled = 1;
1354 /* extra ref for scheduler */
1355 ksocknal_conn_addref(conn);
1357 wake_up (&sched->kss_waitq);
1360 spin_unlock_bh(&sched->kss_lock);
1362 /* serialise with callbacks */
1363 write_lock_bh(&ksocknal_data.ksnd_global_lock);
1365 ksocknal_lib_reset_callback(conn->ksnc_sock, conn);
1367 /* OK, so this conn may not be completely disengaged from its
1368 * scheduler yet, but it _has_ committed to terminate...
1370 conn->ksnc_scheduler->kss_nconns--;
1372 if (peer_ni->ksnp_error != 0) {
1373 /* peer_ni's last conn closed in error */
1374 LASSERT(list_empty(&peer_ni->ksnp_conns));
1376 peer_ni->ksnp_error = 0; /* avoid multiple notifications */
1379 write_unlock_bh(&ksocknal_data.ksnd_global_lock);
1382 ksocknal_peer_failed(peer_ni);
1384 /* The socket is closed on the final put; either here, or in
1385 * ksocknal_{send,recv}msg(). Since we set up the linger2 option
1386 * when the connection was established, this will close the socket
1387 * immediately, aborting anything buffered in it. Any hung
1388 * zero-copy transmits will therefore complete in finite time.
1390 ksocknal_connsock_decref(conn);
1394 ksocknal_queue_zombie_conn(struct ksock_conn *conn)
1396 /* Queue the conn for the reaper to destroy */
1397 LASSERT(refcount_read(&conn->ksnc_conn_refcount) == 0);
1398 spin_lock_bh(&ksocknal_data.ksnd_reaper_lock);
1400 list_add_tail(&conn->ksnc_list, &ksocknal_data.ksnd_zombie_conns);
1401 wake_up(&ksocknal_data.ksnd_reaper_waitq);
1403 spin_unlock_bh(&ksocknal_data.ksnd_reaper_lock);
1407 ksocknal_destroy_conn(struct ksock_conn *conn)
1411 /* Final coup-de-grace of the reaper */
1412 CDEBUG (D_NET, "connection %p\n", conn);
1414 LASSERT(refcount_read(&conn->ksnc_conn_refcount) == 0);
1415 LASSERT(refcount_read(&conn->ksnc_sock_refcount) == 0);
1416 LASSERT (conn->ksnc_sock == NULL);
1417 LASSERT (conn->ksnc_route == NULL);
1418 LASSERT (!conn->ksnc_tx_scheduled);
1419 LASSERT (!conn->ksnc_rx_scheduled);
1420 LASSERT(list_empty(&conn->ksnc_tx_queue));
1422 /* complete current receive if any */
1423 switch (conn->ksnc_rx_state) {
1424 case SOCKNAL_RX_LNET_PAYLOAD:
1425 last_rcv = conn->ksnc_rx_deadline -
1427 CERROR("Completing partial receive from %s[%d], ip %pISp, with error, wanted: %d, left: %d, last alive is %lld secs ago\n",
1428 libcfs_id2str(conn->ksnc_peer->ksnp_id), conn->ksnc_type,
1429 &conn->ksnc_peeraddr,
1430 conn->ksnc_rx_nob_wanted, conn->ksnc_rx_nob_left,
1431 ktime_get_seconds() - last_rcv);
1432 if (conn->ksnc_lnet_msg)
1433 conn->ksnc_lnet_msg->msg_health_status =
1434 LNET_MSG_STATUS_REMOTE_ERROR;
1435 lnet_finalize(conn->ksnc_lnet_msg, -EIO);
1437 case SOCKNAL_RX_LNET_HEADER:
1438 if (conn->ksnc_rx_started)
1439 CERROR("Incomplete receive of lnet header from %s, ip %pISp, with error, protocol: %d.x.\n",
1440 libcfs_id2str(conn->ksnc_peer->ksnp_id),
1441 &conn->ksnc_peeraddr,
1442 conn->ksnc_proto->pro_version);
1444 case SOCKNAL_RX_KSM_HEADER:
1445 if (conn->ksnc_rx_started)
1446 CERROR("Incomplete receive of ksock message from %s, ip %pISp, with error, protocol: %d.x.\n",
1447 libcfs_id2str(conn->ksnc_peer->ksnp_id),
1448 &conn->ksnc_peeraddr,
1449 conn->ksnc_proto->pro_version);
1451 case SOCKNAL_RX_SLOP:
1452 if (conn->ksnc_rx_started)
1453 CERROR("Incomplete receive of slops from %s, ip %pISp, with error\n",
1454 libcfs_id2str(conn->ksnc_peer->ksnp_id),
1455 &conn->ksnc_peeraddr);
1462 ksocknal_peer_decref(conn->ksnc_peer);
1464 LIBCFS_FREE (conn, sizeof (*conn));
1468 ksocknal_close_peer_conns_locked(struct ksock_peer_ni *peer_ni,
1469 struct sockaddr *addr, int why)
1471 struct ksock_conn *conn;
1472 struct ksock_conn *cnxt;
1475 list_for_each_entry_safe(conn, cnxt, &peer_ni->ksnp_conns, ksnc_list) {
1478 (struct sockaddr *)&conn->ksnc_peeraddr)) {
1480 ksocknal_close_conn_locked(conn, why);
1488 ksocknal_close_conn_and_siblings(struct ksock_conn *conn, int why)
1490 struct ksock_peer_ni *peer_ni = conn->ksnc_peer;
1493 write_lock_bh(&ksocknal_data.ksnd_global_lock);
1495 count = ksocknal_close_peer_conns_locked(
1496 peer_ni, (struct sockaddr *)&conn->ksnc_peeraddr, why);
1498 write_unlock_bh(&ksocknal_data.ksnd_global_lock);
1504 ksocknal_close_matching_conns(struct lnet_process_id id, __u32 ipaddr)
1506 struct ksock_peer_ni *peer_ni;
1507 struct hlist_node *pnxt;
1512 struct sockaddr_in sa = {.sin_family = AF_INET};
1514 write_lock_bh(&ksocknal_data.ksnd_global_lock);
1516 if (id.nid != LNET_NID_ANY) {
1517 lo = hash_min(id.nid, HASH_BITS(ksocknal_data.ksnd_peers));
1521 hi = HASH_SIZE(ksocknal_data.ksnd_peers) - 1;
1524 sa.sin_addr.s_addr = htonl(ipaddr);
1525 for (i = lo; i <= hi; i++) {
1526 hlist_for_each_entry_safe(peer_ni, pnxt,
1527 &ksocknal_data.ksnd_peers[i],
1530 if (!((id.nid == LNET_NID_ANY ||
1531 id.nid == peer_ni->ksnp_id.nid) &&
1532 (id.pid == LNET_PID_ANY ||
1533 id.pid == peer_ni->ksnp_id.pid)))
1536 count += ksocknal_close_peer_conns_locked(
1538 ipaddr ? (struct sockaddr *)&sa : NULL, 0);
1542 write_unlock_bh(&ksocknal_data.ksnd_global_lock);
1544 /* wildcards always succeed */
1545 if (id.nid == LNET_NID_ANY || id.pid == LNET_PID_ANY || ipaddr == 0)
1548 return (count == 0 ? -ENOENT : 0);
1552 ksocknal_notify_gw_down(lnet_nid_t gw_nid)
1554 /* The router is telling me she's been notified of a change in
1557 struct lnet_process_id id = {
1559 .pid = LNET_PID_ANY,
1562 CDEBUG(D_NET, "gw %s down\n", libcfs_nid2str(gw_nid));
1564 /* If the gateway crashed, close all open connections... */
1565 ksocknal_close_matching_conns(id, 0);
1568 /* We can only establish new connections
1569 * if we have autroutes, and these connect on demand. */
1573 ksocknal_push_peer(struct ksock_peer_ni *peer_ni)
1577 struct list_head *tmp;
1578 struct ksock_conn *conn;
1580 for (index = 0; ; index++) {
1581 read_lock(&ksocknal_data.ksnd_global_lock);
1586 list_for_each(tmp, &peer_ni->ksnp_conns) {
1588 conn = list_entry(tmp, struct ksock_conn,
1590 ksocknal_conn_addref(conn);
1595 read_unlock(&ksocknal_data.ksnd_global_lock);
1600 ksocknal_lib_push_conn (conn);
1601 ksocknal_conn_decref(conn);
1606 ksocknal_push(struct lnet_ni *ni, struct lnet_process_id id)
1613 if (id.nid != LNET_NID_ANY) {
1614 lo = hash_min(id.nid, HASH_BITS(ksocknal_data.ksnd_peers));
1618 hi = HASH_SIZE(ksocknal_data.ksnd_peers) - 1;
1621 for (bkt = lo; bkt <= hi; bkt++) {
1622 int peer_off; /* searching offset in peer_ni hash table */
1624 for (peer_off = 0; ; peer_off++) {
1625 struct ksock_peer_ni *peer_ni;
1628 read_lock(&ksocknal_data.ksnd_global_lock);
1629 hlist_for_each_entry(peer_ni,
1630 &ksocknal_data.ksnd_peers[bkt],
1632 if (!((id.nid == LNET_NID_ANY ||
1633 id.nid == peer_ni->ksnp_id.nid) &&
1634 (id.pid == LNET_PID_ANY ||
1635 id.pid == peer_ni->ksnp_id.pid)))
1638 if (i++ == peer_off) {
1639 ksocknal_peer_addref(peer_ni);
1643 read_unlock(&ksocknal_data.ksnd_global_lock);
1645 if (i <= peer_off) /* no match */
1649 ksocknal_push_peer(peer_ni);
1650 ksocknal_peer_decref(peer_ni);
1657 ksocknal_ctl(struct lnet_ni *ni, unsigned int cmd, void *arg)
1659 struct lnet_process_id id = {0};
1660 struct libcfs_ioctl_data *data = arg;
1664 case IOC_LIBCFS_GET_INTERFACE: {
1665 struct ksock_net *net = ni->ni_data;
1666 struct ksock_interface *iface;
1667 struct sockaddr_in *sa;
1669 read_lock(&ksocknal_data.ksnd_global_lock);
1671 if (data->ioc_count >= 1) {
1675 iface = &net->ksnn_interface;
1677 sa = (void *)&iface->ksni_addr;
1678 if (sa->sin_family == AF_INET)
1679 data->ioc_u32[0] = ntohl(sa->sin_addr.s_addr);
1681 data->ioc_u32[0] = 0xFFFFFFFF;
1682 data->ioc_u32[1] = iface->ksni_netmask;
1683 data->ioc_u32[2] = iface->ksni_npeers;
1684 data->ioc_u32[3] = iface->ksni_nroutes;
1687 read_unlock(&ksocknal_data.ksnd_global_lock);
1691 case IOC_LIBCFS_GET_PEER: {
1696 int share_count = 0;
1698 rc = ksocknal_get_peer_info(ni, data->ioc_count,
1699 &id, &myip, &ip, &port,
1700 &conn_count, &share_count);
1704 data->ioc_nid = id.nid;
1705 data->ioc_count = share_count;
1706 data->ioc_u32[0] = ip;
1707 data->ioc_u32[1] = port;
1708 data->ioc_u32[2] = myip;
1709 data->ioc_u32[3] = conn_count;
1710 data->ioc_u32[4] = id.pid;
1714 case IOC_LIBCFS_ADD_PEER: {
1715 struct sockaddr_in sa = {.sin_family = AF_INET};
1717 id.nid = data->ioc_nid;
1718 id.pid = LNET_PID_LUSTRE;
1719 sa.sin_addr.s_addr = htonl(data->ioc_u32[0]);
1720 sa.sin_port = htons(data->ioc_u32[1]);
1721 return ksocknal_add_peer(ni, id, (struct sockaddr *)&sa);
1723 case IOC_LIBCFS_DEL_PEER:
1724 id.nid = data->ioc_nid;
1725 id.pid = LNET_PID_ANY;
1726 return ksocknal_del_peer (ni, id,
1727 data->ioc_u32[0]); /* IP */
1729 case IOC_LIBCFS_GET_CONN: {
1733 struct ksock_conn *conn = ksocknal_get_conn_by_idx(ni, data->ioc_count);
1734 struct sockaddr_in *psa = (void *)&conn->ksnc_peeraddr;
1735 struct sockaddr_in *mysa = (void *)&conn->ksnc_myaddr;
1740 ksocknal_lib_get_conn_tunables(conn, &txmem, &rxmem, &nagle);
1742 data->ioc_count = txmem;
1743 data->ioc_nid = conn->ksnc_peer->ksnp_id.nid;
1744 data->ioc_flags = nagle;
1745 if (psa->sin_family == AF_INET)
1746 data->ioc_u32[0] = ntohl(psa->sin_addr.s_addr);
1748 data->ioc_u32[0] = 0xFFFFFFFF;
1749 data->ioc_u32[1] = rpc_get_port((struct sockaddr *)
1750 &conn->ksnc_peeraddr);
1751 if (mysa->sin_family == AF_INET)
1752 data->ioc_u32[2] = ntohl(mysa->sin_addr.s_addr);
1754 data->ioc_u32[2] = 0xFFFFFFFF;
1755 data->ioc_u32[3] = conn->ksnc_type;
1756 data->ioc_u32[4] = conn->ksnc_scheduler->kss_cpt;
1757 data->ioc_u32[5] = rxmem;
1758 data->ioc_u32[6] = conn->ksnc_peer->ksnp_id.pid;
1759 ksocknal_conn_decref(conn);
1763 case IOC_LIBCFS_CLOSE_CONNECTION:
1764 id.nid = data->ioc_nid;
1765 id.pid = LNET_PID_ANY;
1766 return ksocknal_close_matching_conns (id,
1769 case IOC_LIBCFS_REGISTER_MYNID:
1770 /* Ignore if this is a noop */
1771 if (data->ioc_nid == ni->ni_nid)
1774 CERROR("obsolete IOC_LIBCFS_REGISTER_MYNID: %s(%s)\n",
1775 libcfs_nid2str(data->ioc_nid),
1776 libcfs_nid2str(ni->ni_nid));
1779 case IOC_LIBCFS_PUSH_CONNECTION:
1780 id.nid = data->ioc_nid;
1781 id.pid = LNET_PID_ANY;
1782 return ksocknal_push(ni, id);
1791 ksocknal_free_buffers (void)
1793 LASSERT (atomic_read(&ksocknal_data.ksnd_nactive_txs) == 0);
1795 if (ksocknal_data.ksnd_schedulers != NULL)
1796 cfs_percpt_free(ksocknal_data.ksnd_schedulers);
1798 spin_lock(&ksocknal_data.ksnd_tx_lock);
1800 if (!list_empty(&ksocknal_data.ksnd_idle_noop_txs)) {
1802 struct ksock_tx *tx;
1804 list_splice_init(&ksocknal_data.ksnd_idle_noop_txs, &zlist);
1805 spin_unlock(&ksocknal_data.ksnd_tx_lock);
1807 while (!list_empty(&zlist)) {
1808 tx = list_entry(zlist.next, struct ksock_tx, tx_list);
1809 list_del(&tx->tx_list);
1810 LIBCFS_FREE(tx, tx->tx_desc_size);
1813 spin_unlock(&ksocknal_data.ksnd_tx_lock);
1818 ksocknal_base_shutdown(void)
1820 struct ksock_sched *sched;
1821 struct ksock_peer_ni *peer_ni;
1824 CDEBUG(D_MALLOC, "before NAL cleanup: kmem %lld\n",
1825 libcfs_kmem_read());
1826 LASSERT (ksocknal_data.ksnd_nnets == 0);
1828 switch (ksocknal_data.ksnd_init) {
1833 case SOCKNAL_INIT_ALL:
1834 case SOCKNAL_INIT_DATA:
1835 hash_for_each(ksocknal_data.ksnd_peers, i, peer_ni, ksnp_list)
1838 LASSERT(list_empty(&ksocknal_data.ksnd_nets));
1839 LASSERT(list_empty(&ksocknal_data.ksnd_enomem_conns));
1840 LASSERT(list_empty(&ksocknal_data.ksnd_zombie_conns));
1841 LASSERT(list_empty(&ksocknal_data.ksnd_connd_connreqs));
1842 LASSERT(list_empty(&ksocknal_data.ksnd_connd_routes));
1844 if (ksocknal_data.ksnd_schedulers != NULL) {
1845 cfs_percpt_for_each(sched, i,
1846 ksocknal_data.ksnd_schedulers) {
1848 LASSERT(list_empty(&sched->kss_tx_conns));
1849 LASSERT(list_empty(&sched->kss_rx_conns));
1850 LASSERT(list_empty(&sched->kss_zombie_noop_txs));
1851 LASSERT(sched->kss_nconns == 0);
1855 /* flag threads to terminate; wake and wait for them to die */
1856 ksocknal_data.ksnd_shuttingdown = 1;
1857 wake_up_all(&ksocknal_data.ksnd_connd_waitq);
1858 wake_up_all(&ksocknal_data.ksnd_reaper_waitq);
1860 if (ksocknal_data.ksnd_schedulers != NULL) {
1861 cfs_percpt_for_each(sched, i,
1862 ksocknal_data.ksnd_schedulers)
1863 wake_up_all(&sched->kss_waitq);
1866 wait_var_event_warning(&ksocknal_data.ksnd_nthreads,
1867 atomic_read(&ksocknal_data.ksnd_nthreads) == 0,
1868 "waiting for %d threads to terminate\n",
1869 atomic_read(&ksocknal_data.ksnd_nthreads));
1871 ksocknal_free_buffers();
1873 ksocknal_data.ksnd_init = SOCKNAL_INIT_NOTHING;
1877 CDEBUG(D_MALLOC, "after NAL cleanup: kmem %lld\n",
1878 libcfs_kmem_read());
1880 module_put(THIS_MODULE);
1884 ksocknal_base_startup(void)
1886 struct ksock_sched *sched;
1890 LASSERT(ksocknal_data.ksnd_init == SOCKNAL_INIT_NOTHING);
1891 LASSERT(ksocknal_data.ksnd_nnets == 0);
1893 memset(&ksocknal_data, 0, sizeof(ksocknal_data)); /* zero pointers */
1895 hash_init(ksocknal_data.ksnd_peers);
1897 rwlock_init(&ksocknal_data.ksnd_global_lock);
1898 INIT_LIST_HEAD(&ksocknal_data.ksnd_nets);
1900 spin_lock_init(&ksocknal_data.ksnd_reaper_lock);
1901 INIT_LIST_HEAD(&ksocknal_data.ksnd_enomem_conns);
1902 INIT_LIST_HEAD(&ksocknal_data.ksnd_zombie_conns);
1903 INIT_LIST_HEAD(&ksocknal_data.ksnd_deathrow_conns);
1904 init_waitqueue_head(&ksocknal_data.ksnd_reaper_waitq);
1906 spin_lock_init(&ksocknal_data.ksnd_connd_lock);
1907 INIT_LIST_HEAD(&ksocknal_data.ksnd_connd_connreqs);
1908 INIT_LIST_HEAD(&ksocknal_data.ksnd_connd_routes);
1909 init_waitqueue_head(&ksocknal_data.ksnd_connd_waitq);
1911 spin_lock_init(&ksocknal_data.ksnd_tx_lock);
1912 INIT_LIST_HEAD(&ksocknal_data.ksnd_idle_noop_txs);
1914 /* NB memset above zeros whole of ksocknal_data */
1916 /* flag lists/ptrs/locks initialised */
1917 ksocknal_data.ksnd_init = SOCKNAL_INIT_DATA;
1918 if (!try_module_get(THIS_MODULE))
1921 /* Create a scheduler block per available CPT */
1922 ksocknal_data.ksnd_schedulers = cfs_percpt_alloc(lnet_cpt_table(),
1924 if (ksocknal_data.ksnd_schedulers == NULL)
1927 cfs_percpt_for_each(sched, i, ksocknal_data.ksnd_schedulers) {
1931 * make sure not to allocate more threads than there are
1932 * cores/CPUs in teh CPT
1934 nthrs = cfs_cpt_weight(lnet_cpt_table(), i);
1935 if (*ksocknal_tunables.ksnd_nscheds > 0) {
1936 nthrs = min(nthrs, *ksocknal_tunables.ksnd_nscheds);
1939 * max to half of CPUs, assume another half should be
1940 * reserved for upper layer modules
1942 nthrs = min(max(SOCKNAL_NSCHEDS, nthrs >> 1), nthrs);
1945 sched->kss_nthreads_max = nthrs;
1948 spin_lock_init(&sched->kss_lock);
1949 INIT_LIST_HEAD(&sched->kss_rx_conns);
1950 INIT_LIST_HEAD(&sched->kss_tx_conns);
1951 INIT_LIST_HEAD(&sched->kss_zombie_noop_txs);
1952 init_waitqueue_head(&sched->kss_waitq);
1955 ksocknal_data.ksnd_connd_starting = 0;
1956 ksocknal_data.ksnd_connd_failed_stamp = 0;
1957 ksocknal_data.ksnd_connd_starting_stamp = ktime_get_real_seconds();
1958 /* must have at least 2 connds to remain responsive to accepts while
1960 if (*ksocknal_tunables.ksnd_nconnds < SOCKNAL_CONND_RESV + 1)
1961 *ksocknal_tunables.ksnd_nconnds = SOCKNAL_CONND_RESV + 1;
1963 if (*ksocknal_tunables.ksnd_nconnds_max <
1964 *ksocknal_tunables.ksnd_nconnds) {
1965 ksocknal_tunables.ksnd_nconnds_max =
1966 ksocknal_tunables.ksnd_nconnds;
1969 for (i = 0; i < *ksocknal_tunables.ksnd_nconnds; i++) {
1971 spin_lock_bh(&ksocknal_data.ksnd_connd_lock);
1972 ksocknal_data.ksnd_connd_starting++;
1973 spin_unlock_bh(&ksocknal_data.ksnd_connd_lock);
1976 snprintf(name, sizeof(name), "socknal_cd%02d", i);
1977 rc = ksocknal_thread_start(ksocknal_connd,
1978 (void *)((uintptr_t)i), name);
1980 spin_lock_bh(&ksocknal_data.ksnd_connd_lock);
1981 ksocknal_data.ksnd_connd_starting--;
1982 spin_unlock_bh(&ksocknal_data.ksnd_connd_lock);
1983 CERROR("Can't spawn socknal connd: %d\n", rc);
1988 rc = ksocknal_thread_start(ksocknal_reaper, NULL, "socknal_reaper");
1990 CERROR ("Can't spawn socknal reaper: %d\n", rc);
1994 /* flag everything initialised */
1995 ksocknal_data.ksnd_init = SOCKNAL_INIT_ALL;
2000 ksocknal_base_shutdown();
2005 ksocknal_debug_peerhash(struct lnet_ni *ni)
2007 struct ksock_peer_ni *peer_ni;
2010 read_lock(&ksocknal_data.ksnd_global_lock);
2012 hash_for_each(ksocknal_data.ksnd_peers, i, peer_ni, ksnp_list) {
2013 struct ksock_route *route;
2014 struct ksock_conn *conn;
2016 if (peer_ni->ksnp_ni != ni)
2019 CWARN("Active peer_ni on shutdown: %s, ref %d, "
2020 "closing %d, accepting %d, err %d, zcookie %llu, "
2021 "txq %d, zc_req %d\n", libcfs_id2str(peer_ni->ksnp_id),
2022 refcount_read(&peer_ni->ksnp_refcount),
2023 peer_ni->ksnp_closing,
2024 peer_ni->ksnp_accepting, peer_ni->ksnp_error,
2025 peer_ni->ksnp_zc_next_cookie,
2026 !list_empty(&peer_ni->ksnp_tx_queue),
2027 !list_empty(&peer_ni->ksnp_zc_req_list));
2029 list_for_each_entry(route, &peer_ni->ksnp_routes, ksnr_list) {
2030 CWARN("Route: ref %d, schd %d, conn %d, cnted %d, del %d\n",
2031 refcount_read(&route->ksnr_refcount),
2032 route->ksnr_scheduled, route->ksnr_connecting,
2033 route->ksnr_connected, route->ksnr_deleted);
2036 list_for_each_entry(conn, &peer_ni->ksnp_conns, ksnc_list) {
2037 CWARN("Conn: ref %d, sref %d, t %d, c %d\n",
2038 refcount_read(&conn->ksnc_conn_refcount),
2039 refcount_read(&conn->ksnc_sock_refcount),
2040 conn->ksnc_type, conn->ksnc_closing);
2045 read_unlock(&ksocknal_data.ksnd_global_lock);
2050 ksocknal_shutdown(struct lnet_ni *ni)
2052 struct ksock_net *net = ni->ni_data;
2053 struct lnet_process_id anyid = {
2054 .nid = LNET_NID_ANY,
2055 .pid = LNET_PID_ANY,
2058 LASSERT(ksocknal_data.ksnd_init == SOCKNAL_INIT_ALL);
2059 LASSERT(ksocknal_data.ksnd_nnets > 0);
2061 /* prevent new peers */
2062 atomic_add(SOCKNAL_SHUTDOWN_BIAS, &net->ksnn_npeers);
2064 /* Delete all peers */
2065 ksocknal_del_peer(ni, anyid, 0);
2067 /* Wait for all peer_ni state to clean up */
2068 wait_var_event_warning(&net->ksnn_npeers,
2069 atomic_read(&net->ksnn_npeers) ==
2070 SOCKNAL_SHUTDOWN_BIAS,
2071 "waiting for %d peers to disconnect\n",
2072 ksocknal_debug_peerhash(ni) +
2073 atomic_read(&net->ksnn_npeers) -
2074 SOCKNAL_SHUTDOWN_BIAS);
2076 LASSERT(net->ksnn_interface.ksni_npeers == 0);
2077 LASSERT(net->ksnn_interface.ksni_nroutes == 0);
2079 list_del(&net->ksnn_list);
2080 LIBCFS_FREE(net, sizeof(*net));
2082 ksocknal_data.ksnd_nnets--;
2083 if (ksocknal_data.ksnd_nnets == 0)
2084 ksocknal_base_shutdown();
2088 ksocknal_search_new_ipif(struct ksock_net *net)
2091 char *ifnam = &net->ksnn_interface.ksni_name[0];
2092 char *colon = strchr(ifnam, ':');
2094 struct ksock_net *tmp;
2099 list_for_each_entry(tmp, &ksocknal_data.ksnd_nets, ksnn_list) {
2100 char *ifnam2 = &tmp->ksnn_interface.ksni_name[0];
2101 char *colon2 = strchr(ifnam2, ':');
2106 found = strcmp(ifnam, ifnam2) == 0;
2119 ksocknal_start_schedulers(struct ksock_sched *sched)
2125 if (sched->kss_nthreads == 0) {
2126 if (*ksocknal_tunables.ksnd_nscheds > 0) {
2127 nthrs = sched->kss_nthreads_max;
2129 nthrs = cfs_cpt_weight(lnet_cpt_table(),
2131 nthrs = min(max(SOCKNAL_NSCHEDS, nthrs >> 1), nthrs);
2132 nthrs = min(SOCKNAL_NSCHEDS_HIGH, nthrs);
2134 nthrs = min(nthrs, sched->kss_nthreads_max);
2136 LASSERT(sched->kss_nthreads <= sched->kss_nthreads_max);
2137 /* increase two threads if there is new interface */
2138 nthrs = min(2, sched->kss_nthreads_max - sched->kss_nthreads);
2141 for (i = 0; i < nthrs; i++) {
2145 id = KSOCK_THREAD_ID(sched->kss_cpt, sched->kss_nthreads + i);
2146 snprintf(name, sizeof(name), "socknal_sd%02d_%02d",
2147 sched->kss_cpt, (int)KSOCK_THREAD_SID(id));
2149 rc = ksocknal_thread_start(ksocknal_scheduler,
2154 CERROR("Can't spawn thread %d for scheduler[%d]: %d\n",
2155 sched->kss_cpt, (int) KSOCK_THREAD_SID(id), rc);
2159 sched->kss_nthreads += i;
2164 ksocknal_net_start_threads(struct ksock_net *net, __u32 *cpts, int ncpts)
2166 int newif = ksocknal_search_new_ipif(net);
2170 if (ncpts > 0 && ncpts > cfs_cpt_number(lnet_cpt_table()))
2173 for (i = 0; i < ncpts; i++) {
2174 struct ksock_sched *sched;
2175 int cpt = (cpts == NULL) ? i : cpts[i];
2177 LASSERT(cpt < cfs_cpt_number(lnet_cpt_table()));
2178 sched = ksocknal_data.ksnd_schedulers[cpt];
2180 if (!newif && sched->kss_nthreads > 0)
2183 rc = ksocknal_start_schedulers(sched);
2191 ksocknal_startup(struct lnet_ni *ni)
2193 struct ksock_net *net;
2194 struct lnet_ioctl_config_lnd_cmn_tunables *net_tunables;
2195 struct ksock_interface *ksi = NULL;
2196 struct lnet_inetdev *ifaces = NULL;
2197 struct sockaddr_in *sa;
2201 LASSERT (ni->ni_net->net_lnd == &the_ksocklnd);
2202 if (ksocknal_data.ksnd_init == SOCKNAL_INIT_NOTHING) {
2203 rc = ksocknal_base_startup();
2207 LIBCFS_ALLOC(net, sizeof(*net));
2210 net->ksnn_incarnation = ktime_get_real_ns();
2212 net_tunables = &ni->ni_net->net_tunables;
2213 if (net_tunables->lct_peer_timeout == -1)
2214 net_tunables->lct_peer_timeout =
2215 *ksocknal_tunables.ksnd_peertimeout;
2217 if (net_tunables->lct_max_tx_credits == -1)
2218 net_tunables->lct_max_tx_credits =
2219 *ksocknal_tunables.ksnd_credits;
2221 if (net_tunables->lct_peer_tx_credits == -1)
2222 net_tunables->lct_peer_tx_credits =
2223 *ksocknal_tunables.ksnd_peertxcredits;
2225 if (net_tunables->lct_peer_tx_credits >
2226 net_tunables->lct_max_tx_credits)
2227 net_tunables->lct_peer_tx_credits =
2228 net_tunables->lct_max_tx_credits;
2230 if (net_tunables->lct_peer_rtr_credits == -1)
2231 net_tunables->lct_peer_rtr_credits =
2232 *ksocknal_tunables.ksnd_peerrtrcredits;
2234 rc = lnet_inet_enumerate(&ifaces, ni->ni_net_ns);
2238 ksi = &net->ksnn_interface;
2240 /* Use the first discovered interface or look in the list */
2241 if (ni->ni_interface) {
2242 for (i = 0; i < rc; i++)
2243 if (strcmp(ifaces[i].li_name, ni->ni_interface) == 0)
2246 /* ni_interfaces doesn't contain the interface we want */
2248 CERROR("ksocklnd: failed to find interface %s\n",
2254 ni->ni_dev_cpt = ifaces[i].li_cpt;
2255 sa = (void *)&ksi->ksni_addr;
2256 memset(sa, 0, sizeof(*sa));
2257 sa->sin_family = AF_INET;
2258 sa->sin_addr.s_addr = htonl(ifaces[i].li_ipaddr);
2259 ksi->ksni_index = ksocknal_ip2index((struct sockaddr *)sa, ni);
2260 ksi->ksni_netmask = ifaces[i].li_netmask;
2261 strlcpy(ksi->ksni_name, ifaces[i].li_name, sizeof(ksi->ksni_name));
2263 /* call it before add it to ksocknal_data.ksnd_nets */
2264 rc = ksocknal_net_start_threads(net, ni->ni_cpts, ni->ni_ncpts);
2269 LASSERT(ksi->ksni_addr.ss_family == AF_INET);
2270 ni->ni_nid = LNET_MKNID(
2271 LNET_NIDNET(ni->ni_nid),
2272 ntohl(((struct sockaddr_in *)
2273 &ksi->ksni_addr)->sin_addr.s_addr));
2274 list_add(&net->ksnn_list, &ksocknal_data.ksnd_nets);
2275 ksocknal_data.ksnd_nnets++;
2280 LIBCFS_FREE(net, sizeof(*net));
2282 if (ksocknal_data.ksnd_nnets == 0)
2283 ksocknal_base_shutdown();
2289 static void __exit ksocklnd_exit(void)
2291 lnet_unregister_lnd(&the_ksocklnd);
2294 static const struct lnet_lnd the_ksocklnd = {
2295 .lnd_type = SOCKLND,
2296 .lnd_startup = ksocknal_startup,
2297 .lnd_shutdown = ksocknal_shutdown,
2298 .lnd_ctl = ksocknal_ctl,
2299 .lnd_send = ksocknal_send,
2300 .lnd_recv = ksocknal_recv,
2301 .lnd_notify_peer_down = ksocknal_notify_gw_down,
2302 .lnd_accept = ksocknal_accept,
2305 static int __init ksocklnd_init(void)
2309 /* check ksnr_connected/connecting field large enough */
2310 BUILD_BUG_ON(SOCKLND_CONN_NTYPES > 4);
2311 BUILD_BUG_ON(SOCKLND_CONN_ACK != SOCKLND_CONN_BULK_IN);
2313 rc = ksocknal_tunables_init();
2317 lnet_register_lnd(&the_ksocklnd);
2322 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
2323 MODULE_DESCRIPTION("TCP Socket LNet Network Driver");
2324 MODULE_VERSION("2.8.0");
2325 MODULE_LICENSE("GPL");
2327 module_init(ksocklnd_init);
2328 module_exit(ksocklnd_exit);