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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lnet/klnds/ralnd/ralnd.c
38 * Author: Eric Barton <eric@bartonsoftware.com>
42 static int kranal_devids[RANAL_MAXDEVS] = {RAPK_MAIN_DEVICE_ID,
43 RAPK_EXPANSION_DEVICE_ID};
47 .lnd_startup = kranal_startup,
48 .lnd_shutdown = kranal_shutdown,
49 .lnd_ctl = kranal_ctl,
50 .lnd_send = kranal_send,
51 .lnd_recv = kranal_recv,
52 .lnd_eager_recv = kranal_eager_recv,
53 .lnd_accept = kranal_accept,
56 kra_data_t kranal_data;
59 kranal_pack_connreq(kra_connreq_t *connreq, kra_conn_t *conn, lnet_nid_t dstnid)
63 memset(connreq, 0, sizeof(*connreq));
65 connreq->racr_magic = RANAL_MSG_MAGIC;
66 connreq->racr_version = RANAL_MSG_VERSION;
68 if (conn == NULL) /* prepping a "stub" reply */
71 connreq->racr_devid = conn->rac_device->rad_id;
72 connreq->racr_srcnid = kranal_data.kra_ni->ni_nid;
73 connreq->racr_dstnid = dstnid;
74 connreq->racr_peerstamp = kranal_data.kra_peerstamp;
75 connreq->racr_connstamp = conn->rac_my_connstamp;
76 connreq->racr_timeout = conn->rac_timeout;
78 rrc = RapkGetRiParams(conn->rac_rihandle, &connreq->racr_riparams);
79 LASSERT(rrc == RAP_SUCCESS);
83 kranal_recv_connreq(struct socket *sock, kra_connreq_t *connreq, int active)
85 int timeout = active ? *kranal_tunables.kra_timeout :
86 lnet_acceptor_timeout();
90 /* return 0 on success, -ve on error, +ve to tell the peer I'm "old" */
92 rc = libcfs_sock_read(sock, &connreq->racr_magic,
93 sizeof(connreq->racr_magic), timeout);
95 CERROR("Read(magic) failed(1): %d\n", rc);
99 if (connreq->racr_magic != RANAL_MSG_MAGIC &&
100 connreq->racr_magic != __swab32(RANAL_MSG_MAGIC)) {
101 /* Unexpected magic! */
103 (connreq->racr_magic == LNET_PROTO_MAGIC ||
104 connreq->racr_magic == __swab32(LNET_PROTO_MAGIC))) {
105 /* future protocol version compatibility!
106 * When LNET unifies protocols over all LNDs, the first
107 * thing sent will be a version query. +ve rc means I
108 * reply with my current magic/version */
112 CERROR("Unexpected magic %08x (%s)\n",
113 connreq->racr_magic, active ? "active" : "passive");
117 swab = (connreq->racr_magic == __swab32(RANAL_MSG_MAGIC));
119 rc = libcfs_sock_read(sock, &connreq->racr_version,
120 sizeof(connreq->racr_version), timeout);
122 CERROR("Read(version) failed: %d\n", rc);
127 __swab16s(&connreq->racr_version);
129 if (connreq->racr_version != RANAL_MSG_VERSION) {
131 CERROR("Unexpected version %d\n", connreq->racr_version);
134 /* If this is a future version of the ralnd protocol, and I'm
135 * passive (accepted the connection), tell my peer I'm "old"
140 rc = libcfs_sock_read(sock, &connreq->racr_devid,
141 sizeof(connreq->racr_version) -
142 offsetof(kra_connreq_t, racr_devid),
145 CERROR("Read(body) failed: %d\n", rc);
150 __swab32s(&connreq->racr_magic);
151 __swab16s(&connreq->racr_version);
152 __swab16s(&connreq->racr_devid);
153 __swab64s(&connreq->racr_srcnid);
154 __swab64s(&connreq->racr_dstnid);
155 __swab64s(&connreq->racr_peerstamp);
156 __swab64s(&connreq->racr_connstamp);
157 __swab32s(&connreq->racr_timeout);
159 __swab32s(&connreq->racr_riparams.HostId);
160 __swab32s(&connreq->racr_riparams.FmaDomainHndl);
161 __swab32s(&connreq->racr_riparams.PTag);
162 __swab32s(&connreq->racr_riparams.CompletionCookie);
165 if (connreq->racr_srcnid == LNET_NID_ANY ||
166 connreq->racr_dstnid == LNET_NID_ANY) {
167 CERROR("Received LNET_NID_ANY\n");
171 if (connreq->racr_timeout < RANAL_MIN_TIMEOUT) {
172 CERROR("Received timeout %d < MIN %d\n",
173 connreq->racr_timeout, RANAL_MIN_TIMEOUT);
181 kranal_close_stale_conns_locked (kra_peer_t *peer, kra_conn_t *newconn)
189 loopback = peer->rap_nid == kranal_data.kra_ni->ni_nid;
191 cfs_list_for_each_safe (ctmp, cnxt, &peer->rap_conns) {
192 conn = cfs_list_entry(ctmp, kra_conn_t, rac_list);
197 if (conn->rac_peerstamp != newconn->rac_peerstamp) {
198 CDEBUG(D_NET, "Closing stale conn nid: %s "
199 " peerstamp:"LPX64"("LPX64")\n",
200 libcfs_nid2str(peer->rap_nid),
201 conn->rac_peerstamp, newconn->rac_peerstamp);
202 LASSERT (conn->rac_peerstamp < newconn->rac_peerstamp);
204 kranal_close_conn_locked(conn, -ESTALE);
208 if (conn->rac_device != newconn->rac_device)
212 newconn->rac_my_connstamp == conn->rac_peer_connstamp &&
213 newconn->rac_peer_connstamp == conn->rac_my_connstamp)
216 LASSERT (conn->rac_peer_connstamp < newconn->rac_peer_connstamp);
218 CDEBUG(D_NET, "Closing stale conn nid: %s"
219 " connstamp:"LPX64"("LPX64")\n",
220 libcfs_nid2str(peer->rap_nid),
221 conn->rac_peer_connstamp, newconn->rac_peer_connstamp);
224 kranal_close_conn_locked(conn, -ESTALE);
231 kranal_conn_isdup_locked(kra_peer_t *peer, kra_conn_t *newconn)
237 loopback = peer->rap_nid == kranal_data.kra_ni->ni_nid;
239 cfs_list_for_each(tmp, &peer->rap_conns) {
240 conn = cfs_list_entry(tmp, kra_conn_t, rac_list);
242 /* 'newconn' is from an earlier version of 'peer'!!! */
243 if (newconn->rac_peerstamp < conn->rac_peerstamp)
246 /* 'conn' is from an earlier version of 'peer': it will be
247 * removed when we cull stale conns later on... */
248 if (newconn->rac_peerstamp > conn->rac_peerstamp)
251 /* Different devices are OK */
252 if (conn->rac_device != newconn->rac_device)
255 /* It's me connecting to myself */
257 newconn->rac_my_connstamp == conn->rac_peer_connstamp &&
258 newconn->rac_peer_connstamp == conn->rac_my_connstamp)
261 /* 'newconn' is an earlier connection from 'peer'!!! */
262 if (newconn->rac_peer_connstamp < conn->rac_peer_connstamp)
265 /* 'conn' is an earlier connection from 'peer': it will be
266 * removed when we cull stale conns later on... */
267 if (newconn->rac_peer_connstamp > conn->rac_peer_connstamp)
270 /* 'newconn' has the SAME connection stamp; 'peer' isn't
271 * playing the game... */
279 kranal_set_conn_uniqueness (kra_conn_t *conn)
283 write_lock_irqsave(&kranal_data.kra_global_lock, flags);
285 conn->rac_my_connstamp = kranal_data.kra_connstamp++;
287 do { /* allocate a unique cqid */
288 conn->rac_cqid = kranal_data.kra_next_cqid++;
289 } while (kranal_cqid2conn_locked(conn->rac_cqid) != NULL);
291 write_unlock_irqrestore(&kranal_data.kra_global_lock, flags);
295 kranal_create_conn(kra_conn_t **connp, kra_device_t *dev)
300 LASSERT (!cfs_in_interrupt());
301 LIBCFS_ALLOC(conn, sizeof(*conn));
306 memset(conn, 0, sizeof(*conn));
307 cfs_atomic_set(&conn->rac_refcount, 1);
308 CFS_INIT_LIST_HEAD(&conn->rac_list);
309 CFS_INIT_LIST_HEAD(&conn->rac_hashlist);
310 CFS_INIT_LIST_HEAD(&conn->rac_schedlist);
311 CFS_INIT_LIST_HEAD(&conn->rac_fmaq);
312 CFS_INIT_LIST_HEAD(&conn->rac_rdmaq);
313 CFS_INIT_LIST_HEAD(&conn->rac_replyq);
314 spin_lock_init(&conn->rac_lock);
316 kranal_set_conn_uniqueness(conn);
318 conn->rac_device = dev;
319 conn->rac_timeout = MAX(*kranal_tunables.kra_timeout, RANAL_MIN_TIMEOUT);
320 kranal_update_reaper_timeout(conn->rac_timeout);
322 rrc = RapkCreateRi(dev->rad_handle, conn->rac_cqid,
323 &conn->rac_rihandle);
324 if (rrc != RAP_SUCCESS) {
325 CERROR("RapkCreateRi failed: %d\n", rrc);
326 LIBCFS_FREE(conn, sizeof(*conn));
330 cfs_atomic_inc(&kranal_data.kra_nconns);
336 kranal_destroy_conn(kra_conn_t *conn)
340 LASSERT (!cfs_in_interrupt());
341 LASSERT (!conn->rac_scheduled);
342 LASSERT (cfs_list_empty(&conn->rac_list));
343 LASSERT (cfs_list_empty(&conn->rac_hashlist));
344 LASSERT (cfs_list_empty(&conn->rac_schedlist));
345 LASSERT (cfs_atomic_read(&conn->rac_refcount) == 0);
346 LASSERT (cfs_list_empty(&conn->rac_fmaq));
347 LASSERT (cfs_list_empty(&conn->rac_rdmaq));
348 LASSERT (cfs_list_empty(&conn->rac_replyq));
350 rrc = RapkDestroyRi(conn->rac_device->rad_handle,
352 LASSERT (rrc == RAP_SUCCESS);
354 if (conn->rac_peer != NULL)
355 kranal_peer_decref(conn->rac_peer);
357 LIBCFS_FREE(conn, sizeof(*conn));
358 cfs_atomic_dec(&kranal_data.kra_nconns);
362 kranal_terminate_conn_locked (kra_conn_t *conn)
364 LASSERT (!cfs_in_interrupt());
365 LASSERT (conn->rac_state == RANAL_CONN_CLOSING);
366 LASSERT (!cfs_list_empty(&conn->rac_hashlist));
367 LASSERT (cfs_list_empty(&conn->rac_list));
369 /* Remove from conn hash table: no new callbacks */
370 cfs_list_del_init(&conn->rac_hashlist);
371 kranal_conn_decref(conn);
373 conn->rac_state = RANAL_CONN_CLOSED;
375 /* schedule to clear out all uncompleted comms in context of dev's
377 kranal_schedule_conn(conn);
381 kranal_close_conn_locked (kra_conn_t *conn, int error)
383 kra_peer_t *peer = conn->rac_peer;
385 CDEBUG_LIMIT(error == 0 ? D_NET : D_NETERROR,
386 "closing conn to %s: error %d\n",
387 libcfs_nid2str(peer->rap_nid), error);
389 LASSERT (!cfs_in_interrupt());
390 LASSERT (conn->rac_state == RANAL_CONN_ESTABLISHED);
391 LASSERT (!cfs_list_empty(&conn->rac_hashlist));
392 LASSERT (!cfs_list_empty(&conn->rac_list));
394 cfs_list_del_init(&conn->rac_list);
396 if (cfs_list_empty(&peer->rap_conns) &&
397 peer->rap_persistence == 0) {
398 /* Non-persistent peer with no more conns... */
399 kranal_unlink_peer_locked(peer);
402 /* Reset RX timeout to ensure we wait for an incoming CLOSE for the
403 * full timeout. If we get a CLOSE we know the peer has stopped all
404 * RDMA. Otherwise if we wait for the full timeout we can also be sure
405 * all RDMA has stopped. */
406 conn->rac_last_rx = jiffies;
409 conn->rac_state = RANAL_CONN_CLOSING;
410 kranal_schedule_conn(conn); /* schedule sending CLOSE */
412 kranal_conn_decref(conn); /* lose peer's ref */
416 kranal_close_conn (kra_conn_t *conn, int error)
421 write_lock_irqsave(&kranal_data.kra_global_lock, flags);
423 if (conn->rac_state == RANAL_CONN_ESTABLISHED)
424 kranal_close_conn_locked(conn, error);
426 write_unlock_irqrestore(&kranal_data.kra_global_lock, flags);
430 kranal_set_conn_params(kra_conn_t *conn, kra_connreq_t *connreq,
431 __u32 peer_ip, int peer_port)
433 kra_device_t *dev = conn->rac_device;
437 /* CAVEAT EMPTOR: we're really overloading rac_last_tx + rac_keepalive
438 * to do RapkCompleteSync() timekeeping (see kibnal_scheduler). */
439 conn->rac_last_tx = jiffies;
440 conn->rac_keepalive = 0;
442 rrc = RapkSetRiParams(conn->rac_rihandle, &connreq->racr_riparams);
443 if (rrc != RAP_SUCCESS) {
444 CERROR("Error setting riparams from %u.%u.%u.%u/%d: %d\n",
445 HIPQUAD(peer_ip), peer_port, rrc);
446 return -ECONNABORTED;
449 /* Schedule conn on rad_new_conns */
450 kranal_conn_addref(conn);
451 spin_lock_irqsave(&dev->rad_lock, flags);
452 cfs_list_add_tail(&conn->rac_schedlist, &dev->rad_new_conns);
453 cfs_waitq_signal(&dev->rad_waitq);
454 spin_unlock_irqrestore(&dev->rad_lock, flags);
456 rrc = RapkWaitToConnect(conn->rac_rihandle);
457 if (rrc != RAP_SUCCESS) {
458 CERROR("Error waiting to connect to %u.%u.%u.%u/%d: %d\n",
459 HIPQUAD(peer_ip), peer_port, rrc);
460 return -ECONNABORTED;
463 /* Scheduler doesn't touch conn apart from to deschedule and decref it
464 * after RapkCompleteSync() return success, so conn is all mine */
466 conn->rac_peerstamp = connreq->racr_peerstamp;
467 conn->rac_peer_connstamp = connreq->racr_connstamp;
468 conn->rac_keepalive = RANAL_TIMEOUT2KEEPALIVE(connreq->racr_timeout);
469 kranal_update_reaper_timeout(conn->rac_keepalive);
474 kranal_passive_conn_handshake (struct socket *sock, lnet_nid_t *src_nidp,
475 lnet_nid_t *dst_nidp, kra_conn_t **connp)
478 unsigned int peer_port;
479 kra_connreq_t rx_connreq;
480 kra_connreq_t tx_connreq;
486 rc = libcfs_sock_getaddr(sock, 1, &peer_ip, &peer_port);
488 CERROR("Can't get peer's IP: %d\n", rc);
492 rc = kranal_recv_connreq(sock, &rx_connreq, 0);
495 CERROR("Can't rx connreq from %u.%u.%u.%u/%d: %d\n",
496 HIPQUAD(peer_ip), peer_port, rc);
501 /* Request from "new" peer: send reply with my MAGIC/VERSION to
502 * tell her I'm old... */
503 kranal_pack_connreq(&tx_connreq, NULL, LNET_NID_ANY);
505 rc = libcfs_sock_write(sock, &tx_connreq, sizeof(tx_connreq),
506 lnet_acceptor_timeout());
508 CERROR("Can't tx stub connreq to %u.%u.%u.%u/%d: %d\n",
509 HIPQUAD(peer_ip), peer_port, rc);
515 if (i == kranal_data.kra_ndevs) {
516 CERROR("Can't match dev %d from %u.%u.%u.%u/%d\n",
517 rx_connreq.racr_devid, HIPQUAD(peer_ip), peer_port);
520 dev = &kranal_data.kra_devices[i];
521 if (dev->rad_id == rx_connreq.racr_devid)
525 rc = kranal_create_conn(&conn, dev);
529 kranal_pack_connreq(&tx_connreq, conn, rx_connreq.racr_srcnid);
531 rc = libcfs_sock_write(sock, &tx_connreq, sizeof(tx_connreq),
532 lnet_acceptor_timeout());
534 CERROR("Can't tx connreq to %u.%u.%u.%u/%d: %d\n",
535 HIPQUAD(peer_ip), peer_port, rc);
536 kranal_conn_decref(conn);
540 rc = kranal_set_conn_params(conn, &rx_connreq, peer_ip, peer_port);
542 kranal_conn_decref(conn);
547 *src_nidp = rx_connreq.racr_srcnid;
548 *dst_nidp = rx_connreq.racr_dstnid;
553 kranal_active_conn_handshake(kra_peer_t *peer,
554 lnet_nid_t *dst_nidp, kra_conn_t **connp)
556 kra_connreq_t connreq;
563 /* spread connections over all devices using both peer NIDs to ensure
564 * all nids use all devices */
565 idx = peer->rap_nid + kranal_data.kra_ni->ni_nid;
566 dev = &kranal_data.kra_devices[idx % kranal_data.kra_ndevs];
568 rc = kranal_create_conn(&conn, dev);
572 kranal_pack_connreq(&connreq, conn, peer->rap_nid);
574 if (the_lnet.ln_testprotocompat != 0) {
575 /* single-shot proto test */
577 if ((the_lnet.ln_testprotocompat & 1) != 0) {
578 connreq.racr_version++;
579 the_lnet.ln_testprotocompat &= ~1;
581 if ((the_lnet.ln_testprotocompat & 2) != 0) {
582 connreq.racr_magic = LNET_PROTO_MAGIC;
583 the_lnet.ln_testprotocompat &= ~2;
588 rc = lnet_connect(&sock, peer->rap_nid,
589 0, peer->rap_ip, peer->rap_port);
593 /* CAVEAT EMPTOR: the passive side receives with a SHORT rx timeout
594 * immediately after accepting a connection, so we connect and then
595 * send immediately. */
597 rc = libcfs_sock_write(sock, &connreq, sizeof(connreq),
598 lnet_acceptor_timeout());
600 CERROR("Can't tx connreq to %u.%u.%u.%u/%d: %d\n",
601 HIPQUAD(peer->rap_ip), peer->rap_port, rc);
605 rc = kranal_recv_connreq(sock, &connreq, 1);
607 CERROR("Can't rx connreq from %u.%u.%u.%u/%d: %d\n",
608 HIPQUAD(peer->rap_ip), peer->rap_port, rc);
612 libcfs_sock_release(sock);
615 if (connreq.racr_srcnid != peer->rap_nid) {
616 CERROR("Unexpected srcnid from %u.%u.%u.%u/%d: "
617 "received %s expected %s\n",
618 HIPQUAD(peer->rap_ip), peer->rap_port,
619 libcfs_nid2str(connreq.racr_srcnid),
620 libcfs_nid2str(peer->rap_nid));
624 if (connreq.racr_devid != dev->rad_id) {
625 CERROR("Unexpected device id from %u.%u.%u.%u/%d: "
626 "received %d expected %d\n",
627 HIPQUAD(peer->rap_ip), peer->rap_port,
628 connreq.racr_devid, dev->rad_id);
632 rc = kranal_set_conn_params(conn, &connreq,
633 peer->rap_ip, peer->rap_port);
638 *dst_nidp = connreq.racr_dstnid;
642 libcfs_sock_release(sock);
644 lnet_connect_console_error(rc, peer->rap_nid,
645 peer->rap_ip, peer->rap_port);
647 kranal_conn_decref(conn);
652 kranal_conn_handshake (struct socket *sock, kra_peer_t *peer)
665 /* active: connd wants to connect to 'peer' */
666 LASSERT (peer != NULL);
667 LASSERT (peer->rap_connecting);
669 rc = kranal_active_conn_handshake(peer, &dst_nid, &conn);
673 write_lock_irqsave(&kranal_data.kra_global_lock, flags);
675 if (!kranal_peer_active(peer)) {
676 /* raced with peer getting unlinked */
677 write_unlock_irqrestore(&kranal_data. \
680 kranal_conn_decref(conn);
684 peer_nid = peer->rap_nid;
686 /* passive: listener accepted 'sock' */
687 LASSERT (peer == NULL);
689 rc = kranal_passive_conn_handshake(sock, &peer_nid,
694 /* assume this is a new peer */
695 rc = kranal_create_peer(&peer, peer_nid);
697 CERROR("Can't create conn for %s\n",
698 libcfs_nid2str(peer_nid));
699 kranal_conn_decref(conn);
703 write_lock_irqsave(&kranal_data.kra_global_lock, flags);
705 peer2 = kranal_find_peer_locked(peer_nid);
709 /* peer_nid already in the peer table */
710 kranal_peer_decref(peer);
715 LASSERT ((!new_peer) != (!kranal_peer_active(peer)));
717 /* Refuse connection if peer thinks we are a different NID. We check
718 * this while holding the global lock, to synch with connection
719 * destruction on NID change. */
720 if (kranal_data.kra_ni->ni_nid != dst_nid) {
721 write_unlock_irqrestore(&kranal_data.kra_global_lock,
724 CERROR("Stale/bad connection with %s: dst_nid %s, expected %s\n",
725 libcfs_nid2str(peer_nid), libcfs_nid2str(dst_nid),
726 libcfs_nid2str(kranal_data.kra_ni->ni_nid));
731 /* Refuse to duplicate an existing connection (both sides might try to
732 * connect at once). NB we return success! We _are_ connected so we
733 * _don't_ have any blocked txs to complete with failure. */
734 rc = kranal_conn_isdup_locked(peer, conn);
736 LASSERT (!cfs_list_empty(&peer->rap_conns));
737 LASSERT (cfs_list_empty(&peer->rap_tx_queue));
738 write_unlock_irqrestore(&kranal_data.kra_global_lock,
740 CWARN("Not creating duplicate connection to %s: %d\n",
741 libcfs_nid2str(peer_nid), rc);
747 /* peer table takes my ref on the new peer */
748 cfs_list_add_tail(&peer->rap_list,
749 kranal_nid2peerlist(peer_nid));
752 /* initialise timestamps before reaper looks at them */
753 conn->rac_last_tx = conn->rac_last_rx = jiffies;
755 kranal_peer_addref(peer); /* +1 ref for conn */
756 conn->rac_peer = peer;
757 cfs_list_add_tail(&conn->rac_list, &peer->rap_conns);
759 kranal_conn_addref(conn); /* +1 ref for conn table */
760 cfs_list_add_tail(&conn->rac_hashlist,
761 kranal_cqid2connlist(conn->rac_cqid));
763 /* Schedule all packets blocking for a connection */
764 while (!cfs_list_empty(&peer->rap_tx_queue)) {
765 tx = cfs_list_entry(peer->rap_tx_queue.next,
768 cfs_list_del(&tx->tx_list);
769 kranal_post_fma(conn, tx);
772 nstale = kranal_close_stale_conns_locked(peer, conn);
774 write_unlock_irqrestore(&kranal_data.kra_global_lock, flags);
776 /* CAVEAT EMPTOR: passive peer can disappear NOW */
779 CWARN("Closed %d stale conns to %s\n", nstale,
780 libcfs_nid2str(peer_nid));
782 CWARN("New connection to %s on devid[%d] = %d\n",
783 libcfs_nid2str(peer_nid),
784 conn->rac_device->rad_idx, conn->rac_device->rad_id);
786 /* Ensure conn gets checked. Transmits may have been queued and an
787 * FMA event may have happened before it got in the cq hash table */
788 kranal_schedule_conn(conn);
793 kranal_peer_decref(peer);
794 kranal_conn_decref(conn);
799 kranal_connect (kra_peer_t *peer)
806 LASSERT (peer->rap_connecting);
808 CDEBUG(D_NET, "About to handshake %s\n",
809 libcfs_nid2str(peer->rap_nid));
811 rc = kranal_conn_handshake(NULL, peer);
813 CDEBUG(D_NET, "Done handshake %s:%d \n",
814 libcfs_nid2str(peer->rap_nid), rc);
816 write_lock_irqsave(&kranal_data.kra_global_lock, flags);
818 LASSERT (peer->rap_connecting);
819 peer->rap_connecting = 0;
822 /* kranal_conn_handshake() queues blocked txs immediately on
823 * success to avoid messages jumping the queue */
824 LASSERT (cfs_list_empty(&peer->rap_tx_queue));
826 peer->rap_reconnect_interval = 0; /* OK to reconnect at any time */
828 write_unlock_irqrestore(&kranal_data.kra_global_lock,
833 peer->rap_reconnect_interval *= 2;
834 peer->rap_reconnect_interval =
835 MAX(peer->rap_reconnect_interval,
836 *kranal_tunables.kra_min_reconnect_interval);
837 peer->rap_reconnect_interval =
838 MIN(peer->rap_reconnect_interval,
839 *kranal_tunables.kra_max_reconnect_interval);
841 peer->rap_reconnect_time = jiffies + peer->rap_reconnect_interval *
844 /* Grab all blocked packets while we have the global lock */
845 cfs_list_add(&zombies, &peer->rap_tx_queue);
846 cfs_list_del_init(&peer->rap_tx_queue);
848 write_unlock_irqrestore(&kranal_data.kra_global_lock, flags);
850 if (cfs_list_empty(&zombies))
853 CNETERR("Dropping packets for %s: connection failed\n",
854 libcfs_nid2str(peer->rap_nid));
857 tx = cfs_list_entry(zombies.next, kra_tx_t, tx_list);
859 cfs_list_del(&tx->tx_list);
860 kranal_tx_done(tx, -EHOSTUNREACH);
862 } while (!cfs_list_empty(&zombies));
866 kranal_free_acceptsock (kra_acceptsock_t *ras)
868 libcfs_sock_release(ras->ras_sock);
869 LIBCFS_FREE(ras, sizeof(*ras));
873 kranal_accept (lnet_ni_t *ni, struct socket *sock)
875 kra_acceptsock_t *ras;
881 rc = libcfs_sock_getaddr(sock, 1, &peer_ip, &peer_port);
882 LASSERT (rc == 0); /* we succeeded before */
884 LIBCFS_ALLOC(ras, sizeof(*ras));
886 CERROR("ENOMEM allocating connection request from "
887 "%u.%u.%u.%u\n", HIPQUAD(peer_ip));
891 ras->ras_sock = sock;
893 spin_lock_irqsave(&kranal_data.kra_connd_lock, flags);
895 cfs_list_add_tail(&ras->ras_list, &kranal_data.kra_connd_acceptq);
896 cfs_waitq_signal(&kranal_data.kra_connd_waitq);
898 spin_unlock_irqrestore(&kranal_data.kra_connd_lock, flags);
903 kranal_create_peer (kra_peer_t **peerp, lnet_nid_t nid)
908 LASSERT (nid != LNET_NID_ANY);
910 LIBCFS_ALLOC(peer, sizeof(*peer));
914 memset(peer, 0, sizeof(*peer)); /* zero flags etc */
917 cfs_atomic_set(&peer->rap_refcount, 1); /* 1 ref for caller */
919 CFS_INIT_LIST_HEAD(&peer->rap_list);
920 CFS_INIT_LIST_HEAD(&peer->rap_connd_list);
921 CFS_INIT_LIST_HEAD(&peer->rap_conns);
922 CFS_INIT_LIST_HEAD(&peer->rap_tx_queue);
924 peer->rap_reconnect_interval = 0; /* OK to connect at any time */
926 write_lock_irqsave(&kranal_data.kra_global_lock, flags);
928 if (kranal_data.kra_nonewpeers) {
929 /* shutdown has started already */
930 write_unlock_irqrestore(&kranal_data.kra_global_lock,
933 LIBCFS_FREE(peer, sizeof(*peer));
934 CERROR("Can't create peer: network shutdown\n");
938 cfs_atomic_inc(&kranal_data.kra_npeers);
940 write_unlock_irqrestore(&kranal_data.kra_global_lock, flags);
947 kranal_destroy_peer (kra_peer_t *peer)
949 CDEBUG(D_NET, "peer %s %p deleted\n",
950 libcfs_nid2str(peer->rap_nid), peer);
952 LASSERT (cfs_atomic_read(&peer->rap_refcount) == 0);
953 LASSERT (peer->rap_persistence == 0);
954 LASSERT (!kranal_peer_active(peer));
955 LASSERT (!peer->rap_connecting);
956 LASSERT (cfs_list_empty(&peer->rap_conns));
957 LASSERT (cfs_list_empty(&peer->rap_tx_queue));
958 LASSERT (cfs_list_empty(&peer->rap_connd_list));
960 LIBCFS_FREE(peer, sizeof(*peer));
962 /* NB a peer's connections keep a reference on their peer until
963 * they are destroyed, so we can be assured that _all_ state to do
964 * with this peer has been cleaned up when its refcount drops to
966 cfs_atomic_dec(&kranal_data.kra_npeers);
970 kranal_find_peer_locked (lnet_nid_t nid)
972 cfs_list_t *peer_list = kranal_nid2peerlist(nid);
976 cfs_list_for_each (tmp, peer_list) {
978 peer = cfs_list_entry(tmp, kra_peer_t, rap_list);
980 LASSERT (peer->rap_persistence > 0 || /* persistent peer */
981 !cfs_list_empty(&peer->rap_conns)); /* active conn */
983 if (peer->rap_nid != nid)
986 CDEBUG(D_NET, "got peer [%p] -> %s (%d)\n",
987 peer, libcfs_nid2str(nid),
988 cfs_atomic_read(&peer->rap_refcount));
995 kranal_find_peer (lnet_nid_t nid)
999 read_lock(&kranal_data.kra_global_lock);
1000 peer = kranal_find_peer_locked(nid);
1001 if (peer != NULL) /* +1 ref for caller? */
1002 kranal_peer_addref(peer);
1003 read_unlock(&kranal_data.kra_global_lock);
1009 kranal_unlink_peer_locked (kra_peer_t *peer)
1011 LASSERT (peer->rap_persistence == 0);
1012 LASSERT (cfs_list_empty(&peer->rap_conns));
1014 LASSERT (kranal_peer_active(peer));
1015 cfs_list_del_init(&peer->rap_list);
1017 /* lose peerlist's ref */
1018 kranal_peer_decref(peer);
1022 kranal_get_peer_info (int index, lnet_nid_t *nidp, __u32 *ipp, int *portp,
1029 read_lock(&kranal_data.kra_global_lock);
1031 for (i = 0; i < kranal_data.kra_peer_hash_size; i++) {
1033 cfs_list_for_each(ptmp, &kranal_data.kra_peers[i]) {
1035 peer = cfs_list_entry(ptmp, kra_peer_t, rap_list);
1036 LASSERT (peer->rap_persistence > 0 ||
1037 !cfs_list_empty(&peer->rap_conns));
1042 *nidp = peer->rap_nid;
1043 *ipp = peer->rap_ip;
1044 *portp = peer->rap_port;
1045 *persistencep = peer->rap_persistence;
1047 read_unlock(&kranal_data.kra_global_lock);
1052 read_unlock(&kranal_data.kra_global_lock);
1057 kranal_add_persistent_peer (lnet_nid_t nid, __u32 ip, int port)
1059 unsigned long flags;
1064 if (nid == LNET_NID_ANY)
1067 rc = kranal_create_peer(&peer, nid);
1071 write_lock_irqsave(&kranal_data.kra_global_lock, flags);
1073 peer2 = kranal_find_peer_locked(nid);
1074 if (peer2 != NULL) {
1075 kranal_peer_decref(peer);
1078 /* peer table takes existing ref on peer */
1079 cfs_list_add_tail(&peer->rap_list,
1080 kranal_nid2peerlist(nid));
1084 peer->rap_port = port;
1085 peer->rap_persistence++;
1087 write_unlock_irqrestore(&kranal_data.kra_global_lock, flags);
1092 kranal_del_peer_locked (kra_peer_t *peer)
1098 peer->rap_persistence = 0;
1100 if (cfs_list_empty(&peer->rap_conns)) {
1101 kranal_unlink_peer_locked(peer);
1103 cfs_list_for_each_safe(ctmp, cnxt, &peer->rap_conns) {
1104 conn = cfs_list_entry(ctmp, kra_conn_t, rac_list);
1106 kranal_close_conn_locked(conn, 0);
1108 /* peer unlinks itself when last conn is closed */
1113 kranal_del_peer (lnet_nid_t nid)
1115 unsigned long flags;
1124 write_lock_irqsave(&kranal_data.kra_global_lock, flags);
1126 if (nid != LNET_NID_ANY)
1127 lo = hi = kranal_nid2peerlist(nid) - kranal_data.kra_peers;
1130 hi = kranal_data.kra_peer_hash_size - 1;
1133 for (i = lo; i <= hi; i++) {
1134 cfs_list_for_each_safe (ptmp, pnxt, &kranal_data.kra_peers[i]) {
1135 peer = cfs_list_entry(ptmp, kra_peer_t, rap_list);
1136 LASSERT (peer->rap_persistence > 0 ||
1137 !cfs_list_empty(&peer->rap_conns));
1139 if (!(nid == LNET_NID_ANY || peer->rap_nid == nid))
1142 kranal_del_peer_locked(peer);
1143 rc = 0; /* matched something */
1147 write_unlock_irqrestore(&kranal_data.kra_global_lock, flags);
1153 kranal_get_conn_by_idx (int index)
1161 read_lock(&kranal_data.kra_global_lock);
1163 for (i = 0; i < kranal_data.kra_peer_hash_size; i++) {
1164 cfs_list_for_each (ptmp, &kranal_data.kra_peers[i]) {
1166 peer = cfs_list_entry(ptmp, kra_peer_t, rap_list);
1167 LASSERT (peer->rap_persistence > 0 ||
1168 !cfs_list_empty(&peer->rap_conns));
1170 cfs_list_for_each (ctmp, &peer->rap_conns) {
1174 conn = cfs_list_entry(ctmp, kra_conn_t,
1176 CDEBUG(D_NET, "++conn[%p] -> %s (%d)\n", conn,
1177 libcfs_nid2str(conn->rac_peer->rap_nid),
1178 cfs_atomic_read(&conn->rac_refcount));
1179 cfs_atomic_inc(&conn->rac_refcount);
1180 read_unlock(&kranal_data.kra_global_lock);
1186 read_unlock(&kranal_data.kra_global_lock);
1191 kranal_close_peer_conns_locked (kra_peer_t *peer, int why)
1198 cfs_list_for_each_safe (ctmp, cnxt, &peer->rap_conns) {
1199 conn = cfs_list_entry(ctmp, kra_conn_t, rac_list);
1202 kranal_close_conn_locked(conn, why);
1209 kranal_close_matching_conns (lnet_nid_t nid)
1211 unsigned long flags;
1220 write_lock_irqsave(&kranal_data.kra_global_lock, flags);
1222 if (nid != LNET_NID_ANY)
1223 lo = hi = kranal_nid2peerlist(nid) - kranal_data.kra_peers;
1226 hi = kranal_data.kra_peer_hash_size - 1;
1229 for (i = lo; i <= hi; i++) {
1230 cfs_list_for_each_safe (ptmp, pnxt, &kranal_data.kra_peers[i]) {
1232 peer = cfs_list_entry(ptmp, kra_peer_t, rap_list);
1233 LASSERT (peer->rap_persistence > 0 ||
1234 !cfs_list_empty(&peer->rap_conns));
1236 if (!(nid == LNET_NID_ANY || nid == peer->rap_nid))
1239 count += kranal_close_peer_conns_locked(peer, 0);
1243 write_unlock_irqrestore(&kranal_data.kra_global_lock, flags);
1245 /* wildcards always succeed */
1246 if (nid == LNET_NID_ANY)
1249 return (count == 0) ? -ENOENT : 0;
1253 kranal_ctl(lnet_ni_t *ni, unsigned int cmd, void *arg)
1255 struct libcfs_ioctl_data *data = arg;
1258 LASSERT (ni == kranal_data.kra_ni);
1261 case IOC_LIBCFS_GET_PEER: {
1265 int share_count = 0;
1267 rc = kranal_get_peer_info(data->ioc_count,
1268 &nid, &ip, &port, &share_count);
1269 data->ioc_nid = nid;
1270 data->ioc_count = share_count;
1271 data->ioc_u32[0] = ip;
1272 data->ioc_u32[1] = port;
1275 case IOC_LIBCFS_ADD_PEER: {
1276 rc = kranal_add_persistent_peer(data->ioc_nid,
1277 data->ioc_u32[0], /* IP */
1278 data->ioc_u32[1]); /* port */
1281 case IOC_LIBCFS_DEL_PEER: {
1282 rc = kranal_del_peer(data->ioc_nid);
1285 case IOC_LIBCFS_GET_CONN: {
1286 kra_conn_t *conn = kranal_get_conn_by_idx(data->ioc_count);
1292 data->ioc_nid = conn->rac_peer->rap_nid;
1293 data->ioc_u32[0] = conn->rac_device->rad_id;
1294 kranal_conn_decref(conn);
1298 case IOC_LIBCFS_CLOSE_CONNECTION: {
1299 rc = kranal_close_matching_conns(data->ioc_nid);
1302 case IOC_LIBCFS_REGISTER_MYNID: {
1303 /* Ignore if this is a noop */
1304 if (data->ioc_nid == ni->ni_nid) {
1307 CERROR("obsolete IOC_LIBCFS_REGISTER_MYNID: %s(%s)\n",
1308 libcfs_nid2str(data->ioc_nid),
1309 libcfs_nid2str(ni->ni_nid));
1320 kranal_free_txdescs(cfs_list_t *freelist)
1324 while (!cfs_list_empty(freelist)) {
1325 tx = cfs_list_entry(freelist->next, kra_tx_t, tx_list);
1327 cfs_list_del(&tx->tx_list);
1328 LIBCFS_FREE(tx->tx_phys, LNET_MAX_IOV * sizeof(*tx->tx_phys));
1329 LIBCFS_FREE(tx, sizeof(*tx));
1334 kranal_alloc_txdescs(cfs_list_t *freelist, int n)
1339 LASSERT (freelist == &kranal_data.kra_idle_txs);
1340 LASSERT (cfs_list_empty(freelist));
1342 for (i = 0; i < n; i++) {
1344 LIBCFS_ALLOC(tx, sizeof(*tx));
1346 CERROR("Can't allocate tx[%d]\n", i);
1347 kranal_free_txdescs(freelist);
1351 LIBCFS_ALLOC(tx->tx_phys,
1352 LNET_MAX_IOV * sizeof(*tx->tx_phys));
1353 if (tx->tx_phys == NULL) {
1354 CERROR("Can't allocate tx[%d]->tx_phys\n", i);
1356 LIBCFS_FREE(tx, sizeof(*tx));
1357 kranal_free_txdescs(freelist);
1361 tx->tx_buftype = RANAL_BUF_NONE;
1362 tx->tx_msg.ram_type = RANAL_MSG_NONE;
1364 cfs_list_add(&tx->tx_list, freelist);
1371 kranal_device_init(int id, kra_device_t *dev)
1373 int total_ntx = *kranal_tunables.kra_ntx;
1377 rrc = RapkGetDeviceByIndex(id, kranal_device_callback,
1379 if (rrc != RAP_SUCCESS) {
1380 CERROR("Can't get Rapidarray Device %d: %d\n", id, rrc);
1384 rrc = RapkReserveRdma(dev->rad_handle, total_ntx);
1385 if (rrc != RAP_SUCCESS) {
1386 CERROR("Can't reserve %d RDMA descriptors"
1387 " for device %d: %d\n", total_ntx, id, rrc);
1391 rrc = RapkCreateCQ(dev->rad_handle, total_ntx, RAP_CQTYPE_SEND,
1392 &dev->rad_rdma_cqh);
1393 if (rrc != RAP_SUCCESS) {
1394 CERROR("Can't create rdma cq size %d for device %d: %d\n",
1395 total_ntx, id, rrc);
1399 rrc = RapkCreateCQ(dev->rad_handle,
1400 *kranal_tunables.kra_fma_cq_size,
1401 RAP_CQTYPE_RECV, &dev->rad_fma_cqh);
1402 if (rrc != RAP_SUCCESS) {
1403 CERROR("Can't create fma cq size %d for device %d: %d\n",
1404 *kranal_tunables.kra_fma_cq_size, id, rrc);
1411 RapkDestroyCQ(dev->rad_handle, dev->rad_rdma_cqh);
1413 RapkReleaseDevice(dev->rad_handle);
1419 kranal_device_fini(kra_device_t *dev)
1421 LASSERT (cfs_list_empty(&dev->rad_ready_conns));
1422 LASSERT (cfs_list_empty(&dev->rad_new_conns));
1423 LASSERT (dev->rad_nphysmap == 0);
1424 LASSERT (dev->rad_nppphysmap == 0);
1425 LASSERT (dev->rad_nvirtmap == 0);
1426 LASSERT (dev->rad_nobvirtmap == 0);
1428 LASSERT(dev->rad_scheduler == NULL);
1429 RapkDestroyCQ(dev->rad_handle, dev->rad_fma_cqh);
1430 RapkDestroyCQ(dev->rad_handle, dev->rad_rdma_cqh);
1431 RapkReleaseDevice(dev->rad_handle);
1435 kranal_shutdown (lnet_ni_t *ni)
1438 unsigned long flags;
1440 CDEBUG(D_MALLOC, "before NAL cleanup: kmem %d\n",
1441 cfs_atomic_read(&libcfs_kmemory));
1443 LASSERT (ni == kranal_data.kra_ni);
1444 LASSERT (ni->ni_data == &kranal_data);
1446 switch (kranal_data.kra_init) {
1448 CERROR("Unexpected state %d\n", kranal_data.kra_init);
1451 case RANAL_INIT_ALL:
1452 /* Prevent new peers from being created */
1453 write_lock_irqsave(&kranal_data.kra_global_lock, flags);
1454 kranal_data.kra_nonewpeers = 1;
1455 write_unlock_irqrestore(&kranal_data.kra_global_lock,
1458 /* Remove all existing peers from the peer table */
1459 kranal_del_peer(LNET_NID_ANY);
1461 /* Wait for pending conn reqs to be handled */
1463 spin_lock_irqsave(&kranal_data.kra_connd_lock, flags);
1464 while (!cfs_list_empty(&kranal_data.kra_connd_acceptq)) {
1465 spin_unlock_irqrestore(&kranal_data.kra_connd_lock,
1468 CDEBUG(((i & (-i)) == i) ? D_WARNING : D_NET, /* 2**n */
1469 "waiting for conn reqs to clean up\n");
1470 cfs_pause(cfs_time_seconds(1));
1472 spin_lock_irqsave(&kranal_data.kra_connd_lock,
1475 spin_unlock_irqrestore(&kranal_data.kra_connd_lock, flags);
1477 /* Wait for all peers to be freed */
1479 while (cfs_atomic_read(&kranal_data.kra_npeers) != 0) {
1481 CDEBUG(((i & (-i)) == i) ? D_WARNING : D_NET, /* 2**n */
1482 "waiting for %d peers to close down\n",
1483 cfs_atomic_read(&kranal_data.kra_npeers));
1484 cfs_pause(cfs_time_seconds(1));
1488 case RANAL_INIT_DATA:
1492 /* Peer state all cleaned up BEFORE setting shutdown, so threads don't
1493 * have to worry about shutdown races. NB connections may be created
1494 * while there are still active connds, but these will be temporary
1495 * since peer creation always fails after the listener has started to
1497 LASSERT (cfs_atomic_read(&kranal_data.kra_npeers) == 0);
1499 /* Flag threads to terminate */
1500 kranal_data.kra_shutdown = 1;
1502 for (i = 0; i < kranal_data.kra_ndevs; i++) {
1503 kra_device_t *dev = &kranal_data.kra_devices[i];
1505 spin_lock_irqsave(&dev->rad_lock, flags);
1506 cfs_waitq_signal(&dev->rad_waitq);
1507 spin_unlock_irqrestore(&dev->rad_lock, flags);
1510 spin_lock_irqsave(&kranal_data.kra_reaper_lock, flags);
1511 cfs_waitq_broadcast(&kranal_data.kra_reaper_waitq);
1512 spin_unlock_irqrestore(&kranal_data.kra_reaper_lock, flags);
1514 LASSERT (cfs_list_empty(&kranal_data.kra_connd_peers));
1515 spin_lock_irqsave(&kranal_data.kra_connd_lock, flags);
1516 cfs_waitq_broadcast(&kranal_data.kra_connd_waitq);
1517 spin_unlock_irqrestore(&kranal_data.kra_connd_lock, flags);
1519 /* Wait for threads to exit */
1521 while (cfs_atomic_read(&kranal_data.kra_nthreads) != 0) {
1523 CDEBUG(((i & (-i)) == i) ? D_WARNING : D_NET, /* power of 2? */
1524 "Waiting for %d threads to terminate\n",
1525 cfs_atomic_read(&kranal_data.kra_nthreads));
1526 cfs_pause(cfs_time_seconds(1));
1529 LASSERT (cfs_atomic_read(&kranal_data.kra_npeers) == 0);
1530 if (kranal_data.kra_peers != NULL) {
1531 for (i = 0; i < kranal_data.kra_peer_hash_size; i++)
1532 LASSERT (cfs_list_empty(&kranal_data.kra_peers[i]));
1534 LIBCFS_FREE(kranal_data.kra_peers,
1535 sizeof (cfs_list_t) *
1536 kranal_data.kra_peer_hash_size);
1539 LASSERT (cfs_atomic_read(&kranal_data.kra_nconns) == 0);
1540 if (kranal_data.kra_conns != NULL) {
1541 for (i = 0; i < kranal_data.kra_conn_hash_size; i++)
1542 LASSERT (cfs_list_empty(&kranal_data.kra_conns[i]));
1544 LIBCFS_FREE(kranal_data.kra_conns,
1545 sizeof (cfs_list_t) *
1546 kranal_data.kra_conn_hash_size);
1549 for (i = 0; i < kranal_data.kra_ndevs; i++)
1550 kranal_device_fini(&kranal_data.kra_devices[i]);
1552 kranal_free_txdescs(&kranal_data.kra_idle_txs);
1554 CDEBUG(D_MALLOC, "after NAL cleanup: kmem %d\n",
1555 cfs_atomic_read(&libcfs_kmemory));
1557 kranal_data.kra_init = RANAL_INIT_NOTHING;
1558 PORTAL_MODULE_UNUSE;
1562 kranal_startup (lnet_ni_t *ni)
1565 int pkmem = cfs_atomic_read(&libcfs_kmemory);
1570 LASSERT (ni->ni_lnd == &the_kralnd);
1572 /* Only 1 instance supported */
1573 if (kranal_data.kra_init != RANAL_INIT_NOTHING) {
1574 CERROR ("Only 1 instance supported\n");
1578 if (lnet_set_ip_niaddr(ni) != 0) {
1579 CERROR ("Can't determine my NID\n");
1583 if (*kranal_tunables.kra_credits > *kranal_tunables.kra_ntx) {
1584 CERROR ("Can't set credits(%d) > ntx(%d)\n",
1585 *kranal_tunables.kra_credits,
1586 *kranal_tunables.kra_ntx);
1590 memset(&kranal_data, 0, sizeof(kranal_data)); /* zero pointers, flags etc */
1592 ni->ni_maxtxcredits = *kranal_tunables.kra_credits;
1593 ni->ni_peertxcredits = *kranal_tunables.kra_peercredits;
1595 ni->ni_data = &kranal_data;
1596 kranal_data.kra_ni = ni;
1598 /* CAVEAT EMPTOR: Every 'Fma' message includes the sender's NID and
1599 * a unique (for all time) connstamp so we can uniquely identify
1600 * the sender. The connstamp is an incrementing counter
1601 * initialised with seconds + microseconds at startup time. So we
1602 * rely on NOT creating connections more frequently on average than
1603 * 1MHz to ensure we don't use old connstamps when we reboot. */
1604 cfs_gettimeofday(&tv);
1605 kranal_data.kra_connstamp =
1606 kranal_data.kra_peerstamp = (((__u64)tv.tv_sec) * 1000000) + tv.tv_usec;
1608 rwlock_init(&kranal_data.kra_global_lock);
1610 for (i = 0; i < RANAL_MAXDEVS; i++ ) {
1611 kra_device_t *dev = &kranal_data.kra_devices[i];
1614 CFS_INIT_LIST_HEAD(&dev->rad_ready_conns);
1615 CFS_INIT_LIST_HEAD(&dev->rad_new_conns);
1616 cfs_waitq_init(&dev->rad_waitq);
1617 spin_lock_init(&dev->rad_lock);
1620 kranal_data.kra_new_min_timeout = CFS_MAX_SCHEDULE_TIMEOUT;
1621 cfs_waitq_init(&kranal_data.kra_reaper_waitq);
1622 spin_lock_init(&kranal_data.kra_reaper_lock);
1624 CFS_INIT_LIST_HEAD(&kranal_data.kra_connd_acceptq);
1625 CFS_INIT_LIST_HEAD(&kranal_data.kra_connd_peers);
1626 cfs_waitq_init(&kranal_data.kra_connd_waitq);
1627 spin_lock_init(&kranal_data.kra_connd_lock);
1629 CFS_INIT_LIST_HEAD(&kranal_data.kra_idle_txs);
1630 spin_lock_init(&kranal_data.kra_tx_lock);
1632 /* OK to call kranal_api_shutdown() to cleanup now */
1633 kranal_data.kra_init = RANAL_INIT_DATA;
1636 kranal_data.kra_peer_hash_size = RANAL_PEER_HASH_SIZE;
1637 LIBCFS_ALLOC(kranal_data.kra_peers,
1638 sizeof(cfs_list_t) *
1639 kranal_data.kra_peer_hash_size);
1640 if (kranal_data.kra_peers == NULL)
1643 for (i = 0; i < kranal_data.kra_peer_hash_size; i++)
1644 CFS_INIT_LIST_HEAD(&kranal_data.kra_peers[i]);
1646 kranal_data.kra_conn_hash_size = RANAL_PEER_HASH_SIZE;
1647 LIBCFS_ALLOC(kranal_data.kra_conns,
1648 sizeof(cfs_list_t) *
1649 kranal_data.kra_conn_hash_size);
1650 if (kranal_data.kra_conns == NULL)
1653 for (i = 0; i < kranal_data.kra_conn_hash_size; i++)
1654 CFS_INIT_LIST_HEAD(&kranal_data.kra_conns[i]);
1656 rc = kranal_alloc_txdescs(&kranal_data.kra_idle_txs,
1657 *kranal_tunables.kra_ntx);
1661 rc = kranal_thread_start(kranal_reaper, NULL);
1663 CERROR("Can't spawn ranal reaper: %d\n", rc);
1667 for (i = 0; i < *kranal_tunables.kra_n_connd; i++) {
1668 rc = kranal_thread_start(kranal_connd, (void *)(unsigned long)i);
1670 CERROR("Can't spawn ranal connd[%d]: %d\n",
1676 LASSERT (kranal_data.kra_ndevs == 0);
1678 /* Use all available RapidArray devices */
1679 for (i = 0; i < RANAL_MAXDEVS; i++) {
1680 dev = &kranal_data.kra_devices[kranal_data.kra_ndevs];
1682 rc = kranal_device_init(kranal_devids[i], dev);
1684 kranal_data.kra_ndevs++;
1687 if (kranal_data.kra_ndevs == 0) {
1688 CERROR("Can't initialise any RapidArray devices\n");
1692 for (i = 0; i < kranal_data.kra_ndevs; i++) {
1693 dev = &kranal_data.kra_devices[i];
1694 rc = kranal_thread_start(kranal_scheduler, dev);
1696 CERROR("Can't spawn ranal scheduler[%d]: %d\n",
1702 /* flag everything initialised */
1703 kranal_data.kra_init = RANAL_INIT_ALL;
1704 /*****************************************************/
1706 CDEBUG(D_MALLOC, "initial kmem %d\n", pkmem);
1710 kranal_shutdown(ni);
1715 kranal_module_fini (void)
1717 lnet_unregister_lnd(&the_kralnd);
1718 kranal_tunables_fini();
1722 kranal_module_init (void)
1726 rc = kranal_tunables_init();
1730 lnet_register_lnd(&the_kralnd);
1735 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
1736 MODULE_DESCRIPTION("Kernel RapidArray LND v0.01");
1737 MODULE_LICENSE("GPL");
1739 module_init(kranal_module_init);
1740 module_exit(kranal_module_fini);