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 /** lnet message has credit and can be submitted to lnd for send/receive */
46 #define LNET_CREDIT_OK 0
47 /** lnet message is waiting for credit */
48 #define LNET_CREDIT_WAIT 1
50 static int local_nid_dist_zero = 1;
51 CFS_MODULE_PARM(local_nid_dist_zero, "i", int, 0444,
55 lnet_fail_nid(lnet_nid_t nid, unsigned int threshold)
59 struct list_head *next;
60 struct list_head cull;
62 LASSERT(the_lnet.ln_init);
64 /* NB: use lnet_net_lock(0) to serialize operations on test peers */
66 /* Adding a new entry */
67 LIBCFS_ALLOC(tp, sizeof(*tp));
72 tp->tp_threshold = threshold;
75 list_add_tail(&tp->tp_list, &the_lnet.ln_test_peers);
80 /* removing entries */
81 INIT_LIST_HEAD(&cull);
85 list_for_each_safe(el, next, &the_lnet.ln_test_peers) {
86 tp = list_entry(el, lnet_test_peer_t, tp_list);
88 if (tp->tp_threshold == 0 || /* needs culling anyway */
89 nid == LNET_NID_ANY || /* removing all entries */
90 tp->tp_nid == nid) { /* matched this one */
91 list_del(&tp->tp_list);
92 list_add(&tp->tp_list, &cull);
98 while (!list_empty(&cull)) {
99 tp = list_entry(cull.next, lnet_test_peer_t, tp_list);
101 list_del(&tp->tp_list);
102 LIBCFS_FREE(tp, sizeof(*tp));
108 fail_peer (lnet_nid_t nid, int outgoing)
110 lnet_test_peer_t *tp;
111 struct list_head *el;
112 struct list_head *next;
113 struct list_head cull;
116 INIT_LIST_HEAD(&cull);
118 /* NB: use lnet_net_lock(0) to serialize operations on test peers */
121 list_for_each_safe(el, next, &the_lnet.ln_test_peers) {
122 tp = list_entry(el, lnet_test_peer_t, tp_list);
124 if (tp->tp_threshold == 0) {
127 /* only cull zombies on outgoing tests,
128 * since we may be at interrupt priority on
129 * incoming messages. */
130 list_del(&tp->tp_list);
131 list_add(&tp->tp_list, &cull);
136 if (tp->tp_nid == LNET_NID_ANY || /* fail every peer */
137 nid == tp->tp_nid) { /* fail this peer */
140 if (tp->tp_threshold != LNET_MD_THRESH_INF) {
143 tp->tp_threshold == 0) {
145 list_del(&tp->tp_list);
146 list_add(&tp->tp_list, &cull);
155 while (!list_empty(&cull)) {
156 tp = list_entry(cull.next, lnet_test_peer_t, tp_list);
157 list_del(&tp->tp_list);
159 LIBCFS_FREE(tp, sizeof(*tp));
166 lnet_iov_nob (unsigned int niov, struct iovec *iov)
168 unsigned int nob = 0;
170 LASSERT(niov == 0 || iov != NULL);
172 nob += (iov++)->iov_len;
176 EXPORT_SYMBOL(lnet_iov_nob);
179 lnet_copy_iov2iov (unsigned int ndiov, struct iovec *diov, unsigned int doffset,
180 unsigned int nsiov, struct iovec *siov, unsigned int soffset,
183 /* NB diov, siov are READ-ONLY */
184 unsigned int this_nob;
189 /* skip complete frags before 'doffset' */
191 while (doffset >= diov->iov_len) {
192 doffset -= diov->iov_len;
198 /* skip complete frags before 'soffset' */
200 while (soffset >= siov->iov_len) {
201 soffset -= siov->iov_len;
210 this_nob = MIN(diov->iov_len - doffset,
211 siov->iov_len - soffset);
212 this_nob = MIN(this_nob, nob);
214 memcpy ((char *)diov->iov_base + doffset,
215 (char *)siov->iov_base + soffset, this_nob);
218 if (diov->iov_len > doffset + this_nob) {
226 if (siov->iov_len > soffset + this_nob) {
235 EXPORT_SYMBOL(lnet_copy_iov2iov);
238 lnet_extract_iov (int dst_niov, struct iovec *dst,
239 int src_niov, struct iovec *src,
240 unsigned int offset, unsigned int len)
242 /* Initialise 'dst' to the subset of 'src' starting at 'offset',
243 * for exactly 'len' bytes, and return the number of entries.
244 * NB not destructive to 'src' */
245 unsigned int frag_len;
248 if (len == 0) /* no data => */
249 return (0); /* no frags */
251 LASSERT (src_niov > 0);
252 while (offset >= src->iov_len) { /* skip initial frags */
253 offset -= src->iov_len;
256 LASSERT (src_niov > 0);
261 LASSERT (src_niov > 0);
262 LASSERT ((int)niov <= dst_niov);
264 frag_len = src->iov_len - offset;
265 dst->iov_base = ((char *)src->iov_base) + offset;
267 if (len <= frag_len) {
272 dst->iov_len = frag_len;
282 EXPORT_SYMBOL(lnet_extract_iov);
286 lnet_kiov_nob (unsigned int niov, lnet_kiov_t *kiov)
293 lnet_copy_kiov2kiov (unsigned int ndkiov, lnet_kiov_t *dkiov, unsigned int doffset,
294 unsigned int nskiov, lnet_kiov_t *skiov, unsigned int soffset,
301 lnet_copy_kiov2iov (unsigned int niov, struct iovec *iov, unsigned int iovoffset,
302 unsigned int nkiov, lnet_kiov_t *kiov, unsigned int kiovoffset,
309 lnet_copy_iov2kiov (unsigned int nkiov, lnet_kiov_t *kiov, unsigned int kiovoffset,
310 unsigned int niov, struct iovec *iov, unsigned int iovoffset,
317 lnet_extract_kiov (int dst_niov, lnet_kiov_t *dst,
318 int src_niov, lnet_kiov_t *src,
319 unsigned int offset, unsigned int len)
324 #else /* __KERNEL__ */
327 lnet_kiov_nob (unsigned int niov, lnet_kiov_t *kiov)
329 unsigned int nob = 0;
331 LASSERT(niov == 0 || kiov != NULL);
333 nob += (kiov++)->kiov_len;
337 EXPORT_SYMBOL(lnet_kiov_nob);
340 lnet_copy_kiov2kiov (unsigned int ndiov, lnet_kiov_t *diov, unsigned int doffset,
341 unsigned int nsiov, lnet_kiov_t *siov, unsigned int soffset,
344 /* NB diov, siov are READ-ONLY */
345 unsigned int this_nob;
352 LASSERT (!in_interrupt ());
355 while (doffset >= diov->kiov_len) {
356 doffset -= diov->kiov_len;
363 while (soffset >= siov->kiov_len) {
364 soffset -= siov->kiov_len;
373 this_nob = MIN(diov->kiov_len - doffset,
374 siov->kiov_len - soffset);
375 this_nob = MIN(this_nob, nob);
378 daddr = ((char *)kmap(diov->kiov_page)) +
379 diov->kiov_offset + doffset;
381 saddr = ((char *)kmap(siov->kiov_page)) +
382 siov->kiov_offset + soffset;
384 /* Vanishing risk of kmap deadlock when mapping 2 pages.
385 * However in practice at least one of the kiovs will be mapped
386 * kernel pages and the map/unmap will be NOOPs */
388 memcpy (daddr, saddr, this_nob);
391 if (diov->kiov_len > doffset + this_nob) {
395 kunmap(diov->kiov_page);
402 if (siov->kiov_len > soffset + this_nob) {
406 kunmap(siov->kiov_page);
415 kunmap(diov->kiov_page);
417 kunmap(siov->kiov_page);
419 EXPORT_SYMBOL(lnet_copy_kiov2kiov);
422 lnet_copy_kiov2iov (unsigned int niov, struct iovec *iov, unsigned int iovoffset,
423 unsigned int nkiov, lnet_kiov_t *kiov, unsigned int kiovoffset,
426 /* NB iov, kiov are READ-ONLY */
427 unsigned int this_nob;
433 LASSERT (!in_interrupt ());
436 while (iovoffset >= iov->iov_len) {
437 iovoffset -= iov->iov_len;
444 while (kiovoffset >= kiov->kiov_len) {
445 kiovoffset -= kiov->kiov_len;
454 this_nob = MIN(iov->iov_len - iovoffset,
455 kiov->kiov_len - kiovoffset);
456 this_nob = MIN(this_nob, nob);
459 addr = ((char *)kmap(kiov->kiov_page)) +
460 kiov->kiov_offset + kiovoffset;
462 memcpy ((char *)iov->iov_base + iovoffset, addr, this_nob);
465 if (iov->iov_len > iovoffset + this_nob) {
466 iovoffset += this_nob;
473 if (kiov->kiov_len > kiovoffset + this_nob) {
475 kiovoffset += this_nob;
477 kunmap(kiov->kiov_page);
487 kunmap(kiov->kiov_page);
489 EXPORT_SYMBOL(lnet_copy_kiov2iov);
492 lnet_copy_iov2kiov (unsigned int nkiov, lnet_kiov_t *kiov, unsigned int kiovoffset,
493 unsigned int niov, struct iovec *iov, unsigned int iovoffset,
496 /* NB kiov, iov are READ-ONLY */
497 unsigned int this_nob;
503 LASSERT (!in_interrupt ());
506 while (kiovoffset >= kiov->kiov_len) {
507 kiovoffset -= kiov->kiov_len;
514 while (iovoffset >= iov->iov_len) {
515 iovoffset -= iov->iov_len;
524 this_nob = MIN(kiov->kiov_len - kiovoffset,
525 iov->iov_len - iovoffset);
526 this_nob = MIN(this_nob, nob);
529 addr = ((char *)kmap(kiov->kiov_page)) +
530 kiov->kiov_offset + kiovoffset;
532 memcpy (addr, (char *)iov->iov_base + iovoffset, this_nob);
535 if (kiov->kiov_len > kiovoffset + this_nob) {
537 kiovoffset += this_nob;
539 kunmap(kiov->kiov_page);
546 if (iov->iov_len > iovoffset + this_nob) {
547 iovoffset += this_nob;
556 kunmap(kiov->kiov_page);
558 EXPORT_SYMBOL(lnet_copy_iov2kiov);
561 lnet_extract_kiov (int dst_niov, lnet_kiov_t *dst,
562 int src_niov, lnet_kiov_t *src,
563 unsigned int offset, unsigned int len)
565 /* Initialise 'dst' to the subset of 'src' starting at 'offset',
566 * for exactly 'len' bytes, and return the number of entries.
567 * NB not destructive to 'src' */
568 unsigned int frag_len;
571 if (len == 0) /* no data => */
572 return (0); /* no frags */
574 LASSERT (src_niov > 0);
575 while (offset >= src->kiov_len) { /* skip initial frags */
576 offset -= src->kiov_len;
579 LASSERT (src_niov > 0);
584 LASSERT (src_niov > 0);
585 LASSERT ((int)niov <= dst_niov);
587 frag_len = src->kiov_len - offset;
588 dst->kiov_page = src->kiov_page;
589 dst->kiov_offset = src->kiov_offset + offset;
591 if (len <= frag_len) {
593 LASSERT (dst->kiov_offset + dst->kiov_len <= PAGE_CACHE_SIZE);
597 dst->kiov_len = frag_len;
598 LASSERT (dst->kiov_offset + dst->kiov_len <= PAGE_CACHE_SIZE);
608 EXPORT_SYMBOL(lnet_extract_kiov);
612 lnet_ni_recv(lnet_ni_t *ni, void *private, lnet_msg_t *msg, int delayed,
613 unsigned int offset, unsigned int mlen, unsigned int rlen)
615 unsigned int niov = 0;
616 struct iovec *iov = NULL;
617 lnet_kiov_t *kiov = NULL;
620 LASSERT (!in_interrupt ());
621 LASSERT (mlen == 0 || msg != NULL);
624 LASSERT(msg->msg_receiving);
625 LASSERT(!msg->msg_sending);
626 LASSERT(rlen == msg->msg_len);
627 LASSERT(mlen <= msg->msg_len);
628 LASSERT(msg->msg_offset == offset);
629 LASSERT(msg->msg_wanted == mlen);
631 msg->msg_receiving = 0;
634 niov = msg->msg_niov;
636 kiov = msg->msg_kiov;
639 LASSERT ((iov == NULL) != (kiov == NULL));
643 rc = (ni->ni_lnd->lnd_recv)(ni, private, msg, delayed,
644 niov, iov, kiov, offset, mlen, rlen);
646 lnet_finalize(ni, msg, rc);
650 lnet_setpayloadbuffer(lnet_msg_t *msg)
652 lnet_libmd_t *md = msg->msg_md;
654 LASSERT (msg->msg_len > 0);
655 LASSERT (!msg->msg_routing);
656 LASSERT (md != NULL);
657 LASSERT (msg->msg_niov == 0);
658 LASSERT (msg->msg_iov == NULL);
659 LASSERT (msg->msg_kiov == NULL);
661 msg->msg_niov = md->md_niov;
662 if ((md->md_options & LNET_MD_KIOV) != 0)
663 msg->msg_kiov = md->md_iov.kiov;
665 msg->msg_iov = md->md_iov.iov;
669 lnet_prep_send(lnet_msg_t *msg, int type, lnet_process_id_t target,
670 unsigned int offset, unsigned int len)
672 msg->msg_type = type;
673 msg->msg_target = target;
675 msg->msg_offset = offset;
678 lnet_setpayloadbuffer(msg);
680 memset (&msg->msg_hdr, 0, sizeof (msg->msg_hdr));
681 msg->msg_hdr.type = cpu_to_le32(type);
682 msg->msg_hdr.dest_nid = cpu_to_le64(target.nid);
683 msg->msg_hdr.dest_pid = cpu_to_le32(target.pid);
684 /* src_nid will be set later */
685 msg->msg_hdr.src_pid = cpu_to_le32(the_lnet.ln_pid);
686 msg->msg_hdr.payload_length = cpu_to_le32(len);
690 lnet_ni_send(lnet_ni_t *ni, lnet_msg_t *msg)
692 void *priv = msg->msg_private;
695 LASSERT (!in_interrupt ());
696 LASSERT (LNET_NETTYP(LNET_NIDNET(ni->ni_nid)) == LOLND ||
697 (msg->msg_txcredit && msg->msg_peertxcredit));
699 rc = (ni->ni_lnd->lnd_send)(ni, priv, msg);
701 lnet_finalize(ni, msg, rc);
705 lnet_ni_eager_recv(lnet_ni_t *ni, lnet_msg_t *msg)
709 LASSERT(!msg->msg_sending);
710 LASSERT(msg->msg_receiving);
711 LASSERT(!msg->msg_rx_ready_delay);
712 LASSERT(ni->ni_lnd->lnd_eager_recv != NULL);
714 msg->msg_rx_ready_delay = 1;
715 rc = (ni->ni_lnd->lnd_eager_recv)(ni, msg->msg_private, msg,
718 CERROR("recv from %s / send to %s aborted: "
719 "eager_recv failed %d\n",
720 libcfs_nid2str(msg->msg_rxpeer->lp_nid),
721 libcfs_id2str(msg->msg_target), rc);
722 LASSERT(rc < 0); /* required by my callers */
728 /* NB: caller shall hold a ref on 'lp' as I'd drop lnet_net_lock */
730 lnet_ni_query_locked(lnet_ni_t *ni, lnet_peer_t *lp)
732 cfs_time_t last_alive = 0;
734 LASSERT(lnet_peer_aliveness_enabled(lp));
735 LASSERT(ni->ni_lnd->lnd_query != NULL);
737 lnet_net_unlock(lp->lp_cpt);
738 (ni->ni_lnd->lnd_query)(ni, lp->lp_nid, &last_alive);
739 lnet_net_lock(lp->lp_cpt);
741 lp->lp_last_query = cfs_time_current();
743 if (last_alive != 0) /* NI has updated timestamp */
744 lp->lp_last_alive = last_alive;
747 /* NB: always called with lnet_net_lock held */
749 lnet_peer_is_alive (lnet_peer_t *lp, cfs_time_t now)
754 LASSERT (lnet_peer_aliveness_enabled(lp));
756 /* Trust lnet_notify() if it has more recent aliveness news, but
757 * ignore the initial assumed death (see lnet_peers_start_down()).
759 if (!lp->lp_alive && lp->lp_alive_count > 0 &&
760 cfs_time_aftereq(lp->lp_timestamp, lp->lp_last_alive))
763 deadline = cfs_time_add(lp->lp_last_alive,
764 cfs_time_seconds(lp->lp_ni->ni_peertimeout));
765 alive = cfs_time_after(deadline, now);
767 /* Update obsolete lp_alive except for routers assumed to be dead
768 * initially, because router checker would update aliveness in this
769 * case, and moreover lp_last_alive at peer creation is assumed.
771 if (alive && !lp->lp_alive &&
772 !(lnet_isrouter(lp) && lp->lp_alive_count == 0))
773 lnet_notify_locked(lp, 0, 1, lp->lp_last_alive);
779 /* NB: returns 1 when alive, 0 when dead, negative when error;
780 * may drop the lnet_net_lock */
782 lnet_peer_alive_locked (lnet_peer_t *lp)
784 cfs_time_t now = cfs_time_current();
786 if (!lnet_peer_aliveness_enabled(lp))
789 if (lnet_peer_is_alive(lp, now))
792 /* Peer appears dead, but we should avoid frequent NI queries (at
793 * most once per lnet_queryinterval seconds). */
794 if (lp->lp_last_query != 0) {
795 static const int lnet_queryinterval = 1;
797 cfs_time_t next_query =
798 cfs_time_add(lp->lp_last_query,
799 cfs_time_seconds(lnet_queryinterval));
801 if (cfs_time_before(now, next_query)) {
803 CWARN("Unexpected aliveness of peer %s: "
805 libcfs_nid2str(lp->lp_nid),
806 (int)now, (int)next_query,
808 lp->lp_ni->ni_peertimeout);
813 /* query NI for latest aliveness news */
814 lnet_ni_query_locked(lp->lp_ni, lp);
816 if (lnet_peer_is_alive(lp, now))
819 lnet_notify_locked(lp, 0, 0, lp->lp_last_alive);
824 * \param msg The message to be sent.
825 * \param do_send True if lnet_ni_send() should be called in this function.
826 * lnet_send() is going to lnet_net_unlock immediately after this, so
827 * it sets do_send FALSE and I don't do the unlock/send/lock bit.
829 * \retval LNET_CREDIT_OK If \a msg sent or OK to send.
830 * \retval LNET_CREDIT_WAIT If \a msg blocked for credit.
831 * \retval -EHOSTUNREACH If the next hop of the message appears dead.
832 * \retval -ECANCELED If the MD of the message has been unlinked.
835 lnet_post_send_locked(lnet_msg_t *msg, int do_send)
837 lnet_peer_t *lp = msg->msg_txpeer;
838 lnet_ni_t *ni = lp->lp_ni;
839 int cpt = msg->msg_tx_cpt;
840 struct lnet_tx_queue *tq = ni->ni_tx_queues[cpt];
842 /* non-lnet_send() callers have checked before */
843 LASSERT(!do_send || msg->msg_tx_delayed);
844 LASSERT(!msg->msg_receiving);
845 LASSERT(msg->msg_tx_committed);
847 /* NB 'lp' is always the next hop */
848 if ((msg->msg_target.pid & LNET_PID_USERFLAG) == 0 &&
849 lnet_peer_alive_locked(lp) == 0) {
850 the_lnet.ln_counters[cpt]->drop_count++;
851 the_lnet.ln_counters[cpt]->drop_length += msg->msg_len;
852 lnet_net_unlock(cpt);
854 CNETERR("Dropping message for %s: peer not alive\n",
855 libcfs_id2str(msg->msg_target));
857 lnet_finalize(ni, msg, -EHOSTUNREACH);
860 return -EHOSTUNREACH;
863 if (msg->msg_md != NULL &&
864 (msg->msg_md->md_flags & LNET_MD_FLAG_ABORTED) != 0) {
865 lnet_net_unlock(cpt);
867 CNETERR("Aborting message for %s: LNetM[DE]Unlink() already "
868 "called on the MD/ME.\n",
869 libcfs_id2str(msg->msg_target));
871 lnet_finalize(ni, msg, -ECANCELED);
877 if (!msg->msg_peertxcredit) {
878 LASSERT((lp->lp_txcredits < 0) ==
879 !list_empty(&lp->lp_txq));
881 msg->msg_peertxcredit = 1;
882 lp->lp_txqnob += msg->msg_len + sizeof(lnet_hdr_t);
885 if (lp->lp_txcredits < lp->lp_mintxcredits)
886 lp->lp_mintxcredits = lp->lp_txcredits;
888 if (lp->lp_txcredits < 0) {
889 msg->msg_tx_delayed = 1;
890 list_add_tail(&msg->msg_list, &lp->lp_txq);
891 return LNET_CREDIT_WAIT;
895 if (!msg->msg_txcredit) {
896 LASSERT((tq->tq_credits < 0) ==
897 !list_empty(&tq->tq_delayed));
899 msg->msg_txcredit = 1;
902 if (tq->tq_credits < tq->tq_credits_min)
903 tq->tq_credits_min = tq->tq_credits;
905 if (tq->tq_credits < 0) {
906 msg->msg_tx_delayed = 1;
907 list_add_tail(&msg->msg_list, &tq->tq_delayed);
908 return LNET_CREDIT_WAIT;
913 lnet_net_unlock(cpt);
914 lnet_ni_send(ni, msg);
917 return LNET_CREDIT_OK;
923 lnet_msg2bufpool(lnet_msg_t *msg)
925 lnet_rtrbufpool_t *rbp;
928 LASSERT(msg->msg_rx_committed);
930 cpt = msg->msg_rx_cpt;
931 rbp = &the_lnet.ln_rtrpools[cpt][0];
933 LASSERT(msg->msg_len <= LNET_MTU);
934 while (msg->msg_len > (unsigned int)rbp->rbp_npages * PAGE_CACHE_SIZE) {
936 LASSERT(rbp < &the_lnet.ln_rtrpools[cpt][LNET_NRBPOOLS]);
943 lnet_post_routed_recv_locked (lnet_msg_t *msg, int do_recv)
945 /* lnet_parse is going to lnet_net_unlock immediately after this, so it
946 * sets do_recv FALSE and I don't do the unlock/send/lock bit.
947 * I return LNET_CREDIT_WAIT if msg blocked and LNET_CREDIT_OK if
948 * received or OK to receive */
949 lnet_peer_t *lp = msg->msg_rxpeer;
950 lnet_rtrbufpool_t *rbp;
953 LASSERT (msg->msg_iov == NULL);
954 LASSERT (msg->msg_kiov == NULL);
955 LASSERT (msg->msg_niov == 0);
956 LASSERT (msg->msg_routing);
957 LASSERT (msg->msg_receiving);
958 LASSERT (!msg->msg_sending);
960 /* non-lnet_parse callers only receive delayed messages */
961 LASSERT(!do_recv || msg->msg_rx_delayed);
963 if (!msg->msg_peerrtrcredit) {
964 LASSERT((lp->lp_rtrcredits < 0) ==
965 !list_empty(&lp->lp_rtrq));
967 msg->msg_peerrtrcredit = 1;
969 if (lp->lp_rtrcredits < lp->lp_minrtrcredits)
970 lp->lp_minrtrcredits = lp->lp_rtrcredits;
972 if (lp->lp_rtrcredits < 0) {
973 /* must have checked eager_recv before here */
974 LASSERT(msg->msg_rx_ready_delay);
975 msg->msg_rx_delayed = 1;
976 list_add_tail(&msg->msg_list, &lp->lp_rtrq);
977 return LNET_CREDIT_WAIT;
981 rbp = lnet_msg2bufpool(msg);
983 if (!msg->msg_rtrcredit) {
984 LASSERT((rbp->rbp_credits < 0) ==
985 !list_empty(&rbp->rbp_msgs));
987 msg->msg_rtrcredit = 1;
989 if (rbp->rbp_credits < rbp->rbp_mincredits)
990 rbp->rbp_mincredits = rbp->rbp_credits;
992 if (rbp->rbp_credits < 0) {
993 /* must have checked eager_recv before here */
994 LASSERT(msg->msg_rx_ready_delay);
995 msg->msg_rx_delayed = 1;
996 list_add_tail(&msg->msg_list, &rbp->rbp_msgs);
997 return LNET_CREDIT_WAIT;
1001 LASSERT(!list_empty(&rbp->rbp_bufs));
1002 rb = list_entry(rbp->rbp_bufs.next, lnet_rtrbuf_t, rb_list);
1003 list_del(&rb->rb_list);
1005 msg->msg_niov = rbp->rbp_npages;
1006 msg->msg_kiov = &rb->rb_kiov[0];
1009 int cpt = msg->msg_rx_cpt;
1011 lnet_net_unlock(cpt);
1012 lnet_ni_recv(lp->lp_ni, msg->msg_private, msg, 1,
1013 0, msg->msg_len, msg->msg_len);
1016 return LNET_CREDIT_OK;
1021 lnet_return_tx_credits_locked(lnet_msg_t *msg)
1023 lnet_peer_t *txpeer = msg->msg_txpeer;
1026 if (msg->msg_txcredit) {
1027 struct lnet_ni *ni = txpeer->lp_ni;
1028 struct lnet_tx_queue *tq = ni->ni_tx_queues[msg->msg_tx_cpt];
1030 /* give back NI txcredits */
1031 msg->msg_txcredit = 0;
1033 LASSERT((tq->tq_credits < 0) ==
1034 !list_empty(&tq->tq_delayed));
1037 if (tq->tq_credits <= 0) {
1038 msg2 = list_entry(tq->tq_delayed.next,
1039 lnet_msg_t, msg_list);
1040 list_del(&msg2->msg_list);
1042 LASSERT(msg2->msg_txpeer->lp_ni == ni);
1043 LASSERT(msg2->msg_tx_delayed);
1045 (void) lnet_post_send_locked(msg2, 1);
1049 if (msg->msg_peertxcredit) {
1050 /* give back peer txcredits */
1051 msg->msg_peertxcredit = 0;
1053 LASSERT((txpeer->lp_txcredits < 0) ==
1054 !list_empty(&txpeer->lp_txq));
1056 txpeer->lp_txqnob -= msg->msg_len + sizeof(lnet_hdr_t);
1057 LASSERT (txpeer->lp_txqnob >= 0);
1059 txpeer->lp_txcredits++;
1060 if (txpeer->lp_txcredits <= 0) {
1061 msg2 = list_entry(txpeer->lp_txq.next,
1062 lnet_msg_t, msg_list);
1063 list_del(&msg2->msg_list);
1065 LASSERT(msg2->msg_txpeer == txpeer);
1066 LASSERT(msg2->msg_tx_delayed);
1068 (void) lnet_post_send_locked(msg2, 1);
1072 if (txpeer != NULL) {
1073 msg->msg_txpeer = NULL;
1074 lnet_peer_decref_locked(txpeer);
1079 lnet_return_rx_credits_locked(lnet_msg_t *msg)
1081 lnet_peer_t *rxpeer = msg->msg_rxpeer;
1085 if (msg->msg_rtrcredit) {
1086 /* give back global router credits */
1088 lnet_rtrbufpool_t *rbp;
1090 /* NB If a msg ever blocks for a buffer in rbp_msgs, it stays
1091 * there until it gets one allocated, or aborts the wait
1093 LASSERT (msg->msg_kiov != NULL);
1095 rb = list_entry(msg->msg_kiov, lnet_rtrbuf_t, rb_kiov[0]);
1097 LASSERT (rbp == lnet_msg2bufpool(msg));
1099 msg->msg_kiov = NULL;
1100 msg->msg_rtrcredit = 0;
1102 LASSERT((rbp->rbp_credits < 0) ==
1103 !list_empty(&rbp->rbp_msgs));
1104 LASSERT((rbp->rbp_credits > 0) ==
1105 !list_empty(&rbp->rbp_bufs));
1107 list_add(&rb->rb_list, &rbp->rbp_bufs);
1109 if (rbp->rbp_credits <= 0) {
1110 msg2 = list_entry(rbp->rbp_msgs.next,
1111 lnet_msg_t, msg_list);
1112 list_del(&msg2->msg_list);
1114 (void) lnet_post_routed_recv_locked(msg2, 1);
1118 if (msg->msg_peerrtrcredit) {
1119 /* give back peer router credits */
1120 msg->msg_peerrtrcredit = 0;
1122 LASSERT((rxpeer->lp_rtrcredits < 0) ==
1123 !list_empty(&rxpeer->lp_rtrq));
1125 rxpeer->lp_rtrcredits++;
1126 if (rxpeer->lp_rtrcredits <= 0) {
1127 msg2 = list_entry(rxpeer->lp_rtrq.next,
1128 lnet_msg_t, msg_list);
1129 list_del(&msg2->msg_list);
1131 (void) lnet_post_routed_recv_locked(msg2, 1);
1135 LASSERT (!msg->msg_rtrcredit);
1136 LASSERT (!msg->msg_peerrtrcredit);
1138 if (rxpeer != NULL) {
1139 msg->msg_rxpeer = NULL;
1140 lnet_peer_decref_locked(rxpeer);
1145 lnet_compare_routes(lnet_route_t *r1, lnet_route_t *r2)
1147 lnet_peer_t *p1 = r1->lr_gateway;
1148 lnet_peer_t *p2 = r2->lr_gateway;
1150 if (r1->lr_priority < r2->lr_priority)
1153 if (r1->lr_priority > r2->lr_priority)
1156 if (r1->lr_hops < r2->lr_hops)
1159 if (r1->lr_hops > r2->lr_hops)
1162 if (p1->lp_txqnob < p2->lp_txqnob)
1165 if (p1->lp_txqnob > p2->lp_txqnob)
1168 if (p1->lp_txcredits > p2->lp_txcredits)
1171 if (p1->lp_txcredits < p2->lp_txcredits)
1174 if (r1->lr_seq - r2->lr_seq <= 0)
1180 static lnet_peer_t *
1181 lnet_find_route_locked(lnet_ni_t *ni, lnet_nid_t target, lnet_nid_t rtr_nid)
1183 lnet_remotenet_t *rnet;
1184 lnet_route_t *route;
1185 lnet_route_t *best_route;
1186 lnet_route_t *last_route;
1187 struct lnet_peer *lp_best;
1188 struct lnet_peer *lp;
1191 /* If @rtr_nid is not LNET_NID_ANY, return the gateway with
1192 * rtr_nid nid, otherwise find the best gateway I can use */
1194 rnet = lnet_find_net_locked(LNET_NIDNET(target));
1199 best_route = last_route = NULL;
1200 list_for_each_entry(route, &rnet->lrn_routes, lr_list) {
1201 lp = route->lr_gateway;
1203 if (!lnet_is_route_alive(route))
1206 if (ni != NULL && lp->lp_ni != ni)
1209 if (lp->lp_nid == rtr_nid) /* it's pre-determined router */
1212 if (lp_best == NULL) {
1213 best_route = last_route = route;
1218 /* no protection on below fields, but it's harmless */
1219 if (last_route->lr_seq - route->lr_seq < 0)
1222 rc = lnet_compare_routes(route, best_route);
1230 /* set sequence number on the best router to the latest sequence + 1
1231 * so we can round-robin all routers, it's race and inaccurate but
1232 * harmless and functional */
1233 if (best_route != NULL)
1234 best_route->lr_seq = last_route->lr_seq + 1;
1239 lnet_send(lnet_nid_t src_nid, lnet_msg_t *msg, lnet_nid_t rtr_nid)
1241 lnet_nid_t dst_nid = msg->msg_target.nid;
1242 struct lnet_ni *src_ni;
1243 struct lnet_ni *local_ni;
1244 struct lnet_peer *lp;
1249 /* NB: rtr_nid is set to LNET_NID_ANY for all current use-cases,
1250 * but we might want to use pre-determined router for ACK/REPLY
1252 /* NB: ni != NULL == interface pre-determined (ACK/REPLY) */
1253 LASSERT (msg->msg_txpeer == NULL);
1254 LASSERT (!msg->msg_sending);
1255 LASSERT (!msg->msg_target_is_router);
1256 LASSERT (!msg->msg_receiving);
1258 msg->msg_sending = 1;
1260 LASSERT(!msg->msg_tx_committed);
1261 cpt = lnet_cpt_of_nid(rtr_nid == LNET_NID_ANY ? dst_nid : rtr_nid);
1265 if (the_lnet.ln_shutdown) {
1266 lnet_net_unlock(cpt);
1270 if (src_nid == LNET_NID_ANY) {
1273 src_ni = lnet_nid2ni_locked(src_nid, cpt);
1274 if (src_ni == NULL) {
1275 lnet_net_unlock(cpt);
1276 LCONSOLE_WARN("Can't send to %s: src %s is not a "
1277 "local nid\n", libcfs_nid2str(dst_nid),
1278 libcfs_nid2str(src_nid));
1281 LASSERT (!msg->msg_routing);
1284 /* Is this for someone on a local network? */
1285 local_ni = lnet_net2ni_locked(LNET_NIDNET(dst_nid), cpt);
1287 if (local_ni != NULL) {
1288 if (src_ni == NULL) {
1290 src_nid = src_ni->ni_nid;
1291 } else if (src_ni == local_ni) {
1292 lnet_ni_decref_locked(local_ni, cpt);
1294 lnet_ni_decref_locked(local_ni, cpt);
1295 lnet_ni_decref_locked(src_ni, cpt);
1296 lnet_net_unlock(cpt);
1297 LCONSOLE_WARN("No route to %s via from %s\n",
1298 libcfs_nid2str(dst_nid),
1299 libcfs_nid2str(src_nid));
1303 LASSERT(src_nid != LNET_NID_ANY);
1304 lnet_msg_commit(msg, cpt);
1306 if (!msg->msg_routing)
1307 msg->msg_hdr.src_nid = cpu_to_le64(src_nid);
1309 if (src_ni == the_lnet.ln_loni) {
1310 /* No send credit hassles with LOLND */
1311 lnet_net_unlock(cpt);
1312 lnet_ni_send(src_ni, msg);
1315 lnet_ni_decref_locked(src_ni, cpt);
1316 lnet_net_unlock(cpt);
1320 rc = lnet_nid2peer_locked(&lp, dst_nid, cpt);
1321 /* lp has ref on src_ni; lose mine */
1322 lnet_ni_decref_locked(src_ni, cpt);
1324 lnet_net_unlock(cpt);
1325 LCONSOLE_WARN("Error %d finding peer %s\n", rc,
1326 libcfs_nid2str(dst_nid));
1327 /* ENOMEM or shutting down */
1330 LASSERT (lp->lp_ni == src_ni);
1333 lnet_net_unlock(cpt);
1336 * - once application finishes computation, check here to update
1337 * router states before it waits for pending IO in LNetEQPoll
1338 * - recursion breaker: router checker sends no message
1339 * to remote networks */
1340 if (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING)
1341 lnet_router_checker();
1345 /* sending to a remote network */
1346 lp = lnet_find_route_locked(src_ni, dst_nid, rtr_nid);
1349 lnet_ni_decref_locked(src_ni, cpt);
1350 lnet_net_unlock(cpt);
1352 LCONSOLE_WARN("No route to %s via %s "
1353 "(all routers down)\n",
1354 libcfs_id2str(msg->msg_target),
1355 libcfs_nid2str(src_nid));
1356 return -EHOSTUNREACH;
1359 /* rtr_nid is LNET_NID_ANY or NID of pre-determined router,
1360 * it's possible that rtr_nid isn't LNET_NID_ANY and lp isn't
1361 * pre-determined router, this can happen if router table
1362 * was changed when we release the lock */
1363 if (rtr_nid != lp->lp_nid) {
1364 cpt2 = lnet_cpt_of_nid_locked(lp->lp_nid);
1367 lnet_ni_decref_locked(src_ni, cpt);
1368 lnet_net_unlock(cpt);
1370 rtr_nid = lp->lp_nid;
1376 CDEBUG(D_NET, "Best route to %s via %s for %s %d\n",
1377 libcfs_nid2str(dst_nid), libcfs_nid2str(lp->lp_nid),
1378 lnet_msgtyp2str(msg->msg_type), msg->msg_len);
1380 if (src_ni == NULL) {
1382 src_nid = src_ni->ni_nid;
1384 LASSERT (src_ni == lp->lp_ni);
1385 lnet_ni_decref_locked(src_ni, cpt);
1388 lnet_peer_addref_locked(lp);
1390 LASSERT(src_nid != LNET_NID_ANY);
1391 lnet_msg_commit(msg, cpt);
1393 if (!msg->msg_routing) {
1394 /* I'm the source and now I know which NI to send on */
1395 msg->msg_hdr.src_nid = cpu_to_le64(src_nid);
1398 msg->msg_target_is_router = 1;
1399 msg->msg_target.nid = lp->lp_nid;
1400 msg->msg_target.pid = LUSTRE_SRV_LNET_PID;
1403 /* 'lp' is our best choice of peer */
1405 LASSERT (!msg->msg_peertxcredit);
1406 LASSERT (!msg->msg_txcredit);
1407 LASSERT (msg->msg_txpeer == NULL);
1409 msg->msg_txpeer = lp; /* msg takes my ref on lp */
1411 rc = lnet_post_send_locked(msg, 0);
1412 lnet_net_unlock(cpt);
1417 if (rc == LNET_CREDIT_OK)
1418 lnet_ni_send(src_ni, msg);
1420 return 0; /* rc == LNET_CREDIT_OK or LNET_CREDIT_WAIT */
1424 lnet_drop_message(lnet_ni_t *ni, int cpt, void *private, unsigned int nob)
1427 the_lnet.ln_counters[cpt]->drop_count++;
1428 the_lnet.ln_counters[cpt]->drop_length += nob;
1429 lnet_net_unlock(cpt);
1431 lnet_ni_recv(ni, private, NULL, 0, 0, 0, nob);
1435 lnet_recv_put(lnet_ni_t *ni, lnet_msg_t *msg)
1437 lnet_hdr_t *hdr = &msg->msg_hdr;
1439 if (msg->msg_wanted != 0)
1440 lnet_setpayloadbuffer(msg);
1442 lnet_build_msg_event(msg, LNET_EVENT_PUT);
1444 /* Must I ACK? If so I'll grab the ack_wmd out of the header and put
1445 * it back into the ACK during lnet_finalize() */
1446 msg->msg_ack = (!lnet_is_wire_handle_none(&hdr->msg.put.ack_wmd) &&
1447 (msg->msg_md->md_options & LNET_MD_ACK_DISABLE) == 0);
1449 lnet_ni_recv(ni, msg->msg_private, msg, msg->msg_rx_delayed,
1450 msg->msg_offset, msg->msg_wanted, hdr->payload_length);
1454 lnet_parse_put(lnet_ni_t *ni, lnet_msg_t *msg)
1456 lnet_hdr_t *hdr = &msg->msg_hdr;
1457 struct lnet_match_info info;
1460 /* Convert put fields to host byte order */
1461 hdr->msg.put.match_bits = le64_to_cpu(hdr->msg.put.match_bits);
1462 hdr->msg.put.ptl_index = le32_to_cpu(hdr->msg.put.ptl_index);
1463 hdr->msg.put.offset = le32_to_cpu(hdr->msg.put.offset);
1465 info.mi_id.nid = hdr->src_nid;
1466 info.mi_id.pid = hdr->src_pid;
1467 info.mi_opc = LNET_MD_OP_PUT;
1468 info.mi_portal = hdr->msg.put.ptl_index;
1469 info.mi_rlength = hdr->payload_length;
1470 info.mi_roffset = hdr->msg.put.offset;
1471 info.mi_mbits = hdr->msg.put.match_bits;
1473 msg->msg_rx_ready_delay = ni->ni_lnd->lnd_eager_recv == NULL;
1476 rc = lnet_ptl_match_md(&info, msg);
1481 case LNET_MATCHMD_OK:
1482 lnet_recv_put(ni, msg);
1485 case LNET_MATCHMD_NONE:
1486 if (msg->msg_rx_delayed) /* attached on delayed list */
1489 rc = lnet_ni_eager_recv(ni, msg);
1494 case LNET_MATCHMD_DROP:
1495 CNETERR("Dropping PUT from %s portal %d match "LPU64
1496 " offset %d length %d: %d\n",
1497 libcfs_id2str(info.mi_id), info.mi_portal,
1498 info.mi_mbits, info.mi_roffset, info.mi_rlength, rc);
1500 return ENOENT; /* +ve: OK but no match */
1505 lnet_parse_get(lnet_ni_t *ni, lnet_msg_t *msg, int rdma_get)
1507 struct lnet_match_info info;
1508 lnet_hdr_t *hdr = &msg->msg_hdr;
1509 lnet_handle_wire_t reply_wmd;
1512 /* Convert get fields to host byte order */
1513 hdr->msg.get.match_bits = le64_to_cpu(hdr->msg.get.match_bits);
1514 hdr->msg.get.ptl_index = le32_to_cpu(hdr->msg.get.ptl_index);
1515 hdr->msg.get.sink_length = le32_to_cpu(hdr->msg.get.sink_length);
1516 hdr->msg.get.src_offset = le32_to_cpu(hdr->msg.get.src_offset);
1518 info.mi_id.nid = hdr->src_nid;
1519 info.mi_id.pid = hdr->src_pid;
1520 info.mi_opc = LNET_MD_OP_GET;
1521 info.mi_portal = hdr->msg.get.ptl_index;
1522 info.mi_rlength = hdr->msg.get.sink_length;
1523 info.mi_roffset = hdr->msg.get.src_offset;
1524 info.mi_mbits = hdr->msg.get.match_bits;
1526 rc = lnet_ptl_match_md(&info, msg);
1527 if (rc == LNET_MATCHMD_DROP) {
1528 CNETERR("Dropping GET from %s portal %d match "LPU64
1529 " offset %d length %d\n",
1530 libcfs_id2str(info.mi_id), info.mi_portal,
1531 info.mi_mbits, info.mi_roffset, info.mi_rlength);
1532 return ENOENT; /* +ve: OK but no match */
1535 LASSERT(rc == LNET_MATCHMD_OK);
1537 lnet_build_msg_event(msg, LNET_EVENT_GET);
1539 reply_wmd = hdr->msg.get.return_wmd;
1541 lnet_prep_send(msg, LNET_MSG_REPLY, info.mi_id,
1542 msg->msg_offset, msg->msg_wanted);
1544 msg->msg_hdr.msg.reply.dst_wmd = reply_wmd;
1547 /* The LND completes the REPLY from her recv procedure */
1548 lnet_ni_recv(ni, msg->msg_private, msg, 0,
1549 msg->msg_offset, msg->msg_len, msg->msg_len);
1553 lnet_ni_recv(ni, msg->msg_private, NULL, 0, 0, 0, 0);
1554 msg->msg_receiving = 0;
1556 rc = lnet_send(ni->ni_nid, msg, LNET_NID_ANY);
1558 /* didn't get as far as lnet_ni_send() */
1559 CERROR("%s: Unable to send REPLY for GET from %s: %d\n",
1560 libcfs_nid2str(ni->ni_nid),
1561 libcfs_id2str(info.mi_id), rc);
1563 lnet_finalize(ni, msg, rc);
1570 lnet_parse_reply(lnet_ni_t *ni, lnet_msg_t *msg)
1572 void *private = msg->msg_private;
1573 lnet_hdr_t *hdr = &msg->msg_hdr;
1574 lnet_process_id_t src = {0};
1580 cpt = lnet_cpt_of_cookie(hdr->msg.reply.dst_wmd.wh_object_cookie);
1583 src.nid = hdr->src_nid;
1584 src.pid = hdr->src_pid;
1586 /* NB handles only looked up by creator (no flips) */
1587 md = lnet_wire_handle2md(&hdr->msg.reply.dst_wmd);
1588 if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) {
1589 CNETERR("%s: Dropping REPLY from %s for %s "
1590 "MD "LPX64"."LPX64"\n",
1591 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
1592 (md == NULL) ? "invalid" : "inactive",
1593 hdr->msg.reply.dst_wmd.wh_interface_cookie,
1594 hdr->msg.reply.dst_wmd.wh_object_cookie);
1595 if (md != NULL && md->md_me != NULL)
1596 CERROR("REPLY MD also attached to portal %d\n",
1597 md->md_me->me_portal);
1599 lnet_res_unlock(cpt);
1600 return ENOENT; /* +ve: OK but no match */
1603 LASSERT (md->md_offset == 0);
1605 rlength = hdr->payload_length;
1606 mlength = MIN(rlength, (int)md->md_length);
1608 if (mlength < rlength &&
1609 (md->md_options & LNET_MD_TRUNCATE) == 0) {
1610 CNETERR("%s: Dropping REPLY from %s length %d "
1611 "for MD "LPX64" would overflow (%d)\n",
1612 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
1613 rlength, hdr->msg.reply.dst_wmd.wh_object_cookie,
1615 lnet_res_unlock(cpt);
1616 return ENOENT; /* +ve: OK but no match */
1619 CDEBUG(D_NET, "%s: Reply from %s of length %d/%d into md "LPX64"\n",
1620 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
1621 mlength, rlength, hdr->msg.reply.dst_wmd.wh_object_cookie);
1623 lnet_msg_attach_md(msg, md, 0, mlength);
1626 lnet_setpayloadbuffer(msg);
1628 lnet_res_unlock(cpt);
1630 lnet_build_msg_event(msg, LNET_EVENT_REPLY);
1632 lnet_ni_recv(ni, private, msg, 0, 0, mlength, rlength);
1637 lnet_parse_ack(lnet_ni_t *ni, lnet_msg_t *msg)
1639 lnet_hdr_t *hdr = &msg->msg_hdr;
1640 lnet_process_id_t src = {0};
1644 src.nid = hdr->src_nid;
1645 src.pid = hdr->src_pid;
1647 /* Convert ack fields to host byte order */
1648 hdr->msg.ack.match_bits = le64_to_cpu(hdr->msg.ack.match_bits);
1649 hdr->msg.ack.mlength = le32_to_cpu(hdr->msg.ack.mlength);
1651 cpt = lnet_cpt_of_cookie(hdr->msg.ack.dst_wmd.wh_object_cookie);
1654 /* NB handles only looked up by creator (no flips) */
1655 md = lnet_wire_handle2md(&hdr->msg.ack.dst_wmd);
1656 if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) {
1657 /* Don't moan; this is expected */
1659 "%s: Dropping ACK from %s to %s MD "LPX64"."LPX64"\n",
1660 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
1661 (md == NULL) ? "invalid" : "inactive",
1662 hdr->msg.ack.dst_wmd.wh_interface_cookie,
1663 hdr->msg.ack.dst_wmd.wh_object_cookie);
1664 if (md != NULL && md->md_me != NULL)
1665 CERROR("Source MD also attached to portal %d\n",
1666 md->md_me->me_portal);
1668 lnet_res_unlock(cpt);
1669 return ENOENT; /* +ve! */
1672 CDEBUG(D_NET, "%s: ACK from %s into md "LPX64"\n",
1673 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
1674 hdr->msg.ack.dst_wmd.wh_object_cookie);
1676 lnet_msg_attach_md(msg, md, 0, 0);
1678 lnet_res_unlock(cpt);
1680 lnet_build_msg_event(msg, LNET_EVENT_ACK);
1682 lnet_ni_recv(ni, msg->msg_private, msg, 0, 0, 0, msg->msg_len);
1687 * \retval LNET_CREDIT_OK If \a msg is forwarded
1688 * \retval LNET_CREDIT_WAIT If \a msg is blocked because w/o buffer
1689 * \retval -ve error code
1692 lnet_parse_forward_locked(lnet_ni_t *ni, lnet_msg_t *msg)
1697 if (msg->msg_rxpeer->lp_rtrcredits <= 0 ||
1698 lnet_msg2bufpool(msg)->rbp_credits <= 0) {
1699 if (ni->ni_lnd->lnd_eager_recv == NULL) {
1700 msg->msg_rx_ready_delay = 1;
1702 lnet_net_unlock(msg->msg_rx_cpt);
1703 rc = lnet_ni_eager_recv(ni, msg);
1704 lnet_net_lock(msg->msg_rx_cpt);
1709 rc = lnet_post_routed_recv_locked(msg, 0);
1717 lnet_msgtyp2str (int type)
1726 case LNET_MSG_REPLY:
1728 case LNET_MSG_HELLO:
1731 return ("<UNKNOWN>");
1734 EXPORT_SYMBOL(lnet_msgtyp2str);
1737 lnet_print_hdr(lnet_hdr_t * hdr)
1739 lnet_process_id_t src = {0};
1740 lnet_process_id_t dst = {0};
1741 char *type_str = lnet_msgtyp2str (hdr->type);
1743 src.nid = hdr->src_nid;
1744 src.pid = hdr->src_pid;
1746 dst.nid = hdr->dest_nid;
1747 dst.pid = hdr->dest_pid;
1749 CWARN("P3 Header at %p of type %s\n", hdr, type_str);
1750 CWARN(" From %s\n", libcfs_id2str(src));
1751 CWARN(" To %s\n", libcfs_id2str(dst));
1753 switch (hdr->type) {
1758 CWARN(" Ptl index %d, ack md "LPX64"."LPX64", "
1759 "match bits "LPU64"\n",
1760 hdr->msg.put.ptl_index,
1761 hdr->msg.put.ack_wmd.wh_interface_cookie,
1762 hdr->msg.put.ack_wmd.wh_object_cookie,
1763 hdr->msg.put.match_bits);
1764 CWARN(" Length %d, offset %d, hdr data "LPX64"\n",
1765 hdr->payload_length, hdr->msg.put.offset,
1766 hdr->msg.put.hdr_data);
1770 CWARN(" Ptl index %d, return md "LPX64"."LPX64", "
1771 "match bits "LPU64"\n", hdr->msg.get.ptl_index,
1772 hdr->msg.get.return_wmd.wh_interface_cookie,
1773 hdr->msg.get.return_wmd.wh_object_cookie,
1774 hdr->msg.get.match_bits);
1775 CWARN(" Length %d, src offset %d\n",
1776 hdr->msg.get.sink_length,
1777 hdr->msg.get.src_offset);
1781 CWARN(" dst md "LPX64"."LPX64", "
1782 "manipulated length %d\n",
1783 hdr->msg.ack.dst_wmd.wh_interface_cookie,
1784 hdr->msg.ack.dst_wmd.wh_object_cookie,
1785 hdr->msg.ack.mlength);
1788 case LNET_MSG_REPLY:
1789 CWARN(" dst md "LPX64"."LPX64", "
1791 hdr->msg.reply.dst_wmd.wh_interface_cookie,
1792 hdr->msg.reply.dst_wmd.wh_object_cookie,
1793 hdr->payload_length);
1799 lnet_parse(lnet_ni_t *ni, lnet_hdr_t *hdr, lnet_nid_t from_nid,
1800 void *private, int rdma_req)
1805 struct lnet_msg *msg;
1806 lnet_pid_t dest_pid;
1807 lnet_nid_t dest_nid;
1809 __u32 payload_length;
1812 LASSERT (!in_interrupt ());
1814 type = le32_to_cpu(hdr->type);
1815 src_nid = le64_to_cpu(hdr->src_nid);
1816 dest_nid = le64_to_cpu(hdr->dest_nid);
1817 dest_pid = le32_to_cpu(hdr->dest_pid);
1818 payload_length = le32_to_cpu(hdr->payload_length);
1820 for_me = (ni->ni_nid == dest_nid);
1821 cpt = lnet_cpt_of_nid(from_nid);
1826 if (payload_length > 0) {
1827 CERROR("%s, src %s: bad %s payload %d (0 expected)\n",
1828 libcfs_nid2str(from_nid),
1829 libcfs_nid2str(src_nid),
1830 lnet_msgtyp2str(type), payload_length);
1836 case LNET_MSG_REPLY:
1837 if (payload_length > (__u32)(for_me ? LNET_MAX_PAYLOAD : LNET_MTU)) {
1838 CERROR("%s, src %s: bad %s payload %d "
1839 "(%d max expected)\n",
1840 libcfs_nid2str(from_nid),
1841 libcfs_nid2str(src_nid),
1842 lnet_msgtyp2str(type),
1844 for_me ? LNET_MAX_PAYLOAD : LNET_MTU);
1850 CERROR("%s, src %s: Bad message type 0x%x\n",
1851 libcfs_nid2str(from_nid),
1852 libcfs_nid2str(src_nid), type);
1856 if (the_lnet.ln_routing &&
1857 ni->ni_last_alive != cfs_time_current_sec()) {
1860 /* NB: so far here is the only place to set NI status to "up */
1861 ni->ni_last_alive = cfs_time_current_sec();
1862 if (ni->ni_status != NULL &&
1863 ni->ni_status->ns_status == LNET_NI_STATUS_DOWN)
1864 ni->ni_status->ns_status = LNET_NI_STATUS_UP;
1868 /* Regard a bad destination NID as a protocol error. Senders should
1869 * know what they're doing; if they don't they're misconfigured, buggy
1870 * or malicious so we chop them off at the knees :) */
1873 if (LNET_NIDNET(dest_nid) == LNET_NIDNET(ni->ni_nid)) {
1874 /* should have gone direct */
1875 CERROR ("%s, src %s: Bad dest nid %s "
1876 "(should have been sent direct)\n",
1877 libcfs_nid2str(from_nid),
1878 libcfs_nid2str(src_nid),
1879 libcfs_nid2str(dest_nid));
1883 if (lnet_islocalnid(dest_nid)) {
1884 /* dest is another local NI; sender should have used
1885 * this node's NID on its own network */
1886 CERROR ("%s, src %s: Bad dest nid %s "
1887 "(it's my nid but on a different network)\n",
1888 libcfs_nid2str(from_nid),
1889 libcfs_nid2str(src_nid),
1890 libcfs_nid2str(dest_nid));
1894 if (rdma_req && type == LNET_MSG_GET) {
1895 CERROR ("%s, src %s: Bad optimized GET for %s "
1896 "(final destination must be me)\n",
1897 libcfs_nid2str(from_nid),
1898 libcfs_nid2str(src_nid),
1899 libcfs_nid2str(dest_nid));
1903 if (!the_lnet.ln_routing) {
1904 CERROR ("%s, src %s: Dropping message for %s "
1905 "(routing not enabled)\n",
1906 libcfs_nid2str(from_nid),
1907 libcfs_nid2str(src_nid),
1908 libcfs_nid2str(dest_nid));
1913 /* Message looks OK; we're not going to return an error, so we MUST
1914 * call back lnd_recv() come what may... */
1916 if (!list_empty(&the_lnet.ln_test_peers) && /* normally we don't */
1917 fail_peer(src_nid, 0)) { /* shall we now? */
1918 CERROR("%s, src %s: Dropping %s to simulate failure\n",
1919 libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
1920 lnet_msgtyp2str(type));
1924 msg = lnet_msg_alloc();
1926 CERROR("%s, src %s: Dropping %s (out of memory)\n",
1927 libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
1928 lnet_msgtyp2str(type));
1932 /* msg zeroed in lnet_msg_alloc; i.e. flags all clear, pointers NULL etc */
1934 msg->msg_type = type;
1935 msg->msg_private = private;
1936 msg->msg_receiving = 1;
1937 msg->msg_len = msg->msg_wanted = payload_length;
1938 msg->msg_offset = 0;
1939 msg->msg_hdr = *hdr;
1940 /* for building message event */
1941 msg->msg_from = from_nid;
1943 msg->msg_target.pid = dest_pid;
1944 msg->msg_target.nid = dest_nid;
1945 msg->msg_routing = 1;
1948 /* convert common msg->hdr fields to host byteorder */
1949 msg->msg_hdr.type = type;
1950 msg->msg_hdr.src_nid = src_nid;
1951 msg->msg_hdr.src_pid = le32_to_cpu(msg->msg_hdr.src_pid);
1952 msg->msg_hdr.dest_nid = dest_nid;
1953 msg->msg_hdr.dest_pid = dest_pid;
1954 msg->msg_hdr.payload_length = payload_length;
1958 rc = lnet_nid2peer_locked(&msg->msg_rxpeer, from_nid, cpt);
1960 lnet_net_unlock(cpt);
1961 CERROR("%s, src %s: Dropping %s "
1962 "(error %d looking up sender)\n",
1963 libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
1964 lnet_msgtyp2str(type), rc);
1969 lnet_msg_commit(msg, cpt);
1972 rc = lnet_parse_forward_locked(ni, msg);
1973 lnet_net_unlock(cpt);
1978 if (rc == LNET_CREDIT_OK) {
1979 lnet_ni_recv(ni, msg->msg_private, msg, 0,
1980 0, payload_length, payload_length);
1985 lnet_net_unlock(cpt);
1989 rc = lnet_parse_ack(ni, msg);
1992 rc = lnet_parse_put(ni, msg);
1995 rc = lnet_parse_get(ni, msg, rdma_req);
1997 case LNET_MSG_REPLY:
1998 rc = lnet_parse_reply(ni, msg);
2003 goto free_drop; /* prevent an unused label if !kernel */
2009 LASSERT (rc == ENOENT);
2012 LASSERT(msg->msg_md == NULL);
2013 lnet_finalize(ni, msg, rc);
2016 lnet_drop_message(ni, cpt, private, payload_length);
2019 EXPORT_SYMBOL(lnet_parse);
2022 lnet_drop_delayed_msg_list(struct list_head *head, char *reason)
2024 while (!list_empty(head)) {
2025 lnet_process_id_t id = {0};
2028 msg = list_entry(head->next, lnet_msg_t, msg_list);
2029 list_del(&msg->msg_list);
2031 id.nid = msg->msg_hdr.src_nid;
2032 id.pid = msg->msg_hdr.src_pid;
2034 LASSERT(msg->msg_md == NULL);
2035 LASSERT(msg->msg_rx_delayed);
2036 LASSERT(msg->msg_rxpeer != NULL);
2037 LASSERT(msg->msg_hdr.type == LNET_MSG_PUT);
2039 CWARN("Dropping delayed PUT from %s portal %d match "LPU64
2040 " offset %d length %d: %s\n",
2042 msg->msg_hdr.msg.put.ptl_index,
2043 msg->msg_hdr.msg.put.match_bits,
2044 msg->msg_hdr.msg.put.offset,
2045 msg->msg_hdr.payload_length, reason);
2047 /* NB I can't drop msg's ref on msg_rxpeer until after I've
2048 * called lnet_drop_message(), so I just hang onto msg as well
2049 * until that's done */
2051 lnet_drop_message(msg->msg_rxpeer->lp_ni,
2052 msg->msg_rxpeer->lp_cpt,
2053 msg->msg_private, msg->msg_len);
2055 * NB: message will not generate event because w/o attached MD,
2056 * but we still should give error code so lnet_msg_decommit()
2057 * can skip counters operations and other checks.
2059 lnet_finalize(msg->msg_rxpeer->lp_ni, msg, -ENOENT);
2064 lnet_recv_delayed_msg_list(struct list_head *head)
2066 while (!list_empty(head)) {
2068 lnet_process_id_t id;
2070 msg = list_entry(head->next, lnet_msg_t, msg_list);
2071 list_del(&msg->msg_list);
2073 /* md won't disappear under me, since each msg
2074 * holds a ref on it */
2076 id.nid = msg->msg_hdr.src_nid;
2077 id.pid = msg->msg_hdr.src_pid;
2079 LASSERT(msg->msg_rx_delayed);
2080 LASSERT(msg->msg_md != NULL);
2081 LASSERT(msg->msg_rxpeer != NULL);
2082 LASSERT(msg->msg_hdr.type == LNET_MSG_PUT);
2084 CDEBUG(D_NET, "Resuming delayed PUT from %s portal %d "
2085 "match "LPU64" offset %d length %d.\n",
2086 libcfs_id2str(id), msg->msg_hdr.msg.put.ptl_index,
2087 msg->msg_hdr.msg.put.match_bits,
2088 msg->msg_hdr.msg.put.offset,
2089 msg->msg_hdr.payload_length);
2091 lnet_recv_put(msg->msg_rxpeer->lp_ni, msg);
2096 * Initiate an asynchronous PUT operation.
2098 * There are several events associated with a PUT: completion of the send on
2099 * the initiator node (LNET_EVENT_SEND), and when the send completes
2100 * successfully, the receipt of an acknowledgment (LNET_EVENT_ACK) indicating
2101 * that the operation was accepted by the target. The event LNET_EVENT_PUT is
2102 * used at the target node to indicate the completion of incoming data
2105 * The local events will be logged in the EQ associated with the MD pointed to
2106 * by \a mdh handle. Using a MD without an associated EQ results in these
2107 * events being discarded. In this case, the caller must have another
2108 * mechanism (e.g., a higher level protocol) for determining when it is safe
2109 * to modify the memory region associated with the MD.
2111 * Note that LNet does not guarantee the order of LNET_EVENT_SEND and
2112 * LNET_EVENT_ACK, though intuitively ACK should happen after SEND.
2114 * \param self Indicates the NID of a local interface through which to send
2115 * the PUT request. Use LNET_NID_ANY to let LNet choose one by itself.
2116 * \param mdh A handle for the MD that describes the memory to be sent. The MD
2117 * must be "free floating" (See LNetMDBind()).
2118 * \param ack Controls whether an acknowledgment is requested.
2119 * Acknowledgments are only sent when they are requested by the initiating
2120 * process and the target MD enables them.
2121 * \param target A process identifier for the target process.
2122 * \param portal The index in the \a target's portal table.
2123 * \param match_bits The match bits to use for MD selection at the target
2125 * \param offset The offset into the target MD (only used when the target
2126 * MD has the LNET_MD_MANAGE_REMOTE option set).
2127 * \param hdr_data 64 bits of user data that can be included in the message
2128 * header. This data is written to an event queue entry at the target if an
2129 * EQ is present on the matching MD.
2131 * \retval 0 Success, and only in this case events will be generated
2132 * and logged to EQ (if it exists).
2133 * \retval -EIO Simulated failure.
2134 * \retval -ENOMEM Memory allocation failure.
2135 * \retval -ENOENT Invalid MD object.
2137 * \see lnet_event_t::hdr_data and lnet_event_kind_t.
2140 LNetPut(lnet_nid_t self, lnet_handle_md_t mdh, lnet_ack_req_t ack,
2141 lnet_process_id_t target, unsigned int portal,
2142 __u64 match_bits, unsigned int offset,
2145 struct lnet_msg *msg;
2146 struct lnet_libmd *md;
2150 LASSERT(the_lnet.ln_init);
2151 LASSERT(the_lnet.ln_refcount > 0);
2153 if (!list_empty(&the_lnet.ln_test_peers) && /* normally we don't */
2154 fail_peer(target.nid, 1)) { /* shall we now? */
2155 CERROR("Dropping PUT to %s: simulated failure\n",
2156 libcfs_id2str(target));
2160 msg = lnet_msg_alloc();
2162 CERROR("Dropping PUT to %s: ENOMEM on lnet_msg_t\n",
2163 libcfs_id2str(target));
2166 msg->msg_vmflush = !!memory_pressure_get();
2168 cpt = lnet_cpt_of_cookie(mdh.cookie);
2171 md = lnet_handle2md(&mdh);
2172 if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) {
2173 CERROR("Dropping PUT ("LPU64":%d:%s): MD (%d) invalid\n",
2174 match_bits, portal, libcfs_id2str(target),
2175 md == NULL ? -1 : md->md_threshold);
2176 if (md != NULL && md->md_me != NULL)
2177 CERROR("Source MD also attached to portal %d\n",
2178 md->md_me->me_portal);
2179 lnet_res_unlock(cpt);
2185 CDEBUG(D_NET, "LNetPut -> %s\n", libcfs_id2str(target));
2187 lnet_msg_attach_md(msg, md, 0, 0);
2189 lnet_prep_send(msg, LNET_MSG_PUT, target, 0, md->md_length);
2191 msg->msg_hdr.msg.put.match_bits = cpu_to_le64(match_bits);
2192 msg->msg_hdr.msg.put.ptl_index = cpu_to_le32(portal);
2193 msg->msg_hdr.msg.put.offset = cpu_to_le32(offset);
2194 msg->msg_hdr.msg.put.hdr_data = hdr_data;
2196 /* NB handles only looked up by creator (no flips) */
2197 if (ack == LNET_ACK_REQ) {
2198 msg->msg_hdr.msg.put.ack_wmd.wh_interface_cookie =
2199 the_lnet.ln_interface_cookie;
2200 msg->msg_hdr.msg.put.ack_wmd.wh_object_cookie =
2201 md->md_lh.lh_cookie;
2203 msg->msg_hdr.msg.put.ack_wmd.wh_interface_cookie =
2204 LNET_WIRE_HANDLE_COOKIE_NONE;
2205 msg->msg_hdr.msg.put.ack_wmd.wh_object_cookie =
2206 LNET_WIRE_HANDLE_COOKIE_NONE;
2209 lnet_res_unlock(cpt);
2211 lnet_build_msg_event(msg, LNET_EVENT_SEND);
2213 rc = lnet_send(self, msg, LNET_NID_ANY);
2215 CNETERR( "Error sending PUT to %s: %d\n",
2216 libcfs_id2str(target), rc);
2217 lnet_finalize (NULL, msg, rc);
2220 /* completion will be signalled by an event */
2223 EXPORT_SYMBOL(LNetPut);
2226 lnet_create_reply_msg (lnet_ni_t *ni, lnet_msg_t *getmsg)
2228 /* The LND can DMA direct to the GET md (i.e. no REPLY msg). This
2229 * returns a msg for the LND to pass to lnet_finalize() when the sink
2230 * data has been received.
2232 * CAVEAT EMPTOR: 'getmsg' is the original GET, which is freed when
2233 * lnet_finalize() is called on it, so the LND must call this first */
2235 struct lnet_msg *msg = lnet_msg_alloc();
2236 struct lnet_libmd *getmd = getmsg->msg_md;
2237 lnet_process_id_t peer_id = getmsg->msg_target;
2240 LASSERT(!getmsg->msg_target_is_router);
2241 LASSERT(!getmsg->msg_routing);
2244 CERROR("%s: Dropping REPLY from %s: can't allocate msg\n",
2245 libcfs_nid2str(ni->ni_nid), libcfs_id2str(peer_id));
2249 cpt = lnet_cpt_of_cookie(getmd->md_lh.lh_cookie);
2252 LASSERT(getmd->md_refcount > 0);
2254 if (getmd->md_threshold == 0) {
2255 CERROR ("%s: Dropping REPLY from %s for inactive MD %p\n",
2256 libcfs_nid2str(ni->ni_nid), libcfs_id2str(peer_id),
2258 lnet_res_unlock(cpt);
2262 LASSERT(getmd->md_offset == 0);
2264 CDEBUG(D_NET, "%s: Reply from %s md %p\n",
2265 libcfs_nid2str(ni->ni_nid), libcfs_id2str(peer_id), getmd);
2267 /* setup information for lnet_build_msg_event */
2268 msg->msg_from = peer_id.nid;
2269 msg->msg_type = LNET_MSG_GET; /* flag this msg as an "optimized" GET */
2270 msg->msg_hdr.src_nid = peer_id.nid;
2271 msg->msg_hdr.payload_length = getmd->md_length;
2272 msg->msg_receiving = 1; /* required by lnet_msg_attach_md */
2274 lnet_msg_attach_md(msg, getmd, getmd->md_offset, getmd->md_length);
2275 lnet_res_unlock(cpt);
2277 cpt = lnet_cpt_of_nid(peer_id.nid);
2280 lnet_msg_commit(msg, cpt);
2281 lnet_net_unlock(cpt);
2283 lnet_build_msg_event(msg, LNET_EVENT_REPLY);
2288 cpt = lnet_cpt_of_nid(peer_id.nid);
2291 the_lnet.ln_counters[cpt]->drop_count++;
2292 the_lnet.ln_counters[cpt]->drop_length += getmd->md_length;
2293 lnet_net_unlock(cpt);
2300 EXPORT_SYMBOL(lnet_create_reply_msg);
2303 lnet_set_reply_msg_len(lnet_ni_t *ni, lnet_msg_t *reply, unsigned int len)
2305 /* Set the REPLY length, now the RDMA that elides the REPLY message has
2306 * completed and I know it. */
2307 LASSERT (reply != NULL);
2308 LASSERT (reply->msg_type == LNET_MSG_GET);
2309 LASSERT (reply->msg_ev.type == LNET_EVENT_REPLY);
2311 /* NB I trusted my peer to RDMA. If she tells me she's written beyond
2312 * the end of my buffer, I might as well be dead. */
2313 LASSERT (len <= reply->msg_ev.mlength);
2315 reply->msg_ev.mlength = len;
2317 EXPORT_SYMBOL(lnet_set_reply_msg_len);
2320 * Initiate an asynchronous GET operation.
2322 * On the initiator node, an LNET_EVENT_SEND is logged when the GET request
2323 * is sent, and an LNET_EVENT_REPLY is logged when the data returned from
2324 * the target node in the REPLY has been written to local MD.
2326 * On the target node, an LNET_EVENT_GET is logged when the GET request
2327 * arrives and is accepted into a MD.
2329 * \param self,target,portal,match_bits,offset See the discussion in LNetPut().
2330 * \param mdh A handle for the MD that describes the memory into which the
2331 * requested data will be received. The MD must be "free floating" (See LNetMDBind()).
2333 * \retval 0 Success, and only in this case events will be generated
2334 * and logged to EQ (if it exists) of the MD.
2335 * \retval -EIO Simulated failure.
2336 * \retval -ENOMEM Memory allocation failure.
2337 * \retval -ENOENT Invalid MD object.
2340 LNetGet(lnet_nid_t self, lnet_handle_md_t mdh,
2341 lnet_process_id_t target, unsigned int portal,
2342 __u64 match_bits, unsigned int offset)
2344 struct lnet_msg *msg;
2345 struct lnet_libmd *md;
2349 LASSERT (the_lnet.ln_init);
2350 LASSERT (the_lnet.ln_refcount > 0);
2352 if (!list_empty(&the_lnet.ln_test_peers) && /* normally we don't */
2353 fail_peer(target.nid, 1)) /* shall we now? */
2355 CERROR("Dropping GET to %s: simulated failure\n",
2356 libcfs_id2str(target));
2360 msg = lnet_msg_alloc();
2362 CERROR("Dropping GET to %s: ENOMEM on lnet_msg_t\n",
2363 libcfs_id2str(target));
2367 cpt = lnet_cpt_of_cookie(mdh.cookie);
2370 md = lnet_handle2md(&mdh);
2371 if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) {
2372 CERROR("Dropping GET ("LPU64":%d:%s): MD (%d) invalid\n",
2373 match_bits, portal, libcfs_id2str(target),
2374 md == NULL ? -1 : md->md_threshold);
2375 if (md != NULL && md->md_me != NULL)
2376 CERROR("REPLY MD also attached to portal %d\n",
2377 md->md_me->me_portal);
2379 lnet_res_unlock(cpt);
2385 CDEBUG(D_NET, "LNetGet -> %s\n", libcfs_id2str(target));
2387 lnet_msg_attach_md(msg, md, 0, 0);
2389 lnet_prep_send(msg, LNET_MSG_GET, target, 0, 0);
2391 msg->msg_hdr.msg.get.match_bits = cpu_to_le64(match_bits);
2392 msg->msg_hdr.msg.get.ptl_index = cpu_to_le32(portal);
2393 msg->msg_hdr.msg.get.src_offset = cpu_to_le32(offset);
2394 msg->msg_hdr.msg.get.sink_length = cpu_to_le32(md->md_length);
2396 /* NB handles only looked up by creator (no flips) */
2397 msg->msg_hdr.msg.get.return_wmd.wh_interface_cookie =
2398 the_lnet.ln_interface_cookie;
2399 msg->msg_hdr.msg.get.return_wmd.wh_object_cookie =
2400 md->md_lh.lh_cookie;
2402 lnet_res_unlock(cpt);
2404 lnet_build_msg_event(msg, LNET_EVENT_SEND);
2406 rc = lnet_send(self, msg, LNET_NID_ANY);
2408 CNETERR("Error sending GET to %s: %d\n",
2409 libcfs_id2str(target), rc);
2410 lnet_finalize(NULL, msg, rc);
2413 /* completion will be signalled by an event */
2416 EXPORT_SYMBOL(LNetGet);
2419 * Calculate distance to node at \a dstnid.
2421 * \param dstnid Target NID.
2422 * \param srcnidp If not NULL, NID of the local interface to reach \a dstnid
2424 * \param orderp If not NULL, order of the route to reach \a dstnid is saved
2427 * \retval 0 If \a dstnid belongs to a local interface, and reserved option
2428 * local_nid_dist_zero is set, which is the default.
2429 * \retval positives Distance to target NID, i.e. number of hops plus one.
2430 * \retval -EHOSTUNREACH If \a dstnid is not reachable.
2433 LNetDist(lnet_nid_t dstnid, lnet_nid_t *srcnidp, __u32 *orderp)
2435 struct list_head *e;
2437 lnet_remotenet_t *rnet;
2438 __u32 dstnet = LNET_NIDNET(dstnid);
2442 struct list_head *rn_list;
2444 /* if !local_nid_dist_zero, I don't return a distance of 0 ever
2445 * (when lustre sees a distance of 0, it substitutes 0@lo), so I
2446 * keep order 0 free for 0@lo and order 1 free for a local NID
2449 LASSERT (the_lnet.ln_init);
2450 LASSERT (the_lnet.ln_refcount > 0);
2452 cpt = lnet_net_lock_current();
2454 list_for_each(e, &the_lnet.ln_nis) {
2455 ni = list_entry(e, lnet_ni_t, ni_list);
2457 if (ni->ni_nid == dstnid) {
2458 if (srcnidp != NULL)
2460 if (orderp != NULL) {
2461 if (LNET_NETTYP(LNET_NIDNET(dstnid)) == LOLND)
2466 lnet_net_unlock(cpt);
2468 return local_nid_dist_zero ? 0 : 1;
2471 if (LNET_NIDNET(ni->ni_nid) == dstnet) {
2472 if (srcnidp != NULL)
2473 *srcnidp = ni->ni_nid;
2476 lnet_net_unlock(cpt);
2483 rn_list = lnet_net2rnethash(dstnet);
2484 list_for_each(e, rn_list) {
2485 rnet = list_entry(e, lnet_remotenet_t, lrn_list);
2487 if (rnet->lrn_net == dstnet) {
2488 lnet_route_t *route;
2489 lnet_route_t *shortest = NULL;
2491 LASSERT(!list_empty(&rnet->lrn_routes));
2493 list_for_each_entry(route, &rnet->lrn_routes,
2495 if (shortest == NULL ||
2496 route->lr_hops < shortest->lr_hops)
2500 LASSERT (shortest != NULL);
2501 hops = shortest->lr_hops;
2502 if (srcnidp != NULL)
2503 *srcnidp = shortest->lr_gateway->lp_ni->ni_nid;
2506 lnet_net_unlock(cpt);
2512 lnet_net_unlock(cpt);
2513 return -EHOSTUNREACH;
2515 EXPORT_SYMBOL(LNetDist);
2518 * Set the number of asynchronous messages expected from a target process.
2520 * This function is only meaningful for userspace callers. It's a no-op when
2521 * called from kernel.
2523 * Asynchronous messages are those that can come from a target when the
2524 * userspace process is not waiting for IO to complete; e.g., AST callbacks
2525 * from Lustre servers. Specifying the expected number of such messages
2526 * allows them to be eagerly received when user process is not running in
2527 * LNet; otherwise network errors may occur.
2529 * \param id Process ID of the target process.
2530 * \param nasync Number of asynchronous messages expected from the target.
2532 * \return 0 on success, and an error code otherwise.
2535 LNetSetAsync(lnet_process_id_t id, int nasync)
2541 lnet_remotenet_t *rnet;
2542 struct list_head *tmp;
2543 lnet_route_t *route;
2551 /* Target on a local network? */
2552 ni = lnet_net2ni(LNET_NIDNET(id.nid));
2554 if (ni->ni_lnd->lnd_setasync != NULL)
2555 rc = (ni->ni_lnd->lnd_setasync)(ni, id, nasync);
2560 /* Target on a remote network: apply to routers */
2562 LIBCFS_ALLOC(nids, maxnids * sizeof(*nids));
2567 /* Snapshot all the router NIDs */
2568 cpt = lnet_net_lock_current();
2569 rnet = lnet_find_net_locked(LNET_NIDNET(id.nid));
2571 list_for_each(tmp, &rnet->lrn_routes) {
2572 if (nnids == maxnids) {
2573 lnet_net_unlock(cpt);
2574 LIBCFS_FREE(nids, maxnids * sizeof(*nids));
2579 route = list_entry(tmp, lnet_route_t, lr_list);
2580 nids[nnids++] = route->lr_gateway->lp_nid;
2583 lnet_net_unlock(cpt);
2585 /* set async on all the routers */
2586 while (nnids-- > 0) {
2587 id.pid = LUSTRE_SRV_LNET_PID;
2588 id.nid = nids[nnids];
2590 ni = lnet_net2ni(LNET_NIDNET(id.nid));
2594 if (ni->ni_lnd->lnd_setasync != NULL) {
2595 rc2 = (ni->ni_lnd->lnd_setasync)(ni, id, nasync);
2602 LIBCFS_FREE(nids, maxnids * sizeof(*nids));
2606 EXPORT_SYMBOL(LNetSetAsync);