4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2016, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lnet/lnet/lib-move.c
34 * Data movement routines
37 #define DEBUG_SUBSYSTEM S_LNET
39 #include <lnet/lib-lnet.h>
40 #include <linux/nsproxy.h>
41 #include <net/net_namespace.h>
43 static int local_nid_dist_zero = 1;
44 module_param(local_nid_dist_zero, int, 0444);
45 MODULE_PARM_DESC(local_nid_dist_zero, "Reserved");
48 lnet_fail_nid(lnet_nid_t nid, unsigned int threshold)
50 struct lnet_test_peer *tp;
52 struct list_head *next;
53 struct list_head cull;
55 /* NB: use lnet_net_lock(0) to serialize operations on test peers */
57 /* Adding a new entry */
58 LIBCFS_ALLOC(tp, sizeof(*tp));
63 tp->tp_threshold = threshold;
66 list_add_tail(&tp->tp_list, &the_lnet.ln_test_peers);
71 /* removing entries */
72 INIT_LIST_HEAD(&cull);
76 list_for_each_safe(el, next, &the_lnet.ln_test_peers) {
77 tp = list_entry(el, struct lnet_test_peer, tp_list);
79 if (tp->tp_threshold == 0 || /* needs culling anyway */
80 nid == LNET_NID_ANY || /* removing all entries */
81 tp->tp_nid == nid) { /* matched this one */
82 list_del(&tp->tp_list);
83 list_add(&tp->tp_list, &cull);
89 while (!list_empty(&cull)) {
90 tp = list_entry(cull.next, struct lnet_test_peer, tp_list);
92 list_del(&tp->tp_list);
93 LIBCFS_FREE(tp, sizeof(*tp));
99 fail_peer (lnet_nid_t nid, int outgoing)
101 struct lnet_test_peer *tp;
102 struct list_head *el;
103 struct list_head *next;
104 struct list_head cull;
107 INIT_LIST_HEAD(&cull);
109 /* NB: use lnet_net_lock(0) to serialize operations on test peers */
112 list_for_each_safe(el, next, &the_lnet.ln_test_peers) {
113 tp = list_entry(el, struct lnet_test_peer, tp_list);
115 if (tp->tp_threshold == 0) {
118 /* only cull zombies on outgoing tests,
119 * since we may be at interrupt priority on
120 * incoming messages. */
121 list_del(&tp->tp_list);
122 list_add(&tp->tp_list, &cull);
127 if (tp->tp_nid == LNET_NID_ANY || /* fail every peer */
128 nid == tp->tp_nid) { /* fail this peer */
131 if (tp->tp_threshold != LNET_MD_THRESH_INF) {
134 tp->tp_threshold == 0) {
136 list_del(&tp->tp_list);
137 list_add(&tp->tp_list, &cull);
146 while (!list_empty(&cull)) {
147 tp = list_entry(cull.next, struct lnet_test_peer, tp_list);
148 list_del(&tp->tp_list);
150 LIBCFS_FREE(tp, sizeof(*tp));
157 lnet_iov_nob(unsigned int niov, struct kvec *iov)
159 unsigned int nob = 0;
161 LASSERT(niov == 0 || iov != NULL);
163 nob += (iov++)->iov_len;
167 EXPORT_SYMBOL(lnet_iov_nob);
170 lnet_copy_iov2iov(unsigned int ndiov, struct kvec *diov, unsigned int doffset,
171 unsigned int nsiov, struct kvec *siov, unsigned int soffset,
174 /* NB diov, siov are READ-ONLY */
175 unsigned int this_nob;
180 /* skip complete frags before 'doffset' */
182 while (doffset >= diov->iov_len) {
183 doffset -= diov->iov_len;
189 /* skip complete frags before 'soffset' */
191 while (soffset >= siov->iov_len) {
192 soffset -= siov->iov_len;
201 this_nob = MIN(diov->iov_len - doffset,
202 siov->iov_len - soffset);
203 this_nob = MIN(this_nob, nob);
205 memcpy((char *)diov->iov_base + doffset,
206 (char *)siov->iov_base + soffset, this_nob);
209 if (diov->iov_len > doffset + this_nob) {
217 if (siov->iov_len > soffset + this_nob) {
226 EXPORT_SYMBOL(lnet_copy_iov2iov);
229 lnet_extract_iov(int dst_niov, struct kvec *dst,
230 int src_niov, struct kvec *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;
273 EXPORT_SYMBOL(lnet_extract_iov);
277 lnet_kiov_nob(unsigned int niov, lnet_kiov_t *kiov)
279 unsigned int nob = 0;
281 LASSERT(niov == 0 || kiov != NULL);
283 nob += (kiov++)->kiov_len;
287 EXPORT_SYMBOL(lnet_kiov_nob);
290 lnet_copy_kiov2kiov(unsigned int ndiov, lnet_kiov_t *diov, unsigned int doffset,
291 unsigned int nsiov, lnet_kiov_t *siov, unsigned int soffset,
294 /* NB diov, siov are READ-ONLY */
295 unsigned int this_nob;
302 LASSERT (!in_interrupt ());
305 while (doffset >= diov->kiov_len) {
306 doffset -= diov->kiov_len;
313 while (soffset >= siov->kiov_len) {
314 soffset -= siov->kiov_len;
323 this_nob = MIN(diov->kiov_len - doffset,
324 siov->kiov_len - soffset);
325 this_nob = MIN(this_nob, nob);
328 daddr = ((char *)kmap(diov->kiov_page)) +
329 diov->kiov_offset + doffset;
331 saddr = ((char *)kmap(siov->kiov_page)) +
332 siov->kiov_offset + soffset;
334 /* Vanishing risk of kmap deadlock when mapping 2 pages.
335 * However in practice at least one of the kiovs will be mapped
336 * kernel pages and the map/unmap will be NOOPs */
338 memcpy (daddr, saddr, this_nob);
341 if (diov->kiov_len > doffset + this_nob) {
345 kunmap(diov->kiov_page);
352 if (siov->kiov_len > soffset + this_nob) {
356 kunmap(siov->kiov_page);
365 kunmap(diov->kiov_page);
367 kunmap(siov->kiov_page);
369 EXPORT_SYMBOL(lnet_copy_kiov2kiov);
372 lnet_copy_kiov2iov (unsigned int niov, struct kvec *iov, unsigned int iovoffset,
373 unsigned int nkiov, lnet_kiov_t *kiov, unsigned int kiovoffset,
376 /* NB iov, kiov are READ-ONLY */
377 unsigned int this_nob;
383 LASSERT (!in_interrupt ());
386 while (iovoffset >= iov->iov_len) {
387 iovoffset -= iov->iov_len;
394 while (kiovoffset >= kiov->kiov_len) {
395 kiovoffset -= kiov->kiov_len;
404 this_nob = MIN(iov->iov_len - iovoffset,
405 kiov->kiov_len - kiovoffset);
406 this_nob = MIN(this_nob, nob);
409 addr = ((char *)kmap(kiov->kiov_page)) +
410 kiov->kiov_offset + kiovoffset;
412 memcpy((char *)iov->iov_base + iovoffset, addr, this_nob);
415 if (iov->iov_len > iovoffset + this_nob) {
416 iovoffset += this_nob;
423 if (kiov->kiov_len > kiovoffset + this_nob) {
425 kiovoffset += this_nob;
427 kunmap(kiov->kiov_page);
437 kunmap(kiov->kiov_page);
439 EXPORT_SYMBOL(lnet_copy_kiov2iov);
442 lnet_copy_iov2kiov(unsigned int nkiov, lnet_kiov_t *kiov, unsigned int kiovoffset,
443 unsigned int niov, struct kvec *iov, unsigned int iovoffset,
446 /* NB kiov, iov are READ-ONLY */
447 unsigned int this_nob;
453 LASSERT (!in_interrupt ());
456 while (kiovoffset >= kiov->kiov_len) {
457 kiovoffset -= kiov->kiov_len;
464 while (iovoffset >= iov->iov_len) {
465 iovoffset -= iov->iov_len;
474 this_nob = MIN(kiov->kiov_len - kiovoffset,
475 iov->iov_len - iovoffset);
476 this_nob = MIN(this_nob, nob);
479 addr = ((char *)kmap(kiov->kiov_page)) +
480 kiov->kiov_offset + kiovoffset;
482 memcpy (addr, (char *)iov->iov_base + iovoffset, this_nob);
485 if (kiov->kiov_len > kiovoffset + this_nob) {
487 kiovoffset += this_nob;
489 kunmap(kiov->kiov_page);
496 if (iov->iov_len > iovoffset + this_nob) {
497 iovoffset += this_nob;
506 kunmap(kiov->kiov_page);
508 EXPORT_SYMBOL(lnet_copy_iov2kiov);
511 lnet_extract_kiov(int dst_niov, lnet_kiov_t *dst,
512 int src_niov, lnet_kiov_t *src,
513 unsigned int offset, unsigned int len)
515 /* Initialise 'dst' to the subset of 'src' starting at 'offset',
516 * for exactly 'len' bytes, and return the number of entries.
517 * NB not destructive to 'src' */
518 unsigned int frag_len;
521 if (len == 0) /* no data => */
522 return (0); /* no frags */
524 LASSERT(src_niov > 0);
525 while (offset >= src->kiov_len) { /* skip initial frags */
526 offset -= src->kiov_len;
529 LASSERT(src_niov > 0);
534 LASSERT(src_niov > 0);
535 LASSERT((int)niov <= dst_niov);
537 frag_len = src->kiov_len - offset;
538 dst->kiov_page = src->kiov_page;
539 dst->kiov_offset = src->kiov_offset + offset;
541 if (len <= frag_len) {
543 LASSERT(dst->kiov_offset + dst->kiov_len <= PAGE_SIZE);
547 dst->kiov_len = frag_len;
548 LASSERT(dst->kiov_offset + dst->kiov_len <= PAGE_SIZE);
558 EXPORT_SYMBOL(lnet_extract_kiov);
561 lnet_ni_recv(struct lnet_ni *ni, void *private, struct lnet_msg *msg,
562 int delayed, unsigned int offset, unsigned int mlen,
565 unsigned int niov = 0;
566 struct kvec *iov = NULL;
567 lnet_kiov_t *kiov = NULL;
570 LASSERT (!in_interrupt ());
571 LASSERT (mlen == 0 || msg != NULL);
574 LASSERT(msg->msg_receiving);
575 LASSERT(!msg->msg_sending);
576 LASSERT(rlen == msg->msg_len);
577 LASSERT(mlen <= msg->msg_len);
578 LASSERT(msg->msg_offset == offset);
579 LASSERT(msg->msg_wanted == mlen);
581 msg->msg_receiving = 0;
584 niov = msg->msg_niov;
586 kiov = msg->msg_kiov;
589 LASSERT ((iov == NULL) != (kiov == NULL));
593 rc = (ni->ni_net->net_lnd->lnd_recv)(ni, private, msg, delayed,
594 niov, iov, kiov, offset, mlen,
597 lnet_finalize(msg, rc);
601 lnet_setpayloadbuffer(struct lnet_msg *msg)
603 struct lnet_libmd *md = msg->msg_md;
605 LASSERT(msg->msg_len > 0);
606 LASSERT(!msg->msg_routing);
608 LASSERT(msg->msg_niov == 0);
609 LASSERT(msg->msg_iov == NULL);
610 LASSERT(msg->msg_kiov == NULL);
612 msg->msg_niov = md->md_niov;
613 if ((md->md_options & LNET_MD_KIOV) != 0)
614 msg->msg_kiov = md->md_iov.kiov;
616 msg->msg_iov = md->md_iov.iov;
620 lnet_prep_send(struct lnet_msg *msg, int type, struct lnet_process_id target,
621 unsigned int offset, unsigned int len)
623 msg->msg_type = type;
624 msg->msg_target = target;
626 msg->msg_offset = offset;
629 lnet_setpayloadbuffer(msg);
631 memset (&msg->msg_hdr, 0, sizeof (msg->msg_hdr));
632 msg->msg_hdr.type = cpu_to_le32(type);
633 /* dest_nid will be overwritten by lnet_select_pathway() */
634 msg->msg_hdr.dest_nid = cpu_to_le64(target.nid);
635 msg->msg_hdr.dest_pid = cpu_to_le32(target.pid);
636 /* src_nid will be set later */
637 msg->msg_hdr.src_pid = cpu_to_le32(the_lnet.ln_pid);
638 msg->msg_hdr.payload_length = cpu_to_le32(len);
642 lnet_ni_send(struct lnet_ni *ni, struct lnet_msg *msg)
644 void *priv = msg->msg_private;
647 LASSERT (!in_interrupt ());
648 LASSERT (LNET_NETTYP(LNET_NIDNET(ni->ni_nid)) == LOLND ||
649 (msg->msg_txcredit && msg->msg_peertxcredit));
651 rc = (ni->ni_net->net_lnd->lnd_send)(ni, priv, msg);
653 lnet_finalize(msg, rc);
657 lnet_ni_eager_recv(struct lnet_ni *ni, struct lnet_msg *msg)
661 LASSERT(!msg->msg_sending);
662 LASSERT(msg->msg_receiving);
663 LASSERT(!msg->msg_rx_ready_delay);
664 LASSERT(ni->ni_net->net_lnd->lnd_eager_recv != NULL);
666 msg->msg_rx_ready_delay = 1;
667 rc = (ni->ni_net->net_lnd->lnd_eager_recv)(ni, msg->msg_private, msg,
670 CERROR("recv from %s / send to %s aborted: "
671 "eager_recv failed %d\n",
672 libcfs_nid2str(msg->msg_rxpeer->lpni_nid),
673 libcfs_id2str(msg->msg_target), rc);
674 LASSERT(rc < 0); /* required by my callers */
681 * This function can be called from two paths:
682 * 1. when sending a message
683 * 2. when decommiting a message (lnet_msg_decommit_tx())
684 * In both these cases the peer_ni should have it's reference count
685 * acquired by the caller and therefore it is safe to drop the spin
686 * lock before calling lnd_query()
689 lnet_ni_query_locked(struct lnet_ni *ni, struct lnet_peer_ni *lp)
691 cfs_time_t last_alive = 0;
692 int cpt = lnet_cpt_of_nid_locked(lp->lpni_nid, ni);
694 LASSERT(lnet_peer_aliveness_enabled(lp));
695 LASSERT(ni->ni_net->net_lnd->lnd_query != NULL);
697 lnet_net_unlock(cpt);
698 (ni->ni_net->net_lnd->lnd_query)(ni, lp->lpni_nid, &last_alive);
701 lp->lpni_last_query = cfs_time_current();
703 if (last_alive != 0) /* NI has updated timestamp */
704 lp->lpni_last_alive = last_alive;
707 /* NB: always called with lnet_net_lock held */
709 lnet_peer_is_alive (struct lnet_peer_ni *lp, cfs_time_t now)
714 LASSERT (lnet_peer_aliveness_enabled(lp));
717 * Trust lnet_notify() if it has more recent aliveness news, but
718 * ignore the initial assumed death (see lnet_peers_start_down()).
720 spin_lock(&lp->lpni_lock);
721 if (!lp->lpni_alive && lp->lpni_alive_count > 0 &&
722 cfs_time_aftereq(lp->lpni_timestamp, lp->lpni_last_alive)) {
723 spin_unlock(&lp->lpni_lock);
728 cfs_time_add(lp->lpni_last_alive,
729 cfs_time_seconds(lp->lpni_net->net_tunables.
731 alive = cfs_time_after(deadline, now);
734 * Update obsolete lp_alive except for routers assumed to be dead
735 * initially, because router checker would update aliveness in this
736 * case, and moreover lpni_last_alive at peer creation is assumed.
738 if (alive && !lp->lpni_alive &&
739 !(lnet_isrouter(lp) && lp->lpni_alive_count == 0)) {
740 spin_unlock(&lp->lpni_lock);
741 lnet_notify_locked(lp, 0, 1, lp->lpni_last_alive);
743 spin_unlock(&lp->lpni_lock);
750 /* NB: returns 1 when alive, 0 when dead, negative when error;
751 * may drop the lnet_net_lock */
753 lnet_peer_alive_locked (struct lnet_ni *ni, struct lnet_peer_ni *lp)
755 cfs_time_t now = cfs_time_current();
757 if (!lnet_peer_aliveness_enabled(lp))
760 if (lnet_peer_is_alive(lp, now))
764 * Peer appears dead, but we should avoid frequent NI queries (at
765 * most once per lnet_queryinterval seconds).
767 if (lp->lpni_last_query != 0) {
768 static const int lnet_queryinterval = 1;
770 cfs_time_t next_query =
771 cfs_time_add(lp->lpni_last_query,
772 cfs_time_seconds(lnet_queryinterval));
774 if (cfs_time_before(now, next_query)) {
776 CWARN("Unexpected aliveness of peer %s: "
778 libcfs_nid2str(lp->lpni_nid),
779 (int)now, (int)next_query,
781 lp->lpni_net->net_tunables.lct_peer_timeout);
786 /* query NI for latest aliveness news */
787 lnet_ni_query_locked(ni, lp);
789 if (lnet_peer_is_alive(lp, now))
792 lnet_notify_locked(lp, 0, 0, lp->lpni_last_alive);
797 * \param msg The message to be sent.
798 * \param do_send True if lnet_ni_send() should be called in this function.
799 * lnet_send() is going to lnet_net_unlock immediately after this, so
800 * it sets do_send FALSE and I don't do the unlock/send/lock bit.
802 * \retval LNET_CREDIT_OK If \a msg sent or OK to send.
803 * \retval LNET_CREDIT_WAIT If \a msg blocked for credit.
804 * \retval -EHOSTUNREACH If the next hop of the message appears dead.
805 * \retval -ECANCELED If the MD of the message has been unlinked.
808 lnet_post_send_locked(struct lnet_msg *msg, int do_send)
810 struct lnet_peer_ni *lp = msg->msg_txpeer;
811 struct lnet_ni *ni = msg->msg_txni;
812 int cpt = msg->msg_tx_cpt;
813 struct lnet_tx_queue *tq = ni->ni_tx_queues[cpt];
815 /* non-lnet_send() callers have checked before */
816 LASSERT(!do_send || msg->msg_tx_delayed);
817 LASSERT(!msg->msg_receiving);
818 LASSERT(msg->msg_tx_committed);
820 /* NB 'lp' is always the next hop */
821 if ((msg->msg_target.pid & LNET_PID_USERFLAG) == 0 &&
822 lnet_peer_alive_locked(ni, lp) == 0) {
823 the_lnet.ln_counters[cpt]->drop_count++;
824 the_lnet.ln_counters[cpt]->drop_length += msg->msg_len;
825 lnet_net_unlock(cpt);
827 atomic_inc(&msg->msg_txpeer->lpni_stats.drop_count);
829 atomic_inc(&msg->msg_txni->ni_stats.drop_count);
831 CNETERR("Dropping message for %s: peer not alive\n",
832 libcfs_id2str(msg->msg_target));
834 lnet_finalize(msg, -EHOSTUNREACH);
837 return -EHOSTUNREACH;
840 if (msg->msg_md != NULL &&
841 (msg->msg_md->md_flags & LNET_MD_FLAG_ABORTED) != 0) {
842 lnet_net_unlock(cpt);
844 CNETERR("Aborting message for %s: LNetM[DE]Unlink() already "
845 "called on the MD/ME.\n",
846 libcfs_id2str(msg->msg_target));
848 lnet_finalize(msg, -ECANCELED);
854 if (!msg->msg_peertxcredit) {
855 spin_lock(&lp->lpni_lock);
856 LASSERT((lp->lpni_txcredits < 0) ==
857 !list_empty(&lp->lpni_txq));
859 msg->msg_peertxcredit = 1;
860 lp->lpni_txqnob += msg->msg_len + sizeof(struct lnet_hdr);
861 lp->lpni_txcredits--;
863 if (lp->lpni_txcredits < lp->lpni_mintxcredits)
864 lp->lpni_mintxcredits = lp->lpni_txcredits;
866 if (lp->lpni_txcredits < 0) {
867 msg->msg_tx_delayed = 1;
868 list_add_tail(&msg->msg_list, &lp->lpni_txq);
869 spin_unlock(&lp->lpni_lock);
870 return LNET_CREDIT_WAIT;
872 spin_unlock(&lp->lpni_lock);
875 if (!msg->msg_txcredit) {
876 LASSERT((tq->tq_credits < 0) ==
877 !list_empty(&tq->tq_delayed));
879 msg->msg_txcredit = 1;
881 atomic_dec(&ni->ni_tx_credits);
883 if (tq->tq_credits < tq->tq_credits_min)
884 tq->tq_credits_min = tq->tq_credits;
886 if (tq->tq_credits < 0) {
887 msg->msg_tx_delayed = 1;
888 list_add_tail(&msg->msg_list, &tq->tq_delayed);
889 return LNET_CREDIT_WAIT;
894 lnet_net_unlock(cpt);
895 lnet_ni_send(ni, msg);
898 return LNET_CREDIT_OK;
902 static struct lnet_rtrbufpool *
903 lnet_msg2bufpool(struct lnet_msg *msg)
905 struct lnet_rtrbufpool *rbp;
908 LASSERT(msg->msg_rx_committed);
910 cpt = msg->msg_rx_cpt;
911 rbp = &the_lnet.ln_rtrpools[cpt][0];
913 LASSERT(msg->msg_len <= LNET_MTU);
914 while (msg->msg_len > (unsigned int)rbp->rbp_npages * PAGE_SIZE) {
916 LASSERT(rbp < &the_lnet.ln_rtrpools[cpt][LNET_NRBPOOLS]);
923 lnet_post_routed_recv_locked(struct lnet_msg *msg, int do_recv)
925 /* lnet_parse is going to lnet_net_unlock immediately after this, so it
926 * sets do_recv FALSE and I don't do the unlock/send/lock bit.
927 * I return LNET_CREDIT_WAIT if msg blocked and LNET_CREDIT_OK if
928 * received or OK to receive */
929 struct lnet_peer_ni *lp = msg->msg_rxpeer;
930 struct lnet_rtrbufpool *rbp;
931 struct lnet_rtrbuf *rb;
933 LASSERT (msg->msg_iov == NULL);
934 LASSERT (msg->msg_kiov == NULL);
935 LASSERT (msg->msg_niov == 0);
936 LASSERT (msg->msg_routing);
937 LASSERT (msg->msg_receiving);
938 LASSERT (!msg->msg_sending);
940 /* non-lnet_parse callers only receive delayed messages */
941 LASSERT(!do_recv || msg->msg_rx_delayed);
943 if (!msg->msg_peerrtrcredit) {
944 spin_lock(&lp->lpni_lock);
945 LASSERT((lp->lpni_rtrcredits < 0) ==
946 !list_empty(&lp->lpni_rtrq));
948 msg->msg_peerrtrcredit = 1;
949 lp->lpni_rtrcredits--;
950 if (lp->lpni_rtrcredits < lp->lpni_minrtrcredits)
951 lp->lpni_minrtrcredits = lp->lpni_rtrcredits;
953 if (lp->lpni_rtrcredits < 0) {
954 /* must have checked eager_recv before here */
955 LASSERT(msg->msg_rx_ready_delay);
956 msg->msg_rx_delayed = 1;
957 list_add_tail(&msg->msg_list, &lp->lpni_rtrq);
958 spin_unlock(&lp->lpni_lock);
959 return LNET_CREDIT_WAIT;
961 spin_unlock(&lp->lpni_lock);
964 rbp = lnet_msg2bufpool(msg);
966 if (!msg->msg_rtrcredit) {
967 msg->msg_rtrcredit = 1;
969 if (rbp->rbp_credits < rbp->rbp_mincredits)
970 rbp->rbp_mincredits = rbp->rbp_credits;
972 if (rbp->rbp_credits < 0) {
973 /* must have checked eager_recv before here */
974 LASSERT(msg->msg_rx_ready_delay);
975 msg->msg_rx_delayed = 1;
976 list_add_tail(&msg->msg_list, &rbp->rbp_msgs);
977 return LNET_CREDIT_WAIT;
981 LASSERT(!list_empty(&rbp->rbp_bufs));
982 rb = list_entry(rbp->rbp_bufs.next, struct lnet_rtrbuf, rb_list);
983 list_del(&rb->rb_list);
985 msg->msg_niov = rbp->rbp_npages;
986 msg->msg_kiov = &rb->rb_kiov[0];
989 int cpt = msg->msg_rx_cpt;
991 lnet_net_unlock(cpt);
992 lnet_ni_recv(msg->msg_rxni, msg->msg_private, msg, 1,
993 0, msg->msg_len, msg->msg_len);
996 return LNET_CREDIT_OK;
1000 lnet_return_tx_credits_locked(struct lnet_msg *msg)
1002 struct lnet_peer_ni *txpeer = msg->msg_txpeer;
1003 struct lnet_ni *txni = msg->msg_txni;
1004 struct lnet_msg *msg2;
1006 if (msg->msg_txcredit) {
1007 struct lnet_ni *ni = msg->msg_txni;
1008 struct lnet_tx_queue *tq = ni->ni_tx_queues[msg->msg_tx_cpt];
1010 /* give back NI txcredits */
1011 msg->msg_txcredit = 0;
1013 LASSERT((tq->tq_credits < 0) ==
1014 !list_empty(&tq->tq_delayed));
1017 atomic_inc(&ni->ni_tx_credits);
1018 if (tq->tq_credits <= 0) {
1019 msg2 = list_entry(tq->tq_delayed.next,
1020 struct lnet_msg, msg_list);
1021 list_del(&msg2->msg_list);
1023 LASSERT(msg2->msg_txni == ni);
1024 LASSERT(msg2->msg_tx_delayed);
1025 LASSERT(msg2->msg_tx_cpt == msg->msg_tx_cpt);
1027 (void) lnet_post_send_locked(msg2, 1);
1031 if (msg->msg_peertxcredit) {
1032 /* give back peer txcredits */
1033 msg->msg_peertxcredit = 0;
1035 spin_lock(&txpeer->lpni_lock);
1036 LASSERT((txpeer->lpni_txcredits < 0) ==
1037 !list_empty(&txpeer->lpni_txq));
1039 txpeer->lpni_txqnob -= msg->msg_len + sizeof(struct lnet_hdr);
1040 LASSERT(txpeer->lpni_txqnob >= 0);
1042 txpeer->lpni_txcredits++;
1043 if (txpeer->lpni_txcredits <= 0) {
1046 msg2 = list_entry(txpeer->lpni_txq.next,
1047 struct lnet_msg, msg_list);
1048 list_del(&msg2->msg_list);
1049 spin_unlock(&txpeer->lpni_lock);
1051 LASSERT(msg2->msg_txpeer == txpeer);
1052 LASSERT(msg2->msg_tx_delayed);
1054 msg2_cpt = msg2->msg_tx_cpt;
1057 * The msg_cpt can be different from the msg2_cpt
1058 * so we need to make sure we lock the correct cpt
1060 * Once we call lnet_post_send_locked() it is no
1061 * longer safe to access msg2, since it could've
1062 * been freed by lnet_finalize(), but we still
1063 * need to relock the correct cpt, so we cache the
1064 * msg2_cpt for the purpose of the check that
1065 * follows the call to lnet_pose_send_locked().
1067 if (msg2_cpt != msg->msg_tx_cpt) {
1068 lnet_net_unlock(msg->msg_tx_cpt);
1069 lnet_net_lock(msg2_cpt);
1071 (void) lnet_post_send_locked(msg2, 1);
1072 if (msg2_cpt != msg->msg_tx_cpt) {
1073 lnet_net_unlock(msg2_cpt);
1074 lnet_net_lock(msg->msg_tx_cpt);
1077 spin_unlock(&txpeer->lpni_lock);
1082 msg->msg_txni = NULL;
1083 lnet_ni_decref_locked(txni, msg->msg_tx_cpt);
1086 if (txpeer != NULL) {
1089 * Once the patch for the health comes in we need to set
1090 * the health of the peer ni to bad when we fail to send
1092 * int status = msg->msg_ev.status;
1094 * lnet_set_peer_ni_health_locked(txpeer, false)
1096 msg->msg_txpeer = NULL;
1097 lnet_peer_ni_decref_locked(txpeer);
1102 lnet_schedule_blocked_locked(struct lnet_rtrbufpool *rbp)
1104 struct lnet_msg *msg;
1106 if (list_empty(&rbp->rbp_msgs))
1108 msg = list_entry(rbp->rbp_msgs.next,
1109 struct lnet_msg, msg_list);
1110 list_del(&msg->msg_list);
1112 (void)lnet_post_routed_recv_locked(msg, 1);
1116 lnet_drop_routed_msgs_locked(struct list_head *list, int cpt)
1118 struct lnet_msg *msg;
1119 struct lnet_msg *tmp;
1121 lnet_net_unlock(cpt);
1123 list_for_each_entry_safe(msg, tmp, list, msg_list) {
1124 lnet_ni_recv(msg->msg_rxni, msg->msg_private, NULL,
1125 0, 0, 0, msg->msg_hdr.payload_length);
1126 list_del_init(&msg->msg_list);
1127 lnet_finalize(msg, -ECANCELED);
1134 lnet_return_rx_credits_locked(struct lnet_msg *msg)
1136 struct lnet_peer_ni *rxpeer = msg->msg_rxpeer;
1137 struct lnet_ni *rxni = msg->msg_rxni;
1138 struct lnet_msg *msg2;
1140 if (msg->msg_rtrcredit) {
1141 /* give back global router credits */
1142 struct lnet_rtrbuf *rb;
1143 struct lnet_rtrbufpool *rbp;
1145 /* NB If a msg ever blocks for a buffer in rbp_msgs, it stays
1146 * there until it gets one allocated, or aborts the wait
1148 LASSERT(msg->msg_kiov != NULL);
1150 rb = list_entry(msg->msg_kiov, struct lnet_rtrbuf, rb_kiov[0]);
1153 msg->msg_kiov = NULL;
1154 msg->msg_rtrcredit = 0;
1156 LASSERT(rbp == lnet_msg2bufpool(msg));
1158 LASSERT((rbp->rbp_credits > 0) ==
1159 !list_empty(&rbp->rbp_bufs));
1161 /* If routing is now turned off, we just drop this buffer and
1162 * don't bother trying to return credits. */
1163 if (!the_lnet.ln_routing) {
1164 lnet_destroy_rtrbuf(rb, rbp->rbp_npages);
1168 /* It is possible that a user has lowered the desired number of
1169 * buffers in this pool. Make sure we never put back
1170 * more buffers than the stated number. */
1171 if (unlikely(rbp->rbp_credits >= rbp->rbp_req_nbuffers)) {
1172 /* Discard this buffer so we don't have too
1174 lnet_destroy_rtrbuf(rb, rbp->rbp_npages);
1175 rbp->rbp_nbuffers--;
1177 list_add(&rb->rb_list, &rbp->rbp_bufs);
1179 if (rbp->rbp_credits <= 0)
1180 lnet_schedule_blocked_locked(rbp);
1185 if (msg->msg_peerrtrcredit) {
1186 /* give back peer router credits */
1187 msg->msg_peerrtrcredit = 0;
1189 spin_lock(&rxpeer->lpni_lock);
1190 LASSERT((rxpeer->lpni_rtrcredits < 0) ==
1191 !list_empty(&rxpeer->lpni_rtrq));
1193 rxpeer->lpni_rtrcredits++;
1195 /* drop all messages which are queued to be routed on that
1197 if (!the_lnet.ln_routing) {
1198 struct list_head drop;
1199 INIT_LIST_HEAD(&drop);
1200 list_splice_init(&rxpeer->lpni_rtrq, &drop);
1201 spin_unlock(&rxpeer->lpni_lock);
1202 lnet_drop_routed_msgs_locked(&drop, msg->msg_rx_cpt);
1203 } else if (rxpeer->lpni_rtrcredits <= 0) {
1204 msg2 = list_entry(rxpeer->lpni_rtrq.next,
1205 struct lnet_msg, msg_list);
1206 list_del(&msg2->msg_list);
1207 spin_unlock(&rxpeer->lpni_lock);
1208 (void) lnet_post_routed_recv_locked(msg2, 1);
1210 spin_unlock(&rxpeer->lpni_lock);
1214 msg->msg_rxni = NULL;
1215 lnet_ni_decref_locked(rxni, msg->msg_rx_cpt);
1217 if (rxpeer != NULL) {
1218 msg->msg_rxpeer = NULL;
1219 lnet_peer_ni_decref_locked(rxpeer);
1224 lnet_compare_peers(struct lnet_peer_ni *p1, struct lnet_peer_ni *p2)
1226 if (p1->lpni_txqnob < p2->lpni_txqnob)
1229 if (p1->lpni_txqnob > p2->lpni_txqnob)
1232 if (p1->lpni_txcredits > p2->lpni_txcredits)
1235 if (p1->lpni_txcredits < p2->lpni_txcredits)
1242 lnet_compare_routes(struct lnet_route *r1, struct lnet_route *r2)
1244 struct lnet_peer_ni *p1 = r1->lr_gateway;
1245 struct lnet_peer_ni *p2 = r2->lr_gateway;
1246 int r1_hops = (r1->lr_hops == LNET_UNDEFINED_HOPS) ? 1 : r1->lr_hops;
1247 int r2_hops = (r2->lr_hops == LNET_UNDEFINED_HOPS) ? 1 : r2->lr_hops;
1250 if (r1->lr_priority < r2->lr_priority)
1253 if (r1->lr_priority > r2->lr_priority)
1256 if (r1_hops < r2_hops)
1259 if (r1_hops > r2_hops)
1262 rc = lnet_compare_peers(p1, p2);
1266 if (r1->lr_seq - r2->lr_seq <= 0)
1272 static struct lnet_peer_ni *
1273 lnet_find_route_locked(struct lnet_net *net, lnet_nid_t target,
1276 struct lnet_remotenet *rnet;
1277 struct lnet_route *route;
1278 struct lnet_route *best_route;
1279 struct lnet_route *last_route;
1280 struct lnet_peer_ni *lpni_best;
1281 struct lnet_peer_ni *lp;
1284 /* If @rtr_nid is not LNET_NID_ANY, return the gateway with
1285 * rtr_nid nid, otherwise find the best gateway I can use */
1287 rnet = lnet_find_rnet_locked(LNET_NIDNET(target));
1292 best_route = last_route = NULL;
1293 list_for_each_entry(route, &rnet->lrn_routes, lr_list) {
1294 lp = route->lr_gateway;
1296 if (!lnet_is_route_alive(route))
1299 if (net != NULL && lp->lpni_net != net)
1302 if (lp->lpni_nid == rtr_nid) /* it's pre-determined router */
1305 if (lpni_best == NULL) {
1306 best_route = last_route = route;
1311 /* no protection on below fields, but it's harmless */
1312 if (last_route->lr_seq - route->lr_seq < 0)
1315 rc = lnet_compare_routes(route, best_route);
1323 /* set sequence number on the best router to the latest sequence + 1
1324 * so we can round-robin all routers, it's race and inaccurate but
1325 * harmless and functional */
1326 if (best_route != NULL)
1327 best_route->lr_seq = last_route->lr_seq + 1;
1331 static struct lnet_ni *
1332 lnet_get_best_ni(struct lnet_net *local_net, struct lnet_ni *cur_ni,
1335 struct lnet_ni *ni = NULL, *best_ni = cur_ni;
1336 unsigned int shortest_distance;
1339 if (best_ni == NULL) {
1340 shortest_distance = UINT_MAX;
1341 best_credits = INT_MIN;
1343 shortest_distance = cfs_cpt_distance(lnet_cpt_table(), md_cpt,
1344 best_ni->ni_dev_cpt);
1345 best_credits = atomic_read(&best_ni->ni_tx_credits);
1348 while ((ni = lnet_get_next_ni_locked(local_net, ni))) {
1349 unsigned int distance;
1352 if (!lnet_is_ni_healthy_locked(ni))
1355 ni_credits = atomic_read(&ni->ni_tx_credits);
1358 * calculate the distance from the CPT on which
1359 * the message memory is allocated to the CPT of
1360 * the NI's physical device
1362 distance = cfs_cpt_distance(lnet_cpt_table(),
1367 * All distances smaller than the NUMA range
1368 * are treated equally.
1370 if (distance < lnet_numa_range)
1371 distance = lnet_numa_range;
1374 * Select on shorter distance, then available
1375 * credits, then round-robin.
1377 if (distance > shortest_distance) {
1379 } else if (distance < shortest_distance) {
1380 shortest_distance = distance;
1381 } else if (ni_credits < best_credits) {
1383 } else if (ni_credits == best_credits) {
1384 if (best_ni && (best_ni)->ni_seq <= ni->ni_seq)
1388 best_credits = ni_credits;
1395 * Traffic to the LNET_RESERVED_PORTAL may not trigger peer discovery,
1396 * because such traffic is required to perform discovery. We therefore
1397 * exclude all GET and PUT on that portal. We also exclude all ACK and
1398 * REPLY traffic, but that is because the portal is not tracked in the
1399 * message structure for these message types. We could restrict this
1400 * further by also checking for LNET_PROTO_PING_MATCHBITS.
1403 lnet_msg_discovery(struct lnet_msg *msg)
1405 if (msg->msg_type == LNET_MSG_PUT) {
1406 if (msg->msg_hdr.msg.put.ptl_index != LNET_RESERVED_PORTAL)
1408 } else if (msg->msg_type == LNET_MSG_GET) {
1409 if (msg->msg_hdr.msg.get.ptl_index != LNET_RESERVED_PORTAL)
1416 lnet_select_pathway(lnet_nid_t src_nid, lnet_nid_t dst_nid,
1417 struct lnet_msg *msg, lnet_nid_t rtr_nid)
1419 struct lnet_ni *best_ni;
1420 struct lnet_peer_ni *best_lpni;
1421 struct lnet_peer_ni *best_gw;
1422 struct lnet_peer_ni *lpni;
1423 struct lnet_peer_ni *final_dst;
1424 struct lnet_peer *peer;
1425 struct lnet_peer_net *peer_net;
1426 struct lnet_net *local_net;
1433 int best_lpni_credits;
1437 * get an initial CPT to use for locking. The idea here is not to
1438 * serialize the calls to select_pathway, so that as many
1439 * operations can run concurrently as possible. To do that we use
1440 * the CPT where this call is being executed. Later on when we
1441 * determine the CPT to use in lnet_message_commit, we switch the
1442 * lock and check if there was any configuration change. If none,
1443 * then we proceed, if there is, then we restart the operation.
1445 cpt = lnet_net_lock_current();
1447 md_cpt = lnet_cpt_of_md(msg->msg_md, msg->msg_offset);
1448 if (md_cpt == CFS_CPT_ANY)
1459 local_found = false;
1462 * lnet_nid2peerni_locked() is the path that will find an
1463 * existing peer_ni, or create one and mark it as having been
1464 * created due to network traffic.
1466 lpni = lnet_nid2peerni_locked(dst_nid, LNET_NID_ANY, cpt);
1468 lnet_net_unlock(cpt);
1469 return PTR_ERR(lpni);
1472 * Now that we have a peer_ni, check if we want to discover
1473 * the peer. Traffic to the LNET_RESERVED_PORTAL should not
1474 * trigger discovery.
1476 peer = lpni->lpni_peer_net->lpn_peer;
1477 if (lnet_msg_discovery(msg) && !lnet_peer_is_uptodate(peer)) {
1478 rc = lnet_discover_peer_locked(lpni, cpt, false);
1480 lnet_peer_ni_decref_locked(lpni);
1481 lnet_net_unlock(cpt);
1484 /* The peer may have changed. */
1485 peer = lpni->lpni_peer_net->lpn_peer;
1486 /* queue message and return */
1487 msg->msg_src_nid_param = src_nid;
1488 msg->msg_rtr_nid_param = rtr_nid;
1489 msg->msg_sending = 0;
1490 list_add_tail(&msg->msg_list, &peer->lp_dc_pendq);
1491 lnet_peer_ni_decref_locked(lpni);
1492 lnet_net_unlock(cpt);
1494 CDEBUG(D_NET, "%s pending discovery\n",
1495 libcfs_nid2str(peer->lp_primary_nid));
1497 return LNET_DC_WAIT;
1499 lnet_peer_ni_decref_locked(lpni);
1501 /* If peer is not healthy then can not send anything to it */
1502 if (!lnet_is_peer_healthy_locked(peer)) {
1503 lnet_net_unlock(cpt);
1504 return -EHOSTUNREACH;
1508 * STEP 1: first jab at determining best_ni
1509 * if src_nid is explicitly specified, then best_ni is already
1510 * pre-determiend for us. Otherwise we need to select the best
1511 * one to use later on
1513 if (src_nid != LNET_NID_ANY) {
1514 best_ni = lnet_nid2ni_locked(src_nid, cpt);
1516 lnet_net_unlock(cpt);
1517 LCONSOLE_WARN("Can't send to %s: src %s is not a "
1518 "local nid\n", libcfs_nid2str(dst_nid),
1519 libcfs_nid2str(src_nid));
1524 if (msg->msg_type == LNET_MSG_REPLY ||
1525 msg->msg_type == LNET_MSG_ACK ||
1526 !lnet_peer_is_multi_rail(peer) ||
1529 * for replies we want to respond on the same peer_ni we
1530 * received the message on if possible. If not, then pick
1531 * a peer_ni to send to
1533 * if the peer is non-multi-rail then you want to send to
1534 * the dst_nid provided as well.
1536 * If the best_ni has already been determined, IE the
1537 * src_nid has been specified, then use the
1538 * destination_nid provided as well, since we're
1539 * continuing a series of related messages for the same
1542 * It is expected to find the lpni using dst_nid, since we
1543 * created it earlier.
1545 best_lpni = lnet_find_peer_ni_locked(dst_nid);
1547 lnet_peer_ni_decref_locked(best_lpni);
1549 if (best_lpni && !lnet_get_net_locked(LNET_NIDNET(dst_nid))) {
1551 * this lpni is not on a local network so we need
1552 * to route this reply.
1554 best_gw = lnet_find_route_locked(NULL,
1555 best_lpni->lpni_nid,
1559 * RULE: Each node considers only the next-hop
1561 * We're going to route the message, so change the peer to
1564 LASSERT(best_gw->lpni_peer_net);
1565 LASSERT(best_gw->lpni_peer_net->lpn_peer);
1566 peer = best_gw->lpni_peer_net->lpn_peer;
1569 * if the router is not multi-rail then use the best_gw
1570 * found to send the message to
1572 if (!lnet_peer_is_multi_rail(peer))
1573 best_lpni = best_gw;
1581 } else if (!best_lpni) {
1582 lnet_net_unlock(cpt);
1583 CERROR("unable to send msg_type %d to "
1584 "originating %s. Destination NID not in DB\n",
1585 msg->msg_type, libcfs_nid2str(dst_nid));
1591 * We must use a consistent source address when sending to a
1592 * non-MR peer. However, a non-MR peer can have multiple NIDs
1593 * on multiple networks, and we may even need to talk to this
1594 * peer on multiple networks -- certain types of
1595 * load-balancing configuration do this.
1597 * So we need to pick the NI the peer prefers for this
1598 * particular network.
1600 if (!lnet_peer_is_multi_rail(peer)) {
1602 lnet_net_unlock(cpt);
1603 CERROR("no route to %s\n",
1604 libcfs_nid2str(dst_nid));
1605 return -EHOSTUNREACH;
1608 /* best ni is already set if src_nid was provided */
1610 /* Get the target peer_ni */
1611 peer_net = lnet_peer_get_net_locked(peer,
1612 LNET_NIDNET(best_lpni->lpni_nid));
1613 LASSERT(peer_net != NULL);
1614 list_for_each_entry(lpni, &peer_net->lpn_peer_nis,
1616 if (lpni->lpni_pref_nnids == 0)
1618 LASSERT(lpni->lpni_pref_nnids == 1);
1619 best_ni = lnet_nid2ni_locked(
1620 lpni->lpni_pref.nid, cpt);
1624 /* if best_ni is still not set just pick one */
1626 best_ni = lnet_net2ni_locked(
1627 best_lpni->lpni_net->net_id, cpt);
1628 /* If there is no best_ni we don't have a route */
1630 lnet_net_unlock(cpt);
1631 CERROR("no path to %s from net %s\n",
1632 libcfs_nid2str(best_lpni->lpni_nid),
1633 libcfs_net2str(best_lpni->lpni_net->net_id));
1634 return -EHOSTUNREACH;
1636 lpni = list_entry(peer_net->lpn_peer_nis.next,
1637 struct lnet_peer_ni,
1640 /* Set preferred NI if necessary. */
1641 if (lpni->lpni_pref_nnids == 0)
1642 lnet_peer_ni_set_non_mr_pref_nid(lpni, best_ni->ni_nid);
1646 * if we already found a best_ni because src_nid is specified and
1647 * best_lpni because we are replying to a message then just send
1650 if (best_ni && best_lpni)
1654 * If we already found a best_ni because src_nid is specified then
1655 * pick the peer then send the message
1661 * pick the best_ni by going through all the possible networks of
1662 * that peer and see which local NI is best suited to talk to that
1665 * Locally connected networks will always be preferred over
1666 * a routed network. If there are only routed paths to the peer,
1667 * then the best route is chosen. If all routes are equal then
1668 * they are used in round robin.
1670 list_for_each_entry(peer_net, &peer->lp_peer_nets, lpn_peer_nets) {
1671 if (!lnet_is_peer_net_healthy_locked(peer_net))
1674 local_net = lnet_get_net_locked(peer_net->lpn_net_id);
1675 if (!local_net && !routing && !local_found) {
1676 struct lnet_peer_ni *net_gw;
1678 lpni = list_entry(peer_net->lpn_peer_nis.next,
1679 struct lnet_peer_ni,
1682 net_gw = lnet_find_route_locked(NULL,
1690 * lnet_find_route_locked() call
1691 * will return the best_Gw on the
1692 * lpni->lpni_nid network.
1693 * However, best_gw and net_gw can
1694 * be on different networks.
1695 * Therefore need to compare them
1696 * to pick the better of either.
1698 if (lnet_compare_peers(best_gw, net_gw) > 0)
1700 if (best_gw->lpni_gw_seq <= net_gw->lpni_gw_seq)
1715 * a gw on this network is found, but there could be
1716 * other better gateways on other networks. So don't pick
1717 * the best_ni until we determine the best_gw.
1722 /* if no local_net found continue */
1727 * Iterate through the NIs in this local Net and select
1728 * the NI to send from. The selection is determined by
1729 * these 3 criterion in the following priority:
1731 * 2. NI available credits
1734 best_ni = lnet_get_best_ni(local_net, best_ni, md_cpt);
1737 if (!best_ni && !best_gw) {
1738 lnet_net_unlock(cpt);
1739 LCONSOLE_WARN("No local ni found to send from to %s\n",
1740 libcfs_nid2str(dst_nid));
1745 best_ni = lnet_get_best_ni(best_gw->lpni_net, best_ni, md_cpt);
1746 LASSERT(best_gw && best_ni);
1749 * We're going to route the message, so change the peer to
1752 LASSERT(best_gw->lpni_peer_net);
1753 LASSERT(best_gw->lpni_peer_net->lpn_peer);
1754 best_gw->lpni_gw_seq++;
1755 peer = best_gw->lpni_peer_net->lpn_peer;
1759 * Now that we selected the NI to use increment its sequence
1760 * number so the Round Robin algorithm will detect that it has
1761 * been used and pick the next NI.
1767 * At this point the best_ni is on a local network on which
1768 * the peer has a peer_ni as well
1770 peer_net = lnet_peer_get_net_locked(peer,
1771 best_ni->ni_net->net_id);
1773 * peer_net is not available or the src_nid is explicitly defined
1774 * and the peer_net for that src_nid is unhealthy. find a route to
1775 * the destination nid.
1778 (src_nid != LNET_NID_ANY &&
1779 !lnet_is_peer_net_healthy_locked(peer_net))) {
1780 best_gw = lnet_find_route_locked(best_ni->ni_net,
1784 * if no route is found for that network then
1785 * move onto the next peer_ni in the peer
1788 lnet_net_unlock(cpt);
1789 LCONSOLE_WARN("No route to peer from %s\n",
1790 libcfs_nid2str(best_ni->ni_nid));
1791 return -EHOSTUNREACH;
1794 CDEBUG(D_NET, "Best route to %s via %s for %s %d\n",
1795 libcfs_nid2str(dst_nid),
1796 libcfs_nid2str(best_gw->lpni_nid),
1797 lnet_msgtyp2str(msg->msg_type), msg->msg_len);
1801 * RULE: Each node considers only the next-hop
1803 * We're going to route the message, so change the peer to
1806 LASSERT(best_gw->lpni_peer_net);
1807 LASSERT(best_gw->lpni_peer_net->lpn_peer);
1808 peer = best_gw->lpni_peer_net->lpn_peer;
1809 } else if (!lnet_is_peer_net_healthy_locked(peer_net)) {
1811 * this peer_net is unhealthy but we still have an opportunity
1812 * to find another peer_net that we can use
1814 __u32 net_id = peer_net->lpn_net_id;
1815 LCONSOLE_WARN("peer net %s unhealthy\n",
1816 libcfs_net2str(net_id));
1821 * Look at the peer NIs for the destination peer that connect
1822 * to the chosen net. If a peer_ni is preferred when using the
1823 * best_ni to communicate, we use that one. If there is no
1824 * preferred peer_ni, or there are multiple preferred peer_ni,
1825 * the available transmit credits are used. If the transmit
1826 * credits are equal, we round-robin over the peer_ni.
1829 best_lpni_credits = INT_MIN;
1832 while ((lpni = lnet_get_next_peer_ni_locked(peer, peer_net, lpni))) {
1834 * if this peer ni is not healthy just skip it, no point in
1835 * examining it further
1837 if (!lnet_is_peer_ni_healthy_locked(lpni))
1839 ni_is_pref = lnet_peer_is_pref_nid_locked(lpni,
1842 /* if this is a preferred peer use it */
1843 if (!preferred && ni_is_pref) {
1845 } else if (preferred && !ni_is_pref) {
1847 * this is not the preferred peer so let's ignore
1851 } else if (lpni->lpni_txcredits < best_lpni_credits) {
1853 * We already have a peer that has more credits
1854 * available than this one. No need to consider
1855 * this peer further.
1858 } else if (lpni->lpni_txcredits == best_lpni_credits) {
1860 * The best peer found so far and the current peer
1861 * have the same number of available credits let's
1862 * make sure to select between them using Round
1866 if (best_lpni->lpni_seq <= lpni->lpni_seq)
1872 best_lpni_credits = lpni->lpni_txcredits;
1875 /* if we still can't find a peer ni then we can't reach it */
1877 __u32 net_id = (peer_net) ? peer_net->lpn_net_id :
1878 LNET_NIDNET(dst_nid);
1879 lnet_net_unlock(cpt);
1880 LCONSOLE_WARN("no peer_ni found on peer net %s\n",
1881 libcfs_net2str(net_id));
1882 return -EHOSTUNREACH;
1887 /* Shortcut for loopback. */
1888 if (best_ni == the_lnet.ln_loni) {
1889 /* No send credit hassles with LOLND */
1890 lnet_ni_addref_locked(best_ni, cpt);
1891 msg->msg_hdr.dest_nid = cpu_to_le64(best_ni->ni_nid);
1892 if (!msg->msg_routing)
1893 msg->msg_hdr.src_nid = cpu_to_le64(best_ni->ni_nid);
1894 msg->msg_target.nid = best_ni->ni_nid;
1895 lnet_msg_commit(msg, cpt);
1896 msg->msg_txni = best_ni;
1897 lnet_net_unlock(cpt);
1899 return LNET_CREDIT_OK;
1902 routing = routing || routing2;
1905 * Increment sequence number of the peer selected so that we
1906 * pick the next one in Round Robin.
1908 best_lpni->lpni_seq++;
1911 * grab a reference on the peer_ni so it sticks around even if
1912 * we need to drop and relock the lnet_net_lock below.
1914 lnet_peer_ni_addref_locked(best_lpni);
1917 * Use lnet_cpt_of_nid() to determine the CPT used to commit the
1918 * message. This ensures that we get a CPT that is correct for
1919 * the NI when the NI has been restricted to a subset of all CPTs.
1920 * If the selected CPT differs from the one currently locked, we
1921 * must unlock and relock the lnet_net_lock(), and then check whether
1922 * the configuration has changed. We don't have a hold on the best_ni
1923 * yet, and it may have vanished.
1925 cpt2 = lnet_cpt_of_nid_locked(best_lpni->lpni_nid, best_ni);
1927 __u32 seq = lnet_get_dlc_seq_locked();
1928 lnet_net_unlock(cpt);
1931 if (seq != lnet_get_dlc_seq_locked()) {
1932 lnet_peer_ni_decref_locked(best_lpni);
1938 * store the best_lpni in the message right away to avoid having
1939 * to do the same operation under different conditions
1941 msg->msg_txpeer = best_lpni;
1942 msg->msg_txni = best_ni;
1945 * grab a reference for the best_ni since now it's in use in this
1946 * send. the reference will need to be dropped when the message is
1947 * finished in lnet_finalize()
1949 lnet_ni_addref_locked(msg->msg_txni, cpt);
1952 * Always set the target.nid to the best peer picked. Either the
1953 * nid will be one of the preconfigured NIDs, or the same NID as
1954 * what was originally set in the target or it will be the NID of
1955 * a router if this message should be routed
1957 msg->msg_target.nid = msg->msg_txpeer->lpni_nid;
1960 * lnet_msg_commit assigns the correct cpt to the message, which
1961 * is used to decrement the correct refcount on the ni when it's
1962 * time to return the credits
1964 lnet_msg_commit(msg, cpt);
1967 * If we are routing the message then we don't need to overwrite
1968 * the src_nid since it would've been set at the origin. Otherwise
1969 * we are the originator so we need to set it.
1971 if (!msg->msg_routing)
1972 msg->msg_hdr.src_nid = cpu_to_le64(msg->msg_txni->ni_nid);
1975 msg->msg_target_is_router = 1;
1976 msg->msg_target.pid = LNET_PID_LUSTRE;
1978 * since we're routing we want to ensure that the
1979 * msg_hdr.dest_nid is set to the final destination. When
1980 * the router receives this message it knows how to route
1983 msg->msg_hdr.dest_nid =
1984 cpu_to_le64(final_dst ? final_dst->lpni_nid : dst_nid);
1987 * if we're not routing set the dest_nid to the best peer
1988 * ni that we picked earlier in the algorithm.
1990 msg->msg_hdr.dest_nid = cpu_to_le64(msg->msg_txpeer->lpni_nid);
1993 rc = lnet_post_send_locked(msg, 0);
1996 CDEBUG(D_NET, "TRACE: %s(%s:%s) -> %s(%s:%s) : %s\n",
1997 libcfs_nid2str(msg->msg_hdr.src_nid),
1998 libcfs_nid2str(msg->msg_txni->ni_nid),
1999 libcfs_nid2str(src_nid),
2000 libcfs_nid2str(msg->msg_hdr.dest_nid),
2001 libcfs_nid2str(dst_nid),
2002 libcfs_nid2str(msg->msg_txpeer->lpni_nid),
2003 lnet_msgtyp2str(msg->msg_type));
2005 lnet_net_unlock(cpt);
2011 lnet_send(lnet_nid_t src_nid, struct lnet_msg *msg, lnet_nid_t rtr_nid)
2013 lnet_nid_t dst_nid = msg->msg_target.nid;
2017 * NB: rtr_nid is set to LNET_NID_ANY for all current use-cases,
2018 * but we might want to use pre-determined router for ACK/REPLY
2021 /* NB: ni != NULL == interface pre-determined (ACK/REPLY) */
2022 LASSERT (msg->msg_txpeer == NULL);
2023 LASSERT (!msg->msg_sending);
2024 LASSERT (!msg->msg_target_is_router);
2025 LASSERT (!msg->msg_receiving);
2027 msg->msg_sending = 1;
2029 LASSERT(!msg->msg_tx_committed);
2031 rc = lnet_select_pathway(src_nid, dst_nid, msg, rtr_nid);
2035 if (rc == LNET_CREDIT_OK)
2036 lnet_ni_send(msg->msg_txni, msg);
2038 /* rc == LNET_CREDIT_OK or LNET_CREDIT_WAIT or LNET_DC_WAIT */
2043 lnet_drop_message(struct lnet_ni *ni, int cpt, void *private, unsigned int nob)
2046 the_lnet.ln_counters[cpt]->drop_count++;
2047 the_lnet.ln_counters[cpt]->drop_length += nob;
2048 lnet_net_unlock(cpt);
2050 lnet_ni_recv(ni, private, NULL, 0, 0, 0, nob);
2054 lnet_recv_put(struct lnet_ni *ni, struct lnet_msg *msg)
2056 struct lnet_hdr *hdr = &msg->msg_hdr;
2058 if (msg->msg_wanted != 0)
2059 lnet_setpayloadbuffer(msg);
2061 lnet_build_msg_event(msg, LNET_EVENT_PUT);
2063 /* Must I ACK? If so I'll grab the ack_wmd out of the header and put
2064 * it back into the ACK during lnet_finalize() */
2065 msg->msg_ack = (!lnet_is_wire_handle_none(&hdr->msg.put.ack_wmd) &&
2066 (msg->msg_md->md_options & LNET_MD_ACK_DISABLE) == 0);
2068 lnet_ni_recv(ni, msg->msg_private, msg, msg->msg_rx_delayed,
2069 msg->msg_offset, msg->msg_wanted, hdr->payload_length);
2073 lnet_parse_put(struct lnet_ni *ni, struct lnet_msg *msg)
2075 struct lnet_hdr *hdr = &msg->msg_hdr;
2076 struct lnet_match_info info;
2080 /* Convert put fields to host byte order */
2081 hdr->msg.put.match_bits = le64_to_cpu(hdr->msg.put.match_bits);
2082 hdr->msg.put.ptl_index = le32_to_cpu(hdr->msg.put.ptl_index);
2083 hdr->msg.put.offset = le32_to_cpu(hdr->msg.put.offset);
2085 /* Primary peer NID. */
2086 info.mi_id.nid = msg->msg_initiator;
2087 info.mi_id.pid = hdr->src_pid;
2088 info.mi_opc = LNET_MD_OP_PUT;
2089 info.mi_portal = hdr->msg.put.ptl_index;
2090 info.mi_rlength = hdr->payload_length;
2091 info.mi_roffset = hdr->msg.put.offset;
2092 info.mi_mbits = hdr->msg.put.match_bits;
2093 info.mi_cpt = lnet_cpt_of_nid(msg->msg_rxpeer->lpni_nid, ni);
2095 msg->msg_rx_ready_delay = ni->ni_net->net_lnd->lnd_eager_recv == NULL;
2096 ready_delay = msg->msg_rx_ready_delay;
2099 rc = lnet_ptl_match_md(&info, msg);
2104 case LNET_MATCHMD_OK:
2105 lnet_recv_put(ni, msg);
2108 case LNET_MATCHMD_NONE:
2110 /* no eager_recv or has already called it, should
2111 * have been attached on delayed list */
2114 rc = lnet_ni_eager_recv(ni, msg);
2121 case LNET_MATCHMD_DROP:
2122 CNETERR("Dropping PUT from %s portal %d match %llu"
2123 " offset %d length %d: %d\n",
2124 libcfs_id2str(info.mi_id), info.mi_portal,
2125 info.mi_mbits, info.mi_roffset, info.mi_rlength, rc);
2127 return -ENOENT; /* -ve: OK but no match */
2132 lnet_parse_get(struct lnet_ni *ni, struct lnet_msg *msg, int rdma_get)
2134 struct lnet_match_info info;
2135 struct lnet_hdr *hdr = &msg->msg_hdr;
2136 struct lnet_process_id source_id;
2137 struct lnet_handle_wire reply_wmd;
2140 /* Convert get fields to host byte order */
2141 hdr->msg.get.match_bits = le64_to_cpu(hdr->msg.get.match_bits);
2142 hdr->msg.get.ptl_index = le32_to_cpu(hdr->msg.get.ptl_index);
2143 hdr->msg.get.sink_length = le32_to_cpu(hdr->msg.get.sink_length);
2144 hdr->msg.get.src_offset = le32_to_cpu(hdr->msg.get.src_offset);
2146 source_id.nid = hdr->src_nid;
2147 source_id.pid = hdr->src_pid;
2148 /* Primary peer NID */
2149 info.mi_id.nid = msg->msg_initiator;
2150 info.mi_id.pid = hdr->src_pid;
2151 info.mi_opc = LNET_MD_OP_GET;
2152 info.mi_portal = hdr->msg.get.ptl_index;
2153 info.mi_rlength = hdr->msg.get.sink_length;
2154 info.mi_roffset = hdr->msg.get.src_offset;
2155 info.mi_mbits = hdr->msg.get.match_bits;
2156 info.mi_cpt = lnet_cpt_of_nid(msg->msg_rxpeer->lpni_nid, ni);
2158 rc = lnet_ptl_match_md(&info, msg);
2159 if (rc == LNET_MATCHMD_DROP) {
2160 CNETERR("Dropping GET from %s portal %d match %llu"
2161 " offset %d length %d\n",
2162 libcfs_id2str(info.mi_id), info.mi_portal,
2163 info.mi_mbits, info.mi_roffset, info.mi_rlength);
2164 return -ENOENT; /* -ve: OK but no match */
2167 LASSERT(rc == LNET_MATCHMD_OK);
2169 lnet_build_msg_event(msg, LNET_EVENT_GET);
2171 reply_wmd = hdr->msg.get.return_wmd;
2173 lnet_prep_send(msg, LNET_MSG_REPLY, source_id,
2174 msg->msg_offset, msg->msg_wanted);
2176 msg->msg_hdr.msg.reply.dst_wmd = reply_wmd;
2179 /* The LND completes the REPLY from her recv procedure */
2180 lnet_ni_recv(ni, msg->msg_private, msg, 0,
2181 msg->msg_offset, msg->msg_len, msg->msg_len);
2185 lnet_ni_recv(ni, msg->msg_private, NULL, 0, 0, 0, 0);
2186 msg->msg_receiving = 0;
2188 rc = lnet_send(ni->ni_nid, msg, LNET_NID_ANY);
2190 /* didn't get as far as lnet_ni_send() */
2191 CERROR("%s: Unable to send REPLY for GET from %s: %d\n",
2192 libcfs_nid2str(ni->ni_nid),
2193 libcfs_id2str(info.mi_id), rc);
2195 lnet_finalize(msg, rc);
2202 lnet_parse_reply(struct lnet_ni *ni, struct lnet_msg *msg)
2204 void *private = msg->msg_private;
2205 struct lnet_hdr *hdr = &msg->msg_hdr;
2206 struct lnet_process_id src = {0};
2207 struct lnet_libmd *md;
2212 cpt = lnet_cpt_of_cookie(hdr->msg.reply.dst_wmd.wh_object_cookie);
2215 src.nid = hdr->src_nid;
2216 src.pid = hdr->src_pid;
2218 /* NB handles only looked up by creator (no flips) */
2219 md = lnet_wire_handle2md(&hdr->msg.reply.dst_wmd);
2220 if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) {
2221 CNETERR("%s: Dropping REPLY from %s for %s "
2223 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
2224 (md == NULL) ? "invalid" : "inactive",
2225 hdr->msg.reply.dst_wmd.wh_interface_cookie,
2226 hdr->msg.reply.dst_wmd.wh_object_cookie);
2227 if (md != NULL && md->md_me != NULL)
2228 CERROR("REPLY MD also attached to portal %d\n",
2229 md->md_me->me_portal);
2231 lnet_res_unlock(cpt);
2232 return -ENOENT; /* -ve: OK but no match */
2235 LASSERT(md->md_offset == 0);
2237 rlength = hdr->payload_length;
2238 mlength = MIN(rlength, (int)md->md_length);
2240 if (mlength < rlength &&
2241 (md->md_options & LNET_MD_TRUNCATE) == 0) {
2242 CNETERR("%s: Dropping REPLY from %s length %d "
2243 "for MD %#llx would overflow (%d)\n",
2244 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
2245 rlength, hdr->msg.reply.dst_wmd.wh_object_cookie,
2247 lnet_res_unlock(cpt);
2248 return -ENOENT; /* -ve: OK but no match */
2251 CDEBUG(D_NET, "%s: Reply from %s of length %d/%d into md %#llx\n",
2252 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
2253 mlength, rlength, hdr->msg.reply.dst_wmd.wh_object_cookie);
2255 lnet_msg_attach_md(msg, md, 0, mlength);
2258 lnet_setpayloadbuffer(msg);
2260 lnet_res_unlock(cpt);
2262 lnet_build_msg_event(msg, LNET_EVENT_REPLY);
2264 lnet_ni_recv(ni, private, msg, 0, 0, mlength, rlength);
2269 lnet_parse_ack(struct lnet_ni *ni, struct lnet_msg *msg)
2271 struct lnet_hdr *hdr = &msg->msg_hdr;
2272 struct lnet_process_id src = {0};
2273 struct lnet_libmd *md;
2276 src.nid = hdr->src_nid;
2277 src.pid = hdr->src_pid;
2279 /* Convert ack fields to host byte order */
2280 hdr->msg.ack.match_bits = le64_to_cpu(hdr->msg.ack.match_bits);
2281 hdr->msg.ack.mlength = le32_to_cpu(hdr->msg.ack.mlength);
2283 cpt = lnet_cpt_of_cookie(hdr->msg.ack.dst_wmd.wh_object_cookie);
2286 /* NB handles only looked up by creator (no flips) */
2287 md = lnet_wire_handle2md(&hdr->msg.ack.dst_wmd);
2288 if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) {
2289 /* Don't moan; this is expected */
2291 "%s: Dropping ACK from %s to %s MD %#llx.%#llx\n",
2292 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
2293 (md == NULL) ? "invalid" : "inactive",
2294 hdr->msg.ack.dst_wmd.wh_interface_cookie,
2295 hdr->msg.ack.dst_wmd.wh_object_cookie);
2296 if (md != NULL && md->md_me != NULL)
2297 CERROR("Source MD also attached to portal %d\n",
2298 md->md_me->me_portal);
2300 lnet_res_unlock(cpt);
2301 return -ENOENT; /* -ve! */
2304 CDEBUG(D_NET, "%s: ACK from %s into md %#llx\n",
2305 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
2306 hdr->msg.ack.dst_wmd.wh_object_cookie);
2308 lnet_msg_attach_md(msg, md, 0, 0);
2310 lnet_res_unlock(cpt);
2312 lnet_build_msg_event(msg, LNET_EVENT_ACK);
2314 lnet_ni_recv(ni, msg->msg_private, msg, 0, 0, 0, msg->msg_len);
2319 * \retval LNET_CREDIT_OK If \a msg is forwarded
2320 * \retval LNET_CREDIT_WAIT If \a msg is blocked because w/o buffer
2321 * \retval -ve error code
2324 lnet_parse_forward_locked(struct lnet_ni *ni, struct lnet_msg *msg)
2328 if (!the_lnet.ln_routing)
2331 if (msg->msg_rxpeer->lpni_rtrcredits <= 0 ||
2332 lnet_msg2bufpool(msg)->rbp_credits <= 0) {
2333 if (ni->ni_net->net_lnd->lnd_eager_recv == NULL) {
2334 msg->msg_rx_ready_delay = 1;
2336 lnet_net_unlock(msg->msg_rx_cpt);
2337 rc = lnet_ni_eager_recv(ni, msg);
2338 lnet_net_lock(msg->msg_rx_cpt);
2343 rc = lnet_post_routed_recv_locked(msg, 0);
2348 lnet_parse_local(struct lnet_ni *ni, struct lnet_msg *msg)
2352 switch (msg->msg_type) {
2354 rc = lnet_parse_ack(ni, msg);
2357 rc = lnet_parse_put(ni, msg);
2360 rc = lnet_parse_get(ni, msg, msg->msg_rdma_get);
2362 case LNET_MSG_REPLY:
2363 rc = lnet_parse_reply(ni, msg);
2365 default: /* prevent an unused label if !kernel */
2370 LASSERT(rc == 0 || rc == -ENOENT);
2375 lnet_msgtyp2str (int type)
2384 case LNET_MSG_REPLY:
2386 case LNET_MSG_HELLO:
2389 return ("<UNKNOWN>");
2394 lnet_print_hdr(struct lnet_hdr *hdr)
2396 struct lnet_process_id src = {
2397 .nid = hdr->src_nid,
2398 .pid = hdr->src_pid,
2400 struct lnet_process_id dst = {
2401 .nid = hdr->dest_nid,
2402 .pid = hdr->dest_pid,
2404 char *type_str = lnet_msgtyp2str(hdr->type);
2406 CWARN("P3 Header at %p of type %s\n", hdr, type_str);
2407 CWARN(" From %s\n", libcfs_id2str(src));
2408 CWARN(" To %s\n", libcfs_id2str(dst));
2410 switch (hdr->type) {
2415 CWARN(" Ptl index %d, ack md %#llx.%#llx, "
2416 "match bits %llu\n",
2417 hdr->msg.put.ptl_index,
2418 hdr->msg.put.ack_wmd.wh_interface_cookie,
2419 hdr->msg.put.ack_wmd.wh_object_cookie,
2420 hdr->msg.put.match_bits);
2421 CWARN(" Length %d, offset %d, hdr data %#llx\n",
2422 hdr->payload_length, hdr->msg.put.offset,
2423 hdr->msg.put.hdr_data);
2427 CWARN(" Ptl index %d, return md %#llx.%#llx, "
2428 "match bits %llu\n", hdr->msg.get.ptl_index,
2429 hdr->msg.get.return_wmd.wh_interface_cookie,
2430 hdr->msg.get.return_wmd.wh_object_cookie,
2431 hdr->msg.get.match_bits);
2432 CWARN(" Length %d, src offset %d\n",
2433 hdr->msg.get.sink_length,
2434 hdr->msg.get.src_offset);
2438 CWARN(" dst md %#llx.%#llx, "
2439 "manipulated length %d\n",
2440 hdr->msg.ack.dst_wmd.wh_interface_cookie,
2441 hdr->msg.ack.dst_wmd.wh_object_cookie,
2442 hdr->msg.ack.mlength);
2445 case LNET_MSG_REPLY:
2446 CWARN(" dst md %#llx.%#llx, "
2448 hdr->msg.reply.dst_wmd.wh_interface_cookie,
2449 hdr->msg.reply.dst_wmd.wh_object_cookie,
2450 hdr->payload_length);
2456 lnet_parse(struct lnet_ni *ni, struct lnet_hdr *hdr, lnet_nid_t from_nid,
2457 void *private, int rdma_req)
2462 struct lnet_msg *msg;
2463 lnet_pid_t dest_pid;
2464 lnet_nid_t dest_nid;
2466 struct lnet_peer_ni *lpni;
2467 __u32 payload_length;
2470 LASSERT (!in_interrupt ());
2472 type = le32_to_cpu(hdr->type);
2473 src_nid = le64_to_cpu(hdr->src_nid);
2474 dest_nid = le64_to_cpu(hdr->dest_nid);
2475 dest_pid = le32_to_cpu(hdr->dest_pid);
2476 payload_length = le32_to_cpu(hdr->payload_length);
2478 for_me = (ni->ni_nid == dest_nid);
2479 cpt = lnet_cpt_of_nid(from_nid, ni);
2481 CDEBUG(D_NET, "TRACE: %s(%s) <- %s : %s - %s\n",
2482 libcfs_nid2str(dest_nid),
2483 libcfs_nid2str(ni->ni_nid),
2484 libcfs_nid2str(src_nid),
2485 lnet_msgtyp2str(type),
2486 (for_me) ? "for me" : "routed");
2491 if (payload_length > 0) {
2492 CERROR("%s, src %s: bad %s payload %d (0 expected)\n",
2493 libcfs_nid2str(from_nid),
2494 libcfs_nid2str(src_nid),
2495 lnet_msgtyp2str(type), payload_length);
2501 case LNET_MSG_REPLY:
2502 if (payload_length >
2503 (__u32)(for_me ? LNET_MAX_PAYLOAD : LNET_MTU)) {
2504 CERROR("%s, src %s: bad %s payload %d "
2505 "(%d max expected)\n",
2506 libcfs_nid2str(from_nid),
2507 libcfs_nid2str(src_nid),
2508 lnet_msgtyp2str(type),
2510 for_me ? LNET_MAX_PAYLOAD : LNET_MTU);
2516 CERROR("%s, src %s: Bad message type 0x%x\n",
2517 libcfs_nid2str(from_nid),
2518 libcfs_nid2str(src_nid), type);
2522 if (the_lnet.ln_routing &&
2523 ni->ni_last_alive != ktime_get_real_seconds()) {
2524 /* NB: so far here is the only place to set NI status to "up */
2526 ni->ni_last_alive = ktime_get_real_seconds();
2527 if (ni->ni_status != NULL &&
2528 ni->ni_status->ns_status == LNET_NI_STATUS_DOWN)
2529 ni->ni_status->ns_status = LNET_NI_STATUS_UP;
2533 /* Regard a bad destination NID as a protocol error. Senders should
2534 * know what they're doing; if they don't they're misconfigured, buggy
2535 * or malicious so we chop them off at the knees :) */
2538 if (LNET_NIDNET(dest_nid) == LNET_NIDNET(ni->ni_nid)) {
2539 /* should have gone direct */
2540 CERROR("%s, src %s: Bad dest nid %s "
2541 "(should have been sent direct)\n",
2542 libcfs_nid2str(from_nid),
2543 libcfs_nid2str(src_nid),
2544 libcfs_nid2str(dest_nid));
2548 if (lnet_islocalnid(dest_nid)) {
2549 /* dest is another local NI; sender should have used
2550 * this node's NID on its own network */
2551 CERROR("%s, src %s: Bad dest nid %s "
2552 "(it's my nid but on a different network)\n",
2553 libcfs_nid2str(from_nid),
2554 libcfs_nid2str(src_nid),
2555 libcfs_nid2str(dest_nid));
2559 if (rdma_req && type == LNET_MSG_GET) {
2560 CERROR("%s, src %s: Bad optimized GET for %s "
2561 "(final destination must be me)\n",
2562 libcfs_nid2str(from_nid),
2563 libcfs_nid2str(src_nid),
2564 libcfs_nid2str(dest_nid));
2568 if (!the_lnet.ln_routing) {
2569 CERROR("%s, src %s: Dropping message for %s "
2570 "(routing not enabled)\n",
2571 libcfs_nid2str(from_nid),
2572 libcfs_nid2str(src_nid),
2573 libcfs_nid2str(dest_nid));
2578 /* Message looks OK; we're not going to return an error, so we MUST
2579 * call back lnd_recv() come what may... */
2581 if (!list_empty(&the_lnet.ln_test_peers) && /* normally we don't */
2582 fail_peer(src_nid, 0)) { /* shall we now? */
2583 CERROR("%s, src %s: Dropping %s to simulate failure\n",
2584 libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
2585 lnet_msgtyp2str(type));
2589 if (!list_empty(&the_lnet.ln_drop_rules) &&
2590 lnet_drop_rule_match(hdr)) {
2591 CDEBUG(D_NET, "%s, src %s, dst %s: Dropping %s to simulate"
2592 "silent message loss\n",
2593 libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
2594 libcfs_nid2str(dest_nid), lnet_msgtyp2str(type));
2599 msg = lnet_msg_alloc();
2601 CERROR("%s, src %s: Dropping %s (out of memory)\n",
2602 libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
2603 lnet_msgtyp2str(type));
2607 /* msg zeroed in lnet_msg_alloc; i.e. flags all clear,
2608 * pointers NULL etc */
2610 msg->msg_type = type;
2611 msg->msg_private = private;
2612 msg->msg_receiving = 1;
2613 msg->msg_rdma_get = rdma_req;
2614 msg->msg_len = msg->msg_wanted = payload_length;
2615 msg->msg_offset = 0;
2616 msg->msg_hdr = *hdr;
2617 /* for building message event */
2618 msg->msg_from = from_nid;
2620 msg->msg_target.pid = dest_pid;
2621 msg->msg_target.nid = dest_nid;
2622 msg->msg_routing = 1;
2625 /* convert common msg->hdr fields to host byteorder */
2626 msg->msg_hdr.type = type;
2627 msg->msg_hdr.src_nid = src_nid;
2628 msg->msg_hdr.src_pid = le32_to_cpu(msg->msg_hdr.src_pid);
2629 msg->msg_hdr.dest_nid = dest_nid;
2630 msg->msg_hdr.dest_pid = dest_pid;
2631 msg->msg_hdr.payload_length = payload_length;
2635 lpni = lnet_nid2peerni_locked(from_nid, ni->ni_nid, cpt);
2637 lnet_net_unlock(cpt);
2638 CERROR("%s, src %s: Dropping %s "
2639 "(error %ld looking up sender)\n",
2640 libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
2641 lnet_msgtyp2str(type), PTR_ERR(lpni));
2643 if (rc == -ESHUTDOWN)
2644 /* We are shutting down. Don't do anything more */
2648 msg->msg_rxpeer = lpni;
2650 lnet_ni_addref_locked(ni, cpt);
2651 /* Multi-Rail: Primary NID of source. */
2652 msg->msg_initiator = lnet_peer_primary_nid_locked(src_nid);
2654 if (lnet_isrouter(msg->msg_rxpeer)) {
2655 lnet_peer_set_alive(msg->msg_rxpeer);
2656 if (avoid_asym_router_failure &&
2657 LNET_NIDNET(src_nid) != LNET_NIDNET(from_nid)) {
2658 /* received a remote message from router, update
2659 * remote NI status on this router.
2660 * NB: multi-hop routed message will be ignored.
2662 lnet_router_ni_update_locked(msg->msg_rxpeer,
2663 LNET_NIDNET(src_nid));
2667 lnet_msg_commit(msg, cpt);
2669 /* message delay simulation */
2670 if (unlikely(!list_empty(&the_lnet.ln_delay_rules) &&
2671 lnet_delay_rule_match_locked(hdr, msg))) {
2672 lnet_net_unlock(cpt);
2677 rc = lnet_parse_forward_locked(ni, msg);
2678 lnet_net_unlock(cpt);
2683 if (rc == LNET_CREDIT_OK) {
2684 lnet_ni_recv(ni, msg->msg_private, msg, 0,
2685 0, payload_length, payload_length);
2690 lnet_net_unlock(cpt);
2692 rc = lnet_parse_local(ni, msg);
2698 LASSERT(msg->msg_md == NULL);
2699 lnet_finalize(msg, rc);
2702 lnet_drop_message(ni, cpt, private, payload_length);
2705 EXPORT_SYMBOL(lnet_parse);
2708 lnet_drop_delayed_msg_list(struct list_head *head, char *reason)
2710 while (!list_empty(head)) {
2711 struct lnet_process_id id = {0};
2712 struct lnet_msg *msg;
2714 msg = list_entry(head->next, struct lnet_msg, msg_list);
2715 list_del(&msg->msg_list);
2717 id.nid = msg->msg_hdr.src_nid;
2718 id.pid = msg->msg_hdr.src_pid;
2720 LASSERT(msg->msg_md == NULL);
2721 LASSERT(msg->msg_rx_delayed);
2722 LASSERT(msg->msg_rxpeer != NULL);
2723 LASSERT(msg->msg_hdr.type == LNET_MSG_PUT);
2725 CWARN("Dropping delayed PUT from %s portal %d match %llu"
2726 " offset %d length %d: %s\n",
2728 msg->msg_hdr.msg.put.ptl_index,
2729 msg->msg_hdr.msg.put.match_bits,
2730 msg->msg_hdr.msg.put.offset,
2731 msg->msg_hdr.payload_length, reason);
2733 /* NB I can't drop msg's ref on msg_rxpeer until after I've
2734 * called lnet_drop_message(), so I just hang onto msg as well
2735 * until that's done */
2737 lnet_drop_message(msg->msg_rxni, msg->msg_rx_cpt,
2738 msg->msg_private, msg->msg_len);
2740 * NB: message will not generate event because w/o attached MD,
2741 * but we still should give error code so lnet_msg_decommit()
2742 * can skip counters operations and other checks.
2744 lnet_finalize(msg, -ENOENT);
2749 lnet_recv_delayed_msg_list(struct list_head *head)
2751 while (!list_empty(head)) {
2752 struct lnet_msg *msg;
2753 struct lnet_process_id id;
2755 msg = list_entry(head->next, struct lnet_msg, msg_list);
2756 list_del(&msg->msg_list);
2758 /* md won't disappear under me, since each msg
2759 * holds a ref on it */
2761 id.nid = msg->msg_hdr.src_nid;
2762 id.pid = msg->msg_hdr.src_pid;
2764 LASSERT(msg->msg_rx_delayed);
2765 LASSERT(msg->msg_md != NULL);
2766 LASSERT(msg->msg_rxpeer != NULL);
2767 LASSERT(msg->msg_rxni != NULL);
2768 LASSERT(msg->msg_hdr.type == LNET_MSG_PUT);
2770 CDEBUG(D_NET, "Resuming delayed PUT from %s portal %d "
2771 "match %llu offset %d length %d.\n",
2772 libcfs_id2str(id), msg->msg_hdr.msg.put.ptl_index,
2773 msg->msg_hdr.msg.put.match_bits,
2774 msg->msg_hdr.msg.put.offset,
2775 msg->msg_hdr.payload_length);
2777 lnet_recv_put(msg->msg_rxni, msg);
2782 * Initiate an asynchronous PUT operation.
2784 * There are several events associated with a PUT: completion of the send on
2785 * the initiator node (LNET_EVENT_SEND), and when the send completes
2786 * successfully, the receipt of an acknowledgment (LNET_EVENT_ACK) indicating
2787 * that the operation was accepted by the target. The event LNET_EVENT_PUT is
2788 * used at the target node to indicate the completion of incoming data
2791 * The local events will be logged in the EQ associated with the MD pointed to
2792 * by \a mdh handle. Using a MD without an associated EQ results in these
2793 * events being discarded. In this case, the caller must have another
2794 * mechanism (e.g., a higher level protocol) for determining when it is safe
2795 * to modify the memory region associated with the MD.
2797 * Note that LNet does not guarantee the order of LNET_EVENT_SEND and
2798 * LNET_EVENT_ACK, though intuitively ACK should happen after SEND.
2800 * \param self Indicates the NID of a local interface through which to send
2801 * the PUT request. Use LNET_NID_ANY to let LNet choose one by itself.
2802 * \param mdh A handle for the MD that describes the memory to be sent. The MD
2803 * must be "free floating" (See LNetMDBind()).
2804 * \param ack Controls whether an acknowledgment is requested.
2805 * Acknowledgments are only sent when they are requested by the initiating
2806 * process and the target MD enables them.
2807 * \param target A process identifier for the target process.
2808 * \param portal The index in the \a target's portal table.
2809 * \param match_bits The match bits to use for MD selection at the target
2811 * \param offset The offset into the target MD (only used when the target
2812 * MD has the LNET_MD_MANAGE_REMOTE option set).
2813 * \param hdr_data 64 bits of user data that can be included in the message
2814 * header. This data is written to an event queue entry at the target if an
2815 * EQ is present on the matching MD.
2817 * \retval 0 Success, and only in this case events will be generated
2818 * and logged to EQ (if it exists).
2819 * \retval -EIO Simulated failure.
2820 * \retval -ENOMEM Memory allocation failure.
2821 * \retval -ENOENT Invalid MD object.
2823 * \see struct lnet_event::hdr_data and lnet_event_kind_t.
2826 LNetPut(lnet_nid_t self, struct lnet_handle_md mdh, enum lnet_ack_req ack,
2827 struct lnet_process_id target, unsigned int portal,
2828 __u64 match_bits, unsigned int offset,
2831 struct lnet_msg *msg;
2832 struct lnet_libmd *md;
2836 LASSERT(the_lnet.ln_refcount > 0);
2838 if (!list_empty(&the_lnet.ln_test_peers) && /* normally we don't */
2839 fail_peer(target.nid, 1)) { /* shall we now? */
2840 CERROR("Dropping PUT to %s: simulated failure\n",
2841 libcfs_id2str(target));
2845 msg = lnet_msg_alloc();
2847 CERROR("Dropping PUT to %s: ENOMEM on struct lnet_msg\n",
2848 libcfs_id2str(target));
2851 msg->msg_vmflush = !!memory_pressure_get();
2853 cpt = lnet_cpt_of_cookie(mdh.cookie);
2856 md = lnet_handle2md(&mdh);
2857 if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) {
2858 CERROR("Dropping PUT (%llu:%d:%s): MD (%d) invalid\n",
2859 match_bits, portal, libcfs_id2str(target),
2860 md == NULL ? -1 : md->md_threshold);
2861 if (md != NULL && md->md_me != NULL)
2862 CERROR("Source MD also attached to portal %d\n",
2863 md->md_me->me_portal);
2864 lnet_res_unlock(cpt);
2870 CDEBUG(D_NET, "LNetPut -> %s\n", libcfs_id2str(target));
2872 lnet_msg_attach_md(msg, md, 0, 0);
2874 lnet_prep_send(msg, LNET_MSG_PUT, target, 0, md->md_length);
2876 msg->msg_hdr.msg.put.match_bits = cpu_to_le64(match_bits);
2877 msg->msg_hdr.msg.put.ptl_index = cpu_to_le32(portal);
2878 msg->msg_hdr.msg.put.offset = cpu_to_le32(offset);
2879 msg->msg_hdr.msg.put.hdr_data = hdr_data;
2881 /* NB handles only looked up by creator (no flips) */
2882 if (ack == LNET_ACK_REQ) {
2883 msg->msg_hdr.msg.put.ack_wmd.wh_interface_cookie =
2884 the_lnet.ln_interface_cookie;
2885 msg->msg_hdr.msg.put.ack_wmd.wh_object_cookie =
2886 md->md_lh.lh_cookie;
2888 msg->msg_hdr.msg.put.ack_wmd.wh_interface_cookie =
2889 LNET_WIRE_HANDLE_COOKIE_NONE;
2890 msg->msg_hdr.msg.put.ack_wmd.wh_object_cookie =
2891 LNET_WIRE_HANDLE_COOKIE_NONE;
2894 lnet_res_unlock(cpt);
2896 lnet_build_msg_event(msg, LNET_EVENT_SEND);
2898 rc = lnet_send(self, msg, LNET_NID_ANY);
2900 CNETERR("Error sending PUT to %s: %d\n",
2901 libcfs_id2str(target), rc);
2902 lnet_finalize(msg, rc);
2905 /* completion will be signalled by an event */
2908 EXPORT_SYMBOL(LNetPut);
2911 * The LND can DMA direct to the GET md (i.e. no REPLY msg). This
2912 * returns a msg for the LND to pass to lnet_finalize() when the sink
2913 * data has been received.
2915 * CAVEAT EMPTOR: 'getmsg' is the original GET, which is freed when
2916 * lnet_finalize() is called on it, so the LND must call this first
2919 lnet_create_reply_msg(struct lnet_ni *ni, struct lnet_msg *getmsg)
2921 struct lnet_msg *msg = lnet_msg_alloc();
2922 struct lnet_libmd *getmd = getmsg->msg_md;
2923 struct lnet_process_id peer_id = getmsg->msg_target;
2926 LASSERT(!getmsg->msg_target_is_router);
2927 LASSERT(!getmsg->msg_routing);
2930 CERROR("%s: Dropping REPLY from %s: can't allocate msg\n",
2931 libcfs_nid2str(ni->ni_nid), libcfs_id2str(peer_id));
2935 cpt = lnet_cpt_of_cookie(getmd->md_lh.lh_cookie);
2938 LASSERT(getmd->md_refcount > 0);
2940 if (getmd->md_threshold == 0) {
2941 CERROR("%s: Dropping REPLY from %s for inactive MD %p\n",
2942 libcfs_nid2str(ni->ni_nid), libcfs_id2str(peer_id),
2944 lnet_res_unlock(cpt);
2948 LASSERT(getmd->md_offset == 0);
2950 CDEBUG(D_NET, "%s: Reply from %s md %p\n",
2951 libcfs_nid2str(ni->ni_nid), libcfs_id2str(peer_id), getmd);
2953 /* setup information for lnet_build_msg_event */
2954 msg->msg_initiator = getmsg->msg_txpeer->lpni_peer_net->lpn_peer->lp_primary_nid;
2955 msg->msg_from = peer_id.nid;
2956 msg->msg_type = LNET_MSG_GET; /* flag this msg as an "optimized" GET */
2957 msg->msg_hdr.src_nid = peer_id.nid;
2958 msg->msg_hdr.payload_length = getmd->md_length;
2959 msg->msg_receiving = 1; /* required by lnet_msg_attach_md */
2961 lnet_msg_attach_md(msg, getmd, getmd->md_offset, getmd->md_length);
2962 lnet_res_unlock(cpt);
2964 cpt = lnet_cpt_of_nid(peer_id.nid, ni);
2967 lnet_msg_commit(msg, cpt);
2968 lnet_net_unlock(cpt);
2970 lnet_build_msg_event(msg, LNET_EVENT_REPLY);
2975 cpt = lnet_cpt_of_nid(peer_id.nid, ni);
2978 the_lnet.ln_counters[cpt]->drop_count++;
2979 the_lnet.ln_counters[cpt]->drop_length += getmd->md_length;
2980 lnet_net_unlock(cpt);
2987 EXPORT_SYMBOL(lnet_create_reply_msg);
2990 lnet_set_reply_msg_len(struct lnet_ni *ni, struct lnet_msg *reply,
2993 /* Set the REPLY length, now the RDMA that elides the REPLY message has
2994 * completed and I know it. */
2995 LASSERT(reply != NULL);
2996 LASSERT(reply->msg_type == LNET_MSG_GET);
2997 LASSERT(reply->msg_ev.type == LNET_EVENT_REPLY);
2999 /* NB I trusted my peer to RDMA. If she tells me she's written beyond
3000 * the end of my buffer, I might as well be dead. */
3001 LASSERT(len <= reply->msg_ev.mlength);
3003 reply->msg_ev.mlength = len;
3005 EXPORT_SYMBOL(lnet_set_reply_msg_len);
3008 * Initiate an asynchronous GET operation.
3010 * On the initiator node, an LNET_EVENT_SEND is logged when the GET request
3011 * is sent, and an LNET_EVENT_REPLY is logged when the data returned from
3012 * the target node in the REPLY has been written to local MD.
3014 * On the target node, an LNET_EVENT_GET is logged when the GET request
3015 * arrives and is accepted into a MD.
3017 * \param self,target,portal,match_bits,offset See the discussion in LNetPut().
3018 * \param mdh A handle for the MD that describes the memory into which the
3019 * requested data will be received. The MD must be "free floating" (See LNetMDBind()).
3021 * \retval 0 Success, and only in this case events will be generated
3022 * and logged to EQ (if it exists) of the MD.
3023 * \retval -EIO Simulated failure.
3024 * \retval -ENOMEM Memory allocation failure.
3025 * \retval -ENOENT Invalid MD object.
3028 LNetGet(lnet_nid_t self, struct lnet_handle_md mdh,
3029 struct lnet_process_id target, unsigned int portal,
3030 __u64 match_bits, unsigned int offset)
3032 struct lnet_msg *msg;
3033 struct lnet_libmd *md;
3037 LASSERT(the_lnet.ln_refcount > 0);
3039 if (!list_empty(&the_lnet.ln_test_peers) && /* normally we don't */
3040 fail_peer(target.nid, 1)) /* shall we now? */
3042 CERROR("Dropping GET to %s: simulated failure\n",
3043 libcfs_id2str(target));
3047 msg = lnet_msg_alloc();
3049 CERROR("Dropping GET to %s: ENOMEM on struct lnet_msg\n",
3050 libcfs_id2str(target));
3054 cpt = lnet_cpt_of_cookie(mdh.cookie);
3057 md = lnet_handle2md(&mdh);
3058 if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) {
3059 CERROR("Dropping GET (%llu:%d:%s): MD (%d) invalid\n",
3060 match_bits, portal, libcfs_id2str(target),
3061 md == NULL ? -1 : md->md_threshold);
3062 if (md != NULL && md->md_me != NULL)
3063 CERROR("REPLY MD also attached to portal %d\n",
3064 md->md_me->me_portal);
3066 lnet_res_unlock(cpt);
3072 CDEBUG(D_NET, "LNetGet -> %s\n", libcfs_id2str(target));
3074 lnet_msg_attach_md(msg, md, 0, 0);
3076 lnet_prep_send(msg, LNET_MSG_GET, target, 0, 0);
3078 msg->msg_hdr.msg.get.match_bits = cpu_to_le64(match_bits);
3079 msg->msg_hdr.msg.get.ptl_index = cpu_to_le32(portal);
3080 msg->msg_hdr.msg.get.src_offset = cpu_to_le32(offset);
3081 msg->msg_hdr.msg.get.sink_length = cpu_to_le32(md->md_length);
3083 /* NB handles only looked up by creator (no flips) */
3084 msg->msg_hdr.msg.get.return_wmd.wh_interface_cookie =
3085 the_lnet.ln_interface_cookie;
3086 msg->msg_hdr.msg.get.return_wmd.wh_object_cookie =
3087 md->md_lh.lh_cookie;
3089 lnet_res_unlock(cpt);
3091 lnet_build_msg_event(msg, LNET_EVENT_SEND);
3093 rc = lnet_send(self, msg, LNET_NID_ANY);
3095 CNETERR("Error sending GET to %s: %d\n",
3096 libcfs_id2str(target), rc);
3097 lnet_finalize(msg, rc);
3100 /* completion will be signalled by an event */
3103 EXPORT_SYMBOL(LNetGet);
3106 * Calculate distance to node at \a dstnid.
3108 * \param dstnid Target NID.
3109 * \param srcnidp If not NULL, NID of the local interface to reach \a dstnid
3111 * \param orderp If not NULL, order of the route to reach \a dstnid is saved
3114 * \retval 0 If \a dstnid belongs to a local interface, and reserved option
3115 * local_nid_dist_zero is set, which is the default.
3116 * \retval positives Distance to target NID, i.e. number of hops plus one.
3117 * \retval -EHOSTUNREACH If \a dstnid is not reachable.
3120 LNetDist(lnet_nid_t dstnid, lnet_nid_t *srcnidp, __u32 *orderp)
3122 struct list_head *e;
3123 struct lnet_ni *ni = NULL;
3124 struct lnet_remotenet *rnet;
3125 __u32 dstnet = LNET_NIDNET(dstnid);
3129 struct list_head *rn_list;
3131 /* if !local_nid_dist_zero, I don't return a distance of 0 ever
3132 * (when lustre sees a distance of 0, it substitutes 0@lo), so I
3133 * keep order 0 free for 0@lo and order 1 free for a local NID
3136 LASSERT(the_lnet.ln_refcount > 0);
3138 cpt = lnet_net_lock_current();
3140 while ((ni = lnet_get_next_ni_locked(NULL, ni))) {
3141 if (ni->ni_nid == dstnid) {
3142 if (srcnidp != NULL)
3144 if (orderp != NULL) {
3145 if (LNET_NETTYP(LNET_NIDNET(dstnid)) == LOLND)
3150 lnet_net_unlock(cpt);
3152 return local_nid_dist_zero ? 0 : 1;
3155 if (LNET_NIDNET(ni->ni_nid) == dstnet) {
3156 /* Check if ni was originally created in
3157 * current net namespace.
3158 * If not, assign order above 0xffff0000,
3159 * to make this ni not a priority. */
3160 if (!net_eq(ni->ni_net_ns, current->nsproxy->net_ns))
3161 order += 0xffff0000;
3163 if (srcnidp != NULL)
3164 *srcnidp = ni->ni_nid;
3167 lnet_net_unlock(cpt);
3174 rn_list = lnet_net2rnethash(dstnet);
3175 list_for_each(e, rn_list) {
3176 rnet = list_entry(e, struct lnet_remotenet, lrn_list);
3178 if (rnet->lrn_net == dstnet) {
3179 struct lnet_route *route;
3180 struct lnet_route *shortest = NULL;
3181 __u32 shortest_hops = LNET_UNDEFINED_HOPS;
3184 LASSERT(!list_empty(&rnet->lrn_routes));
3186 list_for_each_entry(route, &rnet->lrn_routes,
3188 route_hops = route->lr_hops;
3189 if (route_hops == LNET_UNDEFINED_HOPS)
3191 if (shortest == NULL ||
3192 route_hops < shortest_hops) {
3194 shortest_hops = route_hops;
3198 LASSERT(shortest != NULL);
3199 hops = shortest_hops;
3200 if (srcnidp != NULL) {
3201 ni = lnet_get_next_ni_locked(
3202 shortest->lr_gateway->lpni_net,
3204 *srcnidp = ni->ni_nid;
3208 lnet_net_unlock(cpt);
3214 lnet_net_unlock(cpt);
3215 return -EHOSTUNREACH;
3217 EXPORT_SYMBOL(LNetDist);