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(!msg->msg_rx_ready_delay);
696 LASSERT(ni->ni_lnd->lnd_eager_recv != NULL);
698 msg->msg_rx_ready_delay = 1;
699 rc = (ni->ni_lnd->lnd_eager_recv)(ni, msg->msg_private, msg,
702 CERROR("recv from %s / send to %s aborted: "
703 "eager_recv failed %d\n",
704 libcfs_nid2str(msg->msg_rxpeer->lp_nid),
705 libcfs_id2str(msg->msg_target), rc);
706 LASSERT(rc < 0); /* required by my callers */
712 /* NB: caller shall hold a ref on 'lp' as I'd drop lnet_net_lock */
714 lnet_ni_query_locked(lnet_ni_t *ni, lnet_peer_t *lp)
716 cfs_time_t last_alive = 0;
718 LASSERT(lnet_peer_aliveness_enabled(lp));
719 LASSERT(ni->ni_lnd->lnd_query != NULL);
720 LASSERT(the_lnet.ln_routing == 1);
722 lnet_net_unlock(lp->lp_cpt);
723 (ni->ni_lnd->lnd_query)(ni, lp->lp_nid, &last_alive);
724 lnet_net_lock(lp->lp_cpt);
726 lp->lp_last_query = cfs_time_current();
728 if (last_alive != 0) /* NI has updated timestamp */
729 lp->lp_last_alive = last_alive;
732 /* NB: always called with lnet_net_lock held */
734 lnet_peer_is_alive (lnet_peer_t *lp, cfs_time_t now)
739 LASSERT (lnet_peer_aliveness_enabled(lp));
740 LASSERT (the_lnet.ln_routing == 1);
742 /* Trust lnet_notify() if it has more recent aliveness news, but
743 * ignore the initial assumed death (see lnet_peers_start_down()).
745 if (!lp->lp_alive && lp->lp_alive_count > 0 &&
746 cfs_time_aftereq(lp->lp_timestamp, lp->lp_last_alive))
749 deadline = cfs_time_add(lp->lp_last_alive,
750 cfs_time_seconds(lp->lp_ni->ni_peertimeout));
751 alive = cfs_time_after(deadline, now);
753 /* Update obsolete lp_alive except for routers assumed to be dead
754 * initially, because router checker would update aliveness in this
755 * case, and moreover lp_last_alive at peer creation is assumed.
757 if (alive && !lp->lp_alive &&
758 !(lnet_isrouter(lp) && lp->lp_alive_count == 0))
759 lnet_notify_locked(lp, 0, 1, lp->lp_last_alive);
765 /* NB: returns 1 when alive, 0 when dead, negative when error;
766 * may drop the lnet_net_lock */
768 lnet_peer_alive_locked (lnet_peer_t *lp)
770 cfs_time_t now = cfs_time_current();
772 /* LU-630: only router checks peer health. */
773 if (the_lnet.ln_routing == 0)
776 if (!lnet_peer_aliveness_enabled(lp))
779 if (lnet_peer_is_alive(lp, now))
782 /* Peer appears dead, but we should avoid frequent NI queries (at
783 * most once per lnet_queryinterval seconds). */
784 if (lp->lp_last_query != 0) {
785 static const int lnet_queryinterval = 1;
787 cfs_time_t next_query =
788 cfs_time_add(lp->lp_last_query,
789 cfs_time_seconds(lnet_queryinterval));
791 if (cfs_time_before(now, next_query)) {
793 CWARN("Unexpected aliveness of peer %s: "
795 libcfs_nid2str(lp->lp_nid),
796 (int)now, (int)next_query,
798 lp->lp_ni->ni_peertimeout);
803 /* query NI for latest aliveness news */
804 lnet_ni_query_locked(lp->lp_ni, lp);
806 if (lnet_peer_is_alive(lp, now))
809 lnet_notify_locked(lp, 0, 0, lp->lp_last_alive);
814 lnet_post_send_locked(lnet_msg_t *msg, int do_send)
816 /* lnet_send is going to lnet_net_unlock immediately after this,
817 * so it sets do_send FALSE and I don't do the unlock/send/lock bit.
818 * I return EAGAIN if msg blocked, EHOSTUNREACH if msg_txpeer
819 * appears dead, and 0 if sent or OK to send */
820 struct lnet_peer *lp = msg->msg_txpeer;
821 struct lnet_ni *ni = lp->lp_ni;
822 struct lnet_tx_queue *tq;
825 /* non-lnet_send() callers have checked before */
826 LASSERT(!do_send || msg->msg_tx_delayed);
827 LASSERT(!msg->msg_receiving);
828 LASSERT(msg->msg_tx_committed);
830 cpt = msg->msg_tx_cpt;
831 tq = ni->ni_tx_queues[cpt];
833 /* NB 'lp' is always the next hop */
834 if ((msg->msg_target.pid & LNET_PID_USERFLAG) == 0 &&
835 lnet_peer_alive_locked(lp) == 0) {
836 the_lnet.ln_counters[cpt]->drop_count++;
837 the_lnet.ln_counters[cpt]->drop_length += msg->msg_len;
838 lnet_net_unlock(cpt);
840 CNETERR("Dropping message for %s: peer not alive\n",
841 libcfs_id2str(msg->msg_target));
843 lnet_finalize(ni, msg, -EHOSTUNREACH);
849 if (!msg->msg_peertxcredit) {
850 LASSERT ((lp->lp_txcredits < 0) ==
851 !cfs_list_empty(&lp->lp_txq));
853 msg->msg_peertxcredit = 1;
854 lp->lp_txqnob += msg->msg_len + sizeof(lnet_hdr_t);
857 if (lp->lp_txcredits < lp->lp_mintxcredits)
858 lp->lp_mintxcredits = lp->lp_txcredits;
860 if (lp->lp_txcredits < 0) {
861 msg->msg_tx_delayed = 1;
862 cfs_list_add_tail(&msg->msg_list, &lp->lp_txq);
867 if (!msg->msg_txcredit) {
868 LASSERT((tq->tq_credits < 0) ==
869 !cfs_list_empty(&tq->tq_delayed));
871 msg->msg_txcredit = 1;
874 if (tq->tq_credits < tq->tq_credits_min)
875 tq->tq_credits_min = tq->tq_credits;
877 if (tq->tq_credits < 0) {
878 msg->msg_tx_delayed = 1;
879 cfs_list_add_tail(&msg->msg_list, &tq->tq_delayed);
885 lnet_net_unlock(cpt);
886 lnet_ni_send(ni, msg);
895 lnet_msg2bufpool(lnet_msg_t *msg)
897 lnet_rtrbufpool_t *rbp;
900 LASSERT(msg->msg_rx_committed);
902 cpt = msg->msg_rx_cpt;
903 rbp = &the_lnet.ln_rtrpools[cpt][0];
905 LASSERT(msg->msg_len <= LNET_MTU);
906 while (msg->msg_len > (unsigned int)rbp->rbp_npages * CFS_PAGE_SIZE) {
908 LASSERT(rbp < &the_lnet.ln_rtrpools[cpt][LNET_NRBPOOLS]);
915 lnet_post_routed_recv_locked (lnet_msg_t *msg, int do_recv)
917 /* lnet_parse is going to lnet_net_unlock immediately after this, so it
918 * sets do_recv FALSE and I don't do the unlock/send/lock bit. I
919 * return EAGAIN if msg blocked and 0 if received or OK to receive */
920 lnet_peer_t *lp = msg->msg_rxpeer;
921 lnet_rtrbufpool_t *rbp;
924 LASSERT (msg->msg_iov == NULL);
925 LASSERT (msg->msg_kiov == NULL);
926 LASSERT (msg->msg_niov == 0);
927 LASSERT (msg->msg_routing);
928 LASSERT (msg->msg_receiving);
929 LASSERT (!msg->msg_sending);
931 /* non-lnet_parse callers only receive delayed messages */
932 LASSERT(!do_recv || msg->msg_rx_delayed);
934 if (!msg->msg_peerrtrcredit) {
935 LASSERT ((lp->lp_rtrcredits < 0) ==
936 !cfs_list_empty(&lp->lp_rtrq));
938 msg->msg_peerrtrcredit = 1;
940 if (lp->lp_rtrcredits < lp->lp_minrtrcredits)
941 lp->lp_minrtrcredits = lp->lp_rtrcredits;
943 if (lp->lp_rtrcredits < 0) {
944 /* must have checked eager_recv before here */
945 LASSERT(msg->msg_rx_ready_delay);
946 msg->msg_rx_delayed = 1;
947 cfs_list_add_tail(&msg->msg_list, &lp->lp_rtrq);
952 rbp = lnet_msg2bufpool(msg);
954 if (!msg->msg_rtrcredit) {
955 LASSERT ((rbp->rbp_credits < 0) ==
956 !cfs_list_empty(&rbp->rbp_msgs));
958 msg->msg_rtrcredit = 1;
960 if (rbp->rbp_credits < rbp->rbp_mincredits)
961 rbp->rbp_mincredits = rbp->rbp_credits;
963 if (rbp->rbp_credits < 0) {
964 /* must have checked eager_recv before here */
965 LASSERT(msg->msg_rx_ready_delay);
966 msg->msg_rx_delayed = 1;
967 cfs_list_add_tail(&msg->msg_list, &rbp->rbp_msgs);
972 LASSERT (!cfs_list_empty(&rbp->rbp_bufs));
973 rb = cfs_list_entry(rbp->rbp_bufs.next, lnet_rtrbuf_t, rb_list);
974 cfs_list_del(&rb->rb_list);
976 msg->msg_niov = rbp->rbp_npages;
977 msg->msg_kiov = &rb->rb_kiov[0];
980 int cpt = msg->msg_rx_cpt;
982 lnet_net_unlock(cpt);
983 lnet_ni_recv(lp->lp_ni, msg->msg_private, msg, 1,
984 0, msg->msg_len, msg->msg_len);
992 lnet_return_tx_credits_locked(lnet_msg_t *msg)
994 lnet_peer_t *txpeer = msg->msg_txpeer;
997 if (msg->msg_txcredit) {
998 struct lnet_ni *ni = txpeer->lp_ni;
999 struct lnet_tx_queue *tq = ni->ni_tx_queues[msg->msg_tx_cpt];
1001 /* give back NI txcredits */
1002 msg->msg_txcredit = 0;
1004 LASSERT((tq->tq_credits < 0) ==
1005 !cfs_list_empty(&tq->tq_delayed));
1008 if (tq->tq_credits <= 0) {
1009 msg2 = cfs_list_entry(tq->tq_delayed.next,
1010 lnet_msg_t, msg_list);
1011 cfs_list_del(&msg2->msg_list);
1013 LASSERT(msg2->msg_txpeer->lp_ni == ni);
1014 LASSERT(msg2->msg_tx_delayed);
1016 (void) lnet_post_send_locked(msg2, 1);
1020 if (msg->msg_peertxcredit) {
1021 /* give back peer txcredits */
1022 msg->msg_peertxcredit = 0;
1024 LASSERT((txpeer->lp_txcredits < 0) ==
1025 !cfs_list_empty(&txpeer->lp_txq));
1027 txpeer->lp_txqnob -= msg->msg_len + sizeof(lnet_hdr_t);
1028 LASSERT (txpeer->lp_txqnob >= 0);
1030 txpeer->lp_txcredits++;
1031 if (txpeer->lp_txcredits <= 0) {
1032 msg2 = cfs_list_entry(txpeer->lp_txq.next,
1033 lnet_msg_t, msg_list);
1034 cfs_list_del(&msg2->msg_list);
1036 LASSERT(msg2->msg_txpeer == txpeer);
1037 LASSERT(msg2->msg_tx_delayed);
1039 (void) lnet_post_send_locked(msg2, 1);
1043 if (txpeer != NULL) {
1044 msg->msg_txpeer = NULL;
1045 lnet_peer_decref_locked(txpeer);
1050 lnet_return_rx_credits_locked(lnet_msg_t *msg)
1052 lnet_peer_t *rxpeer = msg->msg_rxpeer;
1056 if (msg->msg_rtrcredit) {
1057 /* give back global router credits */
1059 lnet_rtrbufpool_t *rbp;
1061 /* NB If a msg ever blocks for a buffer in rbp_msgs, it stays
1062 * there until it gets one allocated, or aborts the wait
1064 LASSERT (msg->msg_kiov != NULL);
1066 rb = cfs_list_entry(msg->msg_kiov, lnet_rtrbuf_t, rb_kiov[0]);
1068 LASSERT (rbp == lnet_msg2bufpool(msg));
1070 msg->msg_kiov = NULL;
1071 msg->msg_rtrcredit = 0;
1073 LASSERT((rbp->rbp_credits < 0) ==
1074 !cfs_list_empty(&rbp->rbp_msgs));
1075 LASSERT((rbp->rbp_credits > 0) ==
1076 !cfs_list_empty(&rbp->rbp_bufs));
1078 cfs_list_add(&rb->rb_list, &rbp->rbp_bufs);
1080 if (rbp->rbp_credits <= 0) {
1081 msg2 = cfs_list_entry(rbp->rbp_msgs.next,
1082 lnet_msg_t, msg_list);
1083 cfs_list_del(&msg2->msg_list);
1085 (void) lnet_post_routed_recv_locked(msg2, 1);
1089 if (msg->msg_peerrtrcredit) {
1090 /* give back peer router credits */
1091 msg->msg_peerrtrcredit = 0;
1093 LASSERT((rxpeer->lp_rtrcredits < 0) ==
1094 !cfs_list_empty(&rxpeer->lp_rtrq));
1096 rxpeer->lp_rtrcredits++;
1097 if (rxpeer->lp_rtrcredits <= 0) {
1098 msg2 = cfs_list_entry(rxpeer->lp_rtrq.next,
1099 lnet_msg_t, msg_list);
1100 cfs_list_del(&msg2->msg_list);
1102 (void) lnet_post_routed_recv_locked(msg2, 1);
1106 LASSERT (!msg->msg_rtrcredit);
1107 LASSERT (!msg->msg_peerrtrcredit);
1109 if (rxpeer != NULL) {
1110 msg->msg_rxpeer = NULL;
1111 lnet_peer_decref_locked(rxpeer);
1116 lnet_compare_routes(lnet_route_t *r1, lnet_route_t *r2)
1118 lnet_peer_t *p1 = r1->lr_gateway;
1119 lnet_peer_t *p2 = r2->lr_gateway;
1121 if (r1->lr_hops < r2->lr_hops)
1124 if (r1->lr_hops > r2->lr_hops)
1127 if (p1->lp_txqnob < p2->lp_txqnob)
1130 if (p1->lp_txqnob > p2->lp_txqnob)
1133 if (p1->lp_txcredits > p2->lp_txcredits)
1136 if (p1->lp_txcredits < p2->lp_txcredits)
1139 if (r1->lr_seq - r2->lr_seq <= 0)
1145 static lnet_peer_t *
1146 lnet_find_route_locked(lnet_ni_t *ni, lnet_nid_t target, lnet_nid_t rtr_nid)
1148 lnet_remotenet_t *rnet;
1150 lnet_route_t *rtr_best;
1151 lnet_route_t *rtr_last;
1152 struct lnet_peer *lp_best;
1153 struct lnet_peer *lp;
1156 /* If @rtr_nid is not LNET_NID_ANY, return the gateway with
1157 * rtr_nid nid, otherwise find the best gateway I can use */
1159 rnet = lnet_find_net_locked(LNET_NIDNET(target));
1164 rtr_best = rtr_last = NULL;
1165 cfs_list_for_each_entry(rtr, &rnet->lrn_routes, lr_list) {
1166 lp = rtr->lr_gateway;
1168 if (!lp->lp_alive || /* gateway is down */
1169 ((lp->lp_ping_feats & LNET_PING_FEAT_NI_STATUS) != 0 &&
1170 rtr->lr_downis != 0)) /* NI to target is down */
1173 if (ni != NULL && lp->lp_ni != ni)
1176 if (lp->lp_nid == rtr_nid) /* it's pre-determined router */
1179 if (lp_best == NULL) {
1180 rtr_best = rtr_last = rtr;
1185 /* no protection on below fields, but it's harmless */
1186 if (rtr_last->lr_seq - rtr->lr_seq < 0)
1189 rc = lnet_compare_routes(rtr, rtr_best);
1197 /* set sequence number on the best router to the latest sequence + 1
1198 * so we can round-robin all routers, it's race and inaccurate but
1199 * harmless and functional */
1200 if (rtr_best != NULL)
1201 rtr_best->lr_seq = rtr_last->lr_seq + 1;
1206 lnet_send(lnet_nid_t src_nid, lnet_msg_t *msg, lnet_nid_t rtr_nid)
1208 lnet_nid_t dst_nid = msg->msg_target.nid;
1209 struct lnet_ni *src_ni;
1210 struct lnet_ni *local_ni;
1211 struct lnet_peer *lp;
1216 /* NB: rtr_nid is set to LNET_NID_ANY for all current use-cases,
1217 * but we might want to use pre-determined router for ACK/REPLY
1219 /* NB: ni != NULL == interface pre-determined (ACK/REPLY) */
1220 LASSERT (msg->msg_txpeer == NULL);
1221 LASSERT (!msg->msg_sending);
1222 LASSERT (!msg->msg_target_is_router);
1223 LASSERT (!msg->msg_receiving);
1225 msg->msg_sending = 1;
1227 LASSERT(!msg->msg_tx_committed);
1228 cpt = lnet_cpt_of_nid(rtr_nid == LNET_NID_ANY ? dst_nid : rtr_nid);
1232 if (the_lnet.ln_shutdown) {
1233 lnet_net_unlock(cpt);
1237 if (src_nid == LNET_NID_ANY) {
1240 src_ni = lnet_nid2ni_locked(src_nid, cpt);
1241 if (src_ni == NULL) {
1242 lnet_net_unlock(cpt);
1243 LCONSOLE_WARN("Can't send to %s: src %s is not a "
1244 "local nid\n", libcfs_nid2str(dst_nid),
1245 libcfs_nid2str(src_nid));
1248 LASSERT (!msg->msg_routing);
1251 /* Is this for someone on a local network? */
1252 local_ni = lnet_net2ni_locked(LNET_NIDNET(dst_nid), cpt);
1254 if (local_ni != NULL) {
1255 if (src_ni == NULL) {
1257 src_nid = src_ni->ni_nid;
1258 } else if (src_ni == local_ni) {
1259 lnet_ni_decref_locked(local_ni, cpt);
1261 lnet_ni_decref_locked(local_ni, cpt);
1262 lnet_ni_decref_locked(src_ni, cpt);
1263 lnet_net_unlock(cpt);
1264 LCONSOLE_WARN("No route to %s via from %s\n",
1265 libcfs_nid2str(dst_nid),
1266 libcfs_nid2str(src_nid));
1270 LASSERT(src_nid != LNET_NID_ANY);
1271 lnet_msg_commit(msg, cpt);
1273 if (!msg->msg_routing)
1274 msg->msg_hdr.src_nid = cpu_to_le64(src_nid);
1276 if (src_ni == the_lnet.ln_loni) {
1277 /* No send credit hassles with LOLND */
1278 lnet_net_unlock(cpt);
1279 lnet_ni_send(src_ni, msg);
1282 lnet_ni_decref_locked(src_ni, cpt);
1283 lnet_net_unlock(cpt);
1287 rc = lnet_nid2peer_locked(&lp, dst_nid, cpt);
1288 /* lp has ref on src_ni; lose mine */
1289 lnet_ni_decref_locked(src_ni, cpt);
1291 lnet_net_unlock(cpt);
1292 LCONSOLE_WARN("Error %d finding peer %s\n", rc,
1293 libcfs_nid2str(dst_nid));
1294 /* ENOMEM or shutting down */
1297 LASSERT (lp->lp_ni == src_ni);
1300 lnet_net_unlock(cpt);
1303 * - once application finishes computation, check here to update
1304 * router states before it waits for pending IO in LNetEQPoll
1305 * - recursion breaker: router checker sends no message
1306 * to remote networks */
1307 if (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING)
1308 lnet_router_checker();
1312 /* sending to a remote network */
1313 lp = lnet_find_route_locked(src_ni, dst_nid, rtr_nid);
1316 lnet_ni_decref_locked(src_ni, cpt);
1317 lnet_net_unlock(cpt);
1319 LCONSOLE_WARN("No route to %s via %s "
1320 "(all routers down)\n",
1321 libcfs_id2str(msg->msg_target),
1322 libcfs_nid2str(src_nid));
1323 return -EHOSTUNREACH;
1326 /* rtr_nid is LNET_NID_ANY or NID of pre-determined router,
1327 * it's possible that rtr_nid isn't LNET_NID_ANY and lp isn't
1328 * pre-determined router, this can happen if router table
1329 * was changed when we release the lock */
1330 if (rtr_nid != lp->lp_nid) {
1331 cpt2 = lnet_cpt_of_nid_locked(lp->lp_nid);
1334 lnet_ni_decref_locked(src_ni, cpt);
1335 lnet_net_unlock(cpt);
1337 rtr_nid = lp->lp_nid;
1343 CDEBUG(D_NET, "Best route to %s via %s for %s %d\n",
1344 libcfs_nid2str(dst_nid), libcfs_nid2str(lp->lp_nid),
1345 lnet_msgtyp2str(msg->msg_type), msg->msg_len);
1347 if (src_ni == NULL) {
1349 src_nid = src_ni->ni_nid;
1351 LASSERT (src_ni == lp->lp_ni);
1352 lnet_ni_decref_locked(src_ni, cpt);
1355 lnet_peer_addref_locked(lp);
1357 LASSERT(src_nid != LNET_NID_ANY);
1358 lnet_msg_commit(msg, cpt);
1360 if (!msg->msg_routing) {
1361 /* I'm the source and now I know which NI to send on */
1362 msg->msg_hdr.src_nid = cpu_to_le64(src_nid);
1365 msg->msg_target_is_router = 1;
1366 msg->msg_target.nid = lp->lp_nid;
1367 msg->msg_target.pid = LUSTRE_SRV_LNET_PID;
1370 /* 'lp' is our best choice of peer */
1372 LASSERT (!msg->msg_peertxcredit);
1373 LASSERT (!msg->msg_txcredit);
1374 LASSERT (msg->msg_txpeer == NULL);
1376 msg->msg_txpeer = lp; /* msg takes my ref on lp */
1378 rc = lnet_post_send_locked(msg, 0);
1379 lnet_net_unlock(cpt);
1381 if (rc == EHOSTUNREACH)
1382 return -EHOSTUNREACH;
1385 lnet_ni_send(src_ni, msg);
1391 lnet_drop_message(lnet_ni_t *ni, int cpt, void *private, unsigned int nob)
1394 the_lnet.ln_counters[cpt]->drop_count++;
1395 the_lnet.ln_counters[cpt]->drop_length += nob;
1396 lnet_net_unlock(cpt);
1398 lnet_ni_recv(ni, private, NULL, 0, 0, 0, nob);
1402 lnet_recv_put(lnet_ni_t *ni, lnet_msg_t *msg)
1404 lnet_hdr_t *hdr = &msg->msg_hdr;
1406 if (msg->msg_wanted != 0)
1407 lnet_setpayloadbuffer(msg);
1409 lnet_build_msg_event(msg, LNET_EVENT_PUT);
1411 /* Must I ACK? If so I'll grab the ack_wmd out of the header and put
1412 * it back into the ACK during lnet_finalize() */
1413 msg->msg_ack = (!lnet_is_wire_handle_none(&hdr->msg.put.ack_wmd) &&
1414 (msg->msg_md->md_options & LNET_MD_ACK_DISABLE) == 0);
1416 lnet_ni_recv(ni, msg->msg_private, msg, msg->msg_rx_delayed,
1417 msg->msg_offset, msg->msg_wanted, hdr->payload_length);
1421 lnet_parse_put(lnet_ni_t *ni, lnet_msg_t *msg)
1423 lnet_hdr_t *hdr = &msg->msg_hdr;
1424 struct lnet_match_info info;
1427 /* Convert put fields to host byte order */
1428 hdr->msg.put.match_bits = le64_to_cpu(hdr->msg.put.match_bits);
1429 hdr->msg.put.ptl_index = le32_to_cpu(hdr->msg.put.ptl_index);
1430 hdr->msg.put.offset = le32_to_cpu(hdr->msg.put.offset);
1432 info.mi_id.nid = hdr->src_nid;
1433 info.mi_id.pid = hdr->src_pid;
1434 info.mi_opc = LNET_MD_OP_PUT;
1435 info.mi_portal = hdr->msg.put.ptl_index;
1436 info.mi_rlength = hdr->payload_length;
1437 info.mi_roffset = hdr->msg.put.offset;
1438 info.mi_mbits = hdr->msg.put.match_bits;
1440 msg->msg_rx_ready_delay = ni->ni_lnd->lnd_eager_recv == NULL;
1443 rc = lnet_ptl_match_md(&info, msg);
1448 case LNET_MATCHMD_OK:
1449 lnet_recv_put(ni, msg);
1452 case LNET_MATCHMD_NONE:
1453 if (msg->msg_rx_delayed) /* attached on delayed list */
1456 rc = lnet_ni_eager_recv(ni, msg);
1461 case LNET_MATCHMD_DROP:
1462 CNETERR("Dropping PUT from %s portal %d match "LPU64
1463 " offset %d length %d: %d\n",
1464 libcfs_id2str(info.mi_id), info.mi_portal,
1465 info.mi_mbits, info.mi_roffset, info.mi_rlength, rc);
1467 return ENOENT; /* +ve: OK but no match */
1472 lnet_parse_get(lnet_ni_t *ni, lnet_msg_t *msg, int rdma_get)
1474 struct lnet_match_info info;
1475 lnet_hdr_t *hdr = &msg->msg_hdr;
1476 lnet_handle_wire_t reply_wmd;
1479 /* Convert get fields to host byte order */
1480 hdr->msg.get.match_bits = le64_to_cpu(hdr->msg.get.match_bits);
1481 hdr->msg.get.ptl_index = le32_to_cpu(hdr->msg.get.ptl_index);
1482 hdr->msg.get.sink_length = le32_to_cpu(hdr->msg.get.sink_length);
1483 hdr->msg.get.src_offset = le32_to_cpu(hdr->msg.get.src_offset);
1485 info.mi_id.nid = hdr->src_nid;
1486 info.mi_id.pid = hdr->src_pid;
1487 info.mi_opc = LNET_MD_OP_GET;
1488 info.mi_portal = hdr->msg.get.ptl_index;
1489 info.mi_rlength = hdr->msg.get.sink_length;
1490 info.mi_roffset = hdr->msg.get.src_offset;
1491 info.mi_mbits = hdr->msg.get.match_bits;
1493 rc = lnet_ptl_match_md(&info, msg);
1494 if (rc == LNET_MATCHMD_DROP) {
1495 CNETERR("Dropping GET from %s portal %d match "LPU64
1496 " offset %d length %d\n",
1497 libcfs_id2str(info.mi_id), info.mi_portal,
1498 info.mi_mbits, info.mi_roffset, info.mi_rlength);
1499 return ENOENT; /* +ve: OK but no match */
1502 LASSERT(rc == LNET_MATCHMD_OK);
1504 lnet_build_msg_event(msg, LNET_EVENT_GET);
1506 reply_wmd = hdr->msg.get.return_wmd;
1508 lnet_prep_send(msg, LNET_MSG_REPLY, info.mi_id,
1509 msg->msg_offset, msg->msg_wanted);
1511 msg->msg_hdr.msg.reply.dst_wmd = reply_wmd;
1514 /* The LND completes the REPLY from her recv procedure */
1515 lnet_ni_recv(ni, msg->msg_private, msg, 0,
1516 msg->msg_offset, msg->msg_len, msg->msg_len);
1520 lnet_ni_recv(ni, msg->msg_private, NULL, 0, 0, 0, 0);
1521 msg->msg_receiving = 0;
1523 rc = lnet_send(ni->ni_nid, msg, LNET_NID_ANY);
1525 /* didn't get as far as lnet_ni_send() */
1526 CERROR("%s: Unable to send REPLY for GET from %s: %d\n",
1527 libcfs_nid2str(ni->ni_nid),
1528 libcfs_id2str(info.mi_id), rc);
1530 lnet_finalize(ni, msg, rc);
1537 lnet_parse_reply(lnet_ni_t *ni, lnet_msg_t *msg)
1539 void *private = msg->msg_private;
1540 lnet_hdr_t *hdr = &msg->msg_hdr;
1541 lnet_process_id_t src = {0};
1547 cpt = lnet_cpt_of_cookie(hdr->msg.reply.dst_wmd.wh_object_cookie);
1550 src.nid = hdr->src_nid;
1551 src.pid = hdr->src_pid;
1553 /* NB handles only looked up by creator (no flips) */
1554 md = lnet_wire_handle2md(&hdr->msg.reply.dst_wmd);
1555 if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) {
1556 CNETERR("%s: Dropping REPLY from %s for %s "
1557 "MD "LPX64"."LPX64"\n",
1558 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
1559 (md == NULL) ? "invalid" : "inactive",
1560 hdr->msg.reply.dst_wmd.wh_interface_cookie,
1561 hdr->msg.reply.dst_wmd.wh_object_cookie);
1562 if (md != NULL && md->md_me != NULL)
1563 CERROR("REPLY MD also attached to portal %d\n",
1564 md->md_me->me_portal);
1566 lnet_res_unlock(cpt);
1567 return ENOENT; /* +ve: OK but no match */
1570 LASSERT (md->md_offset == 0);
1572 rlength = hdr->payload_length;
1573 mlength = MIN(rlength, (int)md->md_length);
1575 if (mlength < rlength &&
1576 (md->md_options & LNET_MD_TRUNCATE) == 0) {
1577 CNETERR("%s: Dropping REPLY from %s length %d "
1578 "for MD "LPX64" would overflow (%d)\n",
1579 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
1580 rlength, hdr->msg.reply.dst_wmd.wh_object_cookie,
1582 lnet_res_unlock(cpt);
1583 return ENOENT; /* +ve: OK but no match */
1586 CDEBUG(D_NET, "%s: Reply from %s of length %d/%d into md "LPX64"\n",
1587 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
1588 mlength, rlength, hdr->msg.reply.dst_wmd.wh_object_cookie);
1590 lnet_msg_attach_md(msg, md, 0, mlength);
1593 lnet_setpayloadbuffer(msg);
1595 lnet_res_unlock(cpt);
1597 lnet_build_msg_event(msg, LNET_EVENT_REPLY);
1599 lnet_ni_recv(ni, private, msg, 0, 0, mlength, rlength);
1604 lnet_parse_ack(lnet_ni_t *ni, lnet_msg_t *msg)
1606 lnet_hdr_t *hdr = &msg->msg_hdr;
1607 lnet_process_id_t src = {0};
1611 src.nid = hdr->src_nid;
1612 src.pid = hdr->src_pid;
1614 /* Convert ack fields to host byte order */
1615 hdr->msg.ack.match_bits = le64_to_cpu(hdr->msg.ack.match_bits);
1616 hdr->msg.ack.mlength = le32_to_cpu(hdr->msg.ack.mlength);
1618 cpt = lnet_cpt_of_cookie(hdr->msg.ack.dst_wmd.wh_object_cookie);
1621 /* NB handles only looked up by creator (no flips) */
1622 md = lnet_wire_handle2md(&hdr->msg.ack.dst_wmd);
1623 if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) {
1624 /* Don't moan; this is expected */
1626 "%s: Dropping ACK from %s to %s MD "LPX64"."LPX64"\n",
1627 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
1628 (md == NULL) ? "invalid" : "inactive",
1629 hdr->msg.ack.dst_wmd.wh_interface_cookie,
1630 hdr->msg.ack.dst_wmd.wh_object_cookie);
1631 if (md != NULL && md->md_me != NULL)
1632 CERROR("Source MD also attached to portal %d\n",
1633 md->md_me->me_portal);
1635 lnet_res_unlock(cpt);
1636 return ENOENT; /* +ve! */
1639 CDEBUG(D_NET, "%s: ACK from %s into md "LPX64"\n",
1640 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
1641 hdr->msg.ack.dst_wmd.wh_object_cookie);
1643 lnet_msg_attach_md(msg, md, 0, 0);
1645 lnet_res_unlock(cpt);
1647 lnet_build_msg_event(msg, LNET_EVENT_ACK);
1649 lnet_ni_recv(ni, msg->msg_private, msg, 0, 0, 0, msg->msg_len);
1654 lnet_parse_forward_locked(lnet_ni_t *ni, lnet_msg_t *msg)
1659 if (msg->msg_rxpeer->lp_rtrcredits <= 0 ||
1660 lnet_msg2bufpool(msg)->rbp_credits <= 0) {
1661 if (ni->ni_lnd->lnd_eager_recv == NULL) {
1662 msg->msg_rx_ready_delay = 1;
1664 lnet_net_unlock(msg->msg_rx_cpt);
1665 rc = lnet_ni_eager_recv(ni, msg);
1666 lnet_net_lock(msg->msg_rx_cpt);
1671 rc = lnet_post_routed_recv_locked(msg, 0);
1679 lnet_msgtyp2str (int type)
1688 case LNET_MSG_REPLY:
1690 case LNET_MSG_HELLO:
1693 return ("<UNKNOWN>");
1698 lnet_print_hdr(lnet_hdr_t * hdr)
1700 lnet_process_id_t src = {0};
1701 lnet_process_id_t dst = {0};
1702 char *type_str = lnet_msgtyp2str (hdr->type);
1704 src.nid = hdr->src_nid;
1705 src.pid = hdr->src_pid;
1707 dst.nid = hdr->dest_nid;
1708 dst.pid = hdr->dest_pid;
1710 CWARN("P3 Header at %p of type %s\n", hdr, type_str);
1711 CWARN(" From %s\n", libcfs_id2str(src));
1712 CWARN(" To %s\n", libcfs_id2str(dst));
1714 switch (hdr->type) {
1719 CWARN(" Ptl index %d, ack md "LPX64"."LPX64", "
1720 "match bits "LPU64"\n",
1721 hdr->msg.put.ptl_index,
1722 hdr->msg.put.ack_wmd.wh_interface_cookie,
1723 hdr->msg.put.ack_wmd.wh_object_cookie,
1724 hdr->msg.put.match_bits);
1725 CWARN(" Length %d, offset %d, hdr data "LPX64"\n",
1726 hdr->payload_length, hdr->msg.put.offset,
1727 hdr->msg.put.hdr_data);
1731 CWARN(" Ptl index %d, return md "LPX64"."LPX64", "
1732 "match bits "LPU64"\n", hdr->msg.get.ptl_index,
1733 hdr->msg.get.return_wmd.wh_interface_cookie,
1734 hdr->msg.get.return_wmd.wh_object_cookie,
1735 hdr->msg.get.match_bits);
1736 CWARN(" Length %d, src offset %d\n",
1737 hdr->msg.get.sink_length,
1738 hdr->msg.get.src_offset);
1742 CWARN(" dst md "LPX64"."LPX64", "
1743 "manipulated length %d\n",
1744 hdr->msg.ack.dst_wmd.wh_interface_cookie,
1745 hdr->msg.ack.dst_wmd.wh_object_cookie,
1746 hdr->msg.ack.mlength);
1749 case LNET_MSG_REPLY:
1750 CWARN(" dst md "LPX64"."LPX64", "
1752 hdr->msg.reply.dst_wmd.wh_interface_cookie,
1753 hdr->msg.reply.dst_wmd.wh_object_cookie,
1754 hdr->payload_length);
1760 lnet_parse(lnet_ni_t *ni, lnet_hdr_t *hdr, lnet_nid_t from_nid,
1761 void *private, int rdma_req)
1766 struct lnet_msg *msg;
1767 lnet_pid_t dest_pid;
1768 lnet_nid_t dest_nid;
1770 __u32 payload_length;
1773 LASSERT (!cfs_in_interrupt ());
1775 type = le32_to_cpu(hdr->type);
1776 src_nid = le64_to_cpu(hdr->src_nid);
1777 dest_nid = le64_to_cpu(hdr->dest_nid);
1778 dest_pid = le32_to_cpu(hdr->dest_pid);
1779 payload_length = le32_to_cpu(hdr->payload_length);
1781 for_me = (ni->ni_nid == dest_nid);
1782 cpt = lnet_cpt_of_nid(from_nid);
1787 if (payload_length > 0) {
1788 CERROR("%s, src %s: bad %s payload %d (0 expected)\n",
1789 libcfs_nid2str(from_nid),
1790 libcfs_nid2str(src_nid),
1791 lnet_msgtyp2str(type), payload_length);
1797 case LNET_MSG_REPLY:
1798 if (payload_length > (__u32)(for_me ? LNET_MAX_PAYLOAD : LNET_MTU)) {
1799 CERROR("%s, src %s: bad %s payload %d "
1800 "(%d max expected)\n",
1801 libcfs_nid2str(from_nid),
1802 libcfs_nid2str(src_nid),
1803 lnet_msgtyp2str(type),
1805 for_me ? LNET_MAX_PAYLOAD : LNET_MTU);
1811 CERROR("%s, src %s: Bad message type 0x%x\n",
1812 libcfs_nid2str(from_nid),
1813 libcfs_nid2str(src_nid), type);
1817 if (the_lnet.ln_routing &&
1818 ni->ni_last_alive != cfs_time_current_sec()) {
1821 /* NB: so far here is the only place to set NI status to "up */
1822 ni->ni_last_alive = cfs_time_current_sec();
1823 if (ni->ni_status != NULL &&
1824 ni->ni_status->ns_status == LNET_NI_STATUS_DOWN)
1825 ni->ni_status->ns_status = LNET_NI_STATUS_UP;
1829 /* Regard a bad destination NID as a protocol error. Senders should
1830 * know what they're doing; if they don't they're misconfigured, buggy
1831 * or malicious so we chop them off at the knees :) */
1834 if (LNET_NIDNET(dest_nid) == LNET_NIDNET(ni->ni_nid)) {
1835 /* should have gone direct */
1836 CERROR ("%s, src %s: Bad dest nid %s "
1837 "(should have been sent direct)\n",
1838 libcfs_nid2str(from_nid),
1839 libcfs_nid2str(src_nid),
1840 libcfs_nid2str(dest_nid));
1844 if (lnet_islocalnid(dest_nid)) {
1845 /* dest is another local NI; sender should have used
1846 * this node's NID on its own network */
1847 CERROR ("%s, src %s: Bad dest nid %s "
1848 "(it's my nid but on a different network)\n",
1849 libcfs_nid2str(from_nid),
1850 libcfs_nid2str(src_nid),
1851 libcfs_nid2str(dest_nid));
1855 if (rdma_req && type == LNET_MSG_GET) {
1856 CERROR ("%s, src %s: Bad optimized GET for %s "
1857 "(final destination must be me)\n",
1858 libcfs_nid2str(from_nid),
1859 libcfs_nid2str(src_nid),
1860 libcfs_nid2str(dest_nid));
1864 if (!the_lnet.ln_routing) {
1865 CERROR ("%s, src %s: Dropping message for %s "
1866 "(routing not enabled)\n",
1867 libcfs_nid2str(from_nid),
1868 libcfs_nid2str(src_nid),
1869 libcfs_nid2str(dest_nid));
1874 /* Message looks OK; we're not going to return an error, so we MUST
1875 * call back lnd_recv() come what may... */
1877 if (!cfs_list_empty (&the_lnet.ln_test_peers) && /* normally we don't */
1878 fail_peer (src_nid, 0)) /* shall we now? */
1880 CERROR("%s, src %s: Dropping %s to simulate failure\n",
1881 libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
1882 lnet_msgtyp2str(type));
1886 msg = lnet_msg_alloc();
1888 CERROR("%s, src %s: Dropping %s (out of memory)\n",
1889 libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
1890 lnet_msgtyp2str(type));
1894 /* msg zeroed in lnet_msg_alloc; i.e. flags all clear, pointers NULL etc */
1896 msg->msg_type = type;
1897 msg->msg_private = private;
1898 msg->msg_receiving = 1;
1899 msg->msg_len = msg->msg_wanted = payload_length;
1900 msg->msg_offset = 0;
1901 msg->msg_hdr = *hdr;
1902 /* for building message event */
1903 msg->msg_from = from_nid;
1905 msg->msg_target.pid = dest_pid;
1906 msg->msg_target.nid = dest_nid;
1907 msg->msg_routing = 1;
1910 /* convert common msg->hdr fields to host byteorder */
1911 msg->msg_hdr.type = type;
1912 msg->msg_hdr.src_nid = src_nid;
1913 msg->msg_hdr.src_pid = le32_to_cpu(msg->msg_hdr.src_pid);
1914 msg->msg_hdr.dest_nid = dest_nid;
1915 msg->msg_hdr.dest_pid = dest_pid;
1916 msg->msg_hdr.payload_length = payload_length;
1920 rc = lnet_nid2peer_locked(&msg->msg_rxpeer, from_nid, cpt);
1922 lnet_net_unlock(cpt);
1923 CERROR("%s, src %s: Dropping %s "
1924 "(error %d looking up sender)\n",
1925 libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
1926 lnet_msgtyp2str(type), rc);
1931 lnet_msg_commit(msg, cpt);
1934 rc = lnet_parse_forward_locked(ni, msg);
1935 lnet_net_unlock(cpt);
1940 lnet_ni_recv(ni, msg->msg_private, msg, 0,
1941 0, payload_length, payload_length);
1946 lnet_net_unlock(cpt);
1950 rc = lnet_parse_ack(ni, msg);
1953 rc = lnet_parse_put(ni, msg);
1956 rc = lnet_parse_get(ni, msg, rdma_req);
1958 case LNET_MSG_REPLY:
1959 rc = lnet_parse_reply(ni, msg);
1964 goto free_drop; /* prevent an unused label if !kernel */
1970 LASSERT (rc == ENOENT);
1973 LASSERT(msg->msg_md == NULL);
1974 lnet_finalize(ni, msg, rc);
1977 lnet_drop_message(ni, cpt, private, payload_length);
1982 lnet_drop_delayed_msg_list(cfs_list_t *head, char *reason)
1984 while (!cfs_list_empty(head)) {
1985 lnet_process_id_t id = {0};
1988 msg = cfs_list_entry(head->next, lnet_msg_t, msg_list);
1989 cfs_list_del(&msg->msg_list);
1991 id.nid = msg->msg_hdr.src_nid;
1992 id.pid = msg->msg_hdr.src_pid;
1994 LASSERT(msg->msg_md == NULL);
1995 LASSERT(msg->msg_rx_delayed);
1996 LASSERT(msg->msg_rxpeer != NULL);
1997 LASSERT(msg->msg_hdr.type == LNET_MSG_PUT);
1999 CWARN("Dropping delayed PUT from %s portal %d match "LPU64
2000 " offset %d length %d: %s\n",
2002 msg->msg_hdr.msg.put.ptl_index,
2003 msg->msg_hdr.msg.put.match_bits,
2004 msg->msg_hdr.msg.put.offset,
2005 msg->msg_hdr.payload_length, reason);
2007 /* NB I can't drop msg's ref on msg_rxpeer until after I've
2008 * called lnet_drop_message(), so I just hang onto msg as well
2009 * until that's done */
2011 lnet_drop_message(msg->msg_rxpeer->lp_ni,
2012 msg->msg_rxpeer->lp_cpt,
2013 msg->msg_private, msg->msg_len);
2014 /* NB: message will not generate event because w/o attached MD,
2015 * so we just use 0 as the third parameter */
2016 lnet_finalize(msg->msg_rxpeer->lp_ni, msg, 0);
2021 lnet_recv_delayed_msg_list(cfs_list_t *head)
2023 while (!cfs_list_empty(head)) {
2025 lnet_process_id_t id;
2027 msg = cfs_list_entry(head->next, lnet_msg_t, msg_list);
2028 cfs_list_del(&msg->msg_list);
2030 /* md won't disappear under me, since each msg
2031 * holds a ref on it */
2033 id.nid = msg->msg_hdr.src_nid;
2034 id.pid = msg->msg_hdr.src_pid;
2036 LASSERT(msg->msg_rx_delayed);
2037 LASSERT(msg->msg_md != NULL);
2038 LASSERT(msg->msg_rxpeer != NULL);
2039 LASSERT(msg->msg_hdr.type == LNET_MSG_PUT);
2041 CDEBUG(D_NET, "Resuming delayed PUT from %s portal %d "
2042 "match "LPU64" offset %d length %d.\n",
2043 libcfs_id2str(id), msg->msg_hdr.msg.put.ptl_index,
2044 msg->msg_hdr.msg.put.match_bits,
2045 msg->msg_hdr.msg.put.offset,
2046 msg->msg_hdr.payload_length);
2048 lnet_recv_put(msg->msg_rxpeer->lp_ni, msg);
2053 * Initiate an asynchronous PUT operation.
2055 * There are several events associated with a PUT: completion of the send on
2056 * the initiator node (LNET_EVENT_SEND), and when the send completes
2057 * successfully, the receipt of an acknowledgment (LNET_EVENT_ACK) indicating
2058 * that the operation was accepted by the target. The event LNET_EVENT_PUT is
2059 * used at the target node to indicate the completion of incoming data
2062 * The local events will be logged in the EQ associated with the MD pointed to
2063 * by \a mdh handle. Using a MD without an associated EQ results in these
2064 * events being discarded. In this case, the caller must have another
2065 * mechanism (e.g., a higher level protocol) for determining when it is safe
2066 * to modify the memory region associated with the MD.
2068 * Note that LNet does not guarantee the order of LNET_EVENT_SEND and
2069 * LNET_EVENT_ACK, though intuitively ACK should happen after SEND.
2071 * \param self Indicates the NID of a local interface through which to send
2072 * the PUT request. Use LNET_NID_ANY to let LNet choose one by itself.
2073 * \param mdh A handle for the MD that describes the memory to be sent. The MD
2074 * must be "free floating" (See LNetMDBind()).
2075 * \param ack Controls whether an acknowledgment is requested.
2076 * Acknowledgments are only sent when they are requested by the initiating
2077 * process and the target MD enables them.
2078 * \param target A process identifier for the target process.
2079 * \param portal The index in the \a target's portal table.
2080 * \param match_bits The match bits to use for MD selection at the target
2082 * \param offset The offset into the target MD (only used when the target
2083 * MD has the LNET_MD_MANAGE_REMOTE option set).
2084 * \param hdr_data 64 bits of user data that can be included in the message
2085 * header. This data is written to an event queue entry at the target if an
2086 * EQ is present on the matching MD.
2088 * \retval 0 Success, and only in this case events will be generated
2089 * and logged to EQ (if it exists).
2090 * \retval -EIO Simulated failure.
2091 * \retval -ENOMEM Memory allocation failure.
2092 * \retval -ENOENT Invalid MD object.
2094 * \see lnet_event_t::hdr_data and lnet_event_kind_t.
2097 LNetPut(lnet_nid_t self, lnet_handle_md_t mdh, lnet_ack_req_t ack,
2098 lnet_process_id_t target, unsigned int portal,
2099 __u64 match_bits, unsigned int offset,
2102 struct lnet_msg *msg;
2103 struct lnet_libmd *md;
2107 LASSERT (the_lnet.ln_init);
2108 LASSERT (the_lnet.ln_refcount > 0);
2110 if (!cfs_list_empty (&the_lnet.ln_test_peers) && /* normally we don't */
2111 fail_peer (target.nid, 1)) /* shall we now? */
2113 CERROR("Dropping PUT to %s: simulated failure\n",
2114 libcfs_id2str(target));
2118 msg = lnet_msg_alloc();
2120 CERROR("Dropping PUT to %s: ENOMEM on lnet_msg_t\n",
2121 libcfs_id2str(target));
2124 msg->msg_vmflush = !!cfs_memory_pressure_get();
2126 cpt = lnet_cpt_of_cookie(mdh.cookie);
2129 md = lnet_handle2md(&mdh);
2130 if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) {
2131 CERROR("Dropping PUT ("LPU64":%d:%s): MD (%d) invalid\n",
2132 match_bits, portal, libcfs_id2str(target),
2133 md == NULL ? -1 : md->md_threshold);
2134 if (md != NULL && md->md_me != NULL)
2135 CERROR("Source MD also attached to portal %d\n",
2136 md->md_me->me_portal);
2137 lnet_res_unlock(cpt);
2143 CDEBUG(D_NET, "LNetPut -> %s\n", libcfs_id2str(target));
2145 lnet_msg_attach_md(msg, md, 0, 0);
2147 lnet_prep_send(msg, LNET_MSG_PUT, target, 0, md->md_length);
2149 msg->msg_hdr.msg.put.match_bits = cpu_to_le64(match_bits);
2150 msg->msg_hdr.msg.put.ptl_index = cpu_to_le32(portal);
2151 msg->msg_hdr.msg.put.offset = cpu_to_le32(offset);
2152 msg->msg_hdr.msg.put.hdr_data = hdr_data;
2154 /* NB handles only looked up by creator (no flips) */
2155 if (ack == LNET_ACK_REQ) {
2156 msg->msg_hdr.msg.put.ack_wmd.wh_interface_cookie =
2157 the_lnet.ln_interface_cookie;
2158 msg->msg_hdr.msg.put.ack_wmd.wh_object_cookie =
2159 md->md_lh.lh_cookie;
2161 msg->msg_hdr.msg.put.ack_wmd.wh_interface_cookie =
2162 LNET_WIRE_HANDLE_COOKIE_NONE;
2163 msg->msg_hdr.msg.put.ack_wmd.wh_object_cookie =
2164 LNET_WIRE_HANDLE_COOKIE_NONE;
2167 lnet_res_unlock(cpt);
2169 lnet_build_msg_event(msg, LNET_EVENT_SEND);
2171 rc = lnet_send(self, msg, LNET_NID_ANY);
2173 CNETERR( "Error sending PUT to %s: %d\n",
2174 libcfs_id2str(target), rc);
2175 lnet_finalize (NULL, msg, rc);
2178 /* completion will be signalled by an event */
2183 lnet_create_reply_msg (lnet_ni_t *ni, lnet_msg_t *getmsg)
2185 /* The LND can DMA direct to the GET md (i.e. no REPLY msg). This
2186 * returns a msg for the LND to pass to lnet_finalize() when the sink
2187 * data has been received.
2189 * CAVEAT EMPTOR: 'getmsg' is the original GET, which is freed when
2190 * lnet_finalize() is called on it, so the LND must call this first */
2192 struct lnet_msg *msg = lnet_msg_alloc();
2193 struct lnet_libmd *getmd = getmsg->msg_md;
2194 lnet_process_id_t peer_id = getmsg->msg_target;
2197 LASSERT(!getmsg->msg_target_is_router);
2198 LASSERT(!getmsg->msg_routing);
2200 cpt = lnet_cpt_of_cookie(getmd->md_lh.lh_cookie);
2203 LASSERT (getmd->md_refcount > 0);
2206 CERROR ("%s: Dropping REPLY from %s: can't allocate msg\n",
2207 libcfs_nid2str(ni->ni_nid), libcfs_id2str(peer_id));
2211 if (getmd->md_threshold == 0) {
2212 CERROR ("%s: Dropping REPLY from %s for inactive MD %p\n",
2213 libcfs_nid2str(ni->ni_nid), libcfs_id2str(peer_id),
2215 lnet_res_unlock(cpt);
2219 LASSERT(getmd->md_offset == 0);
2221 CDEBUG(D_NET, "%s: Reply from %s md %p\n",
2222 libcfs_nid2str(ni->ni_nid), libcfs_id2str(peer_id), getmd);
2224 /* setup information for lnet_build_msg_event */
2225 msg->msg_from = peer_id.nid;
2226 msg->msg_type = LNET_MSG_GET; /* flag this msg as an "optimized" GET */
2227 msg->msg_hdr.src_nid = peer_id.nid;
2228 msg->msg_hdr.payload_length = getmd->md_length;
2229 msg->msg_receiving = 1; /* required by lnet_msg_attach_md */
2231 lnet_msg_attach_md(msg, getmd, getmd->md_offset, getmd->md_length);
2232 lnet_res_unlock(cpt);
2234 cpt = lnet_cpt_of_nid(peer_id.nid);
2237 lnet_msg_commit(msg, cpt);
2238 lnet_net_unlock(cpt);
2240 lnet_build_msg_event(msg, LNET_EVENT_REPLY);
2245 cpt = lnet_cpt_of_nid(peer_id.nid);
2248 the_lnet.ln_counters[cpt]->drop_count++;
2249 the_lnet.ln_counters[cpt]->drop_length += getmd->md_length;
2250 lnet_net_unlock(cpt);
2259 lnet_set_reply_msg_len(lnet_ni_t *ni, lnet_msg_t *reply, unsigned int len)
2261 /* Set the REPLY length, now the RDMA that elides the REPLY message has
2262 * completed and I know it. */
2263 LASSERT (reply != NULL);
2264 LASSERT (reply->msg_type == LNET_MSG_GET);
2265 LASSERT (reply->msg_ev.type == LNET_EVENT_REPLY);
2267 /* NB I trusted my peer to RDMA. If she tells me she's written beyond
2268 * the end of my buffer, I might as well be dead. */
2269 LASSERT (len <= reply->msg_ev.mlength);
2271 reply->msg_ev.mlength = len;
2275 * Initiate an asynchronous GET operation.
2277 * On the initiator node, an LNET_EVENT_SEND is logged when the GET request
2278 * is sent, and an LNET_EVENT_REPLY is logged when the data returned from
2279 * the target node in the REPLY has been written to local MD.
2281 * On the target node, an LNET_EVENT_GET is logged when the GET request
2282 * arrives and is accepted into a MD.
2284 * \param self,target,portal,match_bits,offset See the discussion in LNetPut().
2285 * \param mdh A handle for the MD that describes the memory into which the
2286 * requested data will be received. The MD must be "free floating" (See LNetMDBind()).
2288 * \retval 0 Success, and only in this case events will be generated
2289 * and logged to EQ (if it exists) of the MD.
2290 * \retval -EIO Simulated failure.
2291 * \retval -ENOMEM Memory allocation failure.
2292 * \retval -ENOENT Invalid MD object.
2295 LNetGet(lnet_nid_t self, lnet_handle_md_t mdh,
2296 lnet_process_id_t target, unsigned int portal,
2297 __u64 match_bits, unsigned int offset)
2299 struct lnet_msg *msg;
2300 struct lnet_libmd *md;
2304 LASSERT (the_lnet.ln_init);
2305 LASSERT (the_lnet.ln_refcount > 0);
2307 if (!cfs_list_empty (&the_lnet.ln_test_peers) && /* normally we don't */
2308 fail_peer (target.nid, 1)) /* shall we now? */
2310 CERROR("Dropping GET to %s: simulated failure\n",
2311 libcfs_id2str(target));
2315 msg = lnet_msg_alloc();
2317 CERROR("Dropping GET to %s: ENOMEM on lnet_msg_t\n",
2318 libcfs_id2str(target));
2322 cpt = lnet_cpt_of_cookie(mdh.cookie);
2325 md = lnet_handle2md(&mdh);
2326 if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) {
2327 CERROR("Dropping GET ("LPU64":%d:%s): MD (%d) invalid\n",
2328 match_bits, portal, libcfs_id2str(target),
2329 md == NULL ? -1 : md->md_threshold);
2330 if (md != NULL && md->md_me != NULL)
2331 CERROR("REPLY MD also attached to portal %d\n",
2332 md->md_me->me_portal);
2334 lnet_res_unlock(cpt);
2341 CDEBUG(D_NET, "LNetGet -> %s\n", libcfs_id2str(target));
2343 lnet_msg_attach_md(msg, md, 0, 0);
2345 lnet_prep_send(msg, LNET_MSG_GET, target, 0, 0);
2347 msg->msg_hdr.msg.get.match_bits = cpu_to_le64(match_bits);
2348 msg->msg_hdr.msg.get.ptl_index = cpu_to_le32(portal);
2349 msg->msg_hdr.msg.get.src_offset = cpu_to_le32(offset);
2350 msg->msg_hdr.msg.get.sink_length = cpu_to_le32(md->md_length);
2352 /* NB handles only looked up by creator (no flips) */
2353 msg->msg_hdr.msg.get.return_wmd.wh_interface_cookie =
2354 the_lnet.ln_interface_cookie;
2355 msg->msg_hdr.msg.get.return_wmd.wh_object_cookie =
2356 md->md_lh.lh_cookie;
2358 lnet_res_unlock(cpt);
2360 lnet_build_msg_event(msg, LNET_EVENT_SEND);
2362 rc = lnet_send(self, msg, LNET_NID_ANY);
2364 CNETERR( "Error sending GET to %s: %d\n",
2365 libcfs_id2str(target), rc);
2366 lnet_finalize (NULL, msg, rc);
2369 /* completion will be signalled by an event */
2374 * Calculate distance to node at \a dstnid.
2376 * \param dstnid Target NID.
2377 * \param srcnidp If not NULL, NID of the local interface to reach \a dstnid
2379 * \param orderp If not NULL, order of the route to reach \a dstnid is saved
2382 * \retval 0 If \a dstnid belongs to a local interface, and reserved option
2383 * local_nid_dist_zero is set, which is the default.
2384 * \retval positives Distance to target NID, i.e. number of hops plus one.
2385 * \retval -EHOSTUNREACH If \a dstnid is not reachable.
2388 LNetDist(lnet_nid_t dstnid, lnet_nid_t *srcnidp, __u32 *orderp)
2392 lnet_remotenet_t *rnet;
2393 __u32 dstnet = LNET_NIDNET(dstnid);
2398 /* if !local_nid_dist_zero, I don't return a distance of 0 ever
2399 * (when lustre sees a distance of 0, it substitutes 0@lo), so I
2400 * keep order 0 free for 0@lo and order 1 free for a local NID
2403 LASSERT (the_lnet.ln_init);
2404 LASSERT (the_lnet.ln_refcount > 0);
2406 cpt = lnet_net_lock_current();
2408 cfs_list_for_each (e, &the_lnet.ln_nis) {
2409 ni = cfs_list_entry(e, lnet_ni_t, ni_list);
2411 if (ni->ni_nid == dstnid) {
2412 if (srcnidp != NULL)
2414 if (orderp != NULL) {
2415 if (LNET_NETTYP(LNET_NIDNET(dstnid)) == LOLND)
2420 lnet_net_unlock(cpt);
2422 return local_nid_dist_zero ? 0 : 1;
2425 if (LNET_NIDNET(ni->ni_nid) == dstnet) {
2426 if (srcnidp != NULL)
2427 *srcnidp = ni->ni_nid;
2430 lnet_net_unlock(cpt);
2437 cfs_list_for_each (e, &the_lnet.ln_remote_nets) {
2438 rnet = cfs_list_entry(e, lnet_remotenet_t, lrn_list);
2440 if (rnet->lrn_net == dstnet) {
2441 lnet_route_t *route;
2442 lnet_route_t *shortest = NULL;
2444 LASSERT (!cfs_list_empty(&rnet->lrn_routes));
2446 cfs_list_for_each_entry(route, &rnet->lrn_routes,
2448 if (shortest == NULL ||
2449 route->lr_hops < shortest->lr_hops)
2453 LASSERT (shortest != NULL);
2454 hops = shortest->lr_hops;
2455 if (srcnidp != NULL)
2456 *srcnidp = shortest->lr_gateway->lp_ni->ni_nid;
2459 lnet_net_unlock(cpt);
2465 lnet_net_unlock(cpt);
2466 return -EHOSTUNREACH;
2470 * Set the number of asynchronous messages expected from a target process.
2472 * This function is only meaningful for userspace callers. It's a no-op when
2473 * called from kernel.
2475 * Asynchronous messages are those that can come from a target when the
2476 * userspace process is not waiting for IO to complete; e.g., AST callbacks
2477 * from Lustre servers. Specifying the expected number of such messages
2478 * allows them to be eagerly received when user process is not running in
2479 * LNet; otherwise network errors may occur.
2481 * \param id Process ID of the target process.
2482 * \param nasync Number of asynchronous messages expected from the target.
2484 * \return 0 on success, and an error code otherwise.
2487 LNetSetAsync(lnet_process_id_t id, int nasync)
2493 lnet_remotenet_t *rnet;
2495 lnet_route_t *route;
2503 /* Target on a local network? */
2504 ni = lnet_net2ni(LNET_NIDNET(id.nid));
2506 if (ni->ni_lnd->lnd_setasync != NULL)
2507 rc = (ni->ni_lnd->lnd_setasync)(ni, id, nasync);
2512 /* Target on a remote network: apply to routers */
2514 LIBCFS_ALLOC(nids, maxnids * sizeof(*nids));
2519 /* Snapshot all the router NIDs */
2520 cpt = lnet_net_lock_current();
2521 rnet = lnet_find_net_locked(LNET_NIDNET(id.nid));
2523 cfs_list_for_each(tmp, &rnet->lrn_routes) {
2524 if (nnids == maxnids) {
2525 lnet_net_unlock(cpt);
2526 LIBCFS_FREE(nids, maxnids * sizeof(*nids));
2531 route = cfs_list_entry(tmp, lnet_route_t, lr_list);
2532 nids[nnids++] = route->lr_gateway->lp_nid;
2535 lnet_net_unlock(cpt);
2537 /* set async on all the routers */
2538 while (nnids-- > 0) {
2539 id.pid = LUSTRE_SRV_LNET_PID;
2540 id.nid = nids[nnids];
2542 ni = lnet_net2ni(LNET_NIDNET(id.nid));
2546 if (ni->ni_lnd->lnd_setasync != NULL) {
2547 rc2 = (ni->ni_lnd->lnd_setasync)(ni, id, nasync);
2554 LIBCFS_FREE(nids, maxnids * sizeof(*nids));