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) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
31 * This file is part of Lustre, http://www.lustre.org/
32 * Lustre is a trademark of Sun Microsystems, Inc.
34 * lnet/lnet/lib-move.c
36 * Data movement routines
39 #define DEBUG_SUBSYSTEM S_LNET
41 #include <lnet/lib-lnet.h>
43 static int local_nid_dist_zero = 1;
44 CFS_MODULE_PARM(local_nid_dist_zero, "i", int, 0444,
48 lnet_fail_nid (lnet_nid_t nid, unsigned int threshold)
55 LASSERT (the_lnet.ln_init);
57 /* NB: use lnet_net_lock(0) to serialize operations on test peers */
59 /* Adding a new entry */
60 LIBCFS_ALLOC(tp, sizeof(*tp));
65 tp->tp_threshold = threshold;
68 cfs_list_add_tail(&tp->tp_list, &the_lnet.ln_test_peers);
73 /* removing entries */
74 CFS_INIT_LIST_HEAD(&cull);
78 cfs_list_for_each_safe (el, next, &the_lnet.ln_test_peers) {
79 tp = cfs_list_entry (el, lnet_test_peer_t, tp_list);
81 if (tp->tp_threshold == 0 || /* needs culling anyway */
82 nid == LNET_NID_ANY || /* removing all entries */
83 tp->tp_nid == nid) /* matched this one */
85 cfs_list_del (&tp->tp_list);
86 cfs_list_add (&tp->tp_list, &cull);
92 while (!cfs_list_empty (&cull)) {
93 tp = cfs_list_entry (cull.next, lnet_test_peer_t, tp_list);
95 cfs_list_del (&tp->tp_list);
96 LIBCFS_FREE(tp, sizeof (*tp));
102 fail_peer (lnet_nid_t nid, int outgoing)
104 lnet_test_peer_t *tp;
110 CFS_INIT_LIST_HEAD (&cull);
112 /* NB: use lnet_net_lock(0) to serialize operations on test peers */
115 cfs_list_for_each_safe (el, next, &the_lnet.ln_test_peers) {
116 tp = cfs_list_entry (el, lnet_test_peer_t, tp_list);
118 if (tp->tp_threshold == 0) {
121 /* only cull zombies on outgoing tests,
122 * since we may be at interrupt priority on
123 * incoming messages. */
124 cfs_list_del (&tp->tp_list);
125 cfs_list_add (&tp->tp_list, &cull);
130 if (tp->tp_nid == LNET_NID_ANY || /* fail every peer */
131 nid == tp->tp_nid) { /* fail this peer */
134 if (tp->tp_threshold != LNET_MD_THRESH_INF) {
137 tp->tp_threshold == 0) {
139 cfs_list_del (&tp->tp_list);
140 cfs_list_add (&tp->tp_list, &cull);
149 while (!cfs_list_empty (&cull)) {
150 tp = cfs_list_entry (cull.next, lnet_test_peer_t, tp_list);
151 cfs_list_del (&tp->tp_list);
153 LIBCFS_FREE(tp, sizeof (*tp));
160 lnet_iov_nob (unsigned int niov, struct iovec *iov)
162 unsigned int nob = 0;
165 nob += (iov++)->iov_len;
171 lnet_copy_iov2iov (unsigned int ndiov, struct iovec *diov, unsigned int doffset,
172 unsigned int nsiov, struct iovec *siov, unsigned int soffset,
175 /* NB diov, siov are READ-ONLY */
176 unsigned int this_nob;
181 /* skip complete frags before 'doffset' */
183 while (doffset >= diov->iov_len) {
184 doffset -= diov->iov_len;
190 /* skip complete frags before 'soffset' */
192 while (soffset >= siov->iov_len) {
193 soffset -= siov->iov_len;
202 this_nob = MIN(diov->iov_len - doffset,
203 siov->iov_len - soffset);
204 this_nob = MIN(this_nob, nob);
206 memcpy ((char *)diov->iov_base + doffset,
207 (char *)siov->iov_base + soffset, this_nob);
210 if (diov->iov_len > doffset + this_nob) {
218 if (siov->iov_len > soffset + this_nob) {
229 lnet_extract_iov (int dst_niov, struct iovec *dst,
230 int src_niov, struct iovec *src,
231 unsigned int offset, unsigned int len)
233 /* Initialise 'dst' to the subset of 'src' starting at 'offset',
234 * for exactly 'len' bytes, and return the number of entries.
235 * NB not destructive to 'src' */
236 unsigned int frag_len;
239 if (len == 0) /* no data => */
240 return (0); /* no frags */
242 LASSERT (src_niov > 0);
243 while (offset >= src->iov_len) { /* skip initial frags */
244 offset -= src->iov_len;
247 LASSERT (src_niov > 0);
252 LASSERT (src_niov > 0);
253 LASSERT ((int)niov <= dst_niov);
255 frag_len = src->iov_len - offset;
256 dst->iov_base = ((char *)src->iov_base) + offset;
258 if (len <= frag_len) {
263 dst->iov_len = frag_len;
276 lnet_kiov_nob (unsigned int niov, lnet_kiov_t *kiov)
283 lnet_copy_kiov2kiov (unsigned int ndkiov, lnet_kiov_t *dkiov, unsigned int doffset,
284 unsigned int nskiov, lnet_kiov_t *skiov, unsigned int soffset,
291 lnet_copy_kiov2iov (unsigned int niov, struct iovec *iov, unsigned int iovoffset,
292 unsigned int nkiov, lnet_kiov_t *kiov, unsigned int kiovoffset,
299 lnet_copy_iov2kiov (unsigned int nkiov, lnet_kiov_t *kiov, unsigned int kiovoffset,
300 unsigned int niov, struct iovec *iov, unsigned int iovoffset,
307 lnet_extract_kiov (int dst_niov, lnet_kiov_t *dst,
308 int src_niov, lnet_kiov_t *src,
309 unsigned int offset, unsigned int len)
314 #else /* __KERNEL__ */
317 lnet_kiov_nob (unsigned int niov, lnet_kiov_t *kiov)
319 unsigned int nob = 0;
322 nob += (kiov++)->kiov_len;
328 lnet_copy_kiov2kiov (unsigned int ndiov, lnet_kiov_t *diov, unsigned int doffset,
329 unsigned int nsiov, lnet_kiov_t *siov, unsigned int soffset,
332 /* NB diov, siov are READ-ONLY */
333 unsigned int this_nob;
340 LASSERT (!cfs_in_interrupt ());
343 while (doffset >= diov->kiov_len) {
344 doffset -= diov->kiov_len;
351 while (soffset >= siov->kiov_len) {
352 soffset -= siov->kiov_len;
361 this_nob = MIN(diov->kiov_len - doffset,
362 siov->kiov_len - soffset);
363 this_nob = MIN(this_nob, nob);
366 daddr = ((char *)cfs_kmap(diov->kiov_page)) +
367 diov->kiov_offset + doffset;
369 saddr = ((char *)cfs_kmap(siov->kiov_page)) +
370 siov->kiov_offset + soffset;
372 /* Vanishing risk of kmap deadlock when mapping 2 pages.
373 * However in practice at least one of the kiovs will be mapped
374 * kernel pages and the map/unmap will be NOOPs */
376 memcpy (daddr, saddr, this_nob);
379 if (diov->kiov_len > doffset + this_nob) {
383 cfs_kunmap(diov->kiov_page);
390 if (siov->kiov_len > soffset + this_nob) {
394 cfs_kunmap(siov->kiov_page);
403 cfs_kunmap(diov->kiov_page);
405 cfs_kunmap(siov->kiov_page);
409 lnet_copy_kiov2iov (unsigned int niov, struct iovec *iov, unsigned int iovoffset,
410 unsigned int nkiov, lnet_kiov_t *kiov, unsigned int kiovoffset,
413 /* NB iov, kiov are READ-ONLY */
414 unsigned int this_nob;
420 LASSERT (!cfs_in_interrupt ());
423 while (iovoffset >= iov->iov_len) {
424 iovoffset -= iov->iov_len;
431 while (kiovoffset >= kiov->kiov_len) {
432 kiovoffset -= kiov->kiov_len;
441 this_nob = MIN(iov->iov_len - iovoffset,
442 kiov->kiov_len - kiovoffset);
443 this_nob = MIN(this_nob, nob);
446 addr = ((char *)cfs_kmap(kiov->kiov_page)) +
447 kiov->kiov_offset + kiovoffset;
449 memcpy ((char *)iov->iov_base + iovoffset, addr, this_nob);
452 if (iov->iov_len > iovoffset + this_nob) {
453 iovoffset += this_nob;
460 if (kiov->kiov_len > kiovoffset + this_nob) {
462 kiovoffset += this_nob;
464 cfs_kunmap(kiov->kiov_page);
474 cfs_kunmap(kiov->kiov_page);
478 lnet_copy_iov2kiov (unsigned int nkiov, lnet_kiov_t *kiov, unsigned int kiovoffset,
479 unsigned int niov, struct iovec *iov, unsigned int iovoffset,
482 /* NB kiov, iov are READ-ONLY */
483 unsigned int this_nob;
489 LASSERT (!cfs_in_interrupt ());
492 while (kiovoffset >= kiov->kiov_len) {
493 kiovoffset -= kiov->kiov_len;
500 while (iovoffset >= iov->iov_len) {
501 iovoffset -= iov->iov_len;
510 this_nob = MIN(kiov->kiov_len - kiovoffset,
511 iov->iov_len - iovoffset);
512 this_nob = MIN(this_nob, nob);
515 addr = ((char *)cfs_kmap(kiov->kiov_page)) +
516 kiov->kiov_offset + kiovoffset;
518 memcpy (addr, (char *)iov->iov_base + iovoffset, this_nob);
521 if (kiov->kiov_len > kiovoffset + this_nob) {
523 kiovoffset += this_nob;
525 cfs_kunmap(kiov->kiov_page);
532 if (iov->iov_len > iovoffset + this_nob) {
533 iovoffset += this_nob;
542 cfs_kunmap(kiov->kiov_page);
546 lnet_extract_kiov (int dst_niov, lnet_kiov_t *dst,
547 int src_niov, lnet_kiov_t *src,
548 unsigned int offset, unsigned int len)
550 /* Initialise 'dst' to the subset of 'src' starting at 'offset',
551 * for exactly 'len' bytes, and return the number of entries.
552 * NB not destructive to 'src' */
553 unsigned int frag_len;
556 if (len == 0) /* no data => */
557 return (0); /* no frags */
559 LASSERT (src_niov > 0);
560 while (offset >= src->kiov_len) { /* skip initial frags */
561 offset -= src->kiov_len;
564 LASSERT (src_niov > 0);
569 LASSERT (src_niov > 0);
570 LASSERT ((int)niov <= dst_niov);
572 frag_len = src->kiov_len - offset;
573 dst->kiov_page = src->kiov_page;
574 dst->kiov_offset = src->kiov_offset + offset;
576 if (len <= frag_len) {
578 LASSERT (dst->kiov_offset + dst->kiov_len <= CFS_PAGE_SIZE);
582 dst->kiov_len = frag_len;
583 LASSERT (dst->kiov_offset + dst->kiov_len <= CFS_PAGE_SIZE);
596 lnet_ni_recv(lnet_ni_t *ni, void *private, lnet_msg_t *msg, int delayed,
597 unsigned int offset, unsigned int mlen, unsigned int rlen)
599 unsigned int niov = 0;
600 struct iovec *iov = NULL;
601 lnet_kiov_t *kiov = NULL;
604 LASSERT (!cfs_in_interrupt ());
605 LASSERT (mlen == 0 || msg != NULL);
608 LASSERT(msg->msg_receiving);
609 LASSERT(!msg->msg_sending);
610 LASSERT(rlen == msg->msg_len);
611 LASSERT(mlen <= msg->msg_len);
612 LASSERT(msg->msg_offset == offset);
613 LASSERT(msg->msg_wanted == mlen);
615 msg->msg_receiving = 0;
618 niov = msg->msg_niov;
620 kiov = msg->msg_kiov;
623 LASSERT ((iov == NULL) != (kiov == NULL));
627 rc = (ni->ni_lnd->lnd_recv)(ni, private, msg, delayed,
628 niov, iov, kiov, offset, mlen, rlen);
630 lnet_finalize(ni, msg, rc);
634 lnet_setpayloadbuffer(lnet_msg_t *msg)
636 lnet_libmd_t *md = msg->msg_md;
638 LASSERT (msg->msg_len > 0);
639 LASSERT (!msg->msg_routing);
640 LASSERT (md != NULL);
641 LASSERT (msg->msg_niov == 0);
642 LASSERT (msg->msg_iov == NULL);
643 LASSERT (msg->msg_kiov == NULL);
645 msg->msg_niov = md->md_niov;
646 if ((md->md_options & LNET_MD_KIOV) != 0)
647 msg->msg_kiov = md->md_iov.kiov;
649 msg->msg_iov = md->md_iov.iov;
653 lnet_prep_send(lnet_msg_t *msg, int type, lnet_process_id_t target,
654 unsigned int offset, unsigned int len)
656 msg->msg_type = type;
657 msg->msg_target = target;
659 msg->msg_offset = offset;
662 lnet_setpayloadbuffer(msg);
664 memset (&msg->msg_hdr, 0, sizeof (msg->msg_hdr));
665 msg->msg_hdr.type = cpu_to_le32(type);
666 msg->msg_hdr.dest_nid = cpu_to_le64(target.nid);
667 msg->msg_hdr.dest_pid = cpu_to_le32(target.pid);
668 /* src_nid will be set later */
669 msg->msg_hdr.src_pid = cpu_to_le32(the_lnet.ln_pid);
670 msg->msg_hdr.payload_length = cpu_to_le32(len);
674 lnet_ni_send(lnet_ni_t *ni, lnet_msg_t *msg)
676 void *priv = msg->msg_private;
679 LASSERT (!cfs_in_interrupt ());
680 LASSERT (LNET_NETTYP(LNET_NIDNET(ni->ni_nid)) == LOLND ||
681 (msg->msg_txcredit && msg->msg_peertxcredit));
683 rc = (ni->ni_lnd->lnd_send)(ni, priv, msg);
685 lnet_finalize(ni, msg, rc);
689 lnet_ni_eager_recv(lnet_ni_t *ni, lnet_msg_t *msg)
693 LASSERT(!msg->msg_sending);
694 LASSERT(msg->msg_receiving);
695 LASSERT(ni->ni_lnd->lnd_eager_recv != NULL);
697 msg->msg_rx_ready_delay = 1;
698 rc = (ni->ni_lnd->lnd_eager_recv)(ni, msg->msg_private, msg,
701 CERROR("recv from %s / send to %s aborted: "
702 "eager_recv failed %d\n",
703 libcfs_nid2str(msg->msg_rxpeer->lp_nid),
704 libcfs_id2str(msg->msg_target), rc);
705 LASSERT(rc < 0); /* required by my callers */
711 /* NB: caller shall hold a ref on 'lp' as I'd drop lnet_net_lock */
713 lnet_ni_query_locked(lnet_ni_t *ni, lnet_peer_t *lp)
715 cfs_time_t last_alive = 0;
717 LASSERT(lnet_peer_aliveness_enabled(lp));
718 LASSERT(ni->ni_lnd->lnd_query != NULL);
719 LASSERT(the_lnet.ln_routing == 1);
721 lnet_net_unlock(lp->lp_cpt);
722 (ni->ni_lnd->lnd_query)(ni, lp->lp_nid, &last_alive);
723 lnet_net_lock(lp->lp_cpt);
725 lp->lp_last_query = cfs_time_current();
727 if (last_alive != 0) /* NI has updated timestamp */
728 lp->lp_last_alive = last_alive;
731 /* NB: always called with lnet_net_lock held */
733 lnet_peer_is_alive (lnet_peer_t *lp, cfs_time_t now)
738 LASSERT (lnet_peer_aliveness_enabled(lp));
739 LASSERT (the_lnet.ln_routing == 1);
741 /* Trust lnet_notify() if it has more recent aliveness news, but
742 * ignore the initial assumed death (see lnet_peers_start_down()).
744 if (!lp->lp_alive && lp->lp_alive_count > 0 &&
745 cfs_time_aftereq(lp->lp_timestamp, lp->lp_last_alive))
748 deadline = cfs_time_add(lp->lp_last_alive,
749 cfs_time_seconds(lp->lp_ni->ni_peertimeout));
750 alive = cfs_time_after(deadline, now);
752 /* Update obsolete lp_alive except for routers assumed to be dead
753 * initially, because router checker would update aliveness in this
754 * case, and moreover lp_last_alive at peer creation is assumed.
756 if (alive && !lp->lp_alive &&
757 !(lnet_isrouter(lp) && lp->lp_alive_count == 0))
758 lnet_notify_locked(lp, 0, 1, lp->lp_last_alive);
764 /* NB: returns 1 when alive, 0 when dead, negative when error;
765 * may drop the lnet_net_lock */
767 lnet_peer_alive_locked (lnet_peer_t *lp)
769 cfs_time_t now = cfs_time_current();
771 /* LU-630: only router checks peer health. */
772 if (the_lnet.ln_routing == 0)
775 if (!lnet_peer_aliveness_enabled(lp))
778 if (lnet_peer_is_alive(lp, now))
781 /* Peer appears dead, but we should avoid frequent NI queries (at
782 * most once per lnet_queryinterval seconds). */
783 if (lp->lp_last_query != 0) {
784 static const int lnet_queryinterval = 1;
786 cfs_time_t next_query =
787 cfs_time_add(lp->lp_last_query,
788 cfs_time_seconds(lnet_queryinterval));
790 if (cfs_time_before(now, next_query)) {
792 CWARN("Unexpected aliveness of peer %s: "
794 libcfs_nid2str(lp->lp_nid),
795 (int)now, (int)next_query,
797 lp->lp_ni->ni_peertimeout);
802 /* query NI for latest aliveness news */
803 lnet_ni_query_locked(lp->lp_ni, lp);
805 if (lnet_peer_is_alive(lp, now))
808 lnet_notify_locked(lp, 0, 0, lp->lp_last_alive);
813 lnet_post_send_locked(lnet_msg_t *msg, int do_send)
815 /* lnet_send is going to lnet_net_unlock immediately after this,
816 * so it sets do_send FALSE and I don't do the unlock/send/lock bit.
817 * I return EAGAIN if msg blocked, EHOSTUNREACH if msg_txpeer
818 * appears dead, and 0 if sent or OK to send */
819 struct lnet_peer *lp = msg->msg_txpeer;
820 struct lnet_ni *ni = lp->lp_ni;
821 struct lnet_tx_queue *tq;
824 /* non-lnet_send() callers have checked before */
825 LASSERT(!do_send || msg->msg_tx_delayed);
826 LASSERT(!msg->msg_receiving);
827 LASSERT(msg->msg_tx_committed);
829 cpt = msg->msg_tx_cpt;
830 tq = ni->ni_tx_queues[cpt];
832 /* NB 'lp' is always the next hop */
833 if ((msg->msg_target.pid & LNET_PID_USERFLAG) == 0 &&
834 lnet_peer_alive_locked(lp) == 0) {
835 the_lnet.ln_counters[cpt]->drop_count++;
836 the_lnet.ln_counters[cpt]->drop_length += msg->msg_len;
837 lnet_net_unlock(cpt);
839 CNETERR("Dropping message for %s: peer not alive\n",
840 libcfs_id2str(msg->msg_target));
842 lnet_finalize(ni, msg, -EHOSTUNREACH);
848 if (!msg->msg_peertxcredit) {
849 LASSERT ((lp->lp_txcredits < 0) ==
850 !cfs_list_empty(&lp->lp_txq));
852 msg->msg_peertxcredit = 1;
853 lp->lp_txqnob += msg->msg_len + sizeof(lnet_hdr_t);
856 if (lp->lp_txcredits < lp->lp_mintxcredits)
857 lp->lp_mintxcredits = lp->lp_txcredits;
859 if (lp->lp_txcredits < 0) {
860 msg->msg_tx_delayed = 1;
861 cfs_list_add_tail(&msg->msg_list, &lp->lp_txq);
866 if (!msg->msg_txcredit) {
867 LASSERT((tq->tq_credits < 0) ==
868 !cfs_list_empty(&tq->tq_delayed));
870 msg->msg_txcredit = 1;
873 if (tq->tq_credits < tq->tq_credits_min)
874 tq->tq_credits_min = tq->tq_credits;
876 if (tq->tq_credits < 0) {
877 msg->msg_tx_delayed = 1;
878 cfs_list_add_tail(&msg->msg_list, &tq->tq_delayed);
884 lnet_net_unlock(cpt);
885 lnet_ni_send(ni, msg);
894 lnet_msg2bufpool(lnet_msg_t *msg)
896 lnet_rtrbufpool_t *rbp;
899 LASSERT(msg->msg_rx_committed);
901 cpt = msg->msg_rx_cpt;
902 rbp = &the_lnet.ln_rtrpools[cpt][0];
904 LASSERT(msg->msg_len <= LNET_MTU);
905 while (msg->msg_len > (unsigned int)rbp->rbp_npages * CFS_PAGE_SIZE) {
907 LASSERT(rbp < &the_lnet.ln_rtrpools[cpt][LNET_NRBPOOLS]);
914 lnet_post_routed_recv_locked (lnet_msg_t *msg, int do_recv)
916 /* lnet_parse is going to lnet_net_unlock immediately after this, so it
917 * sets do_recv FALSE and I don't do the unlock/send/lock bit. I
918 * return EAGAIN if msg blocked and 0 if received or OK to receive */
919 lnet_peer_t *lp = msg->msg_rxpeer;
920 lnet_rtrbufpool_t *rbp;
923 LASSERT (msg->msg_iov == NULL);
924 LASSERT (msg->msg_kiov == NULL);
925 LASSERT (msg->msg_niov == 0);
926 LASSERT (msg->msg_routing);
927 LASSERT (msg->msg_receiving);
928 LASSERT (!msg->msg_sending);
930 /* non-lnet_parse callers only receive delayed messages */
931 LASSERT(!do_recv || msg->msg_rx_delayed);
933 if (!msg->msg_peerrtrcredit) {
934 LASSERT ((lp->lp_rtrcredits < 0) ==
935 !cfs_list_empty(&lp->lp_rtrq));
937 msg->msg_peerrtrcredit = 1;
939 if (lp->lp_rtrcredits < lp->lp_minrtrcredits)
940 lp->lp_minrtrcredits = lp->lp_rtrcredits;
942 if (lp->lp_rtrcredits < 0) {
943 /* must have checked eager_recv before here */
944 LASSERT(msg->msg_rx_ready_delay);
945 msg->msg_rx_delayed = 1;
946 cfs_list_add_tail(&msg->msg_list, &lp->lp_rtrq);
951 rbp = lnet_msg2bufpool(msg);
953 if (!msg->msg_rtrcredit) {
954 LASSERT ((rbp->rbp_credits < 0) ==
955 !cfs_list_empty(&rbp->rbp_msgs));
957 msg->msg_rtrcredit = 1;
959 if (rbp->rbp_credits < rbp->rbp_mincredits)
960 rbp->rbp_mincredits = rbp->rbp_credits;
962 if (rbp->rbp_credits < 0) {
963 /* must have checked eager_recv before here */
964 LASSERT(msg->msg_rx_ready_delay);
965 msg->msg_rx_delayed = 1;
966 cfs_list_add_tail(&msg->msg_list, &rbp->rbp_msgs);
971 LASSERT (!cfs_list_empty(&rbp->rbp_bufs));
972 rb = cfs_list_entry(rbp->rbp_bufs.next, lnet_rtrbuf_t, rb_list);
973 cfs_list_del(&rb->rb_list);
975 msg->msg_niov = rbp->rbp_npages;
976 msg->msg_kiov = &rb->rb_kiov[0];
979 int cpt = msg->msg_rx_cpt;
981 lnet_net_unlock(cpt);
982 lnet_ni_recv(lp->lp_ni, msg->msg_private, msg, 1,
983 0, msg->msg_len, msg->msg_len);
991 lnet_return_tx_credits_locked(lnet_msg_t *msg)
993 lnet_peer_t *txpeer = msg->msg_txpeer;
996 if (msg->msg_txcredit) {
997 struct lnet_ni *ni = txpeer->lp_ni;
998 struct lnet_tx_queue *tq = ni->ni_tx_queues[msg->msg_tx_cpt];
1000 /* give back NI txcredits */
1001 msg->msg_txcredit = 0;
1003 LASSERT((tq->tq_credits < 0) ==
1004 !cfs_list_empty(&tq->tq_delayed));
1007 if (tq->tq_credits <= 0) {
1008 msg2 = cfs_list_entry(tq->tq_delayed.next,
1009 lnet_msg_t, msg_list);
1010 cfs_list_del(&msg2->msg_list);
1012 LASSERT(msg2->msg_txpeer->lp_ni == ni);
1013 LASSERT(msg2->msg_tx_delayed);
1015 (void) lnet_post_send_locked(msg2, 1);
1019 if (msg->msg_peertxcredit) {
1020 /* give back peer txcredits */
1021 msg->msg_peertxcredit = 0;
1023 LASSERT((txpeer->lp_txcredits < 0) ==
1024 !cfs_list_empty(&txpeer->lp_txq));
1026 txpeer->lp_txqnob -= msg->msg_len + sizeof(lnet_hdr_t);
1027 LASSERT (txpeer->lp_txqnob >= 0);
1029 txpeer->lp_txcredits++;
1030 if (txpeer->lp_txcredits <= 0) {
1031 msg2 = cfs_list_entry(txpeer->lp_txq.next,
1032 lnet_msg_t, msg_list);
1033 cfs_list_del(&msg2->msg_list);
1035 LASSERT(msg2->msg_txpeer == txpeer);
1036 LASSERT(msg2->msg_tx_delayed);
1038 (void) lnet_post_send_locked(msg2, 1);
1042 if (txpeer != NULL) {
1043 msg->msg_txpeer = NULL;
1044 lnet_peer_decref_locked(txpeer);
1049 lnet_return_rx_credits_locked(lnet_msg_t *msg)
1051 lnet_peer_t *rxpeer = msg->msg_rxpeer;
1055 if (msg->msg_rtrcredit) {
1056 /* give back global router credits */
1058 lnet_rtrbufpool_t *rbp;
1060 /* NB If a msg ever blocks for a buffer in rbp_msgs, it stays
1061 * there until it gets one allocated, or aborts the wait
1063 LASSERT (msg->msg_kiov != NULL);
1065 rb = cfs_list_entry(msg->msg_kiov, lnet_rtrbuf_t, rb_kiov[0]);
1067 LASSERT (rbp == lnet_msg2bufpool(msg));
1069 msg->msg_kiov = NULL;
1070 msg->msg_rtrcredit = 0;
1072 LASSERT((rbp->rbp_credits < 0) ==
1073 !cfs_list_empty(&rbp->rbp_msgs));
1074 LASSERT((rbp->rbp_credits > 0) ==
1075 !cfs_list_empty(&rbp->rbp_bufs));
1077 cfs_list_add(&rb->rb_list, &rbp->rbp_bufs);
1079 if (rbp->rbp_credits <= 0) {
1080 msg2 = cfs_list_entry(rbp->rbp_msgs.next,
1081 lnet_msg_t, msg_list);
1082 cfs_list_del(&msg2->msg_list);
1084 (void) lnet_post_routed_recv_locked(msg2, 1);
1088 if (msg->msg_peerrtrcredit) {
1089 /* give back peer router credits */
1090 msg->msg_peerrtrcredit = 0;
1092 LASSERT((rxpeer->lp_rtrcredits < 0) ==
1093 !cfs_list_empty(&rxpeer->lp_rtrq));
1095 rxpeer->lp_rtrcredits++;
1096 if (rxpeer->lp_rtrcredits <= 0) {
1097 msg2 = cfs_list_entry(rxpeer->lp_rtrq.next,
1098 lnet_msg_t, msg_list);
1099 cfs_list_del(&msg2->msg_list);
1101 (void) lnet_post_routed_recv_locked(msg2, 1);
1105 LASSERT (!msg->msg_rtrcredit);
1106 LASSERT (!msg->msg_peerrtrcredit);
1108 if (rxpeer != NULL) {
1109 msg->msg_rxpeer = NULL;
1110 lnet_peer_decref_locked(rxpeer);
1115 lnet_compare_routes(lnet_route_t *r1, lnet_route_t *r2)
1117 lnet_peer_t *p1 = r1->lr_gateway;
1118 lnet_peer_t *p2 = r2->lr_gateway;
1120 if (r1->lr_hops < r2->lr_hops)
1123 if (r1->lr_hops > r2->lr_hops)
1126 if (p1->lp_txqnob < p2->lp_txqnob)
1129 if (p1->lp_txqnob > p2->lp_txqnob)
1132 if (p1->lp_txcredits > p2->lp_txcredits)
1135 if (p1->lp_txcredits < p2->lp_txcredits)
1138 if (r1->lr_seq - r2->lr_seq <= 0)
1144 static lnet_peer_t *
1145 lnet_find_route_locked(lnet_ni_t *ni, lnet_nid_t target, lnet_nid_t rtr_nid)
1147 lnet_remotenet_t *rnet;
1149 lnet_route_t *rtr_best;
1150 lnet_route_t *rtr_last;
1151 struct lnet_peer *lp_best;
1152 struct lnet_peer *lp;
1155 /* If @rtr_nid is not LNET_NID_ANY, return the gateway with
1156 * rtr_nid nid, otherwise find the best gateway I can use */
1158 rnet = lnet_find_net_locked(LNET_NIDNET(target));
1163 rtr_best = rtr_last = NULL;
1164 cfs_list_for_each_entry(rtr, &rnet->lrn_routes, lr_list) {
1165 lp = rtr->lr_gateway;
1167 if (!lp->lp_alive || /* gateway is down */
1168 (lp->lp_ping_version == LNET_PROTO_PING_VERSION &&
1169 rtr->lr_downis != 0)) /* NI to target is down */
1172 if (ni != NULL && lp->lp_ni != ni)
1175 if (lp->lp_nid == rtr_nid) /* it's pre-determined router */
1178 if (lp_best == NULL) {
1179 rtr_best = rtr_last = rtr;
1184 /* no protection on below fields, but it's harmless */
1185 if (rtr_last->lr_seq - rtr->lr_seq < 0)
1188 rc = lnet_compare_routes(rtr, rtr_best);
1196 /* set sequence number on the best router to the latest sequence + 1
1197 * so we can round-robin all routers, it's race and inaccurate but
1198 * harmless and functional */
1199 if (rtr_best != NULL)
1200 rtr_best->lr_seq = rtr_last->lr_seq + 1;
1205 lnet_send(lnet_nid_t src_nid, lnet_msg_t *msg, lnet_nid_t rtr_nid)
1207 lnet_nid_t dst_nid = msg->msg_target.nid;
1208 struct lnet_ni *src_ni;
1209 struct lnet_ni *local_ni;
1210 struct lnet_peer *lp;
1215 /* NB: rtr_nid is set to LNET_NID_ANY for all current use-cases,
1216 * but we might want to use pre-determined router for ACK/REPLY
1218 /* NB: ni != NULL == interface pre-determined (ACK/REPLY) */
1219 LASSERT (msg->msg_txpeer == NULL);
1220 LASSERT (!msg->msg_sending);
1221 LASSERT (!msg->msg_target_is_router);
1222 LASSERT (!msg->msg_receiving);
1224 msg->msg_sending = 1;
1226 LASSERT(!msg->msg_tx_committed);
1227 cpt = lnet_cpt_of_nid(rtr_nid == LNET_NID_ANY ? dst_nid : rtr_nid);
1231 if (the_lnet.ln_shutdown) {
1232 lnet_net_unlock(cpt);
1236 if (src_nid == LNET_NID_ANY) {
1239 src_ni = lnet_nid2ni_locked(src_nid, cpt);
1240 if (src_ni == NULL) {
1241 lnet_net_unlock(cpt);
1242 LCONSOLE_WARN("Can't send to %s: src %s is not a "
1243 "local nid\n", libcfs_nid2str(dst_nid),
1244 libcfs_nid2str(src_nid));
1247 LASSERT (!msg->msg_routing);
1250 /* Is this for someone on a local network? */
1251 local_ni = lnet_net2ni_locked(LNET_NIDNET(dst_nid), cpt);
1253 if (local_ni != NULL) {
1254 if (src_ni == NULL) {
1256 src_nid = src_ni->ni_nid;
1257 } else if (src_ni == local_ni) {
1258 lnet_ni_decref_locked(local_ni, cpt);
1260 lnet_ni_decref_locked(local_ni, cpt);
1261 lnet_ni_decref_locked(src_ni, cpt);
1262 lnet_net_unlock(cpt);
1263 LCONSOLE_WARN("No route to %s via from %s\n",
1264 libcfs_nid2str(dst_nid),
1265 libcfs_nid2str(src_nid));
1269 LASSERT(src_nid != LNET_NID_ANY);
1270 lnet_msg_commit(msg, cpt);
1272 if (!msg->msg_routing)
1273 msg->msg_hdr.src_nid = cpu_to_le64(src_nid);
1275 if (src_ni == the_lnet.ln_loni) {
1276 /* No send credit hassles with LOLND */
1277 lnet_net_unlock(cpt);
1278 lnet_ni_send(src_ni, msg);
1281 lnet_ni_decref_locked(src_ni, cpt);
1282 lnet_net_unlock(cpt);
1286 rc = lnet_nid2peer_locked(&lp, dst_nid, cpt);
1287 /* lp has ref on src_ni; lose mine */
1288 lnet_ni_decref_locked(src_ni, cpt);
1290 lnet_net_unlock(cpt);
1291 LCONSOLE_WARN("Error %d finding peer %s\n", rc,
1292 libcfs_nid2str(dst_nid));
1293 /* ENOMEM or shutting down */
1296 LASSERT (lp->lp_ni == src_ni);
1299 lnet_net_unlock(cpt);
1302 * - once application finishes computation, check here to update
1303 * router states before it waits for pending IO in LNetEQPoll
1304 * - recursion breaker: router checker sends no message
1305 * to remote networks */
1306 if (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING)
1307 lnet_router_checker();
1311 /* sending to a remote network */
1312 lp = lnet_find_route_locked(src_ni, dst_nid, rtr_nid);
1315 lnet_ni_decref_locked(src_ni, cpt);
1316 lnet_net_unlock(cpt);
1318 LCONSOLE_WARN("No route to %s via %s "
1319 "(all routers down)\n",
1320 libcfs_id2str(msg->msg_target),
1321 libcfs_nid2str(src_nid));
1322 return -EHOSTUNREACH;
1325 /* rtr_nid is LNET_NID_ANY or NID of pre-determined router,
1326 * it's possible that rtr_nid isn't LNET_NID_ANY and lp isn't
1327 * pre-determined router, this can happen if router table
1328 * was changed when we release the lock */
1329 if (rtr_nid != lp->lp_nid) {
1330 cpt2 = lnet_cpt_of_nid_locked(lp->lp_nid);
1333 lnet_ni_decref_locked(src_ni, cpt);
1334 lnet_net_unlock(cpt);
1336 rtr_nid = lp->lp_nid;
1342 CDEBUG(D_NET, "Best route to %s via %s for %s %d\n",
1343 libcfs_nid2str(dst_nid), libcfs_nid2str(lp->lp_nid),
1344 lnet_msgtyp2str(msg->msg_type), msg->msg_len);
1346 if (src_ni == NULL) {
1348 src_nid = src_ni->ni_nid;
1350 LASSERT (src_ni == lp->lp_ni);
1351 lnet_ni_decref_locked(src_ni, cpt);
1354 lnet_peer_addref_locked(lp);
1356 LASSERT(src_nid != LNET_NID_ANY);
1357 lnet_msg_commit(msg, cpt);
1359 if (!msg->msg_routing) {
1360 /* I'm the source and now I know which NI to send on */
1361 msg->msg_hdr.src_nid = cpu_to_le64(src_nid);
1364 msg->msg_target_is_router = 1;
1365 msg->msg_target.nid = lp->lp_nid;
1366 msg->msg_target.pid = LUSTRE_SRV_LNET_PID;
1369 /* 'lp' is our best choice of peer */
1371 LASSERT (!msg->msg_peertxcredit);
1372 LASSERT (!msg->msg_txcredit);
1373 LASSERT (msg->msg_txpeer == NULL);
1375 msg->msg_txpeer = lp; /* msg takes my ref on lp */
1377 rc = lnet_post_send_locked(msg, 0);
1378 lnet_net_unlock(cpt);
1380 if (rc == EHOSTUNREACH)
1381 return -EHOSTUNREACH;
1384 lnet_ni_send(src_ni, msg);
1390 lnet_drop_message(lnet_ni_t *ni, int cpt, void *private, unsigned int nob)
1393 the_lnet.ln_counters[cpt]->drop_count++;
1394 the_lnet.ln_counters[cpt]->drop_length += nob;
1395 lnet_net_unlock(cpt);
1397 lnet_ni_recv(ni, private, NULL, 0, 0, 0, nob);
1401 lnet_recv_put(lnet_ni_t *ni, lnet_msg_t *msg)
1403 lnet_hdr_t *hdr = &msg->msg_hdr;
1405 if (msg->msg_wanted != 0)
1406 lnet_setpayloadbuffer(msg);
1408 lnet_build_msg_event(msg, LNET_EVENT_PUT);
1410 /* Must I ACK? If so I'll grab the ack_wmd out of the header and put
1411 * it back into the ACK during lnet_finalize() */
1412 msg->msg_ack = (!lnet_is_wire_handle_none(&hdr->msg.put.ack_wmd) &&
1413 (msg->msg_md->md_options & LNET_MD_ACK_DISABLE) == 0);
1415 lnet_ni_recv(ni, msg->msg_private, msg, msg->msg_rx_delayed,
1416 msg->msg_offset, msg->msg_wanted, hdr->payload_length);
1420 lnet_parse_put(lnet_ni_t *ni, lnet_msg_t *msg)
1422 lnet_hdr_t *hdr = &msg->msg_hdr;
1423 struct lnet_match_info info;
1426 /* Convert put fields to host byte order */
1427 hdr->msg.put.match_bits = le64_to_cpu(hdr->msg.put.match_bits);
1428 hdr->msg.put.ptl_index = le32_to_cpu(hdr->msg.put.ptl_index);
1429 hdr->msg.put.offset = le32_to_cpu(hdr->msg.put.offset);
1431 info.mi_id.nid = hdr->src_nid;
1432 info.mi_id.pid = hdr->src_pid;
1433 info.mi_opc = LNET_MD_OP_PUT;
1434 info.mi_portal = hdr->msg.put.ptl_index;
1435 info.mi_rlength = hdr->payload_length;
1436 info.mi_roffset = hdr->msg.put.offset;
1437 info.mi_mbits = hdr->msg.put.match_bits;
1439 msg->msg_rx_ready_delay = ni->ni_lnd->lnd_eager_recv == NULL;
1442 rc = lnet_ptl_match_md(&info, msg);
1447 case LNET_MATCHMD_OK:
1448 lnet_recv_put(ni, msg);
1451 case LNET_MATCHMD_NONE:
1452 if (msg->msg_rx_delayed) /* attached on delayed list */
1455 rc = lnet_ni_eager_recv(ni, msg);
1460 case LNET_MATCHMD_DROP:
1461 CNETERR("Dropping PUT from %s portal %d match "LPU64
1462 " offset %d length %d: %d\n",
1463 libcfs_id2str(info.mi_id), info.mi_portal,
1464 info.mi_mbits, info.mi_roffset, info.mi_rlength, rc);
1466 return ENOENT; /* +ve: OK but no match */
1471 lnet_parse_get(lnet_ni_t *ni, lnet_msg_t *msg, int rdma_get)
1473 struct lnet_match_info info;
1474 lnet_hdr_t *hdr = &msg->msg_hdr;
1475 lnet_handle_wire_t reply_wmd;
1478 /* Convert get fields to host byte order */
1479 hdr->msg.get.match_bits = le64_to_cpu(hdr->msg.get.match_bits);
1480 hdr->msg.get.ptl_index = le32_to_cpu(hdr->msg.get.ptl_index);
1481 hdr->msg.get.sink_length = le32_to_cpu(hdr->msg.get.sink_length);
1482 hdr->msg.get.src_offset = le32_to_cpu(hdr->msg.get.src_offset);
1484 info.mi_id.nid = hdr->src_nid;
1485 info.mi_id.pid = hdr->src_pid;
1486 info.mi_opc = LNET_MD_OP_GET;
1487 info.mi_portal = hdr->msg.get.ptl_index;
1488 info.mi_rlength = hdr->msg.get.sink_length;
1489 info.mi_roffset = hdr->msg.get.src_offset;
1490 info.mi_mbits = hdr->msg.get.match_bits;
1492 rc = lnet_ptl_match_md(&info, msg);
1493 if (rc == LNET_MATCHMD_DROP) {
1494 CNETERR("Dropping GET from %s portal %d match "LPU64
1495 " offset %d length %d\n",
1496 libcfs_id2str(info.mi_id), info.mi_portal,
1497 info.mi_mbits, info.mi_roffset, info.mi_rlength);
1498 return ENOENT; /* +ve: OK but no match */
1501 LASSERT(rc == LNET_MATCHMD_OK);
1503 lnet_build_msg_event(msg, LNET_EVENT_GET);
1505 reply_wmd = hdr->msg.get.return_wmd;
1507 lnet_prep_send(msg, LNET_MSG_REPLY, info.mi_id,
1508 msg->msg_offset, msg->msg_wanted);
1510 msg->msg_hdr.msg.reply.dst_wmd = reply_wmd;
1513 /* The LND completes the REPLY from her recv procedure */
1514 lnet_ni_recv(ni, msg->msg_private, msg, 0,
1515 msg->msg_offset, msg->msg_len, msg->msg_len);
1519 lnet_ni_recv(ni, msg->msg_private, NULL, 0, 0, 0, 0);
1520 msg->msg_receiving = 0;
1522 rc = lnet_send(ni->ni_nid, msg, LNET_NID_ANY);
1524 /* didn't get as far as lnet_ni_send() */
1525 CERROR("%s: Unable to send REPLY for GET from %s: %d\n",
1526 libcfs_nid2str(ni->ni_nid),
1527 libcfs_id2str(info.mi_id), rc);
1529 lnet_finalize(ni, msg, rc);
1536 lnet_parse_reply(lnet_ni_t *ni, lnet_msg_t *msg)
1538 void *private = msg->msg_private;
1539 lnet_hdr_t *hdr = &msg->msg_hdr;
1540 lnet_process_id_t src = {0};
1546 cpt = lnet_cpt_of_cookie(hdr->msg.reply.dst_wmd.wh_object_cookie);
1549 src.nid = hdr->src_nid;
1550 src.pid = hdr->src_pid;
1552 /* NB handles only looked up by creator (no flips) */
1553 md = lnet_wire_handle2md(&hdr->msg.reply.dst_wmd);
1554 if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) {
1555 CNETERR("%s: Dropping REPLY from %s for %s "
1556 "MD "LPX64"."LPX64"\n",
1557 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
1558 (md == NULL) ? "invalid" : "inactive",
1559 hdr->msg.reply.dst_wmd.wh_interface_cookie,
1560 hdr->msg.reply.dst_wmd.wh_object_cookie);
1561 if (md != NULL && md->md_me != NULL)
1562 CERROR("REPLY MD also attached to portal %d\n",
1563 md->md_me->me_portal);
1565 lnet_res_unlock(cpt);
1566 return ENOENT; /* +ve: OK but no match */
1569 LASSERT (md->md_offset == 0);
1571 rlength = hdr->payload_length;
1572 mlength = MIN(rlength, (int)md->md_length);
1574 if (mlength < rlength &&
1575 (md->md_options & LNET_MD_TRUNCATE) == 0) {
1576 CNETERR("%s: Dropping REPLY from %s length %d "
1577 "for MD "LPX64" would overflow (%d)\n",
1578 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
1579 rlength, hdr->msg.reply.dst_wmd.wh_object_cookie,
1581 lnet_res_unlock(cpt);
1582 return ENOENT; /* +ve: OK but no match */
1585 CDEBUG(D_NET, "%s: Reply from %s of length %d/%d into md "LPX64"\n",
1586 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
1587 mlength, rlength, hdr->msg.reply.dst_wmd.wh_object_cookie);
1589 lnet_msg_attach_md(msg, md, 0, mlength);
1592 lnet_setpayloadbuffer(msg);
1594 lnet_res_unlock(cpt);
1596 lnet_build_msg_event(msg, LNET_EVENT_REPLY);
1598 lnet_ni_recv(ni, private, msg, 0, 0, mlength, rlength);
1603 lnet_parse_ack(lnet_ni_t *ni, lnet_msg_t *msg)
1605 lnet_hdr_t *hdr = &msg->msg_hdr;
1606 lnet_process_id_t src = {0};
1610 src.nid = hdr->src_nid;
1611 src.pid = hdr->src_pid;
1613 /* Convert ack fields to host byte order */
1614 hdr->msg.ack.match_bits = le64_to_cpu(hdr->msg.ack.match_bits);
1615 hdr->msg.ack.mlength = le32_to_cpu(hdr->msg.ack.mlength);
1617 cpt = lnet_cpt_of_cookie(hdr->msg.ack.dst_wmd.wh_object_cookie);
1620 /* NB handles only looked up by creator (no flips) */
1621 md = lnet_wire_handle2md(&hdr->msg.ack.dst_wmd);
1622 if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) {
1623 /* Don't moan; this is expected */
1625 "%s: Dropping ACK from %s to %s MD "LPX64"."LPX64"\n",
1626 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
1627 (md == NULL) ? "invalid" : "inactive",
1628 hdr->msg.ack.dst_wmd.wh_interface_cookie,
1629 hdr->msg.ack.dst_wmd.wh_object_cookie);
1630 if (md != NULL && md->md_me != NULL)
1631 CERROR("Source MD also attached to portal %d\n",
1632 md->md_me->me_portal);
1634 lnet_res_unlock(cpt);
1635 return ENOENT; /* +ve! */
1638 CDEBUG(D_NET, "%s: ACK from %s into md "LPX64"\n",
1639 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
1640 hdr->msg.ack.dst_wmd.wh_object_cookie);
1642 lnet_msg_attach_md(msg, md, 0, 0);
1644 lnet_res_unlock(cpt);
1646 lnet_build_msg_event(msg, LNET_EVENT_ACK);
1648 lnet_ni_recv(ni, msg->msg_private, msg, 0, 0, 0, msg->msg_len);
1653 lnet_parse_forward_locked(lnet_ni_t *ni, lnet_msg_t *msg)
1658 if (msg->msg_rxpeer->lp_rtrcredits <= 0 ||
1659 lnet_msg2bufpool(msg)->rbp_credits <= 0) {
1660 if (ni->ni_lnd->lnd_eager_recv == NULL) {
1661 msg->msg_rx_ready_delay = 1;
1663 lnet_net_unlock(msg->msg_rx_cpt);
1664 rc = lnet_ni_eager_recv(ni, msg);
1665 lnet_net_lock(msg->msg_rx_cpt);
1670 rc = lnet_post_routed_recv_locked(msg, 0);
1678 lnet_msgtyp2str (int type)
1687 case LNET_MSG_REPLY:
1689 case LNET_MSG_HELLO:
1692 return ("<UNKNOWN>");
1697 lnet_print_hdr(lnet_hdr_t * hdr)
1699 lnet_process_id_t src = {0};
1700 lnet_process_id_t dst = {0};
1701 char *type_str = lnet_msgtyp2str (hdr->type);
1703 src.nid = hdr->src_nid;
1704 src.pid = hdr->src_pid;
1706 dst.nid = hdr->dest_nid;
1707 dst.pid = hdr->dest_pid;
1709 CWARN("P3 Header at %p of type %s\n", hdr, type_str);
1710 CWARN(" From %s\n", libcfs_id2str(src));
1711 CWARN(" To %s\n", libcfs_id2str(dst));
1713 switch (hdr->type) {
1718 CWARN(" Ptl index %d, ack md "LPX64"."LPX64", "
1719 "match bits "LPU64"\n",
1720 hdr->msg.put.ptl_index,
1721 hdr->msg.put.ack_wmd.wh_interface_cookie,
1722 hdr->msg.put.ack_wmd.wh_object_cookie,
1723 hdr->msg.put.match_bits);
1724 CWARN(" Length %d, offset %d, hdr data "LPX64"\n",
1725 hdr->payload_length, hdr->msg.put.offset,
1726 hdr->msg.put.hdr_data);
1730 CWARN(" Ptl index %d, return md "LPX64"."LPX64", "
1731 "match bits "LPU64"\n", hdr->msg.get.ptl_index,
1732 hdr->msg.get.return_wmd.wh_interface_cookie,
1733 hdr->msg.get.return_wmd.wh_object_cookie,
1734 hdr->msg.get.match_bits);
1735 CWARN(" Length %d, src offset %d\n",
1736 hdr->msg.get.sink_length,
1737 hdr->msg.get.src_offset);
1741 CWARN(" dst md "LPX64"."LPX64", "
1742 "manipulated length %d\n",
1743 hdr->msg.ack.dst_wmd.wh_interface_cookie,
1744 hdr->msg.ack.dst_wmd.wh_object_cookie,
1745 hdr->msg.ack.mlength);
1748 case LNET_MSG_REPLY:
1749 CWARN(" dst md "LPX64"."LPX64", "
1751 hdr->msg.reply.dst_wmd.wh_interface_cookie,
1752 hdr->msg.reply.dst_wmd.wh_object_cookie,
1753 hdr->payload_length);
1759 lnet_parse(lnet_ni_t *ni, lnet_hdr_t *hdr, lnet_nid_t from_nid,
1760 void *private, int rdma_req)
1765 struct lnet_msg *msg;
1766 lnet_pid_t dest_pid;
1767 lnet_nid_t dest_nid;
1769 __u32 payload_length;
1772 LASSERT (!cfs_in_interrupt ());
1774 type = le32_to_cpu(hdr->type);
1775 src_nid = le64_to_cpu(hdr->src_nid);
1776 dest_nid = le64_to_cpu(hdr->dest_nid);
1777 dest_pid = le32_to_cpu(hdr->dest_pid);
1778 payload_length = le32_to_cpu(hdr->payload_length);
1780 for_me = (ni->ni_nid == dest_nid);
1781 cpt = lnet_cpt_of_nid(from_nid);
1786 if (payload_length > 0) {
1787 CERROR("%s, src %s: bad %s payload %d (0 expected)\n",
1788 libcfs_nid2str(from_nid),
1789 libcfs_nid2str(src_nid),
1790 lnet_msgtyp2str(type), payload_length);
1796 case LNET_MSG_REPLY:
1797 if (payload_length > (__u32)(for_me ? LNET_MAX_PAYLOAD : LNET_MTU)) {
1798 CERROR("%s, src %s: bad %s payload %d "
1799 "(%d max expected)\n",
1800 libcfs_nid2str(from_nid),
1801 libcfs_nid2str(src_nid),
1802 lnet_msgtyp2str(type),
1804 for_me ? LNET_MAX_PAYLOAD : LNET_MTU);
1810 CERROR("%s, src %s: Bad message type 0x%x\n",
1811 libcfs_nid2str(from_nid),
1812 libcfs_nid2str(src_nid), type);
1816 if (the_lnet.ln_routing &&
1817 ni->ni_last_alive != cfs_time_current_sec()) {
1820 /* NB: so far here is the only place to set NI status to "up */
1821 ni->ni_last_alive = cfs_time_current_sec();
1822 if (ni->ni_status != NULL &&
1823 ni->ni_status->ns_status == LNET_NI_STATUS_DOWN)
1824 ni->ni_status->ns_status = LNET_NI_STATUS_UP;
1828 /* Regard a bad destination NID as a protocol error. Senders should
1829 * know what they're doing; if they don't they're misconfigured, buggy
1830 * or malicious so we chop them off at the knees :) */
1833 if (LNET_NIDNET(dest_nid) == LNET_NIDNET(ni->ni_nid)) {
1834 /* should have gone direct */
1835 CERROR ("%s, src %s: Bad dest nid %s "
1836 "(should have been sent direct)\n",
1837 libcfs_nid2str(from_nid),
1838 libcfs_nid2str(src_nid),
1839 libcfs_nid2str(dest_nid));
1843 if (lnet_islocalnid(dest_nid)) {
1844 /* dest is another local NI; sender should have used
1845 * this node's NID on its own network */
1846 CERROR ("%s, src %s: Bad dest nid %s "
1847 "(it's my nid but on a different network)\n",
1848 libcfs_nid2str(from_nid),
1849 libcfs_nid2str(src_nid),
1850 libcfs_nid2str(dest_nid));
1854 if (rdma_req && type == LNET_MSG_GET) {
1855 CERROR ("%s, src %s: Bad optimized GET for %s "
1856 "(final destination must be me)\n",
1857 libcfs_nid2str(from_nid),
1858 libcfs_nid2str(src_nid),
1859 libcfs_nid2str(dest_nid));
1863 if (!the_lnet.ln_routing) {
1864 CERROR ("%s, src %s: Dropping message for %s "
1865 "(routing not enabled)\n",
1866 libcfs_nid2str(from_nid),
1867 libcfs_nid2str(src_nid),
1868 libcfs_nid2str(dest_nid));
1873 /* Message looks OK; we're not going to return an error, so we MUST
1874 * call back lnd_recv() come what may... */
1876 if (!cfs_list_empty (&the_lnet.ln_test_peers) && /* normally we don't */
1877 fail_peer (src_nid, 0)) /* shall we now? */
1879 CERROR("%s, src %s: Dropping %s to simulate failure\n",
1880 libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
1881 lnet_msgtyp2str(type));
1885 msg = lnet_msg_alloc();
1887 CERROR("%s, src %s: Dropping %s (out of memory)\n",
1888 libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
1889 lnet_msgtyp2str(type));
1893 /* msg zeroed in lnet_msg_alloc; i.e. flags all clear, pointers NULL etc */
1895 msg->msg_type = type;
1896 msg->msg_private = private;
1897 msg->msg_receiving = 1;
1898 msg->msg_len = msg->msg_wanted = payload_length;
1899 msg->msg_offset = 0;
1900 msg->msg_hdr = *hdr;
1901 /* for building message event */
1902 msg->msg_from = from_nid;
1904 msg->msg_target.pid = dest_pid;
1905 msg->msg_target.nid = dest_nid;
1906 msg->msg_routing = 1;
1909 /* convert common msg->hdr fields to host byteorder */
1910 msg->msg_hdr.type = type;
1911 msg->msg_hdr.src_nid = src_nid;
1912 msg->msg_hdr.src_pid = le32_to_cpu(msg->msg_hdr.src_pid);
1913 msg->msg_hdr.dest_nid = dest_nid;
1914 msg->msg_hdr.dest_pid = dest_pid;
1915 msg->msg_hdr.payload_length = payload_length;
1919 rc = lnet_nid2peer_locked(&msg->msg_rxpeer, from_nid, cpt);
1921 lnet_net_unlock(cpt);
1922 CERROR("%s, src %s: Dropping %s "
1923 "(error %d looking up sender)\n",
1924 libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
1925 lnet_msgtyp2str(type), rc);
1930 lnet_msg_commit(msg, cpt);
1933 rc = lnet_parse_forward_locked(ni, msg);
1934 lnet_net_unlock(cpt);
1939 lnet_ni_recv(ni, msg->msg_private, msg, 0,
1940 0, payload_length, payload_length);
1945 lnet_net_unlock(cpt);
1949 rc = lnet_parse_ack(ni, msg);
1952 rc = lnet_parse_put(ni, msg);
1955 rc = lnet_parse_get(ni, msg, rdma_req);
1957 case LNET_MSG_REPLY:
1958 rc = lnet_parse_reply(ni, msg);
1963 goto free_drop; /* prevent an unused label if !kernel */
1969 LASSERT (rc == ENOENT);
1972 LASSERT(msg->msg_md == NULL);
1973 lnet_finalize(ni, msg, rc);
1976 lnet_drop_message(ni, cpt, private, payload_length);
1981 lnet_drop_delayed_msg_list(cfs_list_t *head, char *reason)
1983 while (!cfs_list_empty(head)) {
1984 lnet_process_id_t id = {0};
1987 msg = cfs_list_entry(head->next, lnet_msg_t, msg_list);
1988 cfs_list_del(&msg->msg_list);
1990 id.nid = msg->msg_hdr.src_nid;
1991 id.pid = msg->msg_hdr.src_pid;
1993 LASSERT(msg->msg_md == NULL);
1994 LASSERT(msg->msg_rx_delayed);
1995 LASSERT(msg->msg_rxpeer != NULL);
1996 LASSERT(msg->msg_hdr.type == LNET_MSG_PUT);
1998 CWARN("Dropping delayed PUT from %s portal %d match "LPU64
1999 " offset %d length %d: %s\n",
2001 msg->msg_hdr.msg.put.ptl_index,
2002 msg->msg_hdr.msg.put.match_bits,
2003 msg->msg_hdr.msg.put.offset,
2004 msg->msg_hdr.payload_length, reason);
2006 /* NB I can't drop msg's ref on msg_rxpeer until after I've
2007 * called lnet_drop_message(), so I just hang onto msg as well
2008 * until that's done */
2010 lnet_drop_message(msg->msg_rxpeer->lp_ni,
2011 msg->msg_rxpeer->lp_cpt,
2012 msg->msg_private, msg->msg_len);
2014 lnet_net_lock(msg->msg_rxpeer->lp_cpt);
2015 lnet_peer_decref_locked(msg->msg_rxpeer);
2016 lnet_net_unlock(msg->msg_rxpeer->lp_cpt);
2023 lnet_recv_delayed_msg_list(cfs_list_t *head)
2025 while (!cfs_list_empty(head)) {
2027 lnet_process_id_t id;
2029 msg = cfs_list_entry(head->next, lnet_msg_t, msg_list);
2030 cfs_list_del(&msg->msg_list);
2032 /* md won't disappear under me, since each msg
2033 * holds a ref on it */
2035 id.nid = msg->msg_hdr.src_nid;
2036 id.pid = msg->msg_hdr.src_pid;
2038 LASSERT(msg->msg_rx_delayed);
2039 LASSERT(msg->msg_md != NULL);
2040 LASSERT(msg->msg_rxpeer != NULL);
2041 LASSERT(msg->msg_hdr.type == LNET_MSG_PUT);
2043 CDEBUG(D_NET, "Resuming delayed PUT from %s portal %d "
2044 "match "LPU64" offset %d length %d.\n",
2045 libcfs_id2str(id), msg->msg_hdr.msg.put.ptl_index,
2046 msg->msg_hdr.msg.put.match_bits,
2047 msg->msg_hdr.msg.put.offset,
2048 msg->msg_hdr.payload_length);
2050 lnet_recv_put(msg->msg_rxpeer->lp_ni, msg);
2055 * Initiate an asynchronous PUT operation.
2057 * There are several events associated with a PUT: completion of the send on
2058 * the initiator node (LNET_EVENT_SEND), and when the send completes
2059 * successfully, the receipt of an acknowledgment (LNET_EVENT_ACK) indicating
2060 * that the operation was accepted by the target. The event LNET_EVENT_PUT is
2061 * used at the target node to indicate the completion of incoming data
2064 * The local events will be logged in the EQ associated with the MD pointed to
2065 * by \a mdh handle. Using a MD without an associated EQ results in these
2066 * events being discarded. In this case, the caller must have another
2067 * mechanism (e.g., a higher level protocol) for determining when it is safe
2068 * to modify the memory region associated with the MD.
2070 * Note that LNet does not guarantee the order of LNET_EVENT_SEND and
2071 * LNET_EVENT_ACK, though intuitively ACK should happen after SEND.
2073 * \param self Indicates the NID of a local interface through which to send
2074 * the PUT request. Use LNET_NID_ANY to let LNet choose one by itself.
2075 * \param mdh A handle for the MD that describes the memory to be sent. The MD
2076 * must be "free floating" (See LNetMDBind()).
2077 * \param ack Controls whether an acknowledgment is requested.
2078 * Acknowledgments are only sent when they are requested by the initiating
2079 * process and the target MD enables them.
2080 * \param target A process identifier for the target process.
2081 * \param portal The index in the \a target's portal table.
2082 * \param match_bits The match bits to use for MD selection at the target
2084 * \param offset The offset into the target MD (only used when the target
2085 * MD has the LNET_MD_MANAGE_REMOTE option set).
2086 * \param hdr_data 64 bits of user data that can be included in the message
2087 * header. This data is written to an event queue entry at the target if an
2088 * EQ is present on the matching MD.
2090 * \retval 0 Success, and only in this case events will be generated
2091 * and logged to EQ (if it exists).
2092 * \retval -EIO Simulated failure.
2093 * \retval -ENOMEM Memory allocation failure.
2094 * \retval -ENOENT Invalid MD object.
2096 * \see lnet_event_t::hdr_data and lnet_event_kind_t.
2099 LNetPut(lnet_nid_t self, lnet_handle_md_t mdh, lnet_ack_req_t ack,
2100 lnet_process_id_t target, unsigned int portal,
2101 __u64 match_bits, unsigned int offset,
2104 struct lnet_msg *msg;
2105 struct lnet_libmd *md;
2109 LASSERT (the_lnet.ln_init);
2110 LASSERT (the_lnet.ln_refcount > 0);
2112 if (!cfs_list_empty (&the_lnet.ln_test_peers) && /* normally we don't */
2113 fail_peer (target.nid, 1)) /* shall we now? */
2115 CERROR("Dropping PUT to %s: simulated failure\n",
2116 libcfs_id2str(target));
2120 msg = lnet_msg_alloc();
2122 CERROR("Dropping PUT to %s: ENOMEM on lnet_msg_t\n",
2123 libcfs_id2str(target));
2126 msg->msg_vmflush = !!cfs_memory_pressure_get();
2128 cpt = lnet_cpt_of_cookie(mdh.cookie);
2131 md = lnet_handle2md(&mdh);
2132 if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) {
2133 CERROR("Dropping PUT ("LPU64":%d:%s): MD (%d) invalid\n",
2134 match_bits, portal, libcfs_id2str(target),
2135 md == NULL ? -1 : md->md_threshold);
2136 if (md != NULL && md->md_me != NULL)
2137 CERROR("Source MD also attached to portal %d\n",
2138 md->md_me->me_portal);
2139 lnet_res_unlock(cpt);
2145 CDEBUG(D_NET, "LNetPut -> %s\n", libcfs_id2str(target));
2147 lnet_msg_attach_md(msg, md, 0, 0);
2149 lnet_prep_send(msg, LNET_MSG_PUT, target, 0, md->md_length);
2151 msg->msg_hdr.msg.put.match_bits = cpu_to_le64(match_bits);
2152 msg->msg_hdr.msg.put.ptl_index = cpu_to_le32(portal);
2153 msg->msg_hdr.msg.put.offset = cpu_to_le32(offset);
2154 msg->msg_hdr.msg.put.hdr_data = hdr_data;
2156 /* NB handles only looked up by creator (no flips) */
2157 if (ack == LNET_ACK_REQ) {
2158 msg->msg_hdr.msg.put.ack_wmd.wh_interface_cookie =
2159 the_lnet.ln_interface_cookie;
2160 msg->msg_hdr.msg.put.ack_wmd.wh_object_cookie =
2161 md->md_lh.lh_cookie;
2163 msg->msg_hdr.msg.put.ack_wmd.wh_interface_cookie =
2164 LNET_WIRE_HANDLE_COOKIE_NONE;
2165 msg->msg_hdr.msg.put.ack_wmd.wh_object_cookie =
2166 LNET_WIRE_HANDLE_COOKIE_NONE;
2169 lnet_res_unlock(cpt);
2171 lnet_build_msg_event(msg, LNET_EVENT_SEND);
2173 rc = lnet_send(self, msg, LNET_NID_ANY);
2175 CNETERR( "Error sending PUT to %s: %d\n",
2176 libcfs_id2str(target), rc);
2177 lnet_finalize (NULL, msg, rc);
2180 /* completion will be signalled by an event */
2185 lnet_create_reply_msg (lnet_ni_t *ni, lnet_msg_t *getmsg)
2187 /* The LND can DMA direct to the GET md (i.e. no REPLY msg). This
2188 * returns a msg for the LND to pass to lnet_finalize() when the sink
2189 * data has been received.
2191 * CAVEAT EMPTOR: 'getmsg' is the original GET, which is freed when
2192 * lnet_finalize() is called on it, so the LND must call this first */
2194 struct lnet_msg *msg = lnet_msg_alloc();
2195 struct lnet_libmd *getmd = getmsg->msg_md;
2196 lnet_process_id_t peer_id = getmsg->msg_target;
2199 LASSERT(!getmsg->msg_target_is_router);
2200 LASSERT(!getmsg->msg_routing);
2202 cpt = lnet_cpt_of_cookie(getmd->md_lh.lh_cookie);
2205 LASSERT (getmd->md_refcount > 0);
2208 CERROR ("%s: Dropping REPLY from %s: can't allocate msg\n",
2209 libcfs_nid2str(ni->ni_nid), libcfs_id2str(peer_id));
2213 if (getmd->md_threshold == 0) {
2214 CERROR ("%s: Dropping REPLY from %s for inactive MD %p\n",
2215 libcfs_nid2str(ni->ni_nid), libcfs_id2str(peer_id),
2217 lnet_res_unlock(cpt);
2221 LASSERT (getmd->md_offset == 0);
2223 CDEBUG(D_NET, "%s: Reply from %s md %p\n",
2224 libcfs_nid2str(ni->ni_nid), libcfs_id2str(peer_id), getmd);
2226 /* setup information for lnet_build_msg_event */
2227 msg->msg_from = peer_id.nid;
2228 msg->msg_type = LNET_MSG_GET; /* flag this msg as an "optimized" GET */
2229 msg->msg_hdr.src_nid = peer_id.nid;
2230 msg->msg_hdr.payload_length = getmd->md_length;
2231 msg->msg_receiving = 1; /* required by lnet_msg_attach_md */
2233 lnet_msg_attach_md(msg, getmd, getmd->md_offset, getmd->md_length);
2234 lnet_res_unlock(cpt);
2236 cpt = lnet_cpt_of_nid(peer_id.nid);
2239 lnet_msg_commit(msg, cpt);
2240 lnet_net_unlock(cpt);
2242 lnet_build_msg_event(msg, LNET_EVENT_REPLY);
2247 cpt = lnet_cpt_of_nid(peer_id.nid);
2250 the_lnet.ln_counters[cpt]->drop_count++;
2251 the_lnet.ln_counters[cpt]->drop_length += getmd->md_length;
2252 lnet_net_unlock(cpt);
2261 lnet_set_reply_msg_len(lnet_ni_t *ni, lnet_msg_t *reply, unsigned int len)
2263 /* Set the REPLY length, now the RDMA that elides the REPLY message has
2264 * completed and I know it. */
2265 LASSERT (reply != NULL);
2266 LASSERT (reply->msg_type == LNET_MSG_GET);
2267 LASSERT (reply->msg_ev.type == LNET_EVENT_REPLY);
2269 /* NB I trusted my peer to RDMA. If she tells me she's written beyond
2270 * the end of my buffer, I might as well be dead. */
2271 LASSERT (len <= reply->msg_ev.mlength);
2273 reply->msg_ev.mlength = len;
2277 * Initiate an asynchronous GET operation.
2279 * On the initiator node, an LNET_EVENT_SEND is logged when the GET request
2280 * is sent, and an LNET_EVENT_REPLY is logged when the data returned from
2281 * the target node in the REPLY has been written to local MD.
2283 * On the target node, an LNET_EVENT_GET is logged when the GET request
2284 * arrives and is accepted into a MD.
2286 * \param self,target,portal,match_bits,offset See the discussion in LNetPut().
2287 * \param mdh A handle for the MD that describes the memory into which the
2288 * requested data will be received. The MD must be "free floating" (See LNetMDBind()).
2290 * \retval 0 Success, and only in this case events will be generated
2291 * and logged to EQ (if it exists) of the MD.
2292 * \retval -EIO Simulated failure.
2293 * \retval -ENOMEM Memory allocation failure.
2294 * \retval -ENOENT Invalid MD object.
2297 LNetGet(lnet_nid_t self, lnet_handle_md_t mdh,
2298 lnet_process_id_t target, unsigned int portal,
2299 __u64 match_bits, unsigned int offset)
2301 struct lnet_msg *msg;
2302 struct lnet_libmd *md;
2306 LASSERT (the_lnet.ln_init);
2307 LASSERT (the_lnet.ln_refcount > 0);
2309 if (!cfs_list_empty (&the_lnet.ln_test_peers) && /* normally we don't */
2310 fail_peer (target.nid, 1)) /* shall we now? */
2312 CERROR("Dropping GET to %s: simulated failure\n",
2313 libcfs_id2str(target));
2317 msg = lnet_msg_alloc();
2319 CERROR("Dropping GET to %s: ENOMEM on lnet_msg_t\n",
2320 libcfs_id2str(target));
2324 cpt = lnet_cpt_of_cookie(mdh.cookie);
2327 md = lnet_handle2md(&mdh);
2328 if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) {
2329 CERROR("Dropping GET ("LPU64":%d:%s): MD (%d) invalid\n",
2330 match_bits, portal, libcfs_id2str(target),
2331 md == NULL ? -1 : md->md_threshold);
2332 if (md != NULL && md->md_me != NULL)
2333 CERROR("REPLY MD also attached to portal %d\n",
2334 md->md_me->me_portal);
2336 lnet_res_unlock(cpt);
2343 CDEBUG(D_NET, "LNetGet -> %s\n", libcfs_id2str(target));
2345 lnet_msg_attach_md(msg, md, 0, 0);
2347 lnet_prep_send(msg, LNET_MSG_GET, target, 0, 0);
2349 msg->msg_hdr.msg.get.match_bits = cpu_to_le64(match_bits);
2350 msg->msg_hdr.msg.get.ptl_index = cpu_to_le32(portal);
2351 msg->msg_hdr.msg.get.src_offset = cpu_to_le32(offset);
2352 msg->msg_hdr.msg.get.sink_length = cpu_to_le32(md->md_length);
2354 /* NB handles only looked up by creator (no flips) */
2355 msg->msg_hdr.msg.get.return_wmd.wh_interface_cookie =
2356 the_lnet.ln_interface_cookie;
2357 msg->msg_hdr.msg.get.return_wmd.wh_object_cookie =
2358 md->md_lh.lh_cookie;
2360 lnet_res_unlock(cpt);
2362 lnet_build_msg_event(msg, LNET_EVENT_SEND);
2364 rc = lnet_send(self, msg, LNET_NID_ANY);
2366 CNETERR( "Error sending GET to %s: %d\n",
2367 libcfs_id2str(target), rc);
2368 lnet_finalize (NULL, msg, rc);
2371 /* completion will be signalled by an event */
2376 * Calculate distance to node at \a dstnid.
2378 * \param dstnid Target NID.
2379 * \param srcnidp If not NULL, NID of the local interface to reach \a dstnid
2381 * \param orderp If not NULL, order of the route to reach \a dstnid is saved
2384 * \retval 0 If \a dstnid belongs to a local interface, and reserved option
2385 * local_nid_dist_zero is set, which is the default.
2386 * \retval positives Distance to target NID, i.e. number of hops plus one.
2387 * \retval -EHOSTUNREACH If \a dstnid is not reachable.
2390 LNetDist(lnet_nid_t dstnid, lnet_nid_t *srcnidp, __u32 *orderp)
2394 lnet_remotenet_t *rnet;
2395 __u32 dstnet = LNET_NIDNET(dstnid);
2400 /* if !local_nid_dist_zero, I don't return a distance of 0 ever
2401 * (when lustre sees a distance of 0, it substitutes 0@lo), so I
2402 * keep order 0 free for 0@lo and order 1 free for a local NID
2405 LASSERT (the_lnet.ln_init);
2406 LASSERT (the_lnet.ln_refcount > 0);
2408 cpt = lnet_net_lock_current();
2410 cfs_list_for_each (e, &the_lnet.ln_nis) {
2411 ni = cfs_list_entry(e, lnet_ni_t, ni_list);
2413 if (ni->ni_nid == dstnid) {
2414 if (srcnidp != NULL)
2416 if (orderp != NULL) {
2417 if (LNET_NETTYP(LNET_NIDNET(dstnid)) == LOLND)
2422 lnet_net_unlock(cpt);
2424 return local_nid_dist_zero ? 0 : 1;
2427 if (LNET_NIDNET(ni->ni_nid) == dstnet) {
2428 if (srcnidp != NULL)
2429 *srcnidp = ni->ni_nid;
2432 lnet_net_unlock(cpt);
2439 cfs_list_for_each (e, &the_lnet.ln_remote_nets) {
2440 rnet = cfs_list_entry(e, lnet_remotenet_t, lrn_list);
2442 if (rnet->lrn_net == dstnet) {
2443 lnet_route_t *route;
2444 lnet_route_t *shortest = NULL;
2446 LASSERT (!cfs_list_empty(&rnet->lrn_routes));
2448 cfs_list_for_each_entry(route, &rnet->lrn_routes,
2450 if (shortest == NULL ||
2451 route->lr_hops < shortest->lr_hops)
2455 LASSERT (shortest != NULL);
2456 hops = shortest->lr_hops;
2457 if (srcnidp != NULL)
2458 *srcnidp = shortest->lr_gateway->lp_ni->ni_nid;
2461 lnet_net_unlock(cpt);
2467 lnet_net_unlock(cpt);
2468 return -EHOSTUNREACH;
2472 * Set the number of asynchronous messages expected from a target process.
2474 * This function is only meaningful for userspace callers. It's a no-op when
2475 * called from kernel.
2477 * Asynchronous messages are those that can come from a target when the
2478 * userspace process is not waiting for IO to complete; e.g., AST callbacks
2479 * from Lustre servers. Specifying the expected number of such messages
2480 * allows them to be eagerly received when user process is not running in
2481 * LNet; otherwise network errors may occur.
2483 * \param id Process ID of the target process.
2484 * \param nasync Number of asynchronous messages expected from the target.
2486 * \return 0 on success, and an error code otherwise.
2489 LNetSetAsync(lnet_process_id_t id, int nasync)
2495 lnet_remotenet_t *rnet;
2497 lnet_route_t *route;
2505 /* Target on a local network? */
2506 ni = lnet_net2ni(LNET_NIDNET(id.nid));
2508 if (ni->ni_lnd->lnd_setasync != NULL)
2509 rc = (ni->ni_lnd->lnd_setasync)(ni, id, nasync);
2514 /* Target on a remote network: apply to routers */
2516 LIBCFS_ALLOC(nids, maxnids * sizeof(*nids));
2521 /* Snapshot all the router NIDs */
2522 cpt = lnet_net_lock_current();
2523 rnet = lnet_find_net_locked(LNET_NIDNET(id.nid));
2525 cfs_list_for_each(tmp, &rnet->lrn_routes) {
2526 if (nnids == maxnids) {
2527 lnet_net_unlock(cpt);
2528 LIBCFS_FREE(nids, maxnids * sizeof(*nids));
2533 route = cfs_list_entry(tmp, lnet_route_t, lr_list);
2534 nids[nnids++] = route->lr_gateway->lp_nid;
2537 lnet_net_unlock(cpt);
2539 /* set async on all the routers */
2540 while (nnids-- > 0) {
2541 id.pid = LUSTRE_SRV_LNET_PID;
2542 id.nid = nids[nnids];
2544 ni = lnet_net2ni(LNET_NIDNET(id.nid));
2548 if (ni->ni_lnd->lnd_setasync != NULL) {
2549 rc2 = (ni->ni_lnd->lnd_setasync)(ni, id, nasync);
2556 LIBCFS_FREE(nids, maxnids * sizeof(*nids));