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;
169 EXPORT_SYMBOL(lnet_iov_nob);
172 lnet_copy_iov2iov (unsigned int ndiov, struct iovec *diov, unsigned int doffset,
173 unsigned int nsiov, struct iovec *siov, unsigned int soffset,
176 /* NB diov, siov are READ-ONLY */
177 unsigned int this_nob;
182 /* skip complete frags before 'doffset' */
184 while (doffset >= diov->iov_len) {
185 doffset -= diov->iov_len;
191 /* skip complete frags before 'soffset' */
193 while (soffset >= siov->iov_len) {
194 soffset -= siov->iov_len;
203 this_nob = MIN(diov->iov_len - doffset,
204 siov->iov_len - soffset);
205 this_nob = MIN(this_nob, nob);
207 memcpy ((char *)diov->iov_base + doffset,
208 (char *)siov->iov_base + soffset, this_nob);
211 if (diov->iov_len > doffset + this_nob) {
219 if (siov->iov_len > soffset + this_nob) {
228 EXPORT_SYMBOL(lnet_copy_iov2iov);
231 lnet_extract_iov (int dst_niov, struct iovec *dst,
232 int src_niov, struct iovec *src,
233 unsigned int offset, unsigned int len)
235 /* Initialise 'dst' to the subset of 'src' starting at 'offset',
236 * for exactly 'len' bytes, and return the number of entries.
237 * NB not destructive to 'src' */
238 unsigned int frag_len;
241 if (len == 0) /* no data => */
242 return (0); /* no frags */
244 LASSERT (src_niov > 0);
245 while (offset >= src->iov_len) { /* skip initial frags */
246 offset -= src->iov_len;
249 LASSERT (src_niov > 0);
254 LASSERT (src_niov > 0);
255 LASSERT ((int)niov <= dst_niov);
257 frag_len = src->iov_len - offset;
258 dst->iov_base = ((char *)src->iov_base) + offset;
260 if (len <= frag_len) {
265 dst->iov_len = frag_len;
275 EXPORT_SYMBOL(lnet_extract_iov);
279 lnet_kiov_nob (unsigned int niov, lnet_kiov_t *kiov)
286 lnet_copy_kiov2kiov (unsigned int ndkiov, lnet_kiov_t *dkiov, unsigned int doffset,
287 unsigned int nskiov, lnet_kiov_t *skiov, unsigned int soffset,
294 lnet_copy_kiov2iov (unsigned int niov, struct iovec *iov, unsigned int iovoffset,
295 unsigned int nkiov, lnet_kiov_t *kiov, unsigned int kiovoffset,
302 lnet_copy_iov2kiov (unsigned int nkiov, lnet_kiov_t *kiov, unsigned int kiovoffset,
303 unsigned int niov, struct iovec *iov, unsigned int iovoffset,
310 lnet_extract_kiov (int dst_niov, lnet_kiov_t *dst,
311 int src_niov, lnet_kiov_t *src,
312 unsigned int offset, unsigned int len)
317 #else /* __KERNEL__ */
320 lnet_kiov_nob (unsigned int niov, lnet_kiov_t *kiov)
322 unsigned int nob = 0;
325 nob += (kiov++)->kiov_len;
329 EXPORT_SYMBOL(lnet_kiov_nob);
332 lnet_copy_kiov2kiov (unsigned int ndiov, lnet_kiov_t *diov, unsigned int doffset,
333 unsigned int nsiov, lnet_kiov_t *siov, unsigned int soffset,
336 /* NB diov, siov are READ-ONLY */
337 unsigned int this_nob;
344 LASSERT (!cfs_in_interrupt ());
347 while (doffset >= diov->kiov_len) {
348 doffset -= diov->kiov_len;
355 while (soffset >= siov->kiov_len) {
356 soffset -= siov->kiov_len;
365 this_nob = MIN(diov->kiov_len - doffset,
366 siov->kiov_len - soffset);
367 this_nob = MIN(this_nob, nob);
370 daddr = ((char *)cfs_kmap(diov->kiov_page)) +
371 diov->kiov_offset + doffset;
373 saddr = ((char *)cfs_kmap(siov->kiov_page)) +
374 siov->kiov_offset + soffset;
376 /* Vanishing risk of kmap deadlock when mapping 2 pages.
377 * However in practice at least one of the kiovs will be mapped
378 * kernel pages and the map/unmap will be NOOPs */
380 memcpy (daddr, saddr, this_nob);
383 if (diov->kiov_len > doffset + this_nob) {
387 cfs_kunmap(diov->kiov_page);
394 if (siov->kiov_len > soffset + this_nob) {
398 cfs_kunmap(siov->kiov_page);
407 cfs_kunmap(diov->kiov_page);
409 cfs_kunmap(siov->kiov_page);
411 EXPORT_SYMBOL(lnet_copy_kiov2kiov);
414 lnet_copy_kiov2iov (unsigned int niov, struct iovec *iov, unsigned int iovoffset,
415 unsigned int nkiov, lnet_kiov_t *kiov, unsigned int kiovoffset,
418 /* NB iov, kiov are READ-ONLY */
419 unsigned int this_nob;
425 LASSERT (!cfs_in_interrupt ());
428 while (iovoffset >= iov->iov_len) {
429 iovoffset -= iov->iov_len;
436 while (kiovoffset >= kiov->kiov_len) {
437 kiovoffset -= kiov->kiov_len;
446 this_nob = MIN(iov->iov_len - iovoffset,
447 kiov->kiov_len - kiovoffset);
448 this_nob = MIN(this_nob, nob);
451 addr = ((char *)cfs_kmap(kiov->kiov_page)) +
452 kiov->kiov_offset + kiovoffset;
454 memcpy ((char *)iov->iov_base + iovoffset, addr, this_nob);
457 if (iov->iov_len > iovoffset + this_nob) {
458 iovoffset += this_nob;
465 if (kiov->kiov_len > kiovoffset + this_nob) {
467 kiovoffset += this_nob;
469 cfs_kunmap(kiov->kiov_page);
479 cfs_kunmap(kiov->kiov_page);
481 EXPORT_SYMBOL(lnet_copy_kiov2iov);
484 lnet_copy_iov2kiov (unsigned int nkiov, lnet_kiov_t *kiov, unsigned int kiovoffset,
485 unsigned int niov, struct iovec *iov, unsigned int iovoffset,
488 /* NB kiov, iov are READ-ONLY */
489 unsigned int this_nob;
495 LASSERT (!cfs_in_interrupt ());
498 while (kiovoffset >= kiov->kiov_len) {
499 kiovoffset -= kiov->kiov_len;
506 while (iovoffset >= iov->iov_len) {
507 iovoffset -= iov->iov_len;
516 this_nob = MIN(kiov->kiov_len - kiovoffset,
517 iov->iov_len - iovoffset);
518 this_nob = MIN(this_nob, nob);
521 addr = ((char *)cfs_kmap(kiov->kiov_page)) +
522 kiov->kiov_offset + kiovoffset;
524 memcpy (addr, (char *)iov->iov_base + iovoffset, this_nob);
527 if (kiov->kiov_len > kiovoffset + this_nob) {
529 kiovoffset += this_nob;
531 cfs_kunmap(kiov->kiov_page);
538 if (iov->iov_len > iovoffset + this_nob) {
539 iovoffset += this_nob;
548 cfs_kunmap(kiov->kiov_page);
550 EXPORT_SYMBOL(lnet_copy_iov2kiov);
553 lnet_extract_kiov (int dst_niov, lnet_kiov_t *dst,
554 int src_niov, lnet_kiov_t *src,
555 unsigned int offset, unsigned int len)
557 /* Initialise 'dst' to the subset of 'src' starting at 'offset',
558 * for exactly 'len' bytes, and return the number of entries.
559 * NB not destructive to 'src' */
560 unsigned int frag_len;
563 if (len == 0) /* no data => */
564 return (0); /* no frags */
566 LASSERT (src_niov > 0);
567 while (offset >= src->kiov_len) { /* skip initial frags */
568 offset -= src->kiov_len;
571 LASSERT (src_niov > 0);
576 LASSERT (src_niov > 0);
577 LASSERT ((int)niov <= dst_niov);
579 frag_len = src->kiov_len - offset;
580 dst->kiov_page = src->kiov_page;
581 dst->kiov_offset = src->kiov_offset + offset;
583 if (len <= frag_len) {
585 LASSERT (dst->kiov_offset + dst->kiov_len <= CFS_PAGE_SIZE);
589 dst->kiov_len = frag_len;
590 LASSERT (dst->kiov_offset + dst->kiov_len <= CFS_PAGE_SIZE);
600 EXPORT_SYMBOL(lnet_extract_kiov);
604 lnet_ni_recv(lnet_ni_t *ni, void *private, lnet_msg_t *msg, int delayed,
605 unsigned int offset, unsigned int mlen, unsigned int rlen)
607 unsigned int niov = 0;
608 struct iovec *iov = NULL;
609 lnet_kiov_t *kiov = NULL;
612 LASSERT (!cfs_in_interrupt ());
613 LASSERT (mlen == 0 || msg != NULL);
616 LASSERT(msg->msg_receiving);
617 LASSERT(!msg->msg_sending);
618 LASSERT(rlen == msg->msg_len);
619 LASSERT(mlen <= msg->msg_len);
620 LASSERT(msg->msg_offset == offset);
621 LASSERT(msg->msg_wanted == mlen);
623 msg->msg_receiving = 0;
626 niov = msg->msg_niov;
628 kiov = msg->msg_kiov;
631 LASSERT ((iov == NULL) != (kiov == NULL));
635 rc = (ni->ni_lnd->lnd_recv)(ni, private, msg, delayed,
636 niov, iov, kiov, offset, mlen, rlen);
638 lnet_finalize(ni, msg, rc);
642 lnet_setpayloadbuffer(lnet_msg_t *msg)
644 lnet_libmd_t *md = msg->msg_md;
646 LASSERT (msg->msg_len > 0);
647 LASSERT (!msg->msg_routing);
648 LASSERT (md != NULL);
649 LASSERT (msg->msg_niov == 0);
650 LASSERT (msg->msg_iov == NULL);
651 LASSERT (msg->msg_kiov == NULL);
653 msg->msg_niov = md->md_niov;
654 if ((md->md_options & LNET_MD_KIOV) != 0)
655 msg->msg_kiov = md->md_iov.kiov;
657 msg->msg_iov = md->md_iov.iov;
661 lnet_prep_send(lnet_msg_t *msg, int type, lnet_process_id_t target,
662 unsigned int offset, unsigned int len)
664 msg->msg_type = type;
665 msg->msg_target = target;
667 msg->msg_offset = offset;
670 lnet_setpayloadbuffer(msg);
672 memset (&msg->msg_hdr, 0, sizeof (msg->msg_hdr));
673 msg->msg_hdr.type = cpu_to_le32(type);
674 msg->msg_hdr.dest_nid = cpu_to_le64(target.nid);
675 msg->msg_hdr.dest_pid = cpu_to_le32(target.pid);
676 /* src_nid will be set later */
677 msg->msg_hdr.src_pid = cpu_to_le32(the_lnet.ln_pid);
678 msg->msg_hdr.payload_length = cpu_to_le32(len);
682 lnet_ni_send(lnet_ni_t *ni, lnet_msg_t *msg)
684 void *priv = msg->msg_private;
687 LASSERT (!cfs_in_interrupt ());
688 LASSERT (LNET_NETTYP(LNET_NIDNET(ni->ni_nid)) == LOLND ||
689 (msg->msg_txcredit && msg->msg_peertxcredit));
691 rc = (ni->ni_lnd->lnd_send)(ni, priv, msg);
693 lnet_finalize(ni, msg, rc);
697 lnet_ni_eager_recv(lnet_ni_t *ni, lnet_msg_t *msg)
701 LASSERT(!msg->msg_sending);
702 LASSERT(msg->msg_receiving);
703 LASSERT(!msg->msg_rx_ready_delay);
704 LASSERT(ni->ni_lnd->lnd_eager_recv != NULL);
706 msg->msg_rx_ready_delay = 1;
707 rc = (ni->ni_lnd->lnd_eager_recv)(ni, msg->msg_private, msg,
710 CERROR("recv from %s / send to %s aborted: "
711 "eager_recv failed %d\n",
712 libcfs_nid2str(msg->msg_rxpeer->lp_nid),
713 libcfs_id2str(msg->msg_target), rc);
714 LASSERT(rc < 0); /* required by my callers */
720 /* NB: caller shall hold a ref on 'lp' as I'd drop lnet_net_lock */
722 lnet_ni_query_locked(lnet_ni_t *ni, lnet_peer_t *lp)
724 cfs_time_t last_alive = 0;
726 LASSERT(lnet_peer_aliveness_enabled(lp));
727 LASSERT(ni->ni_lnd->lnd_query != NULL);
728 LASSERT(the_lnet.ln_routing == 1);
730 lnet_net_unlock(lp->lp_cpt);
731 (ni->ni_lnd->lnd_query)(ni, lp->lp_nid, &last_alive);
732 lnet_net_lock(lp->lp_cpt);
734 lp->lp_last_query = cfs_time_current();
736 if (last_alive != 0) /* NI has updated timestamp */
737 lp->lp_last_alive = last_alive;
740 /* NB: always called with lnet_net_lock held */
742 lnet_peer_is_alive (lnet_peer_t *lp, cfs_time_t now)
747 LASSERT (lnet_peer_aliveness_enabled(lp));
748 LASSERT (the_lnet.ln_routing == 1);
750 /* Trust lnet_notify() if it has more recent aliveness news, but
751 * ignore the initial assumed death (see lnet_peers_start_down()).
753 if (!lp->lp_alive && lp->lp_alive_count > 0 &&
754 cfs_time_aftereq(lp->lp_timestamp, lp->lp_last_alive))
757 deadline = cfs_time_add(lp->lp_last_alive,
758 cfs_time_seconds(lp->lp_ni->ni_peertimeout));
759 alive = cfs_time_after(deadline, now);
761 /* Update obsolete lp_alive except for routers assumed to be dead
762 * initially, because router checker would update aliveness in this
763 * case, and moreover lp_last_alive at peer creation is assumed.
765 if (alive && !lp->lp_alive &&
766 !(lnet_isrouter(lp) && lp->lp_alive_count == 0))
767 lnet_notify_locked(lp, 0, 1, lp->lp_last_alive);
773 /* NB: returns 1 when alive, 0 when dead, negative when error;
774 * may drop the lnet_net_lock */
776 lnet_peer_alive_locked (lnet_peer_t *lp)
778 cfs_time_t now = cfs_time_current();
780 /* LU-630: only router checks peer health. */
781 if (the_lnet.ln_routing == 0)
784 if (!lnet_peer_aliveness_enabled(lp))
787 if (lnet_peer_is_alive(lp, now))
790 /* Peer appears dead, but we should avoid frequent NI queries (at
791 * most once per lnet_queryinterval seconds). */
792 if (lp->lp_last_query != 0) {
793 static const int lnet_queryinterval = 1;
795 cfs_time_t next_query =
796 cfs_time_add(lp->lp_last_query,
797 cfs_time_seconds(lnet_queryinterval));
799 if (cfs_time_before(now, next_query)) {
801 CWARN("Unexpected aliveness of peer %s: "
803 libcfs_nid2str(lp->lp_nid),
804 (int)now, (int)next_query,
806 lp->lp_ni->ni_peertimeout);
811 /* query NI for latest aliveness news */
812 lnet_ni_query_locked(lp->lp_ni, lp);
814 if (lnet_peer_is_alive(lp, now))
817 lnet_notify_locked(lp, 0, 0, lp->lp_last_alive);
822 lnet_post_send_locked(lnet_msg_t *msg, int do_send)
824 /* lnet_send is going to lnet_net_unlock immediately after this,
825 * so it sets do_send FALSE and I don't do the unlock/send/lock bit.
826 * I return EAGAIN if msg blocked, EHOSTUNREACH if msg_txpeer
827 * appears dead, and 0 if sent or OK to send */
828 struct lnet_peer *lp = msg->msg_txpeer;
829 struct lnet_ni *ni = lp->lp_ni;
830 struct lnet_tx_queue *tq;
833 /* non-lnet_send() callers have checked before */
834 LASSERT(!do_send || msg->msg_tx_delayed);
835 LASSERT(!msg->msg_receiving);
836 LASSERT(msg->msg_tx_committed);
838 cpt = msg->msg_tx_cpt;
839 tq = ni->ni_tx_queues[cpt];
841 /* NB 'lp' is always the next hop */
842 if ((msg->msg_target.pid & LNET_PID_USERFLAG) == 0 &&
843 lnet_peer_alive_locked(lp) == 0) {
844 the_lnet.ln_counters[cpt]->drop_count++;
845 the_lnet.ln_counters[cpt]->drop_length += msg->msg_len;
846 lnet_net_unlock(cpt);
848 CNETERR("Dropping message for %s: peer not alive\n",
849 libcfs_id2str(msg->msg_target));
851 lnet_finalize(ni, msg, -EHOSTUNREACH);
857 if (!msg->msg_peertxcredit) {
858 LASSERT ((lp->lp_txcredits < 0) ==
859 !cfs_list_empty(&lp->lp_txq));
861 msg->msg_peertxcredit = 1;
862 lp->lp_txqnob += msg->msg_len + sizeof(lnet_hdr_t);
865 if (lp->lp_txcredits < lp->lp_mintxcredits)
866 lp->lp_mintxcredits = lp->lp_txcredits;
868 if (lp->lp_txcredits < 0) {
869 msg->msg_tx_delayed = 1;
870 cfs_list_add_tail(&msg->msg_list, &lp->lp_txq);
875 if (!msg->msg_txcredit) {
876 LASSERT((tq->tq_credits < 0) ==
877 !cfs_list_empty(&tq->tq_delayed));
879 msg->msg_txcredit = 1;
882 if (tq->tq_credits < tq->tq_credits_min)
883 tq->tq_credits_min = tq->tq_credits;
885 if (tq->tq_credits < 0) {
886 msg->msg_tx_delayed = 1;
887 cfs_list_add_tail(&msg->msg_list, &tq->tq_delayed);
893 lnet_net_unlock(cpt);
894 lnet_ni_send(ni, msg);
903 lnet_msg2bufpool(lnet_msg_t *msg)
905 lnet_rtrbufpool_t *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 * CFS_PAGE_SIZE) {
916 LASSERT(rbp < &the_lnet.ln_rtrpools[cpt][LNET_NRBPOOLS]);
923 lnet_post_routed_recv_locked (lnet_msg_t *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. I
927 * return EAGAIN if msg blocked and 0 if received or OK to receive */
928 lnet_peer_t *lp = msg->msg_rxpeer;
929 lnet_rtrbufpool_t *rbp;
932 LASSERT (msg->msg_iov == NULL);
933 LASSERT (msg->msg_kiov == NULL);
934 LASSERT (msg->msg_niov == 0);
935 LASSERT (msg->msg_routing);
936 LASSERT (msg->msg_receiving);
937 LASSERT (!msg->msg_sending);
939 /* non-lnet_parse callers only receive delayed messages */
940 LASSERT(!do_recv || msg->msg_rx_delayed);
942 if (!msg->msg_peerrtrcredit) {
943 LASSERT ((lp->lp_rtrcredits < 0) ==
944 !cfs_list_empty(&lp->lp_rtrq));
946 msg->msg_peerrtrcredit = 1;
948 if (lp->lp_rtrcredits < lp->lp_minrtrcredits)
949 lp->lp_minrtrcredits = lp->lp_rtrcredits;
951 if (lp->lp_rtrcredits < 0) {
952 /* must have checked eager_recv before here */
953 LASSERT(msg->msg_rx_ready_delay);
954 msg->msg_rx_delayed = 1;
955 cfs_list_add_tail(&msg->msg_list, &lp->lp_rtrq);
960 rbp = lnet_msg2bufpool(msg);
962 if (!msg->msg_rtrcredit) {
963 LASSERT ((rbp->rbp_credits < 0) ==
964 !cfs_list_empty(&rbp->rbp_msgs));
966 msg->msg_rtrcredit = 1;
968 if (rbp->rbp_credits < rbp->rbp_mincredits)
969 rbp->rbp_mincredits = rbp->rbp_credits;
971 if (rbp->rbp_credits < 0) {
972 /* must have checked eager_recv before here */
973 LASSERT(msg->msg_rx_ready_delay);
974 msg->msg_rx_delayed = 1;
975 cfs_list_add_tail(&msg->msg_list, &rbp->rbp_msgs);
980 LASSERT (!cfs_list_empty(&rbp->rbp_bufs));
981 rb = cfs_list_entry(rbp->rbp_bufs.next, lnet_rtrbuf_t, rb_list);
982 cfs_list_del(&rb->rb_list);
984 msg->msg_niov = rbp->rbp_npages;
985 msg->msg_kiov = &rb->rb_kiov[0];
988 int cpt = msg->msg_rx_cpt;
990 lnet_net_unlock(cpt);
991 lnet_ni_recv(lp->lp_ni, msg->msg_private, msg, 1,
992 0, msg->msg_len, msg->msg_len);
1000 lnet_return_tx_credits_locked(lnet_msg_t *msg)
1002 lnet_peer_t *txpeer = msg->msg_txpeer;
1005 if (msg->msg_txcredit) {
1006 struct lnet_ni *ni = txpeer->lp_ni;
1007 struct lnet_tx_queue *tq = ni->ni_tx_queues[msg->msg_tx_cpt];
1009 /* give back NI txcredits */
1010 msg->msg_txcredit = 0;
1012 LASSERT((tq->tq_credits < 0) ==
1013 !cfs_list_empty(&tq->tq_delayed));
1016 if (tq->tq_credits <= 0) {
1017 msg2 = cfs_list_entry(tq->tq_delayed.next,
1018 lnet_msg_t, msg_list);
1019 cfs_list_del(&msg2->msg_list);
1021 LASSERT(msg2->msg_txpeer->lp_ni == ni);
1022 LASSERT(msg2->msg_tx_delayed);
1024 (void) lnet_post_send_locked(msg2, 1);
1028 if (msg->msg_peertxcredit) {
1029 /* give back peer txcredits */
1030 msg->msg_peertxcredit = 0;
1032 LASSERT((txpeer->lp_txcredits < 0) ==
1033 !cfs_list_empty(&txpeer->lp_txq));
1035 txpeer->lp_txqnob -= msg->msg_len + sizeof(lnet_hdr_t);
1036 LASSERT (txpeer->lp_txqnob >= 0);
1038 txpeer->lp_txcredits++;
1039 if (txpeer->lp_txcredits <= 0) {
1040 msg2 = cfs_list_entry(txpeer->lp_txq.next,
1041 lnet_msg_t, msg_list);
1042 cfs_list_del(&msg2->msg_list);
1044 LASSERT(msg2->msg_txpeer == txpeer);
1045 LASSERT(msg2->msg_tx_delayed);
1047 (void) lnet_post_send_locked(msg2, 1);
1051 if (txpeer != NULL) {
1052 msg->msg_txpeer = NULL;
1053 lnet_peer_decref_locked(txpeer);
1058 lnet_return_rx_credits_locked(lnet_msg_t *msg)
1060 lnet_peer_t *rxpeer = msg->msg_rxpeer;
1064 if (msg->msg_rtrcredit) {
1065 /* give back global router credits */
1067 lnet_rtrbufpool_t *rbp;
1069 /* NB If a msg ever blocks for a buffer in rbp_msgs, it stays
1070 * there until it gets one allocated, or aborts the wait
1072 LASSERT (msg->msg_kiov != NULL);
1074 rb = cfs_list_entry(msg->msg_kiov, lnet_rtrbuf_t, rb_kiov[0]);
1076 LASSERT (rbp == lnet_msg2bufpool(msg));
1078 msg->msg_kiov = NULL;
1079 msg->msg_rtrcredit = 0;
1081 LASSERT((rbp->rbp_credits < 0) ==
1082 !cfs_list_empty(&rbp->rbp_msgs));
1083 LASSERT((rbp->rbp_credits > 0) ==
1084 !cfs_list_empty(&rbp->rbp_bufs));
1086 cfs_list_add(&rb->rb_list, &rbp->rbp_bufs);
1088 if (rbp->rbp_credits <= 0) {
1089 msg2 = cfs_list_entry(rbp->rbp_msgs.next,
1090 lnet_msg_t, msg_list);
1091 cfs_list_del(&msg2->msg_list);
1093 (void) lnet_post_routed_recv_locked(msg2, 1);
1097 if (msg->msg_peerrtrcredit) {
1098 /* give back peer router credits */
1099 msg->msg_peerrtrcredit = 0;
1101 LASSERT((rxpeer->lp_rtrcredits < 0) ==
1102 !cfs_list_empty(&rxpeer->lp_rtrq));
1104 rxpeer->lp_rtrcredits++;
1105 if (rxpeer->lp_rtrcredits <= 0) {
1106 msg2 = cfs_list_entry(rxpeer->lp_rtrq.next,
1107 lnet_msg_t, msg_list);
1108 cfs_list_del(&msg2->msg_list);
1110 (void) lnet_post_routed_recv_locked(msg2, 1);
1114 LASSERT (!msg->msg_rtrcredit);
1115 LASSERT (!msg->msg_peerrtrcredit);
1117 if (rxpeer != NULL) {
1118 msg->msg_rxpeer = NULL;
1119 lnet_peer_decref_locked(rxpeer);
1124 lnet_compare_routes(lnet_route_t *r1, lnet_route_t *r2)
1126 lnet_peer_t *p1 = r1->lr_gateway;
1127 lnet_peer_t *p2 = r2->lr_gateway;
1129 if (r1->lr_hops < r2->lr_hops)
1132 if (r1->lr_hops > r2->lr_hops)
1135 if (p1->lp_txqnob < p2->lp_txqnob)
1138 if (p1->lp_txqnob > p2->lp_txqnob)
1141 if (p1->lp_txcredits > p2->lp_txcredits)
1144 if (p1->lp_txcredits < p2->lp_txcredits)
1147 if (r1->lr_seq - r2->lr_seq <= 0)
1153 static lnet_peer_t *
1154 lnet_find_route_locked(lnet_ni_t *ni, lnet_nid_t target, lnet_nid_t rtr_nid)
1156 lnet_remotenet_t *rnet;
1158 lnet_route_t *rtr_best;
1159 lnet_route_t *rtr_last;
1160 struct lnet_peer *lp_best;
1161 struct lnet_peer *lp;
1164 /* If @rtr_nid is not LNET_NID_ANY, return the gateway with
1165 * rtr_nid nid, otherwise find the best gateway I can use */
1167 rnet = lnet_find_net_locked(LNET_NIDNET(target));
1172 rtr_best = rtr_last = NULL;
1173 cfs_list_for_each_entry(rtr, &rnet->lrn_routes, lr_list) {
1174 lp = rtr->lr_gateway;
1176 if (!lp->lp_alive || /* gateway is down */
1177 ((lp->lp_ping_feats & LNET_PING_FEAT_NI_STATUS) != 0 &&
1178 rtr->lr_downis != 0)) /* NI to target is down */
1181 if (ni != NULL && lp->lp_ni != ni)
1184 if (lp->lp_nid == rtr_nid) /* it's pre-determined router */
1187 if (lp_best == NULL) {
1188 rtr_best = rtr_last = rtr;
1193 /* no protection on below fields, but it's harmless */
1194 if (rtr_last->lr_seq - rtr->lr_seq < 0)
1197 rc = lnet_compare_routes(rtr, rtr_best);
1205 /* set sequence number on the best router to the latest sequence + 1
1206 * so we can round-robin all routers, it's race and inaccurate but
1207 * harmless and functional */
1208 if (rtr_best != NULL)
1209 rtr_best->lr_seq = rtr_last->lr_seq + 1;
1214 lnet_send(lnet_nid_t src_nid, lnet_msg_t *msg, lnet_nid_t rtr_nid)
1216 lnet_nid_t dst_nid = msg->msg_target.nid;
1217 struct lnet_ni *src_ni;
1218 struct lnet_ni *local_ni;
1219 struct lnet_peer *lp;
1224 /* NB: rtr_nid is set to LNET_NID_ANY for all current use-cases,
1225 * but we might want to use pre-determined router for ACK/REPLY
1227 /* NB: ni != NULL == interface pre-determined (ACK/REPLY) */
1228 LASSERT (msg->msg_txpeer == NULL);
1229 LASSERT (!msg->msg_sending);
1230 LASSERT (!msg->msg_target_is_router);
1231 LASSERT (!msg->msg_receiving);
1233 msg->msg_sending = 1;
1235 LASSERT(!msg->msg_tx_committed);
1236 cpt = lnet_cpt_of_nid(rtr_nid == LNET_NID_ANY ? dst_nid : rtr_nid);
1240 if (the_lnet.ln_shutdown) {
1241 lnet_net_unlock(cpt);
1245 if (src_nid == LNET_NID_ANY) {
1248 src_ni = lnet_nid2ni_locked(src_nid, cpt);
1249 if (src_ni == NULL) {
1250 lnet_net_unlock(cpt);
1251 LCONSOLE_WARN("Can't send to %s: src %s is not a "
1252 "local nid\n", libcfs_nid2str(dst_nid),
1253 libcfs_nid2str(src_nid));
1256 LASSERT (!msg->msg_routing);
1259 /* Is this for someone on a local network? */
1260 local_ni = lnet_net2ni_locked(LNET_NIDNET(dst_nid), cpt);
1262 if (local_ni != NULL) {
1263 if (src_ni == NULL) {
1265 src_nid = src_ni->ni_nid;
1266 } else if (src_ni == local_ni) {
1267 lnet_ni_decref_locked(local_ni, cpt);
1269 lnet_ni_decref_locked(local_ni, cpt);
1270 lnet_ni_decref_locked(src_ni, cpt);
1271 lnet_net_unlock(cpt);
1272 LCONSOLE_WARN("No route to %s via from %s\n",
1273 libcfs_nid2str(dst_nid),
1274 libcfs_nid2str(src_nid));
1278 LASSERT(src_nid != LNET_NID_ANY);
1279 lnet_msg_commit(msg, cpt);
1281 if (!msg->msg_routing)
1282 msg->msg_hdr.src_nid = cpu_to_le64(src_nid);
1284 if (src_ni == the_lnet.ln_loni) {
1285 /* No send credit hassles with LOLND */
1286 lnet_net_unlock(cpt);
1287 lnet_ni_send(src_ni, msg);
1290 lnet_ni_decref_locked(src_ni, cpt);
1291 lnet_net_unlock(cpt);
1295 rc = lnet_nid2peer_locked(&lp, dst_nid, cpt);
1296 /* lp has ref on src_ni; lose mine */
1297 lnet_ni_decref_locked(src_ni, cpt);
1299 lnet_net_unlock(cpt);
1300 LCONSOLE_WARN("Error %d finding peer %s\n", rc,
1301 libcfs_nid2str(dst_nid));
1302 /* ENOMEM or shutting down */
1305 LASSERT (lp->lp_ni == src_ni);
1308 lnet_net_unlock(cpt);
1311 * - once application finishes computation, check here to update
1312 * router states before it waits for pending IO in LNetEQPoll
1313 * - recursion breaker: router checker sends no message
1314 * to remote networks */
1315 if (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING)
1316 lnet_router_checker();
1320 /* sending to a remote network */
1321 lp = lnet_find_route_locked(src_ni, dst_nid, rtr_nid);
1324 lnet_ni_decref_locked(src_ni, cpt);
1325 lnet_net_unlock(cpt);
1327 LCONSOLE_WARN("No route to %s via %s "
1328 "(all routers down)\n",
1329 libcfs_id2str(msg->msg_target),
1330 libcfs_nid2str(src_nid));
1331 return -EHOSTUNREACH;
1334 /* rtr_nid is LNET_NID_ANY or NID of pre-determined router,
1335 * it's possible that rtr_nid isn't LNET_NID_ANY and lp isn't
1336 * pre-determined router, this can happen if router table
1337 * was changed when we release the lock */
1338 if (rtr_nid != lp->lp_nid) {
1339 cpt2 = lnet_cpt_of_nid_locked(lp->lp_nid);
1342 lnet_ni_decref_locked(src_ni, cpt);
1343 lnet_net_unlock(cpt);
1345 rtr_nid = lp->lp_nid;
1351 CDEBUG(D_NET, "Best route to %s via %s for %s %d\n",
1352 libcfs_nid2str(dst_nid), libcfs_nid2str(lp->lp_nid),
1353 lnet_msgtyp2str(msg->msg_type), msg->msg_len);
1355 if (src_ni == NULL) {
1357 src_nid = src_ni->ni_nid;
1359 LASSERT (src_ni == lp->lp_ni);
1360 lnet_ni_decref_locked(src_ni, cpt);
1363 lnet_peer_addref_locked(lp);
1365 LASSERT(src_nid != LNET_NID_ANY);
1366 lnet_msg_commit(msg, cpt);
1368 if (!msg->msg_routing) {
1369 /* I'm the source and now I know which NI to send on */
1370 msg->msg_hdr.src_nid = cpu_to_le64(src_nid);
1373 msg->msg_target_is_router = 1;
1374 msg->msg_target.nid = lp->lp_nid;
1375 msg->msg_target.pid = LUSTRE_SRV_LNET_PID;
1378 /* 'lp' is our best choice of peer */
1380 LASSERT (!msg->msg_peertxcredit);
1381 LASSERT (!msg->msg_txcredit);
1382 LASSERT (msg->msg_txpeer == NULL);
1384 msg->msg_txpeer = lp; /* msg takes my ref on lp */
1386 rc = lnet_post_send_locked(msg, 0);
1387 lnet_net_unlock(cpt);
1389 if (rc == EHOSTUNREACH)
1390 return -EHOSTUNREACH;
1393 lnet_ni_send(src_ni, msg);
1399 lnet_drop_message(lnet_ni_t *ni, int cpt, void *private, unsigned int nob)
1402 the_lnet.ln_counters[cpt]->drop_count++;
1403 the_lnet.ln_counters[cpt]->drop_length += nob;
1404 lnet_net_unlock(cpt);
1406 lnet_ni_recv(ni, private, NULL, 0, 0, 0, nob);
1410 lnet_recv_put(lnet_ni_t *ni, lnet_msg_t *msg)
1412 lnet_hdr_t *hdr = &msg->msg_hdr;
1414 if (msg->msg_wanted != 0)
1415 lnet_setpayloadbuffer(msg);
1417 lnet_build_msg_event(msg, LNET_EVENT_PUT);
1419 /* Must I ACK? If so I'll grab the ack_wmd out of the header and put
1420 * it back into the ACK during lnet_finalize() */
1421 msg->msg_ack = (!lnet_is_wire_handle_none(&hdr->msg.put.ack_wmd) &&
1422 (msg->msg_md->md_options & LNET_MD_ACK_DISABLE) == 0);
1424 lnet_ni_recv(ni, msg->msg_private, msg, msg->msg_rx_delayed,
1425 msg->msg_offset, msg->msg_wanted, hdr->payload_length);
1429 lnet_parse_put(lnet_ni_t *ni, lnet_msg_t *msg)
1431 lnet_hdr_t *hdr = &msg->msg_hdr;
1432 struct lnet_match_info info;
1435 /* Convert put fields to host byte order */
1436 hdr->msg.put.match_bits = le64_to_cpu(hdr->msg.put.match_bits);
1437 hdr->msg.put.ptl_index = le32_to_cpu(hdr->msg.put.ptl_index);
1438 hdr->msg.put.offset = le32_to_cpu(hdr->msg.put.offset);
1440 info.mi_id.nid = hdr->src_nid;
1441 info.mi_id.pid = hdr->src_pid;
1442 info.mi_opc = LNET_MD_OP_PUT;
1443 info.mi_portal = hdr->msg.put.ptl_index;
1444 info.mi_rlength = hdr->payload_length;
1445 info.mi_roffset = hdr->msg.put.offset;
1446 info.mi_mbits = hdr->msg.put.match_bits;
1448 msg->msg_rx_ready_delay = ni->ni_lnd->lnd_eager_recv == NULL;
1451 rc = lnet_ptl_match_md(&info, msg);
1456 case LNET_MATCHMD_OK:
1457 lnet_recv_put(ni, msg);
1460 case LNET_MATCHMD_NONE:
1461 if (msg->msg_rx_delayed) /* attached on delayed list */
1464 rc = lnet_ni_eager_recv(ni, msg);
1469 case LNET_MATCHMD_DROP:
1470 CNETERR("Dropping PUT from %s portal %d match "LPU64
1471 " offset %d length %d: %d\n",
1472 libcfs_id2str(info.mi_id), info.mi_portal,
1473 info.mi_mbits, info.mi_roffset, info.mi_rlength, rc);
1475 return ENOENT; /* +ve: OK but no match */
1480 lnet_parse_get(lnet_ni_t *ni, lnet_msg_t *msg, int rdma_get)
1482 struct lnet_match_info info;
1483 lnet_hdr_t *hdr = &msg->msg_hdr;
1484 lnet_handle_wire_t reply_wmd;
1487 /* Convert get fields to host byte order */
1488 hdr->msg.get.match_bits = le64_to_cpu(hdr->msg.get.match_bits);
1489 hdr->msg.get.ptl_index = le32_to_cpu(hdr->msg.get.ptl_index);
1490 hdr->msg.get.sink_length = le32_to_cpu(hdr->msg.get.sink_length);
1491 hdr->msg.get.src_offset = le32_to_cpu(hdr->msg.get.src_offset);
1493 info.mi_id.nid = hdr->src_nid;
1494 info.mi_id.pid = hdr->src_pid;
1495 info.mi_opc = LNET_MD_OP_GET;
1496 info.mi_portal = hdr->msg.get.ptl_index;
1497 info.mi_rlength = hdr->msg.get.sink_length;
1498 info.mi_roffset = hdr->msg.get.src_offset;
1499 info.mi_mbits = hdr->msg.get.match_bits;
1501 rc = lnet_ptl_match_md(&info, msg);
1502 if (rc == LNET_MATCHMD_DROP) {
1503 CNETERR("Dropping GET from %s portal %d match "LPU64
1504 " offset %d length %d\n",
1505 libcfs_id2str(info.mi_id), info.mi_portal,
1506 info.mi_mbits, info.mi_roffset, info.mi_rlength);
1507 return ENOENT; /* +ve: OK but no match */
1510 LASSERT(rc == LNET_MATCHMD_OK);
1512 lnet_build_msg_event(msg, LNET_EVENT_GET);
1514 reply_wmd = hdr->msg.get.return_wmd;
1516 lnet_prep_send(msg, LNET_MSG_REPLY, info.mi_id,
1517 msg->msg_offset, msg->msg_wanted);
1519 msg->msg_hdr.msg.reply.dst_wmd = reply_wmd;
1522 /* The LND completes the REPLY from her recv procedure */
1523 lnet_ni_recv(ni, msg->msg_private, msg, 0,
1524 msg->msg_offset, msg->msg_len, msg->msg_len);
1528 lnet_ni_recv(ni, msg->msg_private, NULL, 0, 0, 0, 0);
1529 msg->msg_receiving = 0;
1531 rc = lnet_send(ni->ni_nid, msg, LNET_NID_ANY);
1533 /* didn't get as far as lnet_ni_send() */
1534 CERROR("%s: Unable to send REPLY for GET from %s: %d\n",
1535 libcfs_nid2str(ni->ni_nid),
1536 libcfs_id2str(info.mi_id), rc);
1538 lnet_finalize(ni, msg, rc);
1545 lnet_parse_reply(lnet_ni_t *ni, lnet_msg_t *msg)
1547 void *private = msg->msg_private;
1548 lnet_hdr_t *hdr = &msg->msg_hdr;
1549 lnet_process_id_t src = {0};
1555 cpt = lnet_cpt_of_cookie(hdr->msg.reply.dst_wmd.wh_object_cookie);
1558 src.nid = hdr->src_nid;
1559 src.pid = hdr->src_pid;
1561 /* NB handles only looked up by creator (no flips) */
1562 md = lnet_wire_handle2md(&hdr->msg.reply.dst_wmd);
1563 if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) {
1564 CNETERR("%s: Dropping REPLY from %s for %s "
1565 "MD "LPX64"."LPX64"\n",
1566 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
1567 (md == NULL) ? "invalid" : "inactive",
1568 hdr->msg.reply.dst_wmd.wh_interface_cookie,
1569 hdr->msg.reply.dst_wmd.wh_object_cookie);
1570 if (md != NULL && md->md_me != NULL)
1571 CERROR("REPLY MD also attached to portal %d\n",
1572 md->md_me->me_portal);
1574 lnet_res_unlock(cpt);
1575 return ENOENT; /* +ve: OK but no match */
1578 LASSERT (md->md_offset == 0);
1580 rlength = hdr->payload_length;
1581 mlength = MIN(rlength, (int)md->md_length);
1583 if (mlength < rlength &&
1584 (md->md_options & LNET_MD_TRUNCATE) == 0) {
1585 CNETERR("%s: Dropping REPLY from %s length %d "
1586 "for MD "LPX64" would overflow (%d)\n",
1587 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
1588 rlength, hdr->msg.reply.dst_wmd.wh_object_cookie,
1590 lnet_res_unlock(cpt);
1591 return ENOENT; /* +ve: OK but no match */
1594 CDEBUG(D_NET, "%s: Reply from %s of length %d/%d into md "LPX64"\n",
1595 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
1596 mlength, rlength, hdr->msg.reply.dst_wmd.wh_object_cookie);
1598 lnet_msg_attach_md(msg, md, 0, mlength);
1601 lnet_setpayloadbuffer(msg);
1603 lnet_res_unlock(cpt);
1605 lnet_build_msg_event(msg, LNET_EVENT_REPLY);
1607 lnet_ni_recv(ni, private, msg, 0, 0, mlength, rlength);
1612 lnet_parse_ack(lnet_ni_t *ni, lnet_msg_t *msg)
1614 lnet_hdr_t *hdr = &msg->msg_hdr;
1615 lnet_process_id_t src = {0};
1619 src.nid = hdr->src_nid;
1620 src.pid = hdr->src_pid;
1622 /* Convert ack fields to host byte order */
1623 hdr->msg.ack.match_bits = le64_to_cpu(hdr->msg.ack.match_bits);
1624 hdr->msg.ack.mlength = le32_to_cpu(hdr->msg.ack.mlength);
1626 cpt = lnet_cpt_of_cookie(hdr->msg.ack.dst_wmd.wh_object_cookie);
1629 /* NB handles only looked up by creator (no flips) */
1630 md = lnet_wire_handle2md(&hdr->msg.ack.dst_wmd);
1631 if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) {
1632 /* Don't moan; this is expected */
1634 "%s: Dropping ACK from %s to %s MD "LPX64"."LPX64"\n",
1635 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
1636 (md == NULL) ? "invalid" : "inactive",
1637 hdr->msg.ack.dst_wmd.wh_interface_cookie,
1638 hdr->msg.ack.dst_wmd.wh_object_cookie);
1639 if (md != NULL && md->md_me != NULL)
1640 CERROR("Source MD also attached to portal %d\n",
1641 md->md_me->me_portal);
1643 lnet_res_unlock(cpt);
1644 return ENOENT; /* +ve! */
1647 CDEBUG(D_NET, "%s: ACK from %s into md "LPX64"\n",
1648 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
1649 hdr->msg.ack.dst_wmd.wh_object_cookie);
1651 lnet_msg_attach_md(msg, md, 0, 0);
1653 lnet_res_unlock(cpt);
1655 lnet_build_msg_event(msg, LNET_EVENT_ACK);
1657 lnet_ni_recv(ni, msg->msg_private, msg, 0, 0, 0, msg->msg_len);
1662 lnet_parse_forward_locked(lnet_ni_t *ni, lnet_msg_t *msg)
1667 if (msg->msg_rxpeer->lp_rtrcredits <= 0 ||
1668 lnet_msg2bufpool(msg)->rbp_credits <= 0) {
1669 if (ni->ni_lnd->lnd_eager_recv == NULL) {
1670 msg->msg_rx_ready_delay = 1;
1672 lnet_net_unlock(msg->msg_rx_cpt);
1673 rc = lnet_ni_eager_recv(ni, msg);
1674 lnet_net_lock(msg->msg_rx_cpt);
1679 rc = lnet_post_routed_recv_locked(msg, 0);
1687 lnet_msgtyp2str (int type)
1696 case LNET_MSG_REPLY:
1698 case LNET_MSG_HELLO:
1701 return ("<UNKNOWN>");
1704 EXPORT_SYMBOL(lnet_msgtyp2str);
1707 lnet_print_hdr(lnet_hdr_t * hdr)
1709 lnet_process_id_t src = {0};
1710 lnet_process_id_t dst = {0};
1711 char *type_str = lnet_msgtyp2str (hdr->type);
1713 src.nid = hdr->src_nid;
1714 src.pid = hdr->src_pid;
1716 dst.nid = hdr->dest_nid;
1717 dst.pid = hdr->dest_pid;
1719 CWARN("P3 Header at %p of type %s\n", hdr, type_str);
1720 CWARN(" From %s\n", libcfs_id2str(src));
1721 CWARN(" To %s\n", libcfs_id2str(dst));
1723 switch (hdr->type) {
1728 CWARN(" Ptl index %d, ack md "LPX64"."LPX64", "
1729 "match bits "LPU64"\n",
1730 hdr->msg.put.ptl_index,
1731 hdr->msg.put.ack_wmd.wh_interface_cookie,
1732 hdr->msg.put.ack_wmd.wh_object_cookie,
1733 hdr->msg.put.match_bits);
1734 CWARN(" Length %d, offset %d, hdr data "LPX64"\n",
1735 hdr->payload_length, hdr->msg.put.offset,
1736 hdr->msg.put.hdr_data);
1740 CWARN(" Ptl index %d, return md "LPX64"."LPX64", "
1741 "match bits "LPU64"\n", hdr->msg.get.ptl_index,
1742 hdr->msg.get.return_wmd.wh_interface_cookie,
1743 hdr->msg.get.return_wmd.wh_object_cookie,
1744 hdr->msg.get.match_bits);
1745 CWARN(" Length %d, src offset %d\n",
1746 hdr->msg.get.sink_length,
1747 hdr->msg.get.src_offset);
1751 CWARN(" dst md "LPX64"."LPX64", "
1752 "manipulated length %d\n",
1753 hdr->msg.ack.dst_wmd.wh_interface_cookie,
1754 hdr->msg.ack.dst_wmd.wh_object_cookie,
1755 hdr->msg.ack.mlength);
1758 case LNET_MSG_REPLY:
1759 CWARN(" dst md "LPX64"."LPX64", "
1761 hdr->msg.reply.dst_wmd.wh_interface_cookie,
1762 hdr->msg.reply.dst_wmd.wh_object_cookie,
1763 hdr->payload_length);
1769 lnet_parse(lnet_ni_t *ni, lnet_hdr_t *hdr, lnet_nid_t from_nid,
1770 void *private, int rdma_req)
1775 struct lnet_msg *msg;
1776 lnet_pid_t dest_pid;
1777 lnet_nid_t dest_nid;
1779 __u32 payload_length;
1782 LASSERT (!cfs_in_interrupt ());
1784 type = le32_to_cpu(hdr->type);
1785 src_nid = le64_to_cpu(hdr->src_nid);
1786 dest_nid = le64_to_cpu(hdr->dest_nid);
1787 dest_pid = le32_to_cpu(hdr->dest_pid);
1788 payload_length = le32_to_cpu(hdr->payload_length);
1790 for_me = (ni->ni_nid == dest_nid);
1791 cpt = lnet_cpt_of_nid(from_nid);
1796 if (payload_length > 0) {
1797 CERROR("%s, src %s: bad %s payload %d (0 expected)\n",
1798 libcfs_nid2str(from_nid),
1799 libcfs_nid2str(src_nid),
1800 lnet_msgtyp2str(type), payload_length);
1806 case LNET_MSG_REPLY:
1807 if (payload_length > (__u32)(for_me ? LNET_MAX_PAYLOAD : LNET_MTU)) {
1808 CERROR("%s, src %s: bad %s payload %d "
1809 "(%d max expected)\n",
1810 libcfs_nid2str(from_nid),
1811 libcfs_nid2str(src_nid),
1812 lnet_msgtyp2str(type),
1814 for_me ? LNET_MAX_PAYLOAD : LNET_MTU);
1820 CERROR("%s, src %s: Bad message type 0x%x\n",
1821 libcfs_nid2str(from_nid),
1822 libcfs_nid2str(src_nid), type);
1826 if (the_lnet.ln_routing &&
1827 ni->ni_last_alive != cfs_time_current_sec()) {
1830 /* NB: so far here is the only place to set NI status to "up */
1831 ni->ni_last_alive = cfs_time_current_sec();
1832 if (ni->ni_status != NULL &&
1833 ni->ni_status->ns_status == LNET_NI_STATUS_DOWN)
1834 ni->ni_status->ns_status = LNET_NI_STATUS_UP;
1838 /* Regard a bad destination NID as a protocol error. Senders should
1839 * know what they're doing; if they don't they're misconfigured, buggy
1840 * or malicious so we chop them off at the knees :) */
1843 if (LNET_NIDNET(dest_nid) == LNET_NIDNET(ni->ni_nid)) {
1844 /* should have gone direct */
1845 CERROR ("%s, src %s: Bad dest nid %s "
1846 "(should have been sent direct)\n",
1847 libcfs_nid2str(from_nid),
1848 libcfs_nid2str(src_nid),
1849 libcfs_nid2str(dest_nid));
1853 if (lnet_islocalnid(dest_nid)) {
1854 /* dest is another local NI; sender should have used
1855 * this node's NID on its own network */
1856 CERROR ("%s, src %s: Bad dest nid %s "
1857 "(it's my nid but on a different network)\n",
1858 libcfs_nid2str(from_nid),
1859 libcfs_nid2str(src_nid),
1860 libcfs_nid2str(dest_nid));
1864 if (rdma_req && type == LNET_MSG_GET) {
1865 CERROR ("%s, src %s: Bad optimized GET for %s "
1866 "(final destination must be me)\n",
1867 libcfs_nid2str(from_nid),
1868 libcfs_nid2str(src_nid),
1869 libcfs_nid2str(dest_nid));
1873 if (!the_lnet.ln_routing) {
1874 CERROR ("%s, src %s: Dropping message for %s "
1875 "(routing not enabled)\n",
1876 libcfs_nid2str(from_nid),
1877 libcfs_nid2str(src_nid),
1878 libcfs_nid2str(dest_nid));
1883 /* Message looks OK; we're not going to return an error, so we MUST
1884 * call back lnd_recv() come what may... */
1886 if (!cfs_list_empty (&the_lnet.ln_test_peers) && /* normally we don't */
1887 fail_peer (src_nid, 0)) /* shall we now? */
1889 CERROR("%s, src %s: Dropping %s to simulate failure\n",
1890 libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
1891 lnet_msgtyp2str(type));
1895 msg = lnet_msg_alloc();
1897 CERROR("%s, src %s: Dropping %s (out of memory)\n",
1898 libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
1899 lnet_msgtyp2str(type));
1903 /* msg zeroed in lnet_msg_alloc; i.e. flags all clear, pointers NULL etc */
1905 msg->msg_type = type;
1906 msg->msg_private = private;
1907 msg->msg_receiving = 1;
1908 msg->msg_len = msg->msg_wanted = payload_length;
1909 msg->msg_offset = 0;
1910 msg->msg_hdr = *hdr;
1911 /* for building message event */
1912 msg->msg_from = from_nid;
1914 msg->msg_target.pid = dest_pid;
1915 msg->msg_target.nid = dest_nid;
1916 msg->msg_routing = 1;
1919 /* convert common msg->hdr fields to host byteorder */
1920 msg->msg_hdr.type = type;
1921 msg->msg_hdr.src_nid = src_nid;
1922 msg->msg_hdr.src_pid = le32_to_cpu(msg->msg_hdr.src_pid);
1923 msg->msg_hdr.dest_nid = dest_nid;
1924 msg->msg_hdr.dest_pid = dest_pid;
1925 msg->msg_hdr.payload_length = payload_length;
1929 rc = lnet_nid2peer_locked(&msg->msg_rxpeer, from_nid, cpt);
1931 lnet_net_unlock(cpt);
1932 CERROR("%s, src %s: Dropping %s "
1933 "(error %d looking up sender)\n",
1934 libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
1935 lnet_msgtyp2str(type), rc);
1940 lnet_msg_commit(msg, cpt);
1943 rc = lnet_parse_forward_locked(ni, msg);
1944 lnet_net_unlock(cpt);
1949 lnet_ni_recv(ni, msg->msg_private, msg, 0,
1950 0, payload_length, payload_length);
1955 lnet_net_unlock(cpt);
1959 rc = lnet_parse_ack(ni, msg);
1962 rc = lnet_parse_put(ni, msg);
1965 rc = lnet_parse_get(ni, msg, rdma_req);
1967 case LNET_MSG_REPLY:
1968 rc = lnet_parse_reply(ni, msg);
1973 goto free_drop; /* prevent an unused label if !kernel */
1979 LASSERT (rc == ENOENT);
1982 LASSERT(msg->msg_md == NULL);
1983 lnet_finalize(ni, msg, rc);
1986 lnet_drop_message(ni, cpt, private, payload_length);
1989 EXPORT_SYMBOL(lnet_parse);
1992 lnet_drop_delayed_msg_list(cfs_list_t *head, char *reason)
1994 while (!cfs_list_empty(head)) {
1995 lnet_process_id_t id = {0};
1998 msg = cfs_list_entry(head->next, lnet_msg_t, msg_list);
1999 cfs_list_del(&msg->msg_list);
2001 id.nid = msg->msg_hdr.src_nid;
2002 id.pid = msg->msg_hdr.src_pid;
2004 LASSERT(msg->msg_md == NULL);
2005 LASSERT(msg->msg_rx_delayed);
2006 LASSERT(msg->msg_rxpeer != NULL);
2007 LASSERT(msg->msg_hdr.type == LNET_MSG_PUT);
2009 CWARN("Dropping delayed PUT from %s portal %d match "LPU64
2010 " offset %d length %d: %s\n",
2012 msg->msg_hdr.msg.put.ptl_index,
2013 msg->msg_hdr.msg.put.match_bits,
2014 msg->msg_hdr.msg.put.offset,
2015 msg->msg_hdr.payload_length, reason);
2017 /* NB I can't drop msg's ref on msg_rxpeer until after I've
2018 * called lnet_drop_message(), so I just hang onto msg as well
2019 * until that's done */
2021 lnet_drop_message(msg->msg_rxpeer->lp_ni,
2022 msg->msg_rxpeer->lp_cpt,
2023 msg->msg_private, msg->msg_len);
2025 * NB: message will not generate event because w/o attached MD,
2026 * but we still should give error code so lnet_msg_decommit()
2027 * can skip counters operations and other checks.
2029 lnet_finalize(msg->msg_rxpeer->lp_ni, msg, -ENOENT);
2034 lnet_recv_delayed_msg_list(cfs_list_t *head)
2036 while (!cfs_list_empty(head)) {
2038 lnet_process_id_t id;
2040 msg = cfs_list_entry(head->next, lnet_msg_t, msg_list);
2041 cfs_list_del(&msg->msg_list);
2043 /* md won't disappear under me, since each msg
2044 * holds a ref on it */
2046 id.nid = msg->msg_hdr.src_nid;
2047 id.pid = msg->msg_hdr.src_pid;
2049 LASSERT(msg->msg_rx_delayed);
2050 LASSERT(msg->msg_md != NULL);
2051 LASSERT(msg->msg_rxpeer != NULL);
2052 LASSERT(msg->msg_hdr.type == LNET_MSG_PUT);
2054 CDEBUG(D_NET, "Resuming delayed PUT from %s portal %d "
2055 "match "LPU64" offset %d length %d.\n",
2056 libcfs_id2str(id), msg->msg_hdr.msg.put.ptl_index,
2057 msg->msg_hdr.msg.put.match_bits,
2058 msg->msg_hdr.msg.put.offset,
2059 msg->msg_hdr.payload_length);
2061 lnet_recv_put(msg->msg_rxpeer->lp_ni, msg);
2066 * Initiate an asynchronous PUT operation.
2068 * There are several events associated with a PUT: completion of the send on
2069 * the initiator node (LNET_EVENT_SEND), and when the send completes
2070 * successfully, the receipt of an acknowledgment (LNET_EVENT_ACK) indicating
2071 * that the operation was accepted by the target. The event LNET_EVENT_PUT is
2072 * used at the target node to indicate the completion of incoming data
2075 * The local events will be logged in the EQ associated with the MD pointed to
2076 * by \a mdh handle. Using a MD without an associated EQ results in these
2077 * events being discarded. In this case, the caller must have another
2078 * mechanism (e.g., a higher level protocol) for determining when it is safe
2079 * to modify the memory region associated with the MD.
2081 * Note that LNet does not guarantee the order of LNET_EVENT_SEND and
2082 * LNET_EVENT_ACK, though intuitively ACK should happen after SEND.
2084 * \param self Indicates the NID of a local interface through which to send
2085 * the PUT request. Use LNET_NID_ANY to let LNet choose one by itself.
2086 * \param mdh A handle for the MD that describes the memory to be sent. The MD
2087 * must be "free floating" (See LNetMDBind()).
2088 * \param ack Controls whether an acknowledgment is requested.
2089 * Acknowledgments are only sent when they are requested by the initiating
2090 * process and the target MD enables them.
2091 * \param target A process identifier for the target process.
2092 * \param portal The index in the \a target's portal table.
2093 * \param match_bits The match bits to use for MD selection at the target
2095 * \param offset The offset into the target MD (only used when the target
2096 * MD has the LNET_MD_MANAGE_REMOTE option set).
2097 * \param hdr_data 64 bits of user data that can be included in the message
2098 * header. This data is written to an event queue entry at the target if an
2099 * EQ is present on the matching MD.
2101 * \retval 0 Success, and only in this case events will be generated
2102 * and logged to EQ (if it exists).
2103 * \retval -EIO Simulated failure.
2104 * \retval -ENOMEM Memory allocation failure.
2105 * \retval -ENOENT Invalid MD object.
2107 * \see lnet_event_t::hdr_data and lnet_event_kind_t.
2110 LNetPut(lnet_nid_t self, lnet_handle_md_t mdh, lnet_ack_req_t ack,
2111 lnet_process_id_t target, unsigned int portal,
2112 __u64 match_bits, unsigned int offset,
2115 struct lnet_msg *msg;
2116 struct lnet_libmd *md;
2120 LASSERT (the_lnet.ln_init);
2121 LASSERT (the_lnet.ln_refcount > 0);
2123 if (!cfs_list_empty (&the_lnet.ln_test_peers) && /* normally we don't */
2124 fail_peer (target.nid, 1)) /* shall we now? */
2126 CERROR("Dropping PUT to %s: simulated failure\n",
2127 libcfs_id2str(target));
2131 msg = lnet_msg_alloc();
2133 CERROR("Dropping PUT to %s: ENOMEM on lnet_msg_t\n",
2134 libcfs_id2str(target));
2137 msg->msg_vmflush = !!cfs_memory_pressure_get();
2139 cpt = lnet_cpt_of_cookie(mdh.cookie);
2142 md = lnet_handle2md(&mdh);
2143 if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) {
2144 CERROR("Dropping PUT ("LPU64":%d:%s): MD (%d) invalid\n",
2145 match_bits, portal, libcfs_id2str(target),
2146 md == NULL ? -1 : md->md_threshold);
2147 if (md != NULL && md->md_me != NULL)
2148 CERROR("Source MD also attached to portal %d\n",
2149 md->md_me->me_portal);
2150 lnet_res_unlock(cpt);
2156 CDEBUG(D_NET, "LNetPut -> %s\n", libcfs_id2str(target));
2158 lnet_msg_attach_md(msg, md, 0, 0);
2160 lnet_prep_send(msg, LNET_MSG_PUT, target, 0, md->md_length);
2162 msg->msg_hdr.msg.put.match_bits = cpu_to_le64(match_bits);
2163 msg->msg_hdr.msg.put.ptl_index = cpu_to_le32(portal);
2164 msg->msg_hdr.msg.put.offset = cpu_to_le32(offset);
2165 msg->msg_hdr.msg.put.hdr_data = hdr_data;
2167 /* NB handles only looked up by creator (no flips) */
2168 if (ack == LNET_ACK_REQ) {
2169 msg->msg_hdr.msg.put.ack_wmd.wh_interface_cookie =
2170 the_lnet.ln_interface_cookie;
2171 msg->msg_hdr.msg.put.ack_wmd.wh_object_cookie =
2172 md->md_lh.lh_cookie;
2174 msg->msg_hdr.msg.put.ack_wmd.wh_interface_cookie =
2175 LNET_WIRE_HANDLE_COOKIE_NONE;
2176 msg->msg_hdr.msg.put.ack_wmd.wh_object_cookie =
2177 LNET_WIRE_HANDLE_COOKIE_NONE;
2180 lnet_res_unlock(cpt);
2182 lnet_build_msg_event(msg, LNET_EVENT_SEND);
2184 rc = lnet_send(self, msg, LNET_NID_ANY);
2186 CNETERR( "Error sending PUT to %s: %d\n",
2187 libcfs_id2str(target), rc);
2188 lnet_finalize (NULL, msg, rc);
2191 /* completion will be signalled by an event */
2194 EXPORT_SYMBOL(LNetPut);
2197 lnet_create_reply_msg (lnet_ni_t *ni, lnet_msg_t *getmsg)
2199 /* The LND can DMA direct to the GET md (i.e. no REPLY msg). This
2200 * returns a msg for the LND to pass to lnet_finalize() when the sink
2201 * data has been received.
2203 * CAVEAT EMPTOR: 'getmsg' is the original GET, which is freed when
2204 * lnet_finalize() is called on it, so the LND must call this first */
2206 struct lnet_msg *msg = lnet_msg_alloc();
2207 struct lnet_libmd *getmd = getmsg->msg_md;
2208 lnet_process_id_t peer_id = getmsg->msg_target;
2211 LASSERT(!getmsg->msg_target_is_router);
2212 LASSERT(!getmsg->msg_routing);
2214 cpt = lnet_cpt_of_cookie(getmd->md_lh.lh_cookie);
2217 LASSERT (getmd->md_refcount > 0);
2220 CERROR ("%s: Dropping REPLY from %s: can't allocate msg\n",
2221 libcfs_nid2str(ni->ni_nid), libcfs_id2str(peer_id));
2225 if (getmd->md_threshold == 0) {
2226 CERROR ("%s: Dropping REPLY from %s for inactive MD %p\n",
2227 libcfs_nid2str(ni->ni_nid), libcfs_id2str(peer_id),
2229 lnet_res_unlock(cpt);
2233 LASSERT(getmd->md_offset == 0);
2235 CDEBUG(D_NET, "%s: Reply from %s md %p\n",
2236 libcfs_nid2str(ni->ni_nid), libcfs_id2str(peer_id), getmd);
2238 /* setup information for lnet_build_msg_event */
2239 msg->msg_from = peer_id.nid;
2240 msg->msg_type = LNET_MSG_GET; /* flag this msg as an "optimized" GET */
2241 msg->msg_hdr.src_nid = peer_id.nid;
2242 msg->msg_hdr.payload_length = getmd->md_length;
2243 msg->msg_receiving = 1; /* required by lnet_msg_attach_md */
2245 lnet_msg_attach_md(msg, getmd, getmd->md_offset, getmd->md_length);
2246 lnet_res_unlock(cpt);
2248 cpt = lnet_cpt_of_nid(peer_id.nid);
2251 lnet_msg_commit(msg, cpt);
2252 lnet_net_unlock(cpt);
2254 lnet_build_msg_event(msg, LNET_EVENT_REPLY);
2259 cpt = lnet_cpt_of_nid(peer_id.nid);
2262 the_lnet.ln_counters[cpt]->drop_count++;
2263 the_lnet.ln_counters[cpt]->drop_length += getmd->md_length;
2264 lnet_net_unlock(cpt);
2271 EXPORT_SYMBOL(lnet_create_reply_msg);
2274 lnet_set_reply_msg_len(lnet_ni_t *ni, lnet_msg_t *reply, unsigned int len)
2276 /* Set the REPLY length, now the RDMA that elides the REPLY message has
2277 * completed and I know it. */
2278 LASSERT (reply != NULL);
2279 LASSERT (reply->msg_type == LNET_MSG_GET);
2280 LASSERT (reply->msg_ev.type == LNET_EVENT_REPLY);
2282 /* NB I trusted my peer to RDMA. If she tells me she's written beyond
2283 * the end of my buffer, I might as well be dead. */
2284 LASSERT (len <= reply->msg_ev.mlength);
2286 reply->msg_ev.mlength = len;
2288 EXPORT_SYMBOL(lnet_set_reply_msg_len);
2291 * Initiate an asynchronous GET operation.
2293 * On the initiator node, an LNET_EVENT_SEND is logged when the GET request
2294 * is sent, and an LNET_EVENT_REPLY is logged when the data returned from
2295 * the target node in the REPLY has been written to local MD.
2297 * On the target node, an LNET_EVENT_GET is logged when the GET request
2298 * arrives and is accepted into a MD.
2300 * \param self,target,portal,match_bits,offset See the discussion in LNetPut().
2301 * \param mdh A handle for the MD that describes the memory into which the
2302 * requested data will be received. The MD must be "free floating" (See LNetMDBind()).
2304 * \retval 0 Success, and only in this case events will be generated
2305 * and logged to EQ (if it exists) of the MD.
2306 * \retval -EIO Simulated failure.
2307 * \retval -ENOMEM Memory allocation failure.
2308 * \retval -ENOENT Invalid MD object.
2311 LNetGet(lnet_nid_t self, lnet_handle_md_t mdh,
2312 lnet_process_id_t target, unsigned int portal,
2313 __u64 match_bits, unsigned int offset)
2315 struct lnet_msg *msg;
2316 struct lnet_libmd *md;
2320 LASSERT (the_lnet.ln_init);
2321 LASSERT (the_lnet.ln_refcount > 0);
2323 if (!cfs_list_empty (&the_lnet.ln_test_peers) && /* normally we don't */
2324 fail_peer (target.nid, 1)) /* shall we now? */
2326 CERROR("Dropping GET to %s: simulated failure\n",
2327 libcfs_id2str(target));
2331 msg = lnet_msg_alloc();
2333 CERROR("Dropping GET to %s: ENOMEM on lnet_msg_t\n",
2334 libcfs_id2str(target));
2338 cpt = lnet_cpt_of_cookie(mdh.cookie);
2341 md = lnet_handle2md(&mdh);
2342 if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) {
2343 CERROR("Dropping GET ("LPU64":%d:%s): MD (%d) invalid\n",
2344 match_bits, portal, libcfs_id2str(target),
2345 md == NULL ? -1 : md->md_threshold);
2346 if (md != NULL && md->md_me != NULL)
2347 CERROR("REPLY MD also attached to portal %d\n",
2348 md->md_me->me_portal);
2350 lnet_res_unlock(cpt);
2357 CDEBUG(D_NET, "LNetGet -> %s\n", libcfs_id2str(target));
2359 lnet_msg_attach_md(msg, md, 0, 0);
2361 lnet_prep_send(msg, LNET_MSG_GET, target, 0, 0);
2363 msg->msg_hdr.msg.get.match_bits = cpu_to_le64(match_bits);
2364 msg->msg_hdr.msg.get.ptl_index = cpu_to_le32(portal);
2365 msg->msg_hdr.msg.get.src_offset = cpu_to_le32(offset);
2366 msg->msg_hdr.msg.get.sink_length = cpu_to_le32(md->md_length);
2368 /* NB handles only looked up by creator (no flips) */
2369 msg->msg_hdr.msg.get.return_wmd.wh_interface_cookie =
2370 the_lnet.ln_interface_cookie;
2371 msg->msg_hdr.msg.get.return_wmd.wh_object_cookie =
2372 md->md_lh.lh_cookie;
2374 lnet_res_unlock(cpt);
2376 lnet_build_msg_event(msg, LNET_EVENT_SEND);
2378 rc = lnet_send(self, msg, LNET_NID_ANY);
2380 CNETERR( "Error sending GET to %s: %d\n",
2381 libcfs_id2str(target), rc);
2382 lnet_finalize (NULL, msg, rc);
2385 /* completion will be signalled by an event */
2388 EXPORT_SYMBOL(LNetGet);
2391 * Calculate distance to node at \a dstnid.
2393 * \param dstnid Target NID.
2394 * \param srcnidp If not NULL, NID of the local interface to reach \a dstnid
2396 * \param orderp If not NULL, order of the route to reach \a dstnid is saved
2399 * \retval 0 If \a dstnid belongs to a local interface, and reserved option
2400 * local_nid_dist_zero is set, which is the default.
2401 * \retval positives Distance to target NID, i.e. number of hops plus one.
2402 * \retval -EHOSTUNREACH If \a dstnid is not reachable.
2405 LNetDist(lnet_nid_t dstnid, lnet_nid_t *srcnidp, __u32 *orderp)
2409 lnet_remotenet_t *rnet;
2410 __u32 dstnet = LNET_NIDNET(dstnid);
2415 /* if !local_nid_dist_zero, I don't return a distance of 0 ever
2416 * (when lustre sees a distance of 0, it substitutes 0@lo), so I
2417 * keep order 0 free for 0@lo and order 1 free for a local NID
2420 LASSERT (the_lnet.ln_init);
2421 LASSERT (the_lnet.ln_refcount > 0);
2423 cpt = lnet_net_lock_current();
2425 cfs_list_for_each (e, &the_lnet.ln_nis) {
2426 ni = cfs_list_entry(e, lnet_ni_t, ni_list);
2428 if (ni->ni_nid == dstnid) {
2429 if (srcnidp != NULL)
2431 if (orderp != NULL) {
2432 if (LNET_NETTYP(LNET_NIDNET(dstnid)) == LOLND)
2437 lnet_net_unlock(cpt);
2439 return local_nid_dist_zero ? 0 : 1;
2442 if (LNET_NIDNET(ni->ni_nid) == dstnet) {
2443 if (srcnidp != NULL)
2444 *srcnidp = ni->ni_nid;
2447 lnet_net_unlock(cpt);
2454 cfs_list_for_each (e, &the_lnet.ln_remote_nets) {
2455 rnet = cfs_list_entry(e, lnet_remotenet_t, lrn_list);
2457 if (rnet->lrn_net == dstnet) {
2458 lnet_route_t *route;
2459 lnet_route_t *shortest = NULL;
2461 LASSERT (!cfs_list_empty(&rnet->lrn_routes));
2463 cfs_list_for_each_entry(route, &rnet->lrn_routes,
2465 if (shortest == NULL ||
2466 route->lr_hops < shortest->lr_hops)
2470 LASSERT (shortest != NULL);
2471 hops = shortest->lr_hops;
2472 if (srcnidp != NULL)
2473 *srcnidp = shortest->lr_gateway->lp_ni->ni_nid;
2476 lnet_net_unlock(cpt);
2482 lnet_net_unlock(cpt);
2483 return -EHOSTUNREACH;
2485 EXPORT_SYMBOL(LNetDist);
2488 * Set the number of asynchronous messages expected from a target process.
2490 * This function is only meaningful for userspace callers. It's a no-op when
2491 * called from kernel.
2493 * Asynchronous messages are those that can come from a target when the
2494 * userspace process is not waiting for IO to complete; e.g., AST callbacks
2495 * from Lustre servers. Specifying the expected number of such messages
2496 * allows them to be eagerly received when user process is not running in
2497 * LNet; otherwise network errors may occur.
2499 * \param id Process ID of the target process.
2500 * \param nasync Number of asynchronous messages expected from the target.
2502 * \return 0 on success, and an error code otherwise.
2505 LNetSetAsync(lnet_process_id_t id, int nasync)
2511 lnet_remotenet_t *rnet;
2513 lnet_route_t *route;
2521 /* Target on a local network? */
2522 ni = lnet_net2ni(LNET_NIDNET(id.nid));
2524 if (ni->ni_lnd->lnd_setasync != NULL)
2525 rc = (ni->ni_lnd->lnd_setasync)(ni, id, nasync);
2530 /* Target on a remote network: apply to routers */
2532 LIBCFS_ALLOC(nids, maxnids * sizeof(*nids));
2537 /* Snapshot all the router NIDs */
2538 cpt = lnet_net_lock_current();
2539 rnet = lnet_find_net_locked(LNET_NIDNET(id.nid));
2541 cfs_list_for_each(tmp, &rnet->lrn_routes) {
2542 if (nnids == maxnids) {
2543 lnet_net_unlock(cpt);
2544 LIBCFS_FREE(nids, maxnids * sizeof(*nids));
2549 route = cfs_list_entry(tmp, lnet_route_t, lr_list);
2550 nids[nnids++] = route->lr_gateway->lp_nid;
2553 lnet_net_unlock(cpt);
2555 /* set async on all the routers */
2556 while (nnids-- > 0) {
2557 id.pid = LUSTRE_SRV_LNET_PID;
2558 id.nid = nids[nnids];
2560 ni = lnet_net2ni(LNET_NIDNET(id.nid));
2564 if (ni->ni_lnd->lnd_setasync != NULL) {
2565 rc2 = (ni->ni_lnd->lnd_setasync)(ni, id, nasync);
2572 LIBCFS_FREE(nids, maxnids * sizeof(*nids));
2576 EXPORT_SYMBOL(LNetSetAsync);