1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
5 * Data movement routines
7 * Copyright (c) 2001-2003 Cluster File Systems, Inc.
9 * This file is part of Lustre, http://www.lustre.org
11 * Lustre is free software; you can redistribute it and/or
12 * modify it under the terms of version 2 of the GNU General Public
13 * License as published by the Free Software Foundation.
15 * Lustre is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with Lustre; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #define DEBUG_SUBSYSTEM S_LNET
27 #include <lnet/lib-lnet.h>
29 static int local_nid_dist_zero = 1;
30 CFS_MODULE_PARM(local_nid_dist_zero, "i", int, 0444,
34 static void lnet_commit_md (lnet_libmd_t *md, lnet_msg_t *msg);
35 static void lnet_drop_delayed_put(lnet_msg_t *msg, char *reason);
37 #define LNET_MATCHMD_NONE 0 /* Didn't match */
38 #define LNET_MATCHMD_OK 1 /* Matched OK */
39 #define LNET_MATCHMD_DROP 2 /* Must be discarded */
42 lnet_try_match_md (int index, int op_mask, lnet_process_id_t src,
43 unsigned int rlength, unsigned int roffset,
44 __u64 match_bits, lnet_libmd_t *md, lnet_msg_t *msg,
45 unsigned int *mlength_out, unsigned int *offset_out)
47 /* ALWAYS called holding the LNET_LOCK, and can't LNET_UNLOCK;
48 * lnet_match_blocked_msg() relies on this to avoid races */
51 lnet_me_t *me = md->md_me;
53 /* mismatched MD op */
54 if ((md->md_options & op_mask) == 0)
55 return LNET_MATCHMD_NONE;
58 if (lnet_md_exhausted(md))
59 return LNET_MATCHMD_NONE;
61 /* mismatched ME nid/pid? */
62 if (me->me_match_id.nid != LNET_NID_ANY &&
63 me->me_match_id.nid != src.nid)
64 return LNET_MATCHMD_NONE;
66 if (me->me_match_id.pid != LNET_PID_ANY &&
67 me->me_match_id.pid != src.pid)
68 return LNET_MATCHMD_NONE;
70 /* mismatched ME matchbits? */
71 if (((me->me_match_bits ^ match_bits) & ~me->me_ignore_bits) != 0)
72 return LNET_MATCHMD_NONE;
74 /* Hurrah! This _is_ a match; check it out... */
76 if ((md->md_options & LNET_MD_MANAGE_REMOTE) == 0)
77 offset = md->md_offset;
81 if ((md->md_options & LNET_MD_MAX_SIZE) != 0) {
82 mlength = md->md_max_size;
83 LASSERT (md->md_offset + mlength <= md->md_length);
85 mlength = md->md_length - offset;
88 if (rlength <= mlength) { /* fits in allowed space */
90 } else if ((md->md_options & LNET_MD_TRUNCATE) == 0) {
91 /* this packet _really_ is too big */
92 CERROR("Matching packet from %s, match "LPU64
93 " length %d too big: %d left, %d allowed\n",
94 libcfs_id2str(src), match_bits, rlength,
95 md->md_length - offset, mlength);
97 return LNET_MATCHMD_DROP;
100 /* Commit to this ME/MD */
101 CDEBUG(D_NET, "Incoming %s index %x from %s of "
102 "length %d/%d into md "LPX64" [%d] + %d\n",
103 (op_mask == LNET_MD_OP_PUT) ? "put" : "get",
104 index, libcfs_id2str(src), mlength, rlength,
105 md->md_lh.lh_cookie, md->md_niov, offset);
107 lnet_commit_md(md, msg);
108 md->md_offset = offset + mlength;
110 /* NB Caller will set ev.type and ev.hdr_data */
111 msg->msg_ev.initiator = src;
112 msg->msg_ev.pt_index = index;
113 msg->msg_ev.match_bits = match_bits;
114 msg->msg_ev.rlength = rlength;
115 msg->msg_ev.mlength = mlength;
116 msg->msg_ev.offset = offset;
118 lnet_md_deconstruct(md, &msg->msg_ev.md);
119 lnet_md2handle(&msg->msg_ev.md_handle, md);
121 *offset_out = offset;
122 *mlength_out = mlength;
124 /* Auto-unlink NOW, so the ME gets unlinked if required.
125 * We bumped md->md_refcount above so the MD just gets flagged
126 * for unlink when it is finalized. */
127 if ((md->md_flags & LNET_MD_FLAG_AUTO_UNLINK) != 0 &&
128 lnet_md_exhausted(md)) {
132 return LNET_MATCHMD_OK;
136 lnet_match_md(int index, int op_mask, lnet_process_id_t src,
137 unsigned int rlength, unsigned int roffset,
138 __u64 match_bits, lnet_msg_t *msg,
139 unsigned int *mlength_out, unsigned int *offset_out,
140 lnet_libmd_t **md_out)
142 lnet_portal_t *ptl = &the_lnet.ln_portals[index];
143 struct list_head *tmp;
148 CDEBUG (D_NET, "Request from %s of length %d into portal %d "
149 "MB="LPX64"\n", libcfs_id2str(src), rlength, index, match_bits);
151 if (index < 0 || index >= the_lnet.ln_nportals) {
152 CERROR("Invalid portal %d not in [0-%d]\n",
153 index, the_lnet.ln_nportals);
154 return LNET_MATCHMD_DROP;
157 list_for_each (tmp, &ptl->ptl_ml) {
158 me = list_entry(tmp, lnet_me_t, me_list);
161 /* ME attached but MD not attached yet */
165 LASSERT (me == md->md_me);
167 rc = lnet_try_match_md(index, op_mask, src, rlength,
168 roffset, match_bits, md, msg,
169 mlength_out, offset_out);
174 case LNET_MATCHMD_NONE:
177 case LNET_MATCHMD_OK:
179 return LNET_MATCHMD_OK;
181 case LNET_MATCHMD_DROP:
182 return LNET_MATCHMD_DROP;
187 if (op_mask == LNET_MD_OP_GET ||
188 (ptl->ptl_options & LNET_PTL_LAZY) == 0)
189 return LNET_MATCHMD_DROP;
191 return LNET_MATCHMD_NONE;
195 lnet_fail_nid (lnet_nid_t nid, unsigned int threshold)
197 lnet_test_peer_t *tp;
198 struct list_head *el;
199 struct list_head *next;
200 struct list_head cull;
202 LASSERT (the_lnet.ln_init);
204 if (threshold != 0) {
205 /* Adding a new entry */
206 LIBCFS_ALLOC(tp, sizeof(*tp));
211 tp->tp_threshold = threshold;
214 list_add_tail (&tp->tp_list, &the_lnet.ln_test_peers);
219 /* removing entries */
220 CFS_INIT_LIST_HEAD (&cull);
224 list_for_each_safe (el, next, &the_lnet.ln_test_peers) {
225 tp = list_entry (el, lnet_test_peer_t, tp_list);
227 if (tp->tp_threshold == 0 || /* needs culling anyway */
228 nid == LNET_NID_ANY || /* removing all entries */
229 tp->tp_nid == nid) /* matched this one */
231 list_del (&tp->tp_list);
232 list_add (&tp->tp_list, &cull);
238 while (!list_empty (&cull)) {
239 tp = list_entry (cull.next, lnet_test_peer_t, tp_list);
241 list_del (&tp->tp_list);
242 LIBCFS_FREE(tp, sizeof (*tp));
248 fail_peer (lnet_nid_t nid, int outgoing)
250 lnet_test_peer_t *tp;
251 struct list_head *el;
252 struct list_head *next;
253 struct list_head cull;
256 CFS_INIT_LIST_HEAD (&cull);
260 list_for_each_safe (el, next, &the_lnet.ln_test_peers) {
261 tp = list_entry (el, lnet_test_peer_t, tp_list);
263 if (tp->tp_threshold == 0) {
266 /* only cull zombies on outgoing tests,
267 * since we may be at interrupt priority on
268 * incoming messages. */
269 list_del (&tp->tp_list);
270 list_add (&tp->tp_list, &cull);
275 if (tp->tp_nid == LNET_NID_ANY || /* fail every peer */
276 nid == tp->tp_nid) { /* fail this peer */
279 if (tp->tp_threshold != LNET_MD_THRESH_INF) {
282 tp->tp_threshold == 0) {
284 list_del (&tp->tp_list);
285 list_add (&tp->tp_list, &cull);
294 while (!list_empty (&cull)) {
295 tp = list_entry (cull.next, lnet_test_peer_t, tp_list);
296 list_del (&tp->tp_list);
298 LIBCFS_FREE(tp, sizeof (*tp));
305 lnet_iov_nob (unsigned int niov, struct iovec *iov)
307 unsigned int nob = 0;
310 nob += (iov++)->iov_len;
316 lnet_copy_iov2iov (unsigned int ndiov, struct iovec *diov, unsigned int doffset,
317 unsigned int nsiov, struct iovec *siov, unsigned int soffset,
320 /* NB diov, siov are READ-ONLY */
321 unsigned int this_nob;
326 /* skip complete frags before 'doffset' */
328 while (doffset >= diov->iov_len) {
329 doffset -= diov->iov_len;
335 /* skip complete frags before 'soffset' */
337 while (soffset >= siov->iov_len) {
338 soffset -= siov->iov_len;
347 this_nob = MIN(diov->iov_len - doffset,
348 siov->iov_len - soffset);
349 this_nob = MIN(this_nob, nob);
351 memcpy ((char *)diov->iov_base + doffset,
352 (char *)siov->iov_base + soffset, this_nob);
355 if (diov->iov_len > doffset + this_nob) {
363 if (siov->iov_len > soffset + this_nob) {
374 lnet_extract_iov (int dst_niov, struct iovec *dst,
375 int src_niov, struct iovec *src,
376 unsigned int offset, unsigned int len)
378 /* Initialise 'dst' to the subset of 'src' starting at 'offset',
379 * for exactly 'len' bytes, and return the number of entries.
380 * NB not destructive to 'src' */
381 unsigned int frag_len;
384 if (len == 0) /* no data => */
385 return (0); /* no frags */
387 LASSERT (src_niov > 0);
388 while (offset >= src->iov_len) { /* skip initial frags */
389 offset -= src->iov_len;
392 LASSERT (src_niov > 0);
397 LASSERT (src_niov > 0);
398 LASSERT (niov <= dst_niov);
400 frag_len = src->iov_len - offset;
401 dst->iov_base = ((char *)src->iov_base) + offset;
403 if (len <= frag_len) {
408 dst->iov_len = frag_len;
421 lnet_kiov_nob (unsigned int niov, lnet_kiov_t *kiov)
428 lnet_copy_kiov2kiov (unsigned int ndkiov, lnet_kiov_t *dkiov, unsigned int doffset,
429 unsigned int nskiov, lnet_kiov_t *skiov, unsigned int soffset,
436 lnet_copy_kiov2iov (unsigned int niov, struct iovec *iov, unsigned int iovoffset,
437 unsigned int nkiov, lnet_kiov_t *kiov, unsigned int kiovoffset,
444 lnet_copy_iov2kiov (unsigned int nkiov, lnet_kiov_t *kiov, unsigned int kiovoffset,
445 unsigned int niov, struct iovec *iov, unsigned int iovoffset,
452 lnet_extract_kiov (int dst_niov, lnet_kiov_t *dst,
453 int src_niov, lnet_kiov_t *src,
454 unsigned int offset, unsigned int len)
459 #else /* __KERNEL__ */
462 lnet_kiov_nob (unsigned int niov, lnet_kiov_t *kiov)
464 unsigned int nob = 0;
467 nob += (kiov++)->kiov_len;
473 lnet_copy_kiov2kiov (unsigned int ndiov, lnet_kiov_t *diov, unsigned int doffset,
474 unsigned int nsiov, lnet_kiov_t *siov, unsigned int soffset,
477 /* NB diov, siov are READ-ONLY */
478 unsigned int this_nob;
485 LASSERT (!in_interrupt ());
488 while (doffset >= diov->kiov_len) {
489 doffset -= diov->kiov_len;
496 while (soffset >= siov->kiov_len) {
497 soffset -= siov->kiov_len;
506 this_nob = MIN(diov->kiov_len - doffset,
507 siov->kiov_len - soffset);
508 this_nob = MIN(this_nob, nob);
511 daddr = ((char *)cfs_kmap(diov->kiov_page)) +
512 diov->kiov_offset + doffset;
514 saddr = ((char *)cfs_kmap(siov->kiov_page)) +
515 siov->kiov_offset + soffset;
517 /* Vanishing risk of kmap deadlock when mapping 2 pages.
518 * However in practice at least one of the kiovs will be mapped
519 * kernel pages and the map/unmap will be NOOPs */
521 memcpy (daddr, saddr, this_nob);
524 if (diov->kiov_len > doffset + this_nob) {
528 cfs_kunmap(diov->kiov_page);
535 if (siov->kiov_len > soffset + this_nob) {
539 cfs_kunmap(siov->kiov_page);
548 cfs_kunmap(diov->kiov_page);
550 cfs_kunmap(siov->kiov_page);
554 lnet_copy_kiov2iov (unsigned int niov, struct iovec *iov, unsigned int iovoffset,
555 unsigned int nkiov, lnet_kiov_t *kiov, unsigned int kiovoffset,
558 /* NB iov, kiov are READ-ONLY */
559 unsigned int this_nob;
565 LASSERT (!in_interrupt ());
568 while (iovoffset >= iov->iov_len) {
569 iovoffset -= iov->iov_len;
576 while (kiovoffset >= kiov->kiov_len) {
577 kiovoffset -= kiov->kiov_len;
586 this_nob = MIN(iov->iov_len - iovoffset,
587 kiov->kiov_len - kiovoffset);
588 this_nob = MIN(this_nob, nob);
591 addr = ((char *)cfs_kmap(kiov->kiov_page)) +
592 kiov->kiov_offset + kiovoffset;
594 memcpy ((char *)iov->iov_base + iovoffset, addr, this_nob);
597 if (iov->iov_len > iovoffset + this_nob) {
598 iovoffset += this_nob;
605 if (kiov->kiov_len > kiovoffset + this_nob) {
607 kiovoffset += this_nob;
609 cfs_kunmap(kiov->kiov_page);
619 cfs_kunmap(kiov->kiov_page);
623 lnet_copy_iov2kiov (unsigned int nkiov, lnet_kiov_t *kiov, unsigned int kiovoffset,
624 unsigned int niov, struct iovec *iov, unsigned int iovoffset,
627 /* NB kiov, iov are READ-ONLY */
628 unsigned int this_nob;
634 LASSERT (!in_interrupt ());
637 while (kiovoffset >= kiov->kiov_len) {
638 kiovoffset -= kiov->kiov_len;
645 while (iovoffset >= iov->iov_len) {
646 iovoffset -= iov->iov_len;
655 this_nob = MIN(kiov->kiov_len - kiovoffset,
656 iov->iov_len - iovoffset);
657 this_nob = MIN(this_nob, nob);
660 addr = ((char *)cfs_kmap(kiov->kiov_page)) +
661 kiov->kiov_offset + kiovoffset;
663 memcpy (addr, (char *)iov->iov_base + iovoffset, this_nob);
666 if (kiov->kiov_len > kiovoffset + this_nob) {
668 kiovoffset += this_nob;
670 cfs_kunmap(kiov->kiov_page);
677 if (iov->iov_len > iovoffset + this_nob) {
678 iovoffset += this_nob;
687 cfs_kunmap(kiov->kiov_page);
691 lnet_extract_kiov (int dst_niov, lnet_kiov_t *dst,
692 int src_niov, lnet_kiov_t *src,
693 unsigned int offset, unsigned int len)
695 /* Initialise 'dst' to the subset of 'src' starting at 'offset',
696 * for exactly 'len' bytes, and return the number of entries.
697 * NB not destructive to 'src' */
698 unsigned int frag_len;
701 if (len == 0) /* no data => */
702 return (0); /* no frags */
704 LASSERT (src_niov > 0);
705 while (offset >= src->kiov_len) { /* skip initial frags */
706 offset -= src->kiov_len;
709 LASSERT (src_niov > 0);
714 LASSERT (src_niov > 0);
715 LASSERT (niov <= dst_niov);
717 frag_len = src->kiov_len - offset;
718 dst->kiov_page = src->kiov_page;
719 dst->kiov_offset = src->kiov_offset + offset;
721 if (len <= frag_len) {
723 LASSERT (dst->kiov_offset + dst->kiov_len <= CFS_PAGE_SIZE);
727 dst->kiov_len = frag_len;
728 LASSERT (dst->kiov_offset + dst->kiov_len <= CFS_PAGE_SIZE);
741 lnet_ni_recv(lnet_ni_t *ni, void *private, lnet_msg_t *msg, int delayed,
742 unsigned int offset, unsigned int mlen, unsigned int rlen)
744 unsigned int niov = 0;
745 struct iovec *iov = NULL;
746 lnet_kiov_t *kiov = NULL;
749 LASSERT (!in_interrupt ());
750 LASSERT (mlen == 0 || msg != NULL);
753 LASSERT(msg->msg_receiving);
754 LASSERT(!msg->msg_sending);
755 LASSERT(rlen == msg->msg_len);
756 LASSERT(mlen <= msg->msg_len);
758 msg->msg_wanted = mlen;
759 msg->msg_offset = offset;
760 msg->msg_receiving = 0;
763 niov = msg->msg_niov;
765 kiov = msg->msg_kiov;
768 LASSERT ((iov == NULL) != (kiov == NULL));
772 rc = (ni->ni_lnd->lnd_recv)(ni, private, msg, delayed,
773 niov, iov, kiov, offset, mlen, rlen);
775 lnet_finalize(ni, msg, rc);
779 lnet_compare_routers(lnet_peer_t *p1, lnet_peer_t *p2)
781 if (p1->lp_txqnob < p2->lp_txqnob)
784 if (p1->lp_txqnob > p2->lp_txqnob)
787 if (p1->lp_txcredits > p2->lp_txcredits)
790 if (p1->lp_txcredits < p2->lp_txcredits)
798 lnet_setpayloadbuffer(lnet_msg_t *msg)
800 lnet_libmd_t *md = msg->msg_md;
802 LASSERT (msg->msg_len > 0);
803 LASSERT (!msg->msg_routing);
804 LASSERT (md != NULL);
805 LASSERT (msg->msg_niov == 0);
806 LASSERT (msg->msg_iov == NULL);
807 LASSERT (msg->msg_kiov == NULL);
809 msg->msg_niov = md->md_niov;
810 if ((md->md_options & LNET_MD_KIOV) != 0)
811 msg->msg_kiov = md->md_iov.kiov;
813 msg->msg_iov = md->md_iov.iov;
817 lnet_prep_send(lnet_msg_t *msg, int type, lnet_process_id_t target,
818 unsigned int offset, unsigned int len)
820 msg->msg_type = type;
821 msg->msg_target = target;
823 msg->msg_offset = offset;
826 lnet_setpayloadbuffer(msg);
828 memset (&msg->msg_hdr, 0, sizeof (msg->msg_hdr));
829 msg->msg_hdr.type = cpu_to_le32(type);
830 msg->msg_hdr.dest_nid = cpu_to_le64(target.nid);
831 msg->msg_hdr.dest_pid = cpu_to_le32(target.pid);
832 /* src_nid will be set later */
833 msg->msg_hdr.src_pid = cpu_to_le32(the_lnet.ln_pid);
834 msg->msg_hdr.payload_length = cpu_to_le32(len);
838 lnet_ni_send(lnet_ni_t *ni, lnet_msg_t *msg)
840 void *priv = msg->msg_private;
843 LASSERT (!in_interrupt ());
844 LASSERT (LNET_NETTYP(LNET_NIDNET(ni->ni_nid)) == LOLND ||
845 (msg->msg_txcredit && msg->msg_peertxcredit));
847 rc = (ni->ni_lnd->lnd_send)(ni, priv, msg);
849 lnet_finalize(ni, msg, rc);
853 lnet_eager_recv_locked(lnet_msg_t *msg)
859 LASSERT (!msg->msg_delayed);
860 msg->msg_delayed = 1;
862 LASSERT (msg->msg_receiving);
863 LASSERT (!msg->msg_sending);
865 peer = msg->msg_rxpeer;
868 if (ni->ni_lnd->lnd_eager_recv != NULL) {
871 rc = (ni->ni_lnd->lnd_eager_recv)(ni, msg->msg_private, msg,
874 CERROR("recv from %s / send to %s aborted: "
875 "eager_recv failed %d\n",
876 libcfs_nid2str(peer->lp_nid),
877 libcfs_id2str(msg->msg_target), rc);
878 LASSERT (rc < 0); /* required by my callers */
888 lnet_post_send_locked (lnet_msg_t *msg, int do_send)
890 /* lnet_send is going to LNET_UNLOCK immediately after this, so it sets
891 * do_send FALSE and I don't do the unlock/send/lock bit. I return
892 * EAGAIN if msg blocked and 0 if sent or OK to send */
893 lnet_peer_t *lp = msg->msg_txpeer;
894 lnet_ni_t *ni = lp->lp_ni;
896 /* non-lnet_send() callers have checked before */
897 LASSERT (!do_send || msg->msg_delayed);
898 LASSERT (!msg->msg_receiving);
900 if (!msg->msg_peertxcredit) {
901 LASSERT ((lp->lp_txcredits < 0) == !list_empty(&lp->lp_txq));
903 msg->msg_peertxcredit = 1;
904 lp->lp_txqnob += msg->msg_len + sizeof(lnet_hdr_t);
907 if (lp->lp_txcredits < lp->lp_mintxcredits)
908 lp->lp_mintxcredits = lp->lp_txcredits;
910 if (lp->lp_txcredits < 0) {
911 msg->msg_delayed = 1;
912 list_add_tail (&msg->msg_list, &lp->lp_txq);
917 if (!msg->msg_txcredit) {
918 LASSERT ((ni->ni_txcredits < 0) == !list_empty(&ni->ni_txq));
920 msg->msg_txcredit = 1;
923 if (ni->ni_txcredits < ni->ni_mintxcredits)
924 ni->ni_mintxcredits = ni->ni_txcredits;
926 if (ni->ni_txcredits < 0) {
927 msg->msg_delayed = 1;
928 list_add_tail (&msg->msg_list, &ni->ni_txq);
935 lnet_ni_send(ni, msg);
943 lnet_commit_routedmsg (lnet_msg_t *msg)
945 /* ALWAYS called holding the LNET_LOCK */
946 LASSERT (msg->msg_routing);
948 the_lnet.ln_counters.msgs_alloc++;
949 if (the_lnet.ln_counters.msgs_alloc >
950 the_lnet.ln_counters.msgs_max)
951 the_lnet.ln_counters.msgs_max =
952 the_lnet.ln_counters.msgs_alloc;
954 the_lnet.ln_counters.route_count++;
955 the_lnet.ln_counters.route_length += msg->msg_len;
957 LASSERT (!msg->msg_onactivelist);
958 msg->msg_onactivelist = 1;
959 list_add (&msg->msg_activelist, &the_lnet.ln_active_msgs);
963 lnet_msg2bufpool(lnet_msg_t *msg)
965 lnet_rtrbufpool_t *rbp = &the_lnet.ln_rtrpools[0];
967 LASSERT (msg->msg_len <= LNET_MTU);
968 while (msg->msg_len > rbp->rbp_npages * CFS_PAGE_SIZE) {
970 LASSERT (rbp < &the_lnet.ln_rtrpools[LNET_NRBPOOLS]);
977 lnet_post_routed_recv_locked (lnet_msg_t *msg, int do_recv)
979 /* lnet_parse is going to LNET_UNLOCK immediately after this, so it
980 * sets do_recv FALSE and I don't do the unlock/send/lock bit. I
981 * return EAGAIN if msg blocked and 0 if sent or OK to send */
982 lnet_peer_t *lp = msg->msg_rxpeer;
983 lnet_rtrbufpool_t *rbp;
986 LASSERT (msg->msg_iov == NULL);
987 LASSERT (msg->msg_kiov == NULL);
988 LASSERT (msg->msg_niov == 0);
989 LASSERT (msg->msg_routing);
990 LASSERT (msg->msg_receiving);
991 LASSERT (!msg->msg_sending);
993 /* non-lnet_parse callers only send delayed messages */
994 LASSERT (!do_recv || msg->msg_delayed);
996 if (!msg->msg_peerrtrcredit) {
997 LASSERT ((lp->lp_rtrcredits < 0) == !list_empty(&lp->lp_rtrq));
999 msg->msg_peerrtrcredit = 1;
1000 lp->lp_rtrcredits--;
1001 if (lp->lp_rtrcredits < lp->lp_minrtrcredits)
1002 lp->lp_minrtrcredits = lp->lp_rtrcredits;
1004 if (lp->lp_rtrcredits < 0) {
1005 /* must have checked eager_recv before here */
1006 LASSERT (msg->msg_delayed);
1007 list_add_tail(&msg->msg_list, &lp->lp_rtrq);
1012 rbp = lnet_msg2bufpool(msg);
1014 if (!msg->msg_rtrcredit) {
1015 LASSERT ((rbp->rbp_credits < 0) == !list_empty(&rbp->rbp_msgs));
1017 msg->msg_rtrcredit = 1;
1019 if (rbp->rbp_credits < rbp->rbp_mincredits)
1020 rbp->rbp_mincredits = rbp->rbp_credits;
1022 if (rbp->rbp_credits < 0) {
1023 /* must have checked eager_recv before here */
1024 LASSERT (msg->msg_delayed);
1025 list_add_tail(&msg->msg_list, &rbp->rbp_msgs);
1030 LASSERT (!list_empty(&rbp->rbp_bufs));
1031 rb = list_entry(rbp->rbp_bufs.next, lnet_rtrbuf_t, rb_list);
1032 list_del(&rb->rb_list);
1034 msg->msg_niov = rbp->rbp_npages;
1035 msg->msg_kiov = &rb->rb_kiov[0];
1039 lnet_ni_recv(lp->lp_ni, msg->msg_private, msg, 1,
1040 0, msg->msg_len, msg->msg_len);
1048 lnet_return_credits_locked (lnet_msg_t *msg)
1050 lnet_peer_t *txpeer = msg->msg_txpeer;
1051 lnet_peer_t *rxpeer = msg->msg_rxpeer;
1055 if (msg->msg_txcredit) {
1056 /* give back NI txcredits */
1057 msg->msg_txcredit = 0;
1060 LASSERT((ni->ni_txcredits < 0) == !list_empty(&ni->ni_txq));
1063 if (ni->ni_txcredits <= 0) {
1064 msg2 = list_entry(ni->ni_txq.next, lnet_msg_t, msg_list);
1065 list_del(&msg2->msg_list);
1067 LASSERT(msg2->msg_txpeer->lp_ni == ni);
1068 LASSERT(msg2->msg_delayed);
1070 (void) lnet_post_send_locked(msg2, 1);
1074 if (msg->msg_peertxcredit) {
1075 /* give back peer txcredits */
1076 msg->msg_peertxcredit = 0;
1078 LASSERT((txpeer->lp_txcredits < 0) == !list_empty(&txpeer->lp_txq));
1080 txpeer->lp_txqnob -= msg->msg_len + sizeof(lnet_hdr_t);
1081 LASSERT (txpeer->lp_txqnob >= 0);
1083 txpeer->lp_txcredits++;
1084 if (txpeer->lp_txcredits <= 0) {
1085 msg2 = list_entry(txpeer->lp_txq.next,
1086 lnet_msg_t, msg_list);
1087 list_del(&msg2->msg_list);
1089 LASSERT (msg2->msg_txpeer == txpeer);
1090 LASSERT (msg2->msg_delayed);
1092 (void) lnet_post_send_locked(msg2, 1);
1096 if (txpeer != NULL) {
1097 msg->msg_txpeer = NULL;
1098 lnet_peer_decref_locked(txpeer);
1102 if (msg->msg_rtrcredit) {
1103 /* give back global router credits */
1105 lnet_rtrbufpool_t *rbp;
1107 /* NB If a msg ever blocks for a buffer in rbp_msgs, it stays
1108 * there until it gets one allocated, or aborts the wait
1110 LASSERT (msg->msg_kiov != NULL);
1112 rb = list_entry(msg->msg_kiov, lnet_rtrbuf_t, rb_kiov[0]);
1114 LASSERT (rbp == lnet_msg2bufpool(msg));
1116 msg->msg_kiov = NULL;
1117 msg->msg_rtrcredit = 0;
1119 LASSERT((rbp->rbp_credits < 0) == !list_empty(&rbp->rbp_msgs));
1120 LASSERT((rbp->rbp_credits > 0) == !list_empty(&rbp->rbp_bufs));
1122 list_add(&rb->rb_list, &rbp->rbp_bufs);
1124 if (rbp->rbp_credits <= 0) {
1125 msg2 = list_entry(rbp->rbp_msgs.next,
1126 lnet_msg_t, msg_list);
1127 list_del(&msg2->msg_list);
1129 (void) lnet_post_routed_recv_locked(msg2, 1);
1133 if (msg->msg_peerrtrcredit) {
1134 /* give pack peer router credits */
1135 msg->msg_peerrtrcredit = 0;
1137 LASSERT((rxpeer->lp_rtrcredits < 0) == !list_empty(&rxpeer->lp_rtrq));
1139 rxpeer->lp_rtrcredits++;
1140 if (rxpeer->lp_rtrcredits <= 0) {
1141 msg2 = list_entry(rxpeer->lp_rtrq.next,
1142 lnet_msg_t, msg_list);
1143 list_del(&msg2->msg_list);
1145 (void) lnet_post_routed_recv_locked(msg2, 1);
1149 LASSERT (!msg->msg_rtrcredit);
1150 LASSERT (!msg->msg_peerrtrcredit);
1152 if (rxpeer != NULL) {
1153 msg->msg_rxpeer = NULL;
1154 lnet_peer_decref_locked(rxpeer);
1159 lnet_send(lnet_nid_t src_nid, lnet_msg_t *msg)
1161 lnet_nid_t dst_nid = msg->msg_target.nid;
1163 lnet_ni_t *local_ni;
1164 lnet_remotenet_t *rnet;
1165 lnet_route_t *route;
1166 lnet_route_t *best_route;
1167 struct list_head *tmp;
1172 LASSERT (msg->msg_txpeer == NULL);
1173 LASSERT (!msg->msg_sending);
1174 LASSERT (!msg->msg_target_is_router);
1175 LASSERT (!msg->msg_receiving);
1177 msg->msg_sending = 1;
1179 /* NB! ni != NULL == interface pre-determined (ACK/REPLY) */
1183 if (the_lnet.ln_shutdown) {
1188 if (src_nid == LNET_NID_ANY) {
1191 src_ni = lnet_nid2ni_locked(src_nid);
1192 if (src_ni == NULL) {
1194 CERROR("Can't send to %s: src %s is not a local nid\n",
1195 libcfs_nid2str(dst_nid), libcfs_nid2str(src_nid));
1198 LASSERT (!msg->msg_routing);
1201 /* Is this for someone on a local network? */
1202 local_ni = lnet_net2ni_locked(LNET_NIDNET(dst_nid));
1204 if (local_ni != NULL) {
1205 if (src_ni == NULL) {
1207 src_nid = src_ni->ni_nid;
1208 } else if (src_ni == local_ni) {
1209 lnet_ni_decref_locked(local_ni);
1211 lnet_ni_decref_locked(local_ni);
1212 lnet_ni_decref_locked(src_ni);
1214 CERROR("no route to %s via from %s\n",
1215 libcfs_nid2str(dst_nid), libcfs_nid2str(src_nid));
1219 LASSERT (src_nid != LNET_NID_ANY);
1221 if (!msg->msg_routing) {
1222 src_nid = lnet_ptlcompat_srcnid(src_nid, dst_nid);
1223 msg->msg_hdr.src_nid = cpu_to_le64(src_nid);
1226 if (src_ni == the_lnet.ln_loni) {
1227 /* No send credit hassles with LOLND */
1229 lnet_ni_send(src_ni, msg);
1230 lnet_ni_decref(src_ni);
1234 rc = lnet_nid2peer_locked(&lp, dst_nid);
1235 lnet_ni_decref_locked(src_ni); /* lp has ref on src_ni; lose mine */
1238 CERROR("Error %d finding peer %s\n", rc,
1239 libcfs_nid2str(dst_nid));
1240 /* ENOMEM or shutting down */
1243 LASSERT (lp->lp_ni == src_ni);
1245 /* sending to a remote network */
1246 rnet = lnet_find_net_locked(LNET_NIDNET(dst_nid));
1249 lnet_ni_decref_locked(src_ni);
1251 CERROR("No route to %s\n", libcfs_id2str(msg->msg_target));
1252 return -EHOSTUNREACH;
1255 /* Find the best gateway I can use */
1258 list_for_each(tmp, &rnet->lrn_routes) {
1259 route = list_entry(tmp, lnet_route_t, lr_list);
1260 lp2 = route->lr_gateway;
1262 if (lp2->lp_alive &&
1263 (src_ni == NULL || lp2->lp_ni == src_ni) &&
1264 (lp == NULL || lnet_compare_routers(lp2, lp) > 0)) {
1272 lnet_ni_decref_locked(src_ni);
1274 CERROR("No route to %s (all routers down)\n",
1275 libcfs_id2str(msg->msg_target));
1276 return -EHOSTUNREACH;
1279 /* Place selected route at the end of the route list to ensure
1280 * fairness; everything else being equal... */
1281 list_del(&best_route->lr_list);
1282 list_add_tail(&best_route->lr_list, &rnet->lrn_routes);
1284 if (src_ni == NULL) {
1286 src_nid = src_ni->ni_nid;
1288 LASSERT (src_ni == lp->lp_ni);
1289 lnet_ni_decref_locked(src_ni);
1292 lnet_peer_addref_locked(lp);
1294 LASSERT (src_nid != LNET_NID_ANY);
1296 if (!msg->msg_routing) {
1297 /* I'm the source and now I know which NI to send on */
1298 src_nid = lnet_ptlcompat_srcnid(src_nid, dst_nid);
1299 msg->msg_hdr.src_nid = cpu_to_le64(src_nid);
1302 msg->msg_target_is_router = 1;
1303 msg->msg_target.nid = lp->lp_nid;
1304 msg->msg_target.pid = LUSTRE_SRV_LNET_PID;
1307 /* 'lp' is our best choice of peer */
1309 LASSERT (!msg->msg_peertxcredit);
1310 LASSERT (!msg->msg_txcredit);
1311 LASSERT (msg->msg_txpeer == NULL);
1313 msg->msg_txpeer = lp; /* msg takes my ref on lp */
1315 rc = lnet_post_send_locked(msg, 0);
1319 lnet_ni_send(src_ni, msg);
1325 lnet_commit_md (lnet_libmd_t *md, lnet_msg_t *msg)
1327 /* ALWAYS called holding the LNET_LOCK */
1328 /* Here, we commit the MD to a network OP by marking it busy and
1329 * decrementing its threshold. Come what may, the network "owns"
1330 * the MD until a call to lnet_finalize() signals completion. */
1331 LASSERT (!msg->msg_routing);
1336 if (md->md_threshold != LNET_MD_THRESH_INF) {
1337 LASSERT (md->md_threshold > 0);
1341 the_lnet.ln_counters.msgs_alloc++;
1342 if (the_lnet.ln_counters.msgs_alloc >
1343 the_lnet.ln_counters.msgs_max)
1344 the_lnet.ln_counters.msgs_max =
1345 the_lnet.ln_counters.msgs_alloc;
1347 LASSERT (!msg->msg_onactivelist);
1348 msg->msg_onactivelist = 1;
1349 list_add (&msg->msg_activelist, &the_lnet.ln_active_msgs);
1353 lnet_drop_message (lnet_ni_t *ni, void *private, unsigned int nob)
1356 the_lnet.ln_counters.drop_count++;
1357 the_lnet.ln_counters.drop_length += nob;
1360 lnet_ni_recv(ni, private, NULL, 0, 0, 0, nob);
1364 lnet_drop_delayed_put(lnet_msg_t *msg, char *reason)
1366 LASSERT (msg->msg_md == NULL);
1367 LASSERT (msg->msg_delayed);
1368 LASSERT (msg->msg_rxpeer != NULL);
1369 LASSERT (msg->msg_hdr.type == LNET_MSG_PUT);
1371 CWARN("Dropping delayed PUT from %s portal %d match "LPU64
1372 " offset %d length %d: %s\n",
1373 libcfs_id2str((lnet_process_id_t){
1374 .nid = msg->msg_hdr.src_nid,
1375 .pid = msg->msg_hdr.src_pid}),
1376 msg->msg_hdr.msg.put.ptl_index,
1377 msg->msg_hdr.msg.put.match_bits,
1378 msg->msg_hdr.msg.put.offset,
1379 msg->msg_hdr.payload_length,
1382 /* NB I can't drop msg's ref on msg_rxpeer until after I've
1383 * called lnet_drop_message(), so I just hang onto msg as well
1384 * until that's done */
1386 lnet_drop_message(msg->msg_rxpeer->lp_ni,
1387 msg->msg_private, msg->msg_len);
1391 lnet_peer_decref_locked(msg->msg_rxpeer);
1392 msg->msg_rxpeer = NULL;
1400 LNetSetLazyPortal(int portal)
1402 lnet_portal_t *ptl = &the_lnet.ln_portals[portal];
1404 if (portal < 0 || portal >= the_lnet.ln_nportals)
1407 CDEBUG(D_NET, "Setting portal %d lazy\n", portal);
1411 ptl->ptl_options |= LNET_PTL_LAZY;
1419 LNetClearLazyPortal(int portal)
1421 struct list_head zombies;
1422 lnet_portal_t *ptl = &the_lnet.ln_portals[portal];
1425 if (portal < 0 || portal >= the_lnet.ln_nportals)
1430 if ((ptl->ptl_options & LNET_PTL_LAZY) == 0) {
1435 if (the_lnet.ln_shutdown)
1436 CWARN ("Active lazy portal %d on exit\n", portal);
1438 CDEBUG (D_NET, "clearing portal %d lazy\n", portal);
1440 /* grab all the blocked messages atomically */
1441 list_add(&zombies, &ptl->ptl_msgq);
1442 list_del_init(&ptl->ptl_msgq);
1444 ptl->ptl_msgq_version++;
1445 ptl->ptl_options &= ~LNET_PTL_LAZY;
1449 while (!list_empty(&zombies)) {
1450 msg = list_entry(zombies.next, lnet_msg_t, msg_list);
1451 list_del(&msg->msg_list);
1453 lnet_drop_delayed_put(msg, "Clearing lazy portal attr");
1460 lnet_recv_put(lnet_libmd_t *md, lnet_msg_t *msg, int delayed,
1461 unsigned int offset, unsigned int mlength)
1463 lnet_hdr_t *hdr = &msg->msg_hdr;
1467 the_lnet.ln_counters.recv_count++;
1468 the_lnet.ln_counters.recv_length += mlength;
1473 lnet_setpayloadbuffer(msg);
1475 msg->msg_ev.type = LNET_EVENT_PUT;
1476 msg->msg_ev.target.pid = hdr->dest_pid;
1477 msg->msg_ev.target.nid = hdr->dest_nid;
1478 msg->msg_ev.hdr_data = hdr->msg.put.hdr_data;
1480 /* Must I ACK? If so I'll grab the ack_wmd out of the header and put
1481 * it back into the ACK during lnet_finalize() */
1482 msg->msg_ack = (!lnet_is_wire_handle_none(&hdr->msg.put.ack_wmd) &&
1483 (md->md_options & LNET_MD_ACK_DISABLE) == 0);
1485 lnet_ni_recv(msg->msg_rxpeer->lp_ni,
1487 msg, delayed, offset, mlength,
1488 hdr->payload_length);
1491 /* called with LNET_LOCK held */
1493 lnet_match_blocked_msg(lnet_libmd_t *md)
1495 CFS_LIST_HEAD (drops);
1496 CFS_LIST_HEAD (matches);
1497 struct list_head *tmp;
1498 struct list_head *entry;
1500 lnet_me_t *me = md->md_me;
1501 lnet_portal_t *ptl = &the_lnet.ln_portals[me->me_portal];
1503 LASSERT (me->me_portal < the_lnet.ln_nportals);
1505 if ((ptl->ptl_options & LNET_PTL_LAZY) == 0) {
1506 LASSERT (list_empty(&ptl->ptl_msgq));
1510 LASSERT (md->md_refcount == 0); /* a brand new MD */
1512 list_for_each_safe (entry, tmp, &ptl->ptl_msgq) {
1515 unsigned int mlength;
1516 unsigned int offset;
1518 lnet_process_id_t src;
1520 msg = list_entry(entry, lnet_msg_t, msg_list);
1522 LASSERT (msg->msg_delayed);
1524 hdr = &msg->msg_hdr;
1525 index = hdr->msg.put.ptl_index;
1527 src.nid = hdr->src_nid;
1528 src.pid = hdr->src_pid;
1530 rc = lnet_try_match_md(index, LNET_MD_OP_PUT, src,
1531 hdr->payload_length,
1532 hdr->msg.put.offset,
1533 hdr->msg.put.match_bits,
1534 md, msg, &mlength, &offset);
1536 if (rc == LNET_MATCHMD_NONE)
1539 /* Hurrah! This _is_ a match */
1540 list_del(&msg->msg_list);
1541 ptl->ptl_msgq_version++;
1543 if (rc == LNET_MATCHMD_OK) {
1544 list_add_tail(&msg->msg_list, &matches);
1546 CDEBUG(D_NET, "Resuming delayed PUT from %s portal %d "
1547 "match "LPU64" offset %d length %d.\n",
1549 hdr->msg.put.ptl_index,
1550 hdr->msg.put.match_bits,
1551 hdr->msg.put.offset,
1552 hdr->payload_length);
1554 LASSERT (rc == LNET_MATCHMD_DROP);
1556 list_add_tail(&msg->msg_list, &drops);
1559 if (lnet_md_exhausted(md))
1565 list_for_each_safe (entry, tmp, &drops) {
1566 msg = list_entry(entry, lnet_msg_t, msg_list);
1568 list_del(&msg->msg_list);
1570 lnet_drop_delayed_put(msg, "Bad match");
1573 list_for_each_safe (entry, tmp, &matches) {
1574 msg = list_entry(entry, lnet_msg_t, msg_list);
1576 list_del(&msg->msg_list);
1578 /* md won't disappear under me, since each msg
1579 * holds a ref on it */
1580 lnet_recv_put(md, msg, 1,
1582 msg->msg_ev.mlength);
1589 lnet_parse_put(lnet_ni_t *ni, lnet_msg_t *msg)
1593 lnet_hdr_t *hdr = &msg->msg_hdr;
1594 unsigned int rlength = hdr->payload_length;
1595 unsigned int mlength = 0;
1596 unsigned int offset = 0;
1597 lnet_process_id_t src = {/* .nid = */ hdr->src_nid,
1598 /* .pid = */ hdr->src_pid};
1601 /* Convert put fields to host byte order */
1602 hdr->msg.put.match_bits = le64_to_cpu(hdr->msg.put.match_bits);
1603 hdr->msg.put.ptl_index = le32_to_cpu(hdr->msg.put.ptl_index);
1604 hdr->msg.put.offset = le32_to_cpu(hdr->msg.put.offset);
1606 index = hdr->msg.put.ptl_index;
1610 rc = lnet_match_md(index, LNET_MD_OP_PUT, src,
1611 rlength, hdr->msg.put.offset,
1612 hdr->msg.put.match_bits, msg,
1613 &mlength, &offset, &md);
1618 case LNET_MATCHMD_OK:
1620 lnet_recv_put(md, msg, 0, offset, mlength);
1623 case LNET_MATCHMD_NONE:
1624 rc = lnet_eager_recv_locked(msg);
1625 if (rc == 0 && !the_lnet.ln_shutdown) {
1626 list_add_tail(&msg->msg_list,
1627 &the_lnet.ln_portals[index].ptl_msgq);
1629 the_lnet.ln_portals[index].ptl_msgq_version++;
1631 CDEBUG(D_NET, "Delaying PUT from %s portal %d match "
1632 LPU64" offset %d length %d: no match \n",
1633 libcfs_id2str(src), index,
1634 hdr->msg.put.match_bits,
1635 hdr->msg.put.offset, rlength);
1642 case LNET_MATCHMD_DROP:
1644 "Dropping PUT from %s portal %d match "LPU64
1645 " offset %d length %d: %d\n",
1646 libcfs_id2str(src), index,
1647 hdr->msg.put.match_bits,
1648 hdr->msg.put.offset, rlength, rc);
1651 return ENOENT; /* +ve: OK but no match */
1656 lnet_parse_get(lnet_ni_t *ni, lnet_msg_t *msg, int rdma_get)
1658 lnet_hdr_t *hdr = &msg->msg_hdr;
1659 unsigned int mlength = 0;
1660 unsigned int offset = 0;
1661 lnet_process_id_t src = {/* .nid = */ hdr->src_nid,
1662 /* .pid = */ hdr->src_pid};
1663 lnet_handle_wire_t reply_wmd;
1667 /* Convert get fields to host byte order */
1668 hdr->msg.get.match_bits = le64_to_cpu(hdr->msg.get.match_bits);
1669 hdr->msg.get.ptl_index = le32_to_cpu(hdr->msg.get.ptl_index);
1670 hdr->msg.get.sink_length = le32_to_cpu(hdr->msg.get.sink_length);
1671 hdr->msg.get.src_offset = le32_to_cpu(hdr->msg.get.src_offset);
1675 rc = lnet_match_md(hdr->msg.get.ptl_index, LNET_MD_OP_GET, src,
1676 hdr->msg.get.sink_length, hdr->msg.get.src_offset,
1677 hdr->msg.get.match_bits, msg,
1678 &mlength, &offset, &md);
1679 if (rc == LNET_MATCHMD_DROP) {
1681 "Dropping GET from %s portal %d match "LPU64
1682 " offset %d length %d\n",
1684 hdr->msg.get.ptl_index,
1685 hdr->msg.get.match_bits,
1686 hdr->msg.get.src_offset,
1687 hdr->msg.get.sink_length);
1689 return ENOENT; /* +ve: OK but no match */
1692 LASSERT (rc == LNET_MATCHMD_OK);
1694 the_lnet.ln_counters.send_count++;
1695 the_lnet.ln_counters.send_length += mlength;
1699 reply_wmd = hdr->msg.get.return_wmd;
1701 lnet_prep_send(msg, LNET_MSG_REPLY, src, offset, mlength);
1703 msg->msg_hdr.msg.reply.dst_wmd = reply_wmd;
1705 msg->msg_ev.type = LNET_EVENT_GET;
1706 msg->msg_ev.target.pid = hdr->dest_pid;
1707 msg->msg_ev.target.nid = hdr->dest_nid;
1708 msg->msg_ev.hdr_data = 0;
1711 /* The LND completes the REPLY from her recv procedure */
1712 lnet_ni_recv(ni, msg->msg_private, msg, 0,
1713 msg->msg_offset, msg->msg_len, msg->msg_len);
1717 lnet_ni_recv(ni, msg->msg_private, NULL, 0, 0, 0, 0);
1718 msg->msg_receiving = 0;
1720 rc = lnet_send(ni->ni_nid, msg);
1722 /* didn't get as far as lnet_ni_send() */
1723 CERROR("%s: Unable to send REPLY for GET from %s: %d\n",
1724 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src), rc);
1726 lnet_finalize(ni, msg, rc);
1733 lnet_parse_reply(lnet_ni_t *ni, lnet_msg_t *msg)
1735 void *private = msg->msg_private;
1736 lnet_hdr_t *hdr = &msg->msg_hdr;
1737 lnet_process_id_t src = {/* .nid = */ hdr->src_nid,
1738 /* .pid = */ hdr->src_pid};
1745 /* NB handles only looked up by creator (no flips) */
1746 md = lnet_wire_handle2md(&hdr->msg.reply.dst_wmd);
1747 if (md == NULL || md->md_threshold == 0) {
1748 CDEBUG(D_NETERROR, "%s: Dropping REPLY from %s for %s "
1749 "MD "LPX64"."LPX64"\n",
1750 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
1751 (md == NULL) ? "invalid" : "inactive",
1752 hdr->msg.reply.dst_wmd.wh_interface_cookie,
1753 hdr->msg.reply.dst_wmd.wh_object_cookie);
1756 return ENOENT; /* +ve: OK but no match */
1759 LASSERT (md->md_offset == 0);
1761 rlength = hdr->payload_length;
1762 mlength = MIN(rlength, md->md_length);
1764 if (mlength < rlength &&
1765 (md->md_options & LNET_MD_TRUNCATE) == 0) {
1766 CDEBUG(D_NETERROR, "%s: Dropping REPLY from %s length %d "
1767 "for MD "LPX64" would overflow (%d)\n",
1768 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
1769 rlength, hdr->msg.reply.dst_wmd.wh_object_cookie,
1772 return ENOENT; /* +ve: OK but no match */
1775 CDEBUG(D_NET, "%s: Reply from %s of length %d/%d into md "LPX64"\n",
1776 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
1777 mlength, rlength, hdr->msg.reply.dst_wmd.wh_object_cookie);
1779 lnet_commit_md(md, msg);
1782 lnet_setpayloadbuffer(msg);
1784 msg->msg_ev.type = LNET_EVENT_REPLY;
1785 msg->msg_ev.target.pid = hdr->dest_pid;
1786 msg->msg_ev.target.nid = hdr->dest_nid;
1787 msg->msg_ev.initiator = src;
1788 msg->msg_ev.rlength = rlength;
1789 msg->msg_ev.mlength = mlength;
1790 msg->msg_ev.offset = 0;
1792 lnet_md_deconstruct(md, &msg->msg_ev.md);
1793 lnet_md2handle(&msg->msg_ev.md_handle, md);
1795 the_lnet.ln_counters.recv_count++;
1796 the_lnet.ln_counters.recv_length += mlength;
1800 lnet_ni_recv(ni, private, msg, 0, 0, mlength, rlength);
1805 lnet_parse_ack(lnet_ni_t *ni, lnet_msg_t *msg)
1807 lnet_hdr_t *hdr = &msg->msg_hdr;
1808 lnet_process_id_t src = {/* .nid = */ hdr->src_nid,
1809 /* .pid = */ hdr->src_pid};
1812 /* Convert ack fields to host byte order */
1813 hdr->msg.ack.match_bits = le64_to_cpu(hdr->msg.ack.match_bits);
1814 hdr->msg.ack.mlength = le32_to_cpu(hdr->msg.ack.mlength);
1818 /* NB handles only looked up by creator (no flips) */
1819 md = lnet_wire_handle2md(&hdr->msg.ack.dst_wmd);
1820 if (md == NULL || md->md_threshold == 0) {
1821 /* Don't moan; this is expected */
1823 "%s: Dropping ACK from %s to %s MD "LPX64"."LPX64"\n",
1824 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
1825 (md == NULL) ? "invalid" : "inactive",
1826 hdr->msg.ack.dst_wmd.wh_interface_cookie,
1827 hdr->msg.ack.dst_wmd.wh_object_cookie);
1829 return ENOENT; /* +ve! */
1832 CDEBUG(D_NET, "%s: ACK from %s into md "LPX64"\n",
1833 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
1834 hdr->msg.ack.dst_wmd.wh_object_cookie);
1836 lnet_commit_md(md, msg);
1838 msg->msg_ev.type = LNET_EVENT_ACK;
1839 msg->msg_ev.target.pid = hdr->dest_pid;
1840 msg->msg_ev.target.nid = hdr->dest_nid;
1841 msg->msg_ev.initiator = src;
1842 msg->msg_ev.mlength = hdr->msg.ack.mlength;
1843 msg->msg_ev.match_bits = hdr->msg.ack.match_bits;
1845 lnet_md_deconstruct(md, &msg->msg_ev.md);
1846 lnet_md2handle(&msg->msg_ev.md_handle, md);
1848 the_lnet.ln_counters.recv_count++;
1852 lnet_ni_recv(ni, msg->msg_private, msg, 0, 0, 0, msg->msg_len);
1857 lnet_msgtyp2str (int type)
1866 case LNET_MSG_REPLY:
1868 case LNET_MSG_HELLO:
1871 return ("<UNKNOWN>");
1876 lnet_print_hdr(lnet_hdr_t * hdr)
1878 lnet_process_id_t src = {/* .nid = */ hdr->src_nid,
1879 /* .pid = */ hdr->src_pid};
1880 lnet_process_id_t dst = {/* .nid = */ hdr->dest_nid,
1881 /* .pid = */ hdr->dest_pid};
1882 char *type_str = lnet_msgtyp2str (hdr->type);
1884 CWARN("P3 Header at %p of type %s\n", hdr, type_str);
1885 CWARN(" From %s\n", libcfs_id2str(src));
1886 CWARN(" To %s\n", libcfs_id2str(dst));
1888 switch (hdr->type) {
1893 CWARN(" Ptl index %d, ack md "LPX64"."LPX64", "
1894 "match bits "LPU64"\n",
1895 hdr->msg.put.ptl_index,
1896 hdr->msg.put.ack_wmd.wh_interface_cookie,
1897 hdr->msg.put.ack_wmd.wh_object_cookie,
1898 hdr->msg.put.match_bits);
1899 CWARN(" Length %d, offset %d, hdr data "LPX64"\n",
1900 hdr->payload_length, hdr->msg.put.offset,
1901 hdr->msg.put.hdr_data);
1905 CWARN(" Ptl index %d, return md "LPX64"."LPX64", "
1906 "match bits "LPU64"\n", hdr->msg.get.ptl_index,
1907 hdr->msg.get.return_wmd.wh_interface_cookie,
1908 hdr->msg.get.return_wmd.wh_object_cookie,
1909 hdr->msg.get.match_bits);
1910 CWARN(" Length %d, src offset %d\n",
1911 hdr->msg.get.sink_length,
1912 hdr->msg.get.src_offset);
1916 CWARN(" dst md "LPX64"."LPX64", "
1917 "manipulated length %d\n",
1918 hdr->msg.ack.dst_wmd.wh_interface_cookie,
1919 hdr->msg.ack.dst_wmd.wh_object_cookie,
1920 hdr->msg.ack.mlength);
1923 case LNET_MSG_REPLY:
1924 CWARN(" dst md "LPX64"."LPX64", "
1926 hdr->msg.reply.dst_wmd.wh_interface_cookie,
1927 hdr->msg.reply.dst_wmd.wh_object_cookie,
1928 hdr->payload_length);
1935 lnet_parse(lnet_ni_t *ni, lnet_hdr_t *hdr, lnet_nid_t from_nid,
1936 void *private, int rdma_req)
1941 lnet_nid_t dest_nid;
1943 __u32 payload_length;
1946 LASSERT (!in_interrupt ());
1948 type = le32_to_cpu(hdr->type);
1949 src_nid = le64_to_cpu(hdr->src_nid);
1950 dest_nid = le64_to_cpu(hdr->dest_nid);
1951 payload_length = le32_to_cpu(hdr->payload_length);
1953 for_me = lnet_ptlcompat_matchnid(ni->ni_nid, dest_nid);
1958 if (payload_length > 0) {
1959 CERROR("%s, src %s: bad %s payload %d (0 expected)\n",
1960 libcfs_nid2str(from_nid),
1961 libcfs_nid2str(src_nid),
1962 lnet_msgtyp2str(type), payload_length);
1968 case LNET_MSG_REPLY:
1969 if (payload_length > (for_me ? LNET_MAX_PAYLOAD : LNET_MTU)) {
1970 CERROR("%s, src %s: bad %s payload %d "
1971 "(%d max expected)\n",
1972 libcfs_nid2str(from_nid),
1973 libcfs_nid2str(src_nid),
1974 lnet_msgtyp2str(type),
1976 for_me ? LNET_MAX_PAYLOAD : LNET_MTU);
1982 CERROR("%s, src %s: Bad message type 0x%x\n",
1983 libcfs_nid2str(from_nid),
1984 libcfs_nid2str(src_nid), type);
1988 /* Regard a bad destination NID as a protocol error. Senders should
1989 * know what they're doing; if they don't they're misconfigured, buggy
1990 * or malicious so we chop them off at the knees :) */
1993 if (the_lnet.ln_ptlcompat > 0) {
1994 /* portals compatibility is single-network */
1995 CERROR ("%s, src %s: Bad dest nid %s "
1996 "(routing not supported)\n",
1997 libcfs_nid2str(from_nid),
1998 libcfs_nid2str(src_nid),
1999 libcfs_nid2str(dest_nid));
2003 if (the_lnet.ln_ptlcompat == 0 &&
2004 LNET_NIDNET(dest_nid) == LNET_NIDNET(ni->ni_nid)) {
2005 /* should have gone direct */
2006 CERROR ("%s, src %s: Bad dest nid %s "
2007 "(should have been sent direct)\n",
2008 libcfs_nid2str(from_nid),
2009 libcfs_nid2str(src_nid),
2010 libcfs_nid2str(dest_nid));
2014 if (the_lnet.ln_ptlcompat == 0 &&
2015 lnet_islocalnid(dest_nid)) {
2016 /* dest is another local NI; sender should have used
2017 * this node's NID on its own network */
2018 CERROR ("%s, src %s: Bad dest nid %s "
2019 "(it's my nid but on a different network)\n",
2020 libcfs_nid2str(from_nid),
2021 libcfs_nid2str(src_nid),
2022 libcfs_nid2str(dest_nid));
2026 if (rdma_req && type == LNET_MSG_GET) {
2027 CERROR ("%s, src %s: Bad optimized GET for %s "
2028 "(final destination must be me)\n",
2029 libcfs_nid2str(from_nid),
2030 libcfs_nid2str(src_nid),
2031 libcfs_nid2str(dest_nid));
2035 if (!the_lnet.ln_routing) {
2036 CERROR ("%s, src %s: Dropping message for %s "
2037 "(routing not enabled)\n",
2038 libcfs_nid2str(from_nid),
2039 libcfs_nid2str(src_nid),
2040 libcfs_nid2str(dest_nid));
2045 /* Message looks OK; we're not going to return an error, so we MUST
2046 * call back lnd_recv() come what may... */
2048 if (!list_empty (&the_lnet.ln_test_peers) && /* normally we don't */
2049 fail_peer (src_nid, 0)) /* shall we now? */
2051 CERROR("%s, src %s: Dropping %s to simulate failure\n",
2052 libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
2053 lnet_msgtyp2str(type));
2057 msg = lnet_msg_alloc();
2059 CERROR("%s, src %s: Dropping %s (out of memory)\n",
2060 libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
2061 lnet_msgtyp2str(type));
2065 /* msg zeroed in lnet_msg_alloc; i.e. flags all clear, pointers NULL etc */
2067 msg->msg_type = type;
2068 msg->msg_private = private;
2069 msg->msg_receiving = 1;
2070 msg->msg_len = msg->msg_wanted = payload_length;
2071 msg->msg_offset = 0;
2072 msg->msg_hdr = *hdr;
2075 rc = lnet_nid2peer_locked(&msg->msg_rxpeer, from_nid);
2078 CERROR("%s, src %s: Dropping %s "
2079 "(error %d looking up sender)\n",
2080 libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
2081 lnet_msgtyp2str(type), rc);
2090 msg->msg_target.pid = le32_to_cpu(hdr->dest_pid);
2091 msg->msg_target.nid = dest_nid;
2092 msg->msg_routing = 1;
2093 msg->msg_offset = 0;
2096 if (msg->msg_rxpeer->lp_rtrcredits <= 0 ||
2097 lnet_msg2bufpool(msg)->rbp_credits <= 0) {
2098 rc = lnet_eager_recv_locked(msg);
2105 lnet_commit_routedmsg(msg);
2106 rc = lnet_post_routed_recv_locked(msg, 0);
2110 lnet_ni_recv(ni, msg->msg_private, msg, 0,
2111 0, payload_length, payload_length);
2115 /* convert common msg->hdr fields to host byteorder */
2116 msg->msg_hdr.type = type;
2117 msg->msg_hdr.src_nid = src_nid;
2118 msg->msg_hdr.src_pid = le32_to_cpu(msg->msg_hdr.src_pid);
2119 msg->msg_hdr.dest_nid = dest_nid;
2120 msg->msg_hdr.dest_pid = le32_to_cpu(msg->msg_hdr.dest_pid);
2121 msg->msg_hdr.payload_length = payload_length;
2123 msg->msg_ev.sender = from_nid;
2127 rc = lnet_parse_ack(ni, msg);
2130 rc = lnet_parse_put(ni, msg);
2133 rc = lnet_parse_get(ni, msg, rdma_req);
2135 case LNET_MSG_REPLY:
2136 rc = lnet_parse_reply(ni, msg);
2140 goto free_drop; /* prevent an unused label if !kernel */
2146 LASSERT (rc == ENOENT);
2149 LASSERT (msg->msg_md == NULL);
2151 if (msg->msg_rxpeer != NULL) {
2152 lnet_peer_decref_locked(msg->msg_rxpeer);
2153 msg->msg_rxpeer = NULL;
2155 lnet_msg_free(msg); /* expects LNET_LOCK held */
2159 lnet_drop_message(ni, private, payload_length);
2164 LNetPut(lnet_nid_t self, lnet_handle_md_t mdh, lnet_ack_req_t ack,
2165 lnet_process_id_t target, unsigned int portal,
2166 __u64 match_bits, unsigned int offset,
2173 LASSERT (the_lnet.ln_init);
2174 LASSERT (the_lnet.ln_refcount > 0);
2176 if (!list_empty (&the_lnet.ln_test_peers) && /* normally we don't */
2177 fail_peer (target.nid, 1)) /* shall we now? */
2179 CERROR("Dropping PUT to %s: simulated failure\n",
2180 libcfs_id2str(target));
2184 msg = lnet_msg_alloc();
2186 CERROR("Dropping PUT to %s: ENOMEM on lnet_msg_t\n",
2187 libcfs_id2str(target));
2193 md = lnet_handle2md(&mdh);
2194 if (md == NULL || md->md_threshold == 0) {
2198 CERROR("Dropping PUT to %s: MD invalid\n",
2199 libcfs_id2str(target));
2203 CDEBUG(D_NET, "LNetPut -> %s\n", libcfs_id2str(target));
2205 lnet_commit_md(md, msg);
2207 lnet_prep_send(msg, LNET_MSG_PUT, target, 0, md->md_length);
2209 msg->msg_hdr.msg.put.match_bits = cpu_to_le64(match_bits);
2210 msg->msg_hdr.msg.put.ptl_index = cpu_to_le32(portal);
2211 msg->msg_hdr.msg.put.offset = cpu_to_le32(offset);
2212 msg->msg_hdr.msg.put.hdr_data = hdr_data;
2214 /* NB handles only looked up by creator (no flips) */
2215 if (ack == LNET_ACK_REQ) {
2216 msg->msg_hdr.msg.put.ack_wmd.wh_interface_cookie =
2217 the_lnet.ln_interface_cookie;
2218 msg->msg_hdr.msg.put.ack_wmd.wh_object_cookie =
2219 md->md_lh.lh_cookie;
2221 msg->msg_hdr.msg.put.ack_wmd = LNET_WIRE_HANDLE_NONE;
2224 msg->msg_ev.type = LNET_EVENT_SEND;
2225 msg->msg_ev.initiator.nid = LNET_NID_ANY;
2226 msg->msg_ev.initiator.pid = the_lnet.ln_pid;
2227 msg->msg_ev.target = target;
2228 msg->msg_ev.sender = LNET_NID_ANY;
2229 msg->msg_ev.pt_index = portal;
2230 msg->msg_ev.match_bits = match_bits;
2231 msg->msg_ev.rlength = md->md_length;
2232 msg->msg_ev.mlength = md->md_length;
2233 msg->msg_ev.offset = offset;
2234 msg->msg_ev.hdr_data = hdr_data;
2236 lnet_md_deconstruct(md, &msg->msg_ev.md);
2237 lnet_md2handle(&msg->msg_ev.md_handle, md);
2239 the_lnet.ln_counters.send_count++;
2240 the_lnet.ln_counters.send_length += md->md_length;
2244 rc = lnet_send(self, msg);
2246 CERROR("Error sending PUT to %s: %d\n",
2247 libcfs_id2str(target), rc);
2248 lnet_finalize (NULL, msg, rc);
2251 /* completion will be signalled by an event */
2256 lnet_create_reply_msg (lnet_ni_t *ni, lnet_msg_t *getmsg)
2258 /* The LND can DMA direct to the GET md (i.e. no REPLY msg). This
2259 * returns a msg for the LND to pass to lnet_finalize() when the sink
2260 * data has been received.
2262 * CAVEAT EMPTOR: 'getmsg' is the original GET, which is freed when
2263 * lnet_finalize() is called on it, so the LND must call this first */
2265 lnet_msg_t *msg = lnet_msg_alloc();
2266 lnet_libmd_t *getmd = getmsg->msg_md;
2267 lnet_process_id_t peer_id = getmsg->msg_target;
2269 LASSERT (!getmsg->msg_target_is_router);
2270 LASSERT (!getmsg->msg_routing);
2274 LASSERT (getmd->md_refcount > 0);
2277 CERROR ("%s: Dropping REPLY from %s: can't allocate msg\n",
2278 libcfs_nid2str(ni->ni_nid), libcfs_id2str(peer_id));
2282 if (getmd->md_threshold == 0) {
2283 CERROR ("%s: Dropping REPLY from %s for inactive MD %p\n",
2284 libcfs_nid2str(ni->ni_nid), libcfs_id2str(peer_id),
2289 LASSERT (getmd->md_offset == 0);
2291 CDEBUG(D_NET, "%s: Reply from %s md %p\n",
2292 libcfs_nid2str(ni->ni_nid), libcfs_id2str(peer_id), getmd);
2294 lnet_commit_md (getmd, msg);
2296 msg->msg_type = LNET_MSG_GET; /* flag this msg as an "optimized" GET */
2298 msg->msg_ev.type = LNET_EVENT_REPLY;
2299 msg->msg_ev.initiator = peer_id;
2300 msg->msg_ev.sender = peer_id.nid; /* optimized GETs can't be routed */
2301 msg->msg_ev.rlength = msg->msg_ev.mlength = getmd->md_length;
2302 msg->msg_ev.offset = 0;
2304 lnet_md_deconstruct(getmd, &msg->msg_ev.md);
2305 lnet_md2handle(&msg->msg_ev.md_handle, getmd);
2307 the_lnet.ln_counters.recv_count++;
2308 the_lnet.ln_counters.recv_length += getmd->md_length;
2317 the_lnet.ln_counters.drop_count++;
2318 the_lnet.ln_counters.drop_length += getmd->md_length;
2326 lnet_set_reply_msg_len(lnet_ni_t *ni, lnet_msg_t *reply, unsigned int len)
2328 /* Set the REPLY length, now the RDMA that elides the REPLY message has
2329 * completed and I know it. */
2330 LASSERT (reply != NULL);
2331 LASSERT (reply->msg_type == LNET_MSG_GET);
2332 LASSERT (reply->msg_ev.type == LNET_EVENT_REPLY);
2334 /* NB I trusted my peer to RDMA. If she tells me she's written beyond
2335 * the end of my buffer, I might as well be dead. */
2336 LASSERT (len <= reply->msg_ev.mlength);
2338 reply->msg_ev.mlength = len;
2342 LNetGet(lnet_nid_t self, lnet_handle_md_t mdh,
2343 lnet_process_id_t target, unsigned int portal,
2344 __u64 match_bits, unsigned int offset)
2350 LASSERT (the_lnet.ln_init);
2351 LASSERT (the_lnet.ln_refcount > 0);
2353 if (!list_empty (&the_lnet.ln_test_peers) && /* normally we don't */
2354 fail_peer (target.nid, 1)) /* shall we now? */
2356 CERROR("Dropping GET to %s: simulated failure\n",
2357 libcfs_id2str(target));
2361 msg = lnet_msg_alloc();
2363 CERROR("Dropping GET to %s: ENOMEM on lnet_msg_t\n",
2364 libcfs_id2str(target));
2370 md = lnet_handle2md(&mdh);
2371 if (md == NULL || md->md_threshold == 0) {
2375 CERROR("Dropping GET to %s: MD invalid\n",
2376 libcfs_id2str(target));
2380 CDEBUG(D_NET, "LNetGet -> %s\n", libcfs_id2str(target));
2382 lnet_commit_md(md, msg);
2384 lnet_prep_send(msg, LNET_MSG_GET, target, 0, 0);
2386 msg->msg_hdr.msg.get.match_bits = cpu_to_le64(match_bits);
2387 msg->msg_hdr.msg.get.ptl_index = cpu_to_le32(portal);
2388 msg->msg_hdr.msg.get.src_offset = cpu_to_le32(offset);
2389 msg->msg_hdr.msg.get.sink_length = cpu_to_le32(md->md_length);
2391 /* NB handles only looked up by creator (no flips) */
2392 msg->msg_hdr.msg.get.return_wmd.wh_interface_cookie =
2393 the_lnet.ln_interface_cookie;
2394 msg->msg_hdr.msg.get.return_wmd.wh_object_cookie =
2395 md->md_lh.lh_cookie;
2397 msg->msg_ev.type = LNET_EVENT_SEND;
2398 msg->msg_ev.initiator.nid = LNET_NID_ANY;
2399 msg->msg_ev.initiator.pid = the_lnet.ln_pid;
2400 msg->msg_ev.target = target;
2401 msg->msg_ev.sender = LNET_NID_ANY;
2402 msg->msg_ev.pt_index = portal;
2403 msg->msg_ev.match_bits = match_bits;
2404 msg->msg_ev.rlength = md->md_length;
2405 msg->msg_ev.mlength = md->md_length;
2406 msg->msg_ev.offset = offset;
2407 msg->msg_ev.hdr_data = 0;
2409 lnet_md_deconstruct(md, &msg->msg_ev.md);
2410 lnet_md2handle(&msg->msg_ev.md_handle, md);
2412 the_lnet.ln_counters.send_count++;
2416 rc = lnet_send(self, msg);
2418 CERROR("error sending GET to %s: %d\n",
2419 libcfs_id2str(target), rc);
2420 lnet_finalize (NULL, msg, rc);
2423 /* completion will be signalled by an event */
2428 LNetDist (lnet_nid_t dstnid, lnet_nid_t *srcnidp, int *orderp)
2430 struct list_head *e;
2432 lnet_route_t *route;
2433 lnet_remotenet_t *rnet;
2434 __u32 dstnet = LNET_NIDNET(dstnid);
2438 /* if !local_nid_dist_zero, I don't return a distance of 0 ever
2439 * (when lustre sees a distance of 0, it substitutes 0@lo), so I
2440 * keep order 0 free for 0@lo and order 1 free for a local NID
2443 LASSERT (the_lnet.ln_init);
2444 LASSERT (the_lnet.ln_refcount > 0);
2448 list_for_each (e, &the_lnet.ln_nis) {
2449 ni = list_entry(e, lnet_ni_t, ni_list);
2451 if (ni->ni_nid == dstnid ||
2452 (the_lnet.ln_ptlcompat > 0 &&
2453 LNET_NIDNET(dstnid) == 0 &&
2454 LNET_NIDADDR(dstnid) == LNET_NIDADDR(ni->ni_nid) &&
2455 LNET_NETTYP(LNET_NIDNET(ni->ni_nid)) != LOLND)) {
2456 if (srcnidp != NULL)
2458 if (orderp != NULL) {
2459 if (LNET_NETTYP(LNET_NIDNET(dstnid)) == LOLND)
2466 return local_nid_dist_zero ? 0 : 1;
2469 if (LNET_NIDNET(ni->ni_nid) == dstnet ||
2470 (the_lnet.ln_ptlcompat > 0 &&
2472 LNET_NETTYP(LNET_NIDNET(ni->ni_nid)) != LOLND)) {
2473 if (srcnidp != NULL)
2474 *srcnidp = ni->ni_nid;
2484 list_for_each (e, &the_lnet.ln_remote_nets) {
2485 rnet = list_entry(e, lnet_remotenet_t, lrn_list);
2487 if (rnet->lrn_net == dstnet) {
2488 LASSERT (!list_empty(&rnet->lrn_routes));
2489 route = list_entry(rnet->lrn_routes.next,
2490 lnet_route_t, lr_list);
2491 hops = rnet->lrn_hops;
2492 if (srcnidp != NULL)
2493 *srcnidp = route->lr_gateway->lp_ni->ni_nid;
2503 return -EHOSTUNREACH;
2507 LNetSetAsync(lnet_process_id_t id, int nasync)
2513 lnet_remotenet_t *rnet;
2514 struct list_head *tmp;
2515 lnet_route_t *route;
2522 /* Target on a local network? */
2524 ni = lnet_net2ni(LNET_NIDNET(id.nid));
2526 if (ni->ni_lnd->lnd_setasync != NULL)
2527 rc = (ni->ni_lnd->lnd_setasync)(ni, id, nasync);
2532 /* Target on a remote network: apply to routers */
2534 LIBCFS_ALLOC(nids, maxnids * sizeof(*nids));
2539 /* Snapshot all the router NIDs */
2541 rnet = lnet_find_net_locked(LNET_NIDNET(id.nid));
2543 list_for_each(tmp, &rnet->lrn_routes) {
2544 if (nnids == maxnids) {
2546 LIBCFS_FREE(nids, maxnids * sizeof(*nids));
2551 route = list_entry(tmp, lnet_route_t, lr_list);
2552 nids[nnids++] = route->lr_gateway->lp_nid;
2557 /* set async on all the routers */
2558 while (nnids-- > 0) {
2559 id.pid = LUSTRE_SRV_LNET_PID;
2560 id.nid = nids[nnids];
2562 ni = lnet_net2ni(LNET_NIDNET(id.nid));
2566 if (ni->ni_lnd->lnd_setasync != NULL) {
2567 rc2 = (ni->ni_lnd->lnd_setasync)(ni, id, nasync);
2574 LIBCFS_FREE(nids, maxnids * sizeof(*nids));