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.
30 * Copyright (c) 2012, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lnet/lnet/lib-move.c
38 * Data movement routines
41 #define DEBUG_SUBSYSTEM S_LNET
43 #include <lnet/lib-lnet.h>
45 static int local_nid_dist_zero = 1;
46 CFS_MODULE_PARM(local_nid_dist_zero, "i", int, 0444,
50 lnet_fail_nid(lnet_nid_t nid, unsigned int threshold)
54 struct list_head *next;
55 struct list_head cull;
57 LASSERT(the_lnet.ln_init);
59 /* NB: use lnet_net_lock(0) to serialize operations on test peers */
61 /* Adding a new entry */
62 LIBCFS_ALLOC(tp, sizeof(*tp));
67 tp->tp_threshold = threshold;
70 list_add_tail(&tp->tp_list, &the_lnet.ln_test_peers);
75 /* removing entries */
76 INIT_LIST_HEAD(&cull);
80 list_for_each_safe(el, next, &the_lnet.ln_test_peers) {
81 tp = list_entry(el, lnet_test_peer_t, tp_list);
83 if (tp->tp_threshold == 0 || /* needs culling anyway */
84 nid == LNET_NID_ANY || /* removing all entries */
85 tp->tp_nid == nid) { /* matched this one */
86 list_del(&tp->tp_list);
87 list_add(&tp->tp_list, &cull);
93 while (!list_empty(&cull)) {
94 tp = list_entry(cull.next, lnet_test_peer_t, tp_list);
96 list_del(&tp->tp_list);
97 LIBCFS_FREE(tp, sizeof(*tp));
103 fail_peer (lnet_nid_t nid, int outgoing)
105 lnet_test_peer_t *tp;
106 struct list_head *el;
107 struct list_head *next;
108 struct list_head cull;
111 INIT_LIST_HEAD(&cull);
113 /* NB: use lnet_net_lock(0) to serialize operations on test peers */
116 list_for_each_safe(el, next, &the_lnet.ln_test_peers) {
117 tp = list_entry(el, lnet_test_peer_t, tp_list);
119 if (tp->tp_threshold == 0) {
122 /* only cull zombies on outgoing tests,
123 * since we may be at interrupt priority on
124 * incoming messages. */
125 list_del(&tp->tp_list);
126 list_add(&tp->tp_list, &cull);
131 if (tp->tp_nid == LNET_NID_ANY || /* fail every peer */
132 nid == tp->tp_nid) { /* fail this peer */
135 if (tp->tp_threshold != LNET_MD_THRESH_INF) {
138 tp->tp_threshold == 0) {
140 list_del(&tp->tp_list);
141 list_add(&tp->tp_list, &cull);
150 while (!list_empty(&cull)) {
151 tp = list_entry(cull.next, lnet_test_peer_t, tp_list);
152 list_del(&tp->tp_list);
154 LIBCFS_FREE(tp, sizeof(*tp));
161 lnet_iov_nob (unsigned int niov, struct iovec *iov)
163 unsigned int nob = 0;
165 LASSERT(niov == 0 || iov != NULL);
167 nob += (iov++)->iov_len;
171 EXPORT_SYMBOL(lnet_iov_nob);
174 lnet_copy_iov2iov (unsigned int ndiov, struct iovec *diov, unsigned int doffset,
175 unsigned int nsiov, struct iovec *siov, unsigned int soffset,
178 /* NB diov, siov are READ-ONLY */
179 unsigned int this_nob;
184 /* skip complete frags before 'doffset' */
186 while (doffset >= diov->iov_len) {
187 doffset -= diov->iov_len;
193 /* skip complete frags before 'soffset' */
195 while (soffset >= siov->iov_len) {
196 soffset -= siov->iov_len;
205 this_nob = MIN(diov->iov_len - doffset,
206 siov->iov_len - soffset);
207 this_nob = MIN(this_nob, nob);
209 memcpy ((char *)diov->iov_base + doffset,
210 (char *)siov->iov_base + soffset, this_nob);
213 if (diov->iov_len > doffset + this_nob) {
221 if (siov->iov_len > soffset + this_nob) {
230 EXPORT_SYMBOL(lnet_copy_iov2iov);
233 lnet_extract_iov (int dst_niov, struct iovec *dst,
234 int src_niov, struct iovec *src,
235 unsigned int offset, unsigned int len)
237 /* Initialise 'dst' to the subset of 'src' starting at 'offset',
238 * for exactly 'len' bytes, and return the number of entries.
239 * NB not destructive to 'src' */
240 unsigned int frag_len;
243 if (len == 0) /* no data => */
244 return (0); /* no frags */
246 LASSERT (src_niov > 0);
247 while (offset >= src->iov_len) { /* skip initial frags */
248 offset -= src->iov_len;
251 LASSERT (src_niov > 0);
256 LASSERT (src_niov > 0);
257 LASSERT ((int)niov <= dst_niov);
259 frag_len = src->iov_len - offset;
260 dst->iov_base = ((char *)src->iov_base) + offset;
262 if (len <= frag_len) {
267 dst->iov_len = frag_len;
277 EXPORT_SYMBOL(lnet_extract_iov);
281 lnet_kiov_nob (unsigned int niov, lnet_kiov_t *kiov)
288 lnet_copy_kiov2kiov (unsigned int ndkiov, lnet_kiov_t *dkiov, unsigned int doffset,
289 unsigned int nskiov, lnet_kiov_t *skiov, unsigned int soffset,
296 lnet_copy_kiov2iov (unsigned int niov, struct iovec *iov, unsigned int iovoffset,
297 unsigned int nkiov, lnet_kiov_t *kiov, unsigned int kiovoffset,
304 lnet_copy_iov2kiov (unsigned int nkiov, lnet_kiov_t *kiov, unsigned int kiovoffset,
305 unsigned int niov, struct iovec *iov, unsigned int iovoffset,
312 lnet_extract_kiov (int dst_niov, lnet_kiov_t *dst,
313 int src_niov, lnet_kiov_t *src,
314 unsigned int offset, unsigned int len)
319 #else /* __KERNEL__ */
322 lnet_kiov_nob (unsigned int niov, lnet_kiov_t *kiov)
324 unsigned int nob = 0;
326 LASSERT(niov == 0 || kiov != NULL);
328 nob += (kiov++)->kiov_len;
332 EXPORT_SYMBOL(lnet_kiov_nob);
335 lnet_copy_kiov2kiov (unsigned int ndiov, lnet_kiov_t *diov, unsigned int doffset,
336 unsigned int nsiov, lnet_kiov_t *siov, unsigned int soffset,
339 /* NB diov, siov are READ-ONLY */
340 unsigned int this_nob;
347 LASSERT (!in_interrupt ());
350 while (doffset >= diov->kiov_len) {
351 doffset -= diov->kiov_len;
358 while (soffset >= siov->kiov_len) {
359 soffset -= siov->kiov_len;
368 this_nob = MIN(diov->kiov_len - doffset,
369 siov->kiov_len - soffset);
370 this_nob = MIN(this_nob, nob);
373 daddr = ((char *)kmap(diov->kiov_page)) +
374 diov->kiov_offset + doffset;
376 saddr = ((char *)kmap(siov->kiov_page)) +
377 siov->kiov_offset + soffset;
379 /* Vanishing risk of kmap deadlock when mapping 2 pages.
380 * However in practice at least one of the kiovs will be mapped
381 * kernel pages and the map/unmap will be NOOPs */
383 memcpy (daddr, saddr, this_nob);
386 if (diov->kiov_len > doffset + this_nob) {
390 kunmap(diov->kiov_page);
397 if (siov->kiov_len > soffset + this_nob) {
401 kunmap(siov->kiov_page);
410 kunmap(diov->kiov_page);
412 kunmap(siov->kiov_page);
414 EXPORT_SYMBOL(lnet_copy_kiov2kiov);
417 lnet_copy_kiov2iov (unsigned int niov, struct iovec *iov, unsigned int iovoffset,
418 unsigned int nkiov, lnet_kiov_t *kiov, unsigned int kiovoffset,
421 /* NB iov, kiov are READ-ONLY */
422 unsigned int this_nob;
428 LASSERT (!in_interrupt ());
431 while (iovoffset >= iov->iov_len) {
432 iovoffset -= iov->iov_len;
439 while (kiovoffset >= kiov->kiov_len) {
440 kiovoffset -= kiov->kiov_len;
449 this_nob = MIN(iov->iov_len - iovoffset,
450 kiov->kiov_len - kiovoffset);
451 this_nob = MIN(this_nob, nob);
454 addr = ((char *)kmap(kiov->kiov_page)) +
455 kiov->kiov_offset + kiovoffset;
457 memcpy ((char *)iov->iov_base + iovoffset, addr, this_nob);
460 if (iov->iov_len > iovoffset + this_nob) {
461 iovoffset += this_nob;
468 if (kiov->kiov_len > kiovoffset + this_nob) {
470 kiovoffset += this_nob;
472 kunmap(kiov->kiov_page);
482 kunmap(kiov->kiov_page);
484 EXPORT_SYMBOL(lnet_copy_kiov2iov);
487 lnet_copy_iov2kiov (unsigned int nkiov, lnet_kiov_t *kiov, unsigned int kiovoffset,
488 unsigned int niov, struct iovec *iov, unsigned int iovoffset,
491 /* NB kiov, iov are READ-ONLY */
492 unsigned int this_nob;
498 LASSERT (!in_interrupt ());
501 while (kiovoffset >= kiov->kiov_len) {
502 kiovoffset -= kiov->kiov_len;
509 while (iovoffset >= iov->iov_len) {
510 iovoffset -= iov->iov_len;
519 this_nob = MIN(kiov->kiov_len - kiovoffset,
520 iov->iov_len - iovoffset);
521 this_nob = MIN(this_nob, nob);
524 addr = ((char *)kmap(kiov->kiov_page)) +
525 kiov->kiov_offset + kiovoffset;
527 memcpy (addr, (char *)iov->iov_base + iovoffset, this_nob);
530 if (kiov->kiov_len > kiovoffset + this_nob) {
532 kiovoffset += this_nob;
534 kunmap(kiov->kiov_page);
541 if (iov->iov_len > iovoffset + this_nob) {
542 iovoffset += this_nob;
551 kunmap(kiov->kiov_page);
553 EXPORT_SYMBOL(lnet_copy_iov2kiov);
556 lnet_extract_kiov (int dst_niov, lnet_kiov_t *dst,
557 int src_niov, lnet_kiov_t *src,
558 unsigned int offset, unsigned int len)
560 /* Initialise 'dst' to the subset of 'src' starting at 'offset',
561 * for exactly 'len' bytes, and return the number of entries.
562 * NB not destructive to 'src' */
563 unsigned int frag_len;
566 if (len == 0) /* no data => */
567 return (0); /* no frags */
569 LASSERT (src_niov > 0);
570 while (offset >= src->kiov_len) { /* skip initial frags */
571 offset -= src->kiov_len;
574 LASSERT (src_niov > 0);
579 LASSERT (src_niov > 0);
580 LASSERT ((int)niov <= dst_niov);
582 frag_len = src->kiov_len - offset;
583 dst->kiov_page = src->kiov_page;
584 dst->kiov_offset = src->kiov_offset + offset;
586 if (len <= frag_len) {
588 LASSERT (dst->kiov_offset + dst->kiov_len <= PAGE_CACHE_SIZE);
592 dst->kiov_len = frag_len;
593 LASSERT (dst->kiov_offset + dst->kiov_len <= PAGE_CACHE_SIZE);
603 EXPORT_SYMBOL(lnet_extract_kiov);
607 lnet_ni_recv(lnet_ni_t *ni, void *private, lnet_msg_t *msg, int delayed,
608 unsigned int offset, unsigned int mlen, unsigned int rlen)
610 unsigned int niov = 0;
611 struct iovec *iov = NULL;
612 lnet_kiov_t *kiov = NULL;
615 LASSERT (!in_interrupt ());
616 LASSERT (mlen == 0 || msg != NULL);
619 LASSERT(msg->msg_receiving);
620 LASSERT(!msg->msg_sending);
621 LASSERT(rlen == msg->msg_len);
622 LASSERT(mlen <= msg->msg_len);
623 LASSERT(msg->msg_offset == offset);
624 LASSERT(msg->msg_wanted == mlen);
626 msg->msg_receiving = 0;
629 niov = msg->msg_niov;
631 kiov = msg->msg_kiov;
634 LASSERT ((iov == NULL) != (kiov == NULL));
638 rc = (ni->ni_lnd->lnd_recv)(ni, private, msg, delayed,
639 niov, iov, kiov, offset, mlen, rlen);
641 lnet_finalize(ni, msg, rc);
645 lnet_setpayloadbuffer(lnet_msg_t *msg)
647 lnet_libmd_t *md = msg->msg_md;
649 LASSERT (msg->msg_len > 0);
650 LASSERT (!msg->msg_routing);
651 LASSERT (md != NULL);
652 LASSERT (msg->msg_niov == 0);
653 LASSERT (msg->msg_iov == NULL);
654 LASSERT (msg->msg_kiov == NULL);
656 msg->msg_niov = md->md_niov;
657 if ((md->md_options & LNET_MD_KIOV) != 0)
658 msg->msg_kiov = md->md_iov.kiov;
660 msg->msg_iov = md->md_iov.iov;
664 lnet_prep_send(lnet_msg_t *msg, int type, lnet_process_id_t target,
665 unsigned int offset, unsigned int len)
667 msg->msg_type = type;
668 msg->msg_target = target;
670 msg->msg_offset = offset;
673 lnet_setpayloadbuffer(msg);
675 memset (&msg->msg_hdr, 0, sizeof (msg->msg_hdr));
676 msg->msg_hdr.type = cpu_to_le32(type);
677 msg->msg_hdr.dest_nid = cpu_to_le64(target.nid);
678 msg->msg_hdr.dest_pid = cpu_to_le32(target.pid);
679 /* src_nid will be set later */
680 msg->msg_hdr.src_pid = cpu_to_le32(the_lnet.ln_pid);
681 msg->msg_hdr.payload_length = cpu_to_le32(len);
685 lnet_ni_send(lnet_ni_t *ni, lnet_msg_t *msg)
687 void *priv = msg->msg_private;
690 LASSERT (!in_interrupt ());
691 LASSERT (LNET_NETTYP(LNET_NIDNET(ni->ni_nid)) == LOLND ||
692 (msg->msg_txcredit && msg->msg_peertxcredit));
694 rc = (ni->ni_lnd->lnd_send)(ni, priv, msg);
696 lnet_finalize(ni, msg, rc);
700 lnet_ni_eager_recv(lnet_ni_t *ni, lnet_msg_t *msg)
704 LASSERT(!msg->msg_sending);
705 LASSERT(msg->msg_receiving);
706 LASSERT(!msg->msg_rx_ready_delay);
707 LASSERT(ni->ni_lnd->lnd_eager_recv != NULL);
709 msg->msg_rx_ready_delay = 1;
710 rc = (ni->ni_lnd->lnd_eager_recv)(ni, msg->msg_private, msg,
713 CERROR("recv from %s / send to %s aborted: "
714 "eager_recv failed %d\n",
715 libcfs_nid2str(msg->msg_rxpeer->lp_nid),
716 libcfs_id2str(msg->msg_target), rc);
717 LASSERT(rc < 0); /* required by my callers */
723 /* NB: caller shall hold a ref on 'lp' as I'd drop lnet_net_lock */
725 lnet_ni_query_locked(lnet_ni_t *ni, lnet_peer_t *lp)
727 cfs_time_t last_alive = 0;
729 LASSERT(lnet_peer_aliveness_enabled(lp));
730 LASSERT(ni->ni_lnd->lnd_query != NULL);
732 lnet_net_unlock(lp->lp_cpt);
733 (ni->ni_lnd->lnd_query)(ni, lp->lp_nid, &last_alive);
734 lnet_net_lock(lp->lp_cpt);
736 lp->lp_last_query = cfs_time_current();
738 if (last_alive != 0) /* NI has updated timestamp */
739 lp->lp_last_alive = last_alive;
742 /* NB: always called with lnet_net_lock held */
744 lnet_peer_is_alive (lnet_peer_t *lp, cfs_time_t now)
749 LASSERT (lnet_peer_aliveness_enabled(lp));
751 /* Trust lnet_notify() if it has more recent aliveness news, but
752 * ignore the initial assumed death (see lnet_peers_start_down()).
754 if (!lp->lp_alive && lp->lp_alive_count > 0 &&
755 cfs_time_aftereq(lp->lp_timestamp, lp->lp_last_alive))
758 deadline = cfs_time_add(lp->lp_last_alive,
759 cfs_time_seconds(lp->lp_ni->ni_peertimeout));
760 alive = cfs_time_after(deadline, now);
762 /* Update obsolete lp_alive except for routers assumed to be dead
763 * initially, because router checker would update aliveness in this
764 * case, and moreover lp_last_alive at peer creation is assumed.
766 if (alive && !lp->lp_alive &&
767 !(lnet_isrouter(lp) && lp->lp_alive_count == 0))
768 lnet_notify_locked(lp, 0, 1, lp->lp_last_alive);
774 /* NB: returns 1 when alive, 0 when dead, negative when error;
775 * may drop the lnet_net_lock */
777 lnet_peer_alive_locked (lnet_peer_t *lp)
779 cfs_time_t now = cfs_time_current();
781 if (!lnet_peer_aliveness_enabled(lp))
784 if (lnet_peer_is_alive(lp, now))
787 /* Peer appears dead, but we should avoid frequent NI queries (at
788 * most once per lnet_queryinterval seconds). */
789 if (lp->lp_last_query != 0) {
790 static const int lnet_queryinterval = 1;
792 cfs_time_t next_query =
793 cfs_time_add(lp->lp_last_query,
794 cfs_time_seconds(lnet_queryinterval));
796 if (cfs_time_before(now, next_query)) {
798 CWARN("Unexpected aliveness of peer %s: "
800 libcfs_nid2str(lp->lp_nid),
801 (int)now, (int)next_query,
803 lp->lp_ni->ni_peertimeout);
808 /* query NI for latest aliveness news */
809 lnet_ni_query_locked(lp->lp_ni, lp);
811 if (lnet_peer_is_alive(lp, now))
814 lnet_notify_locked(lp, 0, 0, lp->lp_last_alive);
819 * \param msg The message to be sent.
820 * \param do_send True if lnet_ni_send() should be called in this function.
821 * lnet_send() is going to lnet_net_unlock immediately after this, so
822 * it sets do_send FALSE and I don't do the unlock/send/lock bit.
824 * \retval 0 If \a msg sent or OK to send.
825 * \retval -EAGAIN If \a msg blocked for credit.
826 * \retval -EHOSTUNREACH If the next hop of the message appears dead.
827 * \retval -ECANCELED If the MD of the message has been unlinked.
830 lnet_post_send_locked(lnet_msg_t *msg, int do_send)
832 lnet_peer_t *lp = msg->msg_txpeer;
833 lnet_ni_t *ni = lp->lp_ni;
834 int cpt = msg->msg_tx_cpt;
835 struct lnet_tx_queue *tq = ni->ni_tx_queues[cpt];
837 /* non-lnet_send() callers have checked before */
838 LASSERT(!do_send || msg->msg_tx_delayed);
839 LASSERT(!msg->msg_receiving);
840 LASSERT(msg->msg_tx_committed);
842 /* NB 'lp' is always the next hop */
843 if ((msg->msg_target.pid & LNET_PID_USERFLAG) == 0 &&
844 lnet_peer_alive_locked(lp) == 0) {
845 the_lnet.ln_counters[cpt]->drop_count++;
846 the_lnet.ln_counters[cpt]->drop_length += msg->msg_len;
847 lnet_net_unlock(cpt);
849 CNETERR("Dropping message for %s: peer not alive\n",
850 libcfs_id2str(msg->msg_target));
852 lnet_finalize(ni, msg, -EHOSTUNREACH);
855 return -EHOSTUNREACH;
858 if (msg->msg_md != NULL &&
859 (msg->msg_md->md_flags & LNET_MD_FLAG_ABORTED) != 0) {
860 lnet_net_unlock(cpt);
862 CNETERR("Aborting message for %s: LNetM[DE]Unlink() already "
863 "called on the MD/ME.\n",
864 libcfs_id2str(msg->msg_target));
866 lnet_finalize(ni, msg, -ECANCELED);
872 if (!msg->msg_peertxcredit) {
873 LASSERT((lp->lp_txcredits < 0) ==
874 !list_empty(&lp->lp_txq));
876 msg->msg_peertxcredit = 1;
877 lp->lp_txqnob += msg->msg_len + sizeof(lnet_hdr_t);
880 if (lp->lp_txcredits < lp->lp_mintxcredits)
881 lp->lp_mintxcredits = lp->lp_txcredits;
883 if (lp->lp_txcredits < 0) {
884 msg->msg_tx_delayed = 1;
885 list_add_tail(&msg->msg_list, &lp->lp_txq);
890 if (!msg->msg_txcredit) {
891 LASSERT((tq->tq_credits < 0) ==
892 !list_empty(&tq->tq_delayed));
894 msg->msg_txcredit = 1;
897 if (tq->tq_credits < tq->tq_credits_min)
898 tq->tq_credits_min = tq->tq_credits;
900 if (tq->tq_credits < 0) {
901 msg->msg_tx_delayed = 1;
902 list_add_tail(&msg->msg_list, &tq->tq_delayed);
908 lnet_net_unlock(cpt);
909 lnet_ni_send(ni, msg);
918 lnet_msg2bufpool(lnet_msg_t *msg)
920 lnet_rtrbufpool_t *rbp;
923 LASSERT(msg->msg_rx_committed);
925 cpt = msg->msg_rx_cpt;
926 rbp = &the_lnet.ln_rtrpools[cpt][0];
928 LASSERT(msg->msg_len <= LNET_MTU);
929 while (msg->msg_len > (unsigned int)rbp->rbp_npages * PAGE_CACHE_SIZE) {
931 LASSERT(rbp < &the_lnet.ln_rtrpools[cpt][LNET_NRBPOOLS]);
938 lnet_post_routed_recv_locked (lnet_msg_t *msg, int do_recv)
940 /* lnet_parse is going to lnet_net_unlock immediately after this, so it
941 * sets do_recv FALSE and I don't do the unlock/send/lock bit. I
942 * return EAGAIN if msg blocked and 0 if received or OK to receive */
943 lnet_peer_t *lp = msg->msg_rxpeer;
944 lnet_rtrbufpool_t *rbp;
947 LASSERT (msg->msg_iov == NULL);
948 LASSERT (msg->msg_kiov == NULL);
949 LASSERT (msg->msg_niov == 0);
950 LASSERT (msg->msg_routing);
951 LASSERT (msg->msg_receiving);
952 LASSERT (!msg->msg_sending);
954 /* non-lnet_parse callers only receive delayed messages */
955 LASSERT(!do_recv || msg->msg_rx_delayed);
957 if (!msg->msg_peerrtrcredit) {
958 LASSERT((lp->lp_rtrcredits < 0) ==
959 !list_empty(&lp->lp_rtrq));
961 msg->msg_peerrtrcredit = 1;
963 if (lp->lp_rtrcredits < lp->lp_minrtrcredits)
964 lp->lp_minrtrcredits = lp->lp_rtrcredits;
966 if (lp->lp_rtrcredits < 0) {
967 /* must have checked eager_recv before here */
968 LASSERT(msg->msg_rx_ready_delay);
969 msg->msg_rx_delayed = 1;
970 list_add_tail(&msg->msg_list, &lp->lp_rtrq);
975 rbp = lnet_msg2bufpool(msg);
977 if (!msg->msg_rtrcredit) {
978 LASSERT((rbp->rbp_credits < 0) ==
979 !list_empty(&rbp->rbp_msgs));
981 msg->msg_rtrcredit = 1;
983 if (rbp->rbp_credits < rbp->rbp_mincredits)
984 rbp->rbp_mincredits = rbp->rbp_credits;
986 if (rbp->rbp_credits < 0) {
987 /* must have checked eager_recv before here */
988 LASSERT(msg->msg_rx_ready_delay);
989 msg->msg_rx_delayed = 1;
990 list_add_tail(&msg->msg_list, &rbp->rbp_msgs);
995 LASSERT(!list_empty(&rbp->rbp_bufs));
996 rb = list_entry(rbp->rbp_bufs.next, lnet_rtrbuf_t, rb_list);
997 list_del(&rb->rb_list);
999 msg->msg_niov = rbp->rbp_npages;
1000 msg->msg_kiov = &rb->rb_kiov[0];
1003 int cpt = msg->msg_rx_cpt;
1005 lnet_net_unlock(cpt);
1006 lnet_ni_recv(lp->lp_ni, msg->msg_private, msg, 1,
1007 0, msg->msg_len, msg->msg_len);
1015 lnet_return_tx_credits_locked(lnet_msg_t *msg)
1017 lnet_peer_t *txpeer = msg->msg_txpeer;
1020 if (msg->msg_txcredit) {
1021 struct lnet_ni *ni = txpeer->lp_ni;
1022 struct lnet_tx_queue *tq = ni->ni_tx_queues[msg->msg_tx_cpt];
1024 /* give back NI txcredits */
1025 msg->msg_txcredit = 0;
1027 LASSERT((tq->tq_credits < 0) ==
1028 !list_empty(&tq->tq_delayed));
1031 if (tq->tq_credits <= 0) {
1032 msg2 = list_entry(tq->tq_delayed.next,
1033 lnet_msg_t, msg_list);
1034 list_del(&msg2->msg_list);
1036 LASSERT(msg2->msg_txpeer->lp_ni == ni);
1037 LASSERT(msg2->msg_tx_delayed);
1039 (void) lnet_post_send_locked(msg2, 1);
1043 if (msg->msg_peertxcredit) {
1044 /* give back peer txcredits */
1045 msg->msg_peertxcredit = 0;
1047 LASSERT((txpeer->lp_txcredits < 0) ==
1048 !list_empty(&txpeer->lp_txq));
1050 txpeer->lp_txqnob -= msg->msg_len + sizeof(lnet_hdr_t);
1051 LASSERT (txpeer->lp_txqnob >= 0);
1053 txpeer->lp_txcredits++;
1054 if (txpeer->lp_txcredits <= 0) {
1055 msg2 = list_entry(txpeer->lp_txq.next,
1056 lnet_msg_t, msg_list);
1057 list_del(&msg2->msg_list);
1059 LASSERT(msg2->msg_txpeer == txpeer);
1060 LASSERT(msg2->msg_tx_delayed);
1062 (void) lnet_post_send_locked(msg2, 1);
1066 if (txpeer != NULL) {
1067 msg->msg_txpeer = NULL;
1068 lnet_peer_decref_locked(txpeer);
1073 lnet_return_rx_credits_locked(lnet_msg_t *msg)
1075 lnet_peer_t *rxpeer = msg->msg_rxpeer;
1079 if (msg->msg_rtrcredit) {
1080 /* give back global router credits */
1082 lnet_rtrbufpool_t *rbp;
1084 /* NB If a msg ever blocks for a buffer in rbp_msgs, it stays
1085 * there until it gets one allocated, or aborts the wait
1087 LASSERT (msg->msg_kiov != NULL);
1089 rb = list_entry(msg->msg_kiov, lnet_rtrbuf_t, rb_kiov[0]);
1091 LASSERT (rbp == lnet_msg2bufpool(msg));
1093 msg->msg_kiov = NULL;
1094 msg->msg_rtrcredit = 0;
1096 LASSERT((rbp->rbp_credits < 0) ==
1097 !list_empty(&rbp->rbp_msgs));
1098 LASSERT((rbp->rbp_credits > 0) ==
1099 !list_empty(&rbp->rbp_bufs));
1101 list_add(&rb->rb_list, &rbp->rbp_bufs);
1103 if (rbp->rbp_credits <= 0) {
1104 msg2 = list_entry(rbp->rbp_msgs.next,
1105 lnet_msg_t, msg_list);
1106 list_del(&msg2->msg_list);
1108 (void) lnet_post_routed_recv_locked(msg2, 1);
1112 if (msg->msg_peerrtrcredit) {
1113 /* give back peer router credits */
1114 msg->msg_peerrtrcredit = 0;
1116 LASSERT((rxpeer->lp_rtrcredits < 0) ==
1117 !list_empty(&rxpeer->lp_rtrq));
1119 rxpeer->lp_rtrcredits++;
1120 if (rxpeer->lp_rtrcredits <= 0) {
1121 msg2 = list_entry(rxpeer->lp_rtrq.next,
1122 lnet_msg_t, msg_list);
1123 list_del(&msg2->msg_list);
1125 (void) lnet_post_routed_recv_locked(msg2, 1);
1129 LASSERT (!msg->msg_rtrcredit);
1130 LASSERT (!msg->msg_peerrtrcredit);
1132 if (rxpeer != NULL) {
1133 msg->msg_rxpeer = NULL;
1134 lnet_peer_decref_locked(rxpeer);
1139 lnet_compare_routes(lnet_route_t *r1, lnet_route_t *r2)
1141 lnet_peer_t *p1 = r1->lr_gateway;
1142 lnet_peer_t *p2 = r2->lr_gateway;
1144 if (r1->lr_priority < r2->lr_priority)
1147 if (r1->lr_priority > r2->lr_priority)
1150 if (r1->lr_hops < r2->lr_hops)
1153 if (r1->lr_hops > r2->lr_hops)
1156 if (p1->lp_txqnob < p2->lp_txqnob)
1159 if (p1->lp_txqnob > p2->lp_txqnob)
1162 if (p1->lp_txcredits > p2->lp_txcredits)
1165 if (p1->lp_txcredits < p2->lp_txcredits)
1168 if (r1->lr_seq - r2->lr_seq <= 0)
1174 static lnet_peer_t *
1175 lnet_find_route_locked(lnet_ni_t *ni, lnet_nid_t target, lnet_nid_t rtr_nid)
1177 lnet_remotenet_t *rnet;
1178 lnet_route_t *route;
1179 lnet_route_t *best_route;
1180 lnet_route_t *last_route;
1181 struct lnet_peer *lp_best;
1182 struct lnet_peer *lp;
1185 /* If @rtr_nid is not LNET_NID_ANY, return the gateway with
1186 * rtr_nid nid, otherwise find the best gateway I can use */
1188 rnet = lnet_find_net_locked(LNET_NIDNET(target));
1193 best_route = last_route = NULL;
1194 list_for_each_entry(route, &rnet->lrn_routes, lr_list) {
1195 lp = route->lr_gateway;
1197 if (!lnet_is_route_alive(route))
1200 if (ni != NULL && lp->lp_ni != ni)
1203 if (lp->lp_nid == rtr_nid) /* it's pre-determined router */
1206 if (lp_best == NULL) {
1207 best_route = last_route = route;
1212 /* no protection on below fields, but it's harmless */
1213 if (last_route->lr_seq - route->lr_seq < 0)
1216 rc = lnet_compare_routes(route, best_route);
1224 /* set sequence number on the best router to the latest sequence + 1
1225 * so we can round-robin all routers, it's race and inaccurate but
1226 * harmless and functional */
1227 if (best_route != NULL)
1228 best_route->lr_seq = last_route->lr_seq + 1;
1233 lnet_send(lnet_nid_t src_nid, lnet_msg_t *msg, lnet_nid_t rtr_nid)
1235 lnet_nid_t dst_nid = msg->msg_target.nid;
1236 struct lnet_ni *src_ni;
1237 struct lnet_ni *local_ni;
1238 struct lnet_peer *lp;
1243 /* NB: rtr_nid is set to LNET_NID_ANY for all current use-cases,
1244 * but we might want to use pre-determined router for ACK/REPLY
1246 /* NB: ni != NULL == interface pre-determined (ACK/REPLY) */
1247 LASSERT (msg->msg_txpeer == NULL);
1248 LASSERT (!msg->msg_sending);
1249 LASSERT (!msg->msg_target_is_router);
1250 LASSERT (!msg->msg_receiving);
1252 msg->msg_sending = 1;
1254 LASSERT(!msg->msg_tx_committed);
1255 cpt = lnet_cpt_of_nid(rtr_nid == LNET_NID_ANY ? dst_nid : rtr_nid);
1259 if (the_lnet.ln_shutdown) {
1260 lnet_net_unlock(cpt);
1264 if (src_nid == LNET_NID_ANY) {
1267 src_ni = lnet_nid2ni_locked(src_nid, cpt);
1268 if (src_ni == NULL) {
1269 lnet_net_unlock(cpt);
1270 LCONSOLE_WARN("Can't send to %s: src %s is not a "
1271 "local nid\n", libcfs_nid2str(dst_nid),
1272 libcfs_nid2str(src_nid));
1275 LASSERT (!msg->msg_routing);
1278 /* Is this for someone on a local network? */
1279 local_ni = lnet_net2ni_locked(LNET_NIDNET(dst_nid), cpt);
1281 if (local_ni != NULL) {
1282 if (src_ni == NULL) {
1284 src_nid = src_ni->ni_nid;
1285 } else if (src_ni == local_ni) {
1286 lnet_ni_decref_locked(local_ni, cpt);
1288 lnet_ni_decref_locked(local_ni, cpt);
1289 lnet_ni_decref_locked(src_ni, cpt);
1290 lnet_net_unlock(cpt);
1291 LCONSOLE_WARN("No route to %s via from %s\n",
1292 libcfs_nid2str(dst_nid),
1293 libcfs_nid2str(src_nid));
1297 LASSERT(src_nid != LNET_NID_ANY);
1298 lnet_msg_commit(msg, cpt);
1300 if (!msg->msg_routing)
1301 msg->msg_hdr.src_nid = cpu_to_le64(src_nid);
1303 if (src_ni == the_lnet.ln_loni) {
1304 /* No send credit hassles with LOLND */
1305 lnet_net_unlock(cpt);
1306 lnet_ni_send(src_ni, msg);
1309 lnet_ni_decref_locked(src_ni, cpt);
1310 lnet_net_unlock(cpt);
1314 rc = lnet_nid2peer_locked(&lp, dst_nid, cpt);
1315 /* lp has ref on src_ni; lose mine */
1316 lnet_ni_decref_locked(src_ni, cpt);
1318 lnet_net_unlock(cpt);
1319 LCONSOLE_WARN("Error %d finding peer %s\n", rc,
1320 libcfs_nid2str(dst_nid));
1321 /* ENOMEM or shutting down */
1324 LASSERT (lp->lp_ni == src_ni);
1327 lnet_net_unlock(cpt);
1330 * - once application finishes computation, check here to update
1331 * router states before it waits for pending IO in LNetEQPoll
1332 * - recursion breaker: router checker sends no message
1333 * to remote networks */
1334 if (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING)
1335 lnet_router_checker();
1339 /* sending to a remote network */
1340 lp = lnet_find_route_locked(src_ni, dst_nid, rtr_nid);
1343 lnet_ni_decref_locked(src_ni, cpt);
1344 lnet_net_unlock(cpt);
1346 LCONSOLE_WARN("No route to %s via %s "
1347 "(all routers down)\n",
1348 libcfs_id2str(msg->msg_target),
1349 libcfs_nid2str(src_nid));
1350 return -EHOSTUNREACH;
1353 /* rtr_nid is LNET_NID_ANY or NID of pre-determined router,
1354 * it's possible that rtr_nid isn't LNET_NID_ANY and lp isn't
1355 * pre-determined router, this can happen if router table
1356 * was changed when we release the lock */
1357 if (rtr_nid != lp->lp_nid) {
1358 cpt2 = lnet_cpt_of_nid_locked(lp->lp_nid);
1361 lnet_ni_decref_locked(src_ni, cpt);
1362 lnet_net_unlock(cpt);
1364 rtr_nid = lp->lp_nid;
1370 CDEBUG(D_NET, "Best route to %s via %s for %s %d\n",
1371 libcfs_nid2str(dst_nid), libcfs_nid2str(lp->lp_nid),
1372 lnet_msgtyp2str(msg->msg_type), msg->msg_len);
1374 if (src_ni == NULL) {
1376 src_nid = src_ni->ni_nid;
1378 LASSERT (src_ni == lp->lp_ni);
1379 lnet_ni_decref_locked(src_ni, cpt);
1382 lnet_peer_addref_locked(lp);
1384 LASSERT(src_nid != LNET_NID_ANY);
1385 lnet_msg_commit(msg, cpt);
1387 if (!msg->msg_routing) {
1388 /* I'm the source and now I know which NI to send on */
1389 msg->msg_hdr.src_nid = cpu_to_le64(src_nid);
1392 msg->msg_target_is_router = 1;
1393 msg->msg_target.nid = lp->lp_nid;
1394 msg->msg_target.pid = LUSTRE_SRV_LNET_PID;
1397 /* 'lp' is our best choice of peer */
1399 LASSERT (!msg->msg_peertxcredit);
1400 LASSERT (!msg->msg_txcredit);
1401 LASSERT (msg->msg_txpeer == NULL);
1403 msg->msg_txpeer = lp; /* msg takes my ref on lp */
1405 rc = lnet_post_send_locked(msg, 0);
1406 lnet_net_unlock(cpt);
1408 if (rc == -EHOSTUNREACH || rc == -ECANCELED)
1412 lnet_ni_send(src_ni, msg);
1414 return 0; /* rc == 0 or -EAGAIN */
1418 lnet_drop_message(lnet_ni_t *ni, int cpt, void *private, unsigned int nob)
1421 the_lnet.ln_counters[cpt]->drop_count++;
1422 the_lnet.ln_counters[cpt]->drop_length += nob;
1423 lnet_net_unlock(cpt);
1425 lnet_ni_recv(ni, private, NULL, 0, 0, 0, nob);
1429 lnet_recv_put(lnet_ni_t *ni, lnet_msg_t *msg)
1431 lnet_hdr_t *hdr = &msg->msg_hdr;
1433 if (msg->msg_wanted != 0)
1434 lnet_setpayloadbuffer(msg);
1436 lnet_build_msg_event(msg, LNET_EVENT_PUT);
1438 /* Must I ACK? If so I'll grab the ack_wmd out of the header and put
1439 * it back into the ACK during lnet_finalize() */
1440 msg->msg_ack = (!lnet_is_wire_handle_none(&hdr->msg.put.ack_wmd) &&
1441 (msg->msg_md->md_options & LNET_MD_ACK_DISABLE) == 0);
1443 lnet_ni_recv(ni, msg->msg_private, msg, msg->msg_rx_delayed,
1444 msg->msg_offset, msg->msg_wanted, hdr->payload_length);
1448 lnet_parse_put(lnet_ni_t *ni, lnet_msg_t *msg)
1450 lnet_hdr_t *hdr = &msg->msg_hdr;
1451 struct lnet_match_info info;
1454 /* Convert put fields to host byte order */
1455 hdr->msg.put.match_bits = le64_to_cpu(hdr->msg.put.match_bits);
1456 hdr->msg.put.ptl_index = le32_to_cpu(hdr->msg.put.ptl_index);
1457 hdr->msg.put.offset = le32_to_cpu(hdr->msg.put.offset);
1459 info.mi_id.nid = hdr->src_nid;
1460 info.mi_id.pid = hdr->src_pid;
1461 info.mi_opc = LNET_MD_OP_PUT;
1462 info.mi_portal = hdr->msg.put.ptl_index;
1463 info.mi_rlength = hdr->payload_length;
1464 info.mi_roffset = hdr->msg.put.offset;
1465 info.mi_mbits = hdr->msg.put.match_bits;
1467 msg->msg_rx_ready_delay = ni->ni_lnd->lnd_eager_recv == NULL;
1470 rc = lnet_ptl_match_md(&info, msg);
1475 case LNET_MATCHMD_OK:
1476 lnet_recv_put(ni, msg);
1479 case LNET_MATCHMD_NONE:
1480 if (msg->msg_rx_delayed) /* attached on delayed list */
1483 rc = lnet_ni_eager_recv(ni, msg);
1488 case LNET_MATCHMD_DROP:
1489 CNETERR("Dropping PUT from %s portal %d match "LPU64
1490 " offset %d length %d: %d\n",
1491 libcfs_id2str(info.mi_id), info.mi_portal,
1492 info.mi_mbits, info.mi_roffset, info.mi_rlength, rc);
1494 return ENOENT; /* +ve: OK but no match */
1499 lnet_parse_get(lnet_ni_t *ni, lnet_msg_t *msg, int rdma_get)
1501 struct lnet_match_info info;
1502 lnet_hdr_t *hdr = &msg->msg_hdr;
1503 lnet_handle_wire_t reply_wmd;
1506 /* Convert get fields to host byte order */
1507 hdr->msg.get.match_bits = le64_to_cpu(hdr->msg.get.match_bits);
1508 hdr->msg.get.ptl_index = le32_to_cpu(hdr->msg.get.ptl_index);
1509 hdr->msg.get.sink_length = le32_to_cpu(hdr->msg.get.sink_length);
1510 hdr->msg.get.src_offset = le32_to_cpu(hdr->msg.get.src_offset);
1512 info.mi_id.nid = hdr->src_nid;
1513 info.mi_id.pid = hdr->src_pid;
1514 info.mi_opc = LNET_MD_OP_GET;
1515 info.mi_portal = hdr->msg.get.ptl_index;
1516 info.mi_rlength = hdr->msg.get.sink_length;
1517 info.mi_roffset = hdr->msg.get.src_offset;
1518 info.mi_mbits = hdr->msg.get.match_bits;
1520 rc = lnet_ptl_match_md(&info, msg);
1521 if (rc == LNET_MATCHMD_DROP) {
1522 CNETERR("Dropping GET from %s portal %d match "LPU64
1523 " offset %d length %d\n",
1524 libcfs_id2str(info.mi_id), info.mi_portal,
1525 info.mi_mbits, info.mi_roffset, info.mi_rlength);
1526 return ENOENT; /* +ve: OK but no match */
1529 LASSERT(rc == LNET_MATCHMD_OK);
1531 lnet_build_msg_event(msg, LNET_EVENT_GET);
1533 reply_wmd = hdr->msg.get.return_wmd;
1535 lnet_prep_send(msg, LNET_MSG_REPLY, info.mi_id,
1536 msg->msg_offset, msg->msg_wanted);
1538 msg->msg_hdr.msg.reply.dst_wmd = reply_wmd;
1541 /* The LND completes the REPLY from her recv procedure */
1542 lnet_ni_recv(ni, msg->msg_private, msg, 0,
1543 msg->msg_offset, msg->msg_len, msg->msg_len);
1547 lnet_ni_recv(ni, msg->msg_private, NULL, 0, 0, 0, 0);
1548 msg->msg_receiving = 0;
1550 rc = lnet_send(ni->ni_nid, msg, LNET_NID_ANY);
1552 /* didn't get as far as lnet_ni_send() */
1553 CERROR("%s: Unable to send REPLY for GET from %s: %d\n",
1554 libcfs_nid2str(ni->ni_nid),
1555 libcfs_id2str(info.mi_id), rc);
1557 lnet_finalize(ni, msg, rc);
1564 lnet_parse_reply(lnet_ni_t *ni, lnet_msg_t *msg)
1566 void *private = msg->msg_private;
1567 lnet_hdr_t *hdr = &msg->msg_hdr;
1568 lnet_process_id_t src = {0};
1574 cpt = lnet_cpt_of_cookie(hdr->msg.reply.dst_wmd.wh_object_cookie);
1577 src.nid = hdr->src_nid;
1578 src.pid = hdr->src_pid;
1580 /* NB handles only looked up by creator (no flips) */
1581 md = lnet_wire_handle2md(&hdr->msg.reply.dst_wmd);
1582 if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) {
1583 CNETERR("%s: Dropping REPLY from %s for %s "
1584 "MD "LPX64"."LPX64"\n",
1585 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
1586 (md == NULL) ? "invalid" : "inactive",
1587 hdr->msg.reply.dst_wmd.wh_interface_cookie,
1588 hdr->msg.reply.dst_wmd.wh_object_cookie);
1589 if (md != NULL && md->md_me != NULL)
1590 CERROR("REPLY MD also attached to portal %d\n",
1591 md->md_me->me_portal);
1593 lnet_res_unlock(cpt);
1594 return ENOENT; /* +ve: OK but no match */
1597 LASSERT (md->md_offset == 0);
1599 rlength = hdr->payload_length;
1600 mlength = MIN(rlength, (int)md->md_length);
1602 if (mlength < rlength &&
1603 (md->md_options & LNET_MD_TRUNCATE) == 0) {
1604 CNETERR("%s: Dropping REPLY from %s length %d "
1605 "for MD "LPX64" would overflow (%d)\n",
1606 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
1607 rlength, hdr->msg.reply.dst_wmd.wh_object_cookie,
1609 lnet_res_unlock(cpt);
1610 return ENOENT; /* +ve: OK but no match */
1613 CDEBUG(D_NET, "%s: Reply from %s of length %d/%d into md "LPX64"\n",
1614 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
1615 mlength, rlength, hdr->msg.reply.dst_wmd.wh_object_cookie);
1617 lnet_msg_attach_md(msg, md, 0, mlength);
1620 lnet_setpayloadbuffer(msg);
1622 lnet_res_unlock(cpt);
1624 lnet_build_msg_event(msg, LNET_EVENT_REPLY);
1626 lnet_ni_recv(ni, private, msg, 0, 0, mlength, rlength);
1631 lnet_parse_ack(lnet_ni_t *ni, lnet_msg_t *msg)
1633 lnet_hdr_t *hdr = &msg->msg_hdr;
1634 lnet_process_id_t src = {0};
1638 src.nid = hdr->src_nid;
1639 src.pid = hdr->src_pid;
1641 /* Convert ack fields to host byte order */
1642 hdr->msg.ack.match_bits = le64_to_cpu(hdr->msg.ack.match_bits);
1643 hdr->msg.ack.mlength = le32_to_cpu(hdr->msg.ack.mlength);
1645 cpt = lnet_cpt_of_cookie(hdr->msg.ack.dst_wmd.wh_object_cookie);
1648 /* NB handles only looked up by creator (no flips) */
1649 md = lnet_wire_handle2md(&hdr->msg.ack.dst_wmd);
1650 if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) {
1651 /* Don't moan; this is expected */
1653 "%s: Dropping ACK from %s to %s MD "LPX64"."LPX64"\n",
1654 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
1655 (md == NULL) ? "invalid" : "inactive",
1656 hdr->msg.ack.dst_wmd.wh_interface_cookie,
1657 hdr->msg.ack.dst_wmd.wh_object_cookie);
1658 if (md != NULL && md->md_me != NULL)
1659 CERROR("Source MD also attached to portal %d\n",
1660 md->md_me->me_portal);
1662 lnet_res_unlock(cpt);
1663 return ENOENT; /* +ve! */
1666 CDEBUG(D_NET, "%s: ACK from %s into md "LPX64"\n",
1667 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
1668 hdr->msg.ack.dst_wmd.wh_object_cookie);
1670 lnet_msg_attach_md(msg, md, 0, 0);
1672 lnet_res_unlock(cpt);
1674 lnet_build_msg_event(msg, LNET_EVENT_ACK);
1676 lnet_ni_recv(ni, msg->msg_private, msg, 0, 0, 0, msg->msg_len);
1681 lnet_parse_forward_locked(lnet_ni_t *ni, lnet_msg_t *msg)
1686 if (msg->msg_rxpeer->lp_rtrcredits <= 0 ||
1687 lnet_msg2bufpool(msg)->rbp_credits <= 0) {
1688 if (ni->ni_lnd->lnd_eager_recv == NULL) {
1689 msg->msg_rx_ready_delay = 1;
1691 lnet_net_unlock(msg->msg_rx_cpt);
1692 rc = lnet_ni_eager_recv(ni, msg);
1693 lnet_net_lock(msg->msg_rx_cpt);
1698 rc = lnet_post_routed_recv_locked(msg, 0);
1706 lnet_msgtyp2str (int type)
1715 case LNET_MSG_REPLY:
1717 case LNET_MSG_HELLO:
1720 return ("<UNKNOWN>");
1723 EXPORT_SYMBOL(lnet_msgtyp2str);
1726 lnet_print_hdr(lnet_hdr_t * hdr)
1728 lnet_process_id_t src = {0};
1729 lnet_process_id_t dst = {0};
1730 char *type_str = lnet_msgtyp2str (hdr->type);
1732 src.nid = hdr->src_nid;
1733 src.pid = hdr->src_pid;
1735 dst.nid = hdr->dest_nid;
1736 dst.pid = hdr->dest_pid;
1738 CWARN("P3 Header at %p of type %s\n", hdr, type_str);
1739 CWARN(" From %s\n", libcfs_id2str(src));
1740 CWARN(" To %s\n", libcfs_id2str(dst));
1742 switch (hdr->type) {
1747 CWARN(" Ptl index %d, ack md "LPX64"."LPX64", "
1748 "match bits "LPU64"\n",
1749 hdr->msg.put.ptl_index,
1750 hdr->msg.put.ack_wmd.wh_interface_cookie,
1751 hdr->msg.put.ack_wmd.wh_object_cookie,
1752 hdr->msg.put.match_bits);
1753 CWARN(" Length %d, offset %d, hdr data "LPX64"\n",
1754 hdr->payload_length, hdr->msg.put.offset,
1755 hdr->msg.put.hdr_data);
1759 CWARN(" Ptl index %d, return md "LPX64"."LPX64", "
1760 "match bits "LPU64"\n", hdr->msg.get.ptl_index,
1761 hdr->msg.get.return_wmd.wh_interface_cookie,
1762 hdr->msg.get.return_wmd.wh_object_cookie,
1763 hdr->msg.get.match_bits);
1764 CWARN(" Length %d, src offset %d\n",
1765 hdr->msg.get.sink_length,
1766 hdr->msg.get.src_offset);
1770 CWARN(" dst md "LPX64"."LPX64", "
1771 "manipulated length %d\n",
1772 hdr->msg.ack.dst_wmd.wh_interface_cookie,
1773 hdr->msg.ack.dst_wmd.wh_object_cookie,
1774 hdr->msg.ack.mlength);
1777 case LNET_MSG_REPLY:
1778 CWARN(" dst md "LPX64"."LPX64", "
1780 hdr->msg.reply.dst_wmd.wh_interface_cookie,
1781 hdr->msg.reply.dst_wmd.wh_object_cookie,
1782 hdr->payload_length);
1788 lnet_parse(lnet_ni_t *ni, lnet_hdr_t *hdr, lnet_nid_t from_nid,
1789 void *private, int rdma_req)
1794 struct lnet_msg *msg;
1795 lnet_pid_t dest_pid;
1796 lnet_nid_t dest_nid;
1798 __u32 payload_length;
1801 LASSERT (!in_interrupt ());
1803 type = le32_to_cpu(hdr->type);
1804 src_nid = le64_to_cpu(hdr->src_nid);
1805 dest_nid = le64_to_cpu(hdr->dest_nid);
1806 dest_pid = le32_to_cpu(hdr->dest_pid);
1807 payload_length = le32_to_cpu(hdr->payload_length);
1809 for_me = (ni->ni_nid == dest_nid);
1810 cpt = lnet_cpt_of_nid(from_nid);
1815 if (payload_length > 0) {
1816 CERROR("%s, src %s: bad %s payload %d (0 expected)\n",
1817 libcfs_nid2str(from_nid),
1818 libcfs_nid2str(src_nid),
1819 lnet_msgtyp2str(type), payload_length);
1825 case LNET_MSG_REPLY:
1826 if (payload_length > (__u32)(for_me ? LNET_MAX_PAYLOAD : LNET_MTU)) {
1827 CERROR("%s, src %s: bad %s payload %d "
1828 "(%d max expected)\n",
1829 libcfs_nid2str(from_nid),
1830 libcfs_nid2str(src_nid),
1831 lnet_msgtyp2str(type),
1833 for_me ? LNET_MAX_PAYLOAD : LNET_MTU);
1839 CERROR("%s, src %s: Bad message type 0x%x\n",
1840 libcfs_nid2str(from_nid),
1841 libcfs_nid2str(src_nid), type);
1845 if (the_lnet.ln_routing &&
1846 ni->ni_last_alive != cfs_time_current_sec()) {
1849 /* NB: so far here is the only place to set NI status to "up */
1850 ni->ni_last_alive = cfs_time_current_sec();
1851 if (ni->ni_status != NULL &&
1852 ni->ni_status->ns_status == LNET_NI_STATUS_DOWN)
1853 ni->ni_status->ns_status = LNET_NI_STATUS_UP;
1857 /* Regard a bad destination NID as a protocol error. Senders should
1858 * know what they're doing; if they don't they're misconfigured, buggy
1859 * or malicious so we chop them off at the knees :) */
1862 if (LNET_NIDNET(dest_nid) == LNET_NIDNET(ni->ni_nid)) {
1863 /* should have gone direct */
1864 CERROR ("%s, src %s: Bad dest nid %s "
1865 "(should have been sent direct)\n",
1866 libcfs_nid2str(from_nid),
1867 libcfs_nid2str(src_nid),
1868 libcfs_nid2str(dest_nid));
1872 if (lnet_islocalnid(dest_nid)) {
1873 /* dest is another local NI; sender should have used
1874 * this node's NID on its own network */
1875 CERROR ("%s, src %s: Bad dest nid %s "
1876 "(it's my nid but on a different network)\n",
1877 libcfs_nid2str(from_nid),
1878 libcfs_nid2str(src_nid),
1879 libcfs_nid2str(dest_nid));
1883 if (rdma_req && type == LNET_MSG_GET) {
1884 CERROR ("%s, src %s: Bad optimized GET for %s "
1885 "(final destination must be me)\n",
1886 libcfs_nid2str(from_nid),
1887 libcfs_nid2str(src_nid),
1888 libcfs_nid2str(dest_nid));
1892 if (!the_lnet.ln_routing) {
1893 CERROR ("%s, src %s: Dropping message for %s "
1894 "(routing not enabled)\n",
1895 libcfs_nid2str(from_nid),
1896 libcfs_nid2str(src_nid),
1897 libcfs_nid2str(dest_nid));
1902 /* Message looks OK; we're not going to return an error, so we MUST
1903 * call back lnd_recv() come what may... */
1905 if (!list_empty(&the_lnet.ln_test_peers) && /* normally we don't */
1906 fail_peer(src_nid, 0)) { /* shall we now? */
1907 CERROR("%s, src %s: Dropping %s to simulate failure\n",
1908 libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
1909 lnet_msgtyp2str(type));
1913 msg = lnet_msg_alloc();
1915 CERROR("%s, src %s: Dropping %s (out of memory)\n",
1916 libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
1917 lnet_msgtyp2str(type));
1921 /* msg zeroed in lnet_msg_alloc; i.e. flags all clear, pointers NULL etc */
1923 msg->msg_type = type;
1924 msg->msg_private = private;
1925 msg->msg_receiving = 1;
1926 msg->msg_len = msg->msg_wanted = payload_length;
1927 msg->msg_offset = 0;
1928 msg->msg_hdr = *hdr;
1929 /* for building message event */
1930 msg->msg_from = from_nid;
1932 msg->msg_target.pid = dest_pid;
1933 msg->msg_target.nid = dest_nid;
1934 msg->msg_routing = 1;
1937 /* convert common msg->hdr fields to host byteorder */
1938 msg->msg_hdr.type = type;
1939 msg->msg_hdr.src_nid = src_nid;
1940 msg->msg_hdr.src_pid = le32_to_cpu(msg->msg_hdr.src_pid);
1941 msg->msg_hdr.dest_nid = dest_nid;
1942 msg->msg_hdr.dest_pid = dest_pid;
1943 msg->msg_hdr.payload_length = payload_length;
1947 rc = lnet_nid2peer_locked(&msg->msg_rxpeer, from_nid, cpt);
1949 lnet_net_unlock(cpt);
1950 CERROR("%s, src %s: Dropping %s "
1951 "(error %d looking up sender)\n",
1952 libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
1953 lnet_msgtyp2str(type), rc);
1958 lnet_msg_commit(msg, cpt);
1961 rc = lnet_parse_forward_locked(ni, msg);
1962 lnet_net_unlock(cpt);
1967 lnet_ni_recv(ni, msg->msg_private, msg, 0,
1968 0, payload_length, payload_length);
1973 lnet_net_unlock(cpt);
1977 rc = lnet_parse_ack(ni, msg);
1980 rc = lnet_parse_put(ni, msg);
1983 rc = lnet_parse_get(ni, msg, rdma_req);
1985 case LNET_MSG_REPLY:
1986 rc = lnet_parse_reply(ni, msg);
1991 goto free_drop; /* prevent an unused label if !kernel */
1997 LASSERT (rc == ENOENT);
2000 LASSERT(msg->msg_md == NULL);
2001 lnet_finalize(ni, msg, rc);
2004 lnet_drop_message(ni, cpt, private, payload_length);
2007 EXPORT_SYMBOL(lnet_parse);
2010 lnet_drop_delayed_msg_list(struct list_head *head, char *reason)
2012 while (!list_empty(head)) {
2013 lnet_process_id_t id = {0};
2016 msg = list_entry(head->next, lnet_msg_t, msg_list);
2017 list_del(&msg->msg_list);
2019 id.nid = msg->msg_hdr.src_nid;
2020 id.pid = msg->msg_hdr.src_pid;
2022 LASSERT(msg->msg_md == NULL);
2023 LASSERT(msg->msg_rx_delayed);
2024 LASSERT(msg->msg_rxpeer != NULL);
2025 LASSERT(msg->msg_hdr.type == LNET_MSG_PUT);
2027 CWARN("Dropping delayed PUT from %s portal %d match "LPU64
2028 " offset %d length %d: %s\n",
2030 msg->msg_hdr.msg.put.ptl_index,
2031 msg->msg_hdr.msg.put.match_bits,
2032 msg->msg_hdr.msg.put.offset,
2033 msg->msg_hdr.payload_length, reason);
2035 /* NB I can't drop msg's ref on msg_rxpeer until after I've
2036 * called lnet_drop_message(), so I just hang onto msg as well
2037 * until that's done */
2039 lnet_drop_message(msg->msg_rxpeer->lp_ni,
2040 msg->msg_rxpeer->lp_cpt,
2041 msg->msg_private, msg->msg_len);
2043 * NB: message will not generate event because w/o attached MD,
2044 * but we still should give error code so lnet_msg_decommit()
2045 * can skip counters operations and other checks.
2047 lnet_finalize(msg->msg_rxpeer->lp_ni, msg, -ENOENT);
2052 lnet_recv_delayed_msg_list(struct list_head *head)
2054 while (!list_empty(head)) {
2056 lnet_process_id_t id;
2058 msg = list_entry(head->next, lnet_msg_t, msg_list);
2059 list_del(&msg->msg_list);
2061 /* md won't disappear under me, since each msg
2062 * holds a ref on it */
2064 id.nid = msg->msg_hdr.src_nid;
2065 id.pid = msg->msg_hdr.src_pid;
2067 LASSERT(msg->msg_rx_delayed);
2068 LASSERT(msg->msg_md != NULL);
2069 LASSERT(msg->msg_rxpeer != NULL);
2070 LASSERT(msg->msg_hdr.type == LNET_MSG_PUT);
2072 CDEBUG(D_NET, "Resuming delayed PUT from %s portal %d "
2073 "match "LPU64" offset %d length %d.\n",
2074 libcfs_id2str(id), msg->msg_hdr.msg.put.ptl_index,
2075 msg->msg_hdr.msg.put.match_bits,
2076 msg->msg_hdr.msg.put.offset,
2077 msg->msg_hdr.payload_length);
2079 lnet_recv_put(msg->msg_rxpeer->lp_ni, msg);
2084 * Initiate an asynchronous PUT operation.
2086 * There are several events associated with a PUT: completion of the send on
2087 * the initiator node (LNET_EVENT_SEND), and when the send completes
2088 * successfully, the receipt of an acknowledgment (LNET_EVENT_ACK) indicating
2089 * that the operation was accepted by the target. The event LNET_EVENT_PUT is
2090 * used at the target node to indicate the completion of incoming data
2093 * The local events will be logged in the EQ associated with the MD pointed to
2094 * by \a mdh handle. Using a MD without an associated EQ results in these
2095 * events being discarded. In this case, the caller must have another
2096 * mechanism (e.g., a higher level protocol) for determining when it is safe
2097 * to modify the memory region associated with the MD.
2099 * Note that LNet does not guarantee the order of LNET_EVENT_SEND and
2100 * LNET_EVENT_ACK, though intuitively ACK should happen after SEND.
2102 * \param self Indicates the NID of a local interface through which to send
2103 * the PUT request. Use LNET_NID_ANY to let LNet choose one by itself.
2104 * \param mdh A handle for the MD that describes the memory to be sent. The MD
2105 * must be "free floating" (See LNetMDBind()).
2106 * \param ack Controls whether an acknowledgment is requested.
2107 * Acknowledgments are only sent when they are requested by the initiating
2108 * process and the target MD enables them.
2109 * \param target A process identifier for the target process.
2110 * \param portal The index in the \a target's portal table.
2111 * \param match_bits The match bits to use for MD selection at the target
2113 * \param offset The offset into the target MD (only used when the target
2114 * MD has the LNET_MD_MANAGE_REMOTE option set).
2115 * \param hdr_data 64 bits of user data that can be included in the message
2116 * header. This data is written to an event queue entry at the target if an
2117 * EQ is present on the matching MD.
2119 * \retval 0 Success, and only in this case events will be generated
2120 * and logged to EQ (if it exists).
2121 * \retval -EIO Simulated failure.
2122 * \retval -ENOMEM Memory allocation failure.
2123 * \retval -ENOENT Invalid MD object.
2125 * \see lnet_event_t::hdr_data and lnet_event_kind_t.
2128 LNetPut(lnet_nid_t self, lnet_handle_md_t mdh, lnet_ack_req_t ack,
2129 lnet_process_id_t target, unsigned int portal,
2130 __u64 match_bits, unsigned int offset,
2133 struct lnet_msg *msg;
2134 struct lnet_libmd *md;
2138 LASSERT(the_lnet.ln_init);
2139 LASSERT(the_lnet.ln_refcount > 0);
2141 if (!list_empty(&the_lnet.ln_test_peers) && /* normally we don't */
2142 fail_peer(target.nid, 1)) { /* shall we now? */
2143 CERROR("Dropping PUT to %s: simulated failure\n",
2144 libcfs_id2str(target));
2148 msg = lnet_msg_alloc();
2150 CERROR("Dropping PUT to %s: ENOMEM on lnet_msg_t\n",
2151 libcfs_id2str(target));
2154 msg->msg_vmflush = !!memory_pressure_get();
2156 cpt = lnet_cpt_of_cookie(mdh.cookie);
2159 md = lnet_handle2md(&mdh);
2160 if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) {
2161 CERROR("Dropping PUT ("LPU64":%d:%s): MD (%d) invalid\n",
2162 match_bits, portal, libcfs_id2str(target),
2163 md == NULL ? -1 : md->md_threshold);
2164 if (md != NULL && md->md_me != NULL)
2165 CERROR("Source MD also attached to portal %d\n",
2166 md->md_me->me_portal);
2167 lnet_res_unlock(cpt);
2173 CDEBUG(D_NET, "LNetPut -> %s\n", libcfs_id2str(target));
2175 lnet_msg_attach_md(msg, md, 0, 0);
2177 lnet_prep_send(msg, LNET_MSG_PUT, target, 0, md->md_length);
2179 msg->msg_hdr.msg.put.match_bits = cpu_to_le64(match_bits);
2180 msg->msg_hdr.msg.put.ptl_index = cpu_to_le32(portal);
2181 msg->msg_hdr.msg.put.offset = cpu_to_le32(offset);
2182 msg->msg_hdr.msg.put.hdr_data = hdr_data;
2184 /* NB handles only looked up by creator (no flips) */
2185 if (ack == LNET_ACK_REQ) {
2186 msg->msg_hdr.msg.put.ack_wmd.wh_interface_cookie =
2187 the_lnet.ln_interface_cookie;
2188 msg->msg_hdr.msg.put.ack_wmd.wh_object_cookie =
2189 md->md_lh.lh_cookie;
2191 msg->msg_hdr.msg.put.ack_wmd.wh_interface_cookie =
2192 LNET_WIRE_HANDLE_COOKIE_NONE;
2193 msg->msg_hdr.msg.put.ack_wmd.wh_object_cookie =
2194 LNET_WIRE_HANDLE_COOKIE_NONE;
2197 lnet_res_unlock(cpt);
2199 lnet_build_msg_event(msg, LNET_EVENT_SEND);
2201 rc = lnet_send(self, msg, LNET_NID_ANY);
2203 CNETERR( "Error sending PUT to %s: %d\n",
2204 libcfs_id2str(target), rc);
2205 lnet_finalize (NULL, msg, rc);
2208 /* completion will be signalled by an event */
2211 EXPORT_SYMBOL(LNetPut);
2214 lnet_create_reply_msg (lnet_ni_t *ni, lnet_msg_t *getmsg)
2216 /* The LND can DMA direct to the GET md (i.e. no REPLY msg). This
2217 * returns a msg for the LND to pass to lnet_finalize() when the sink
2218 * data has been received.
2220 * CAVEAT EMPTOR: 'getmsg' is the original GET, which is freed when
2221 * lnet_finalize() is called on it, so the LND must call this first */
2223 struct lnet_msg *msg = lnet_msg_alloc();
2224 struct lnet_libmd *getmd = getmsg->msg_md;
2225 lnet_process_id_t peer_id = getmsg->msg_target;
2228 LASSERT(!getmsg->msg_target_is_router);
2229 LASSERT(!getmsg->msg_routing);
2232 CERROR("%s: Dropping REPLY from %s: can't allocate msg\n",
2233 libcfs_nid2str(ni->ni_nid), libcfs_id2str(peer_id));
2237 cpt = lnet_cpt_of_cookie(getmd->md_lh.lh_cookie);
2240 LASSERT(getmd->md_refcount > 0);
2242 if (getmd->md_threshold == 0) {
2243 CERROR ("%s: Dropping REPLY from %s for inactive MD %p\n",
2244 libcfs_nid2str(ni->ni_nid), libcfs_id2str(peer_id),
2246 lnet_res_unlock(cpt);
2250 LASSERT(getmd->md_offset == 0);
2252 CDEBUG(D_NET, "%s: Reply from %s md %p\n",
2253 libcfs_nid2str(ni->ni_nid), libcfs_id2str(peer_id), getmd);
2255 /* setup information for lnet_build_msg_event */
2256 msg->msg_from = peer_id.nid;
2257 msg->msg_type = LNET_MSG_GET; /* flag this msg as an "optimized" GET */
2258 msg->msg_hdr.src_nid = peer_id.nid;
2259 msg->msg_hdr.payload_length = getmd->md_length;
2260 msg->msg_receiving = 1; /* required by lnet_msg_attach_md */
2262 lnet_msg_attach_md(msg, getmd, getmd->md_offset, getmd->md_length);
2263 lnet_res_unlock(cpt);
2265 cpt = lnet_cpt_of_nid(peer_id.nid);
2268 lnet_msg_commit(msg, cpt);
2269 lnet_net_unlock(cpt);
2271 lnet_build_msg_event(msg, LNET_EVENT_REPLY);
2276 cpt = lnet_cpt_of_nid(peer_id.nid);
2279 the_lnet.ln_counters[cpt]->drop_count++;
2280 the_lnet.ln_counters[cpt]->drop_length += getmd->md_length;
2281 lnet_net_unlock(cpt);
2288 EXPORT_SYMBOL(lnet_create_reply_msg);
2291 lnet_set_reply_msg_len(lnet_ni_t *ni, lnet_msg_t *reply, unsigned int len)
2293 /* Set the REPLY length, now the RDMA that elides the REPLY message has
2294 * completed and I know it. */
2295 LASSERT (reply != NULL);
2296 LASSERT (reply->msg_type == LNET_MSG_GET);
2297 LASSERT (reply->msg_ev.type == LNET_EVENT_REPLY);
2299 /* NB I trusted my peer to RDMA. If she tells me she's written beyond
2300 * the end of my buffer, I might as well be dead. */
2301 LASSERT (len <= reply->msg_ev.mlength);
2303 reply->msg_ev.mlength = len;
2305 EXPORT_SYMBOL(lnet_set_reply_msg_len);
2308 * Initiate an asynchronous GET operation.
2310 * On the initiator node, an LNET_EVENT_SEND is logged when the GET request
2311 * is sent, and an LNET_EVENT_REPLY is logged when the data returned from
2312 * the target node in the REPLY has been written to local MD.
2314 * On the target node, an LNET_EVENT_GET is logged when the GET request
2315 * arrives and is accepted into a MD.
2317 * \param self,target,portal,match_bits,offset See the discussion in LNetPut().
2318 * \param mdh A handle for the MD that describes the memory into which the
2319 * requested data will be received. The MD must be "free floating" (See LNetMDBind()).
2321 * \retval 0 Success, and only in this case events will be generated
2322 * and logged to EQ (if it exists) of the MD.
2323 * \retval -EIO Simulated failure.
2324 * \retval -ENOMEM Memory allocation failure.
2325 * \retval -ENOENT Invalid MD object.
2328 LNetGet(lnet_nid_t self, lnet_handle_md_t mdh,
2329 lnet_process_id_t target, unsigned int portal,
2330 __u64 match_bits, unsigned int offset)
2332 struct lnet_msg *msg;
2333 struct lnet_libmd *md;
2337 LASSERT (the_lnet.ln_init);
2338 LASSERT (the_lnet.ln_refcount > 0);
2340 if (!list_empty(&the_lnet.ln_test_peers) && /* normally we don't */
2341 fail_peer(target.nid, 1)) /* shall we now? */
2343 CERROR("Dropping GET to %s: simulated failure\n",
2344 libcfs_id2str(target));
2348 msg = lnet_msg_alloc();
2350 CERROR("Dropping GET to %s: ENOMEM on lnet_msg_t\n",
2351 libcfs_id2str(target));
2355 cpt = lnet_cpt_of_cookie(mdh.cookie);
2358 md = lnet_handle2md(&mdh);
2359 if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) {
2360 CERROR("Dropping GET ("LPU64":%d:%s): MD (%d) invalid\n",
2361 match_bits, portal, libcfs_id2str(target),
2362 md == NULL ? -1 : md->md_threshold);
2363 if (md != NULL && md->md_me != NULL)
2364 CERROR("REPLY MD also attached to portal %d\n",
2365 md->md_me->me_portal);
2367 lnet_res_unlock(cpt);
2373 CDEBUG(D_NET, "LNetGet -> %s\n", libcfs_id2str(target));
2375 lnet_msg_attach_md(msg, md, 0, 0);
2377 lnet_prep_send(msg, LNET_MSG_GET, target, 0, 0);
2379 msg->msg_hdr.msg.get.match_bits = cpu_to_le64(match_bits);
2380 msg->msg_hdr.msg.get.ptl_index = cpu_to_le32(portal);
2381 msg->msg_hdr.msg.get.src_offset = cpu_to_le32(offset);
2382 msg->msg_hdr.msg.get.sink_length = cpu_to_le32(md->md_length);
2384 /* NB handles only looked up by creator (no flips) */
2385 msg->msg_hdr.msg.get.return_wmd.wh_interface_cookie =
2386 the_lnet.ln_interface_cookie;
2387 msg->msg_hdr.msg.get.return_wmd.wh_object_cookie =
2388 md->md_lh.lh_cookie;
2390 lnet_res_unlock(cpt);
2392 lnet_build_msg_event(msg, LNET_EVENT_SEND);
2394 rc = lnet_send(self, msg, LNET_NID_ANY);
2396 CNETERR("Error sending GET to %s: %d\n",
2397 libcfs_id2str(target), rc);
2398 lnet_finalize(NULL, msg, rc);
2401 /* completion will be signalled by an event */
2404 EXPORT_SYMBOL(LNetGet);
2407 * Calculate distance to node at \a dstnid.
2409 * \param dstnid Target NID.
2410 * \param srcnidp If not NULL, NID of the local interface to reach \a dstnid
2412 * \param orderp If not NULL, order of the route to reach \a dstnid is saved
2415 * \retval 0 If \a dstnid belongs to a local interface, and reserved option
2416 * local_nid_dist_zero is set, which is the default.
2417 * \retval positives Distance to target NID, i.e. number of hops plus one.
2418 * \retval -EHOSTUNREACH If \a dstnid is not reachable.
2421 LNetDist(lnet_nid_t dstnid, lnet_nid_t *srcnidp, __u32 *orderp)
2423 struct list_head *e;
2425 lnet_remotenet_t *rnet;
2426 __u32 dstnet = LNET_NIDNET(dstnid);
2430 struct list_head *rn_list;
2432 /* if !local_nid_dist_zero, I don't return a distance of 0 ever
2433 * (when lustre sees a distance of 0, it substitutes 0@lo), so I
2434 * keep order 0 free for 0@lo and order 1 free for a local NID
2437 LASSERT (the_lnet.ln_init);
2438 LASSERT (the_lnet.ln_refcount > 0);
2440 cpt = lnet_net_lock_current();
2442 list_for_each(e, &the_lnet.ln_nis) {
2443 ni = list_entry(e, lnet_ni_t, ni_list);
2445 if (ni->ni_nid == dstnid) {
2446 if (srcnidp != NULL)
2448 if (orderp != NULL) {
2449 if (LNET_NETTYP(LNET_NIDNET(dstnid)) == LOLND)
2454 lnet_net_unlock(cpt);
2456 return local_nid_dist_zero ? 0 : 1;
2459 if (LNET_NIDNET(ni->ni_nid) == dstnet) {
2460 if (srcnidp != NULL)
2461 *srcnidp = ni->ni_nid;
2464 lnet_net_unlock(cpt);
2471 rn_list = lnet_net2rnethash(dstnet);
2472 list_for_each(e, rn_list) {
2473 rnet = list_entry(e, lnet_remotenet_t, lrn_list);
2475 if (rnet->lrn_net == dstnet) {
2476 lnet_route_t *route;
2477 lnet_route_t *shortest = NULL;
2479 LASSERT(!list_empty(&rnet->lrn_routes));
2481 list_for_each_entry(route, &rnet->lrn_routes,
2483 if (shortest == NULL ||
2484 route->lr_hops < shortest->lr_hops)
2488 LASSERT (shortest != NULL);
2489 hops = shortest->lr_hops;
2490 if (srcnidp != NULL)
2491 *srcnidp = shortest->lr_gateway->lp_ni->ni_nid;
2494 lnet_net_unlock(cpt);
2500 lnet_net_unlock(cpt);
2501 return -EHOSTUNREACH;
2503 EXPORT_SYMBOL(LNetDist);
2506 * Set the number of asynchronous messages expected from a target process.
2508 * This function is only meaningful for userspace callers. It's a no-op when
2509 * called from kernel.
2511 * Asynchronous messages are those that can come from a target when the
2512 * userspace process is not waiting for IO to complete; e.g., AST callbacks
2513 * from Lustre servers. Specifying the expected number of such messages
2514 * allows them to be eagerly received when user process is not running in
2515 * LNet; otherwise network errors may occur.
2517 * \param id Process ID of the target process.
2518 * \param nasync Number of asynchronous messages expected from the target.
2520 * \return 0 on success, and an error code otherwise.
2523 LNetSetAsync(lnet_process_id_t id, int nasync)
2529 lnet_remotenet_t *rnet;
2530 struct list_head *tmp;
2531 lnet_route_t *route;
2539 /* Target on a local network? */
2540 ni = lnet_net2ni(LNET_NIDNET(id.nid));
2542 if (ni->ni_lnd->lnd_setasync != NULL)
2543 rc = (ni->ni_lnd->lnd_setasync)(ni, id, nasync);
2548 /* Target on a remote network: apply to routers */
2550 LIBCFS_ALLOC(nids, maxnids * sizeof(*nids));
2555 /* Snapshot all the router NIDs */
2556 cpt = lnet_net_lock_current();
2557 rnet = lnet_find_net_locked(LNET_NIDNET(id.nid));
2559 list_for_each(tmp, &rnet->lrn_routes) {
2560 if (nnids == maxnids) {
2561 lnet_net_unlock(cpt);
2562 LIBCFS_FREE(nids, maxnids * sizeof(*nids));
2567 route = list_entry(tmp, lnet_route_t, lr_list);
2568 nids[nnids++] = route->lr_gateway->lp_nid;
2571 lnet_net_unlock(cpt);
2573 /* set async on all the routers */
2574 while (nnids-- > 0) {
2575 id.pid = LUSTRE_SRV_LNET_PID;
2576 id.nid = nids[nnids];
2578 ni = lnet_net2ni(LNET_NIDNET(id.nid));
2582 if (ni->ni_lnd->lnd_setasync != NULL) {
2583 rc2 = (ni->ni_lnd->lnd_setasync)(ni, id, nasync);
2590 LIBCFS_FREE(nids, maxnids * sizeof(*nids));
2594 EXPORT_SYMBOL(LNetSetAsync);