1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lnet/lnet/lib-move.c
38 * Data movement routines
41 #define DEBUG_SUBSYSTEM S_LNET
43 #include <lnet/lib-lnet.h>
45 static int local_nid_dist_zero = 1;
46 CFS_MODULE_PARM(local_nid_dist_zero, "i", int, 0444,
50 static void lnet_commit_md (lnet_libmd_t *md, lnet_msg_t *msg);
52 #define LNET_MATCHMD_NONE 0 /* Didn't match */
53 #define LNET_MATCHMD_OK 1 /* Matched OK */
54 #define LNET_MATCHMD_DROP 2 /* Must be discarded */
57 lnet_try_match_md (int index, int op_mask, lnet_process_id_t src,
58 unsigned int rlength, unsigned int roffset,
59 __u64 match_bits, lnet_libmd_t *md, lnet_msg_t *msg,
60 unsigned int *mlength_out, unsigned int *offset_out)
62 /* ALWAYS called holding the LNET_LOCK, and can't LNET_UNLOCK;
63 * lnet_match_blocked_msg() relies on this to avoid races */
66 lnet_me_t *me = md->md_me;
68 /* mismatched MD op */
69 if ((md->md_options & op_mask) == 0)
70 return LNET_MATCHMD_NONE;
73 if (lnet_md_exhausted(md))
74 return LNET_MATCHMD_NONE;
76 /* mismatched ME nid/pid? */
77 if (me->me_match_id.nid != LNET_NID_ANY &&
78 me->me_match_id.nid != src.nid)
79 return LNET_MATCHMD_NONE;
81 if (me->me_match_id.pid != LNET_PID_ANY &&
82 me->me_match_id.pid != src.pid)
83 return LNET_MATCHMD_NONE;
85 /* mismatched ME matchbits? */
86 if (((me->me_match_bits ^ match_bits) & ~me->me_ignore_bits) != 0)
87 return LNET_MATCHMD_NONE;
89 /* Hurrah! This _is_ a match; check it out... */
91 if ((md->md_options & LNET_MD_MANAGE_REMOTE) == 0)
92 offset = md->md_offset;
96 if ((md->md_options & LNET_MD_MAX_SIZE) != 0) {
97 mlength = md->md_max_size;
98 LASSERT (md->md_offset + mlength <= md->md_length);
100 mlength = md->md_length - offset;
103 if (rlength <= mlength) { /* fits in allowed space */
105 } else if ((md->md_options & LNET_MD_TRUNCATE) == 0) {
106 /* this packet _really_ is too big */
107 CERROR("Matching packet from %s, match "LPU64
108 " length %d too big: %d left, %d allowed\n",
109 libcfs_id2str(src), match_bits, rlength,
110 md->md_length - offset, mlength);
112 return LNET_MATCHMD_DROP;
115 /* Commit to this ME/MD */
116 CDEBUG(D_NET, "Incoming %s index %x from %s of "
117 "length %d/%d into md "LPX64" [%d] + %d\n",
118 (op_mask == LNET_MD_OP_PUT) ? "put" : "get",
119 index, libcfs_id2str(src), mlength, rlength,
120 md->md_lh.lh_cookie, md->md_niov, offset);
122 lnet_commit_md(md, msg);
123 md->md_offset = offset + mlength;
125 /* NB Caller will set ev.type and ev.hdr_data */
126 msg->msg_ev.initiator = src;
127 msg->msg_ev.pt_index = index;
128 msg->msg_ev.match_bits = match_bits;
129 msg->msg_ev.rlength = rlength;
130 msg->msg_ev.mlength = mlength;
131 msg->msg_ev.offset = offset;
133 lnet_md_deconstruct(md, &msg->msg_ev.md);
134 lnet_md2handle(&msg->msg_ev.md_handle, md);
136 *offset_out = offset;
137 *mlength_out = mlength;
139 /* Auto-unlink NOW, so the ME gets unlinked if required.
140 * We bumped md->md_refcount above so the MD just gets flagged
141 * for unlink when it is finalized. */
142 if ((md->md_flags & LNET_MD_FLAG_AUTO_UNLINK) != 0 &&
143 lnet_md_exhausted(md)) {
147 return LNET_MATCHMD_OK;
151 lnet_match_md(int index, int op_mask, lnet_process_id_t src,
152 unsigned int rlength, unsigned int roffset,
153 __u64 match_bits, lnet_msg_t *msg,
154 unsigned int *mlength_out, unsigned int *offset_out,
155 lnet_libmd_t **md_out)
157 lnet_portal_t *ptl = &the_lnet.ln_portals[index];
163 CDEBUG (D_NET, "Request from %s of length %d into portal %d "
164 "MB="LPX64"\n", libcfs_id2str(src), rlength, index, match_bits);
166 if (index < 0 || index >= the_lnet.ln_nportals) {
167 CERROR("Invalid portal %d not in [0-%d]\n",
168 index, the_lnet.ln_nportals);
169 return LNET_MATCHMD_DROP;
172 cfs_list_for_each_entry_safe_typed (me, tmp, &ptl->ptl_ml,
173 lnet_me_t, me_list) {
176 /* ME attached but MD not attached yet */
180 LASSERT (me == md->md_me);
182 rc = lnet_try_match_md(index, op_mask, src, rlength,
183 roffset, match_bits, md, msg,
184 mlength_out, offset_out);
189 case LNET_MATCHMD_NONE:
192 case LNET_MATCHMD_OK:
194 return LNET_MATCHMD_OK;
196 case LNET_MATCHMD_DROP:
197 return LNET_MATCHMD_DROP;
202 if (op_mask == LNET_MD_OP_GET ||
203 (ptl->ptl_options & LNET_PTL_LAZY) == 0)
204 return LNET_MATCHMD_DROP;
206 return LNET_MATCHMD_NONE;
210 lnet_fail_nid (lnet_nid_t nid, unsigned int threshold)
212 lnet_test_peer_t *tp;
217 LASSERT (the_lnet.ln_init);
219 if (threshold != 0) {
220 /* Adding a new entry */
221 LIBCFS_ALLOC(tp, sizeof(*tp));
226 tp->tp_threshold = threshold;
229 cfs_list_add_tail (&tp->tp_list, &the_lnet.ln_test_peers);
234 /* removing entries */
235 CFS_INIT_LIST_HEAD (&cull);
239 cfs_list_for_each_safe (el, next, &the_lnet.ln_test_peers) {
240 tp = cfs_list_entry (el, lnet_test_peer_t, tp_list);
242 if (tp->tp_threshold == 0 || /* needs culling anyway */
243 nid == LNET_NID_ANY || /* removing all entries */
244 tp->tp_nid == nid) /* matched this one */
246 cfs_list_del (&tp->tp_list);
247 cfs_list_add (&tp->tp_list, &cull);
253 while (!cfs_list_empty (&cull)) {
254 tp = cfs_list_entry (cull.next, lnet_test_peer_t, tp_list);
256 cfs_list_del (&tp->tp_list);
257 LIBCFS_FREE(tp, sizeof (*tp));
263 fail_peer (lnet_nid_t nid, int outgoing)
265 lnet_test_peer_t *tp;
271 CFS_INIT_LIST_HEAD (&cull);
275 cfs_list_for_each_safe (el, next, &the_lnet.ln_test_peers) {
276 tp = cfs_list_entry (el, lnet_test_peer_t, tp_list);
278 if (tp->tp_threshold == 0) {
281 /* only cull zombies on outgoing tests,
282 * since we may be at interrupt priority on
283 * incoming messages. */
284 cfs_list_del (&tp->tp_list);
285 cfs_list_add (&tp->tp_list, &cull);
290 if (tp->tp_nid == LNET_NID_ANY || /* fail every peer */
291 nid == tp->tp_nid) { /* fail this peer */
294 if (tp->tp_threshold != LNET_MD_THRESH_INF) {
297 tp->tp_threshold == 0) {
299 cfs_list_del (&tp->tp_list);
300 cfs_list_add (&tp->tp_list, &cull);
309 while (!cfs_list_empty (&cull)) {
310 tp = cfs_list_entry (cull.next, lnet_test_peer_t, tp_list);
311 cfs_list_del (&tp->tp_list);
313 LIBCFS_FREE(tp, sizeof (*tp));
320 lnet_iov_nob (unsigned int niov, struct iovec *iov)
322 unsigned int nob = 0;
325 nob += (iov++)->iov_len;
331 lnet_copy_iov2iov (unsigned int ndiov, struct iovec *diov, unsigned int doffset,
332 unsigned int nsiov, struct iovec *siov, unsigned int soffset,
335 /* NB diov, siov are READ-ONLY */
336 unsigned int this_nob;
341 /* skip complete frags before 'doffset' */
343 while (doffset >= diov->iov_len) {
344 doffset -= diov->iov_len;
350 /* skip complete frags before 'soffset' */
352 while (soffset >= siov->iov_len) {
353 soffset -= siov->iov_len;
362 this_nob = MIN(diov->iov_len - doffset,
363 siov->iov_len - soffset);
364 this_nob = MIN(this_nob, nob);
366 memcpy ((char *)diov->iov_base + doffset,
367 (char *)siov->iov_base + soffset, this_nob);
370 if (diov->iov_len > doffset + this_nob) {
378 if (siov->iov_len > soffset + this_nob) {
389 lnet_extract_iov (int dst_niov, struct iovec *dst,
390 int src_niov, struct iovec *src,
391 unsigned int offset, unsigned int len)
393 /* Initialise 'dst' to the subset of 'src' starting at 'offset',
394 * for exactly 'len' bytes, and return the number of entries.
395 * NB not destructive to 'src' */
396 unsigned int frag_len;
399 if (len == 0) /* no data => */
400 return (0); /* no frags */
402 LASSERT (src_niov > 0);
403 while (offset >= src->iov_len) { /* skip initial frags */
404 offset -= src->iov_len;
407 LASSERT (src_niov > 0);
412 LASSERT (src_niov > 0);
413 LASSERT ((int)niov <= dst_niov);
415 frag_len = src->iov_len - offset;
416 dst->iov_base = ((char *)src->iov_base) + offset;
418 if (len <= frag_len) {
423 dst->iov_len = frag_len;
436 lnet_kiov_nob (unsigned int niov, lnet_kiov_t *kiov)
443 lnet_copy_kiov2kiov (unsigned int ndkiov, lnet_kiov_t *dkiov, unsigned int doffset,
444 unsigned int nskiov, lnet_kiov_t *skiov, unsigned int soffset,
451 lnet_copy_kiov2iov (unsigned int niov, struct iovec *iov, unsigned int iovoffset,
452 unsigned int nkiov, lnet_kiov_t *kiov, unsigned int kiovoffset,
459 lnet_copy_iov2kiov (unsigned int nkiov, lnet_kiov_t *kiov, unsigned int kiovoffset,
460 unsigned int niov, struct iovec *iov, unsigned int iovoffset,
467 lnet_extract_kiov (int dst_niov, lnet_kiov_t *dst,
468 int src_niov, lnet_kiov_t *src,
469 unsigned int offset, unsigned int len)
474 #else /* __KERNEL__ */
477 lnet_kiov_nob (unsigned int niov, lnet_kiov_t *kiov)
479 unsigned int nob = 0;
482 nob += (kiov++)->kiov_len;
488 lnet_copy_kiov2kiov (unsigned int ndiov, lnet_kiov_t *diov, unsigned int doffset,
489 unsigned int nsiov, lnet_kiov_t *siov, unsigned int soffset,
492 /* NB diov, siov are READ-ONLY */
493 unsigned int this_nob;
500 LASSERT (!cfs_in_interrupt ());
503 while (doffset >= diov->kiov_len) {
504 doffset -= diov->kiov_len;
511 while (soffset >= siov->kiov_len) {
512 soffset -= siov->kiov_len;
521 this_nob = MIN(diov->kiov_len - doffset,
522 siov->kiov_len - soffset);
523 this_nob = MIN(this_nob, nob);
526 daddr = ((char *)cfs_kmap(diov->kiov_page)) +
527 diov->kiov_offset + doffset;
529 saddr = ((char *)cfs_kmap(siov->kiov_page)) +
530 siov->kiov_offset + soffset;
532 /* Vanishing risk of kmap deadlock when mapping 2 pages.
533 * However in practice at least one of the kiovs will be mapped
534 * kernel pages and the map/unmap will be NOOPs */
536 memcpy (daddr, saddr, this_nob);
539 if (diov->kiov_len > doffset + this_nob) {
543 cfs_kunmap(diov->kiov_page);
550 if (siov->kiov_len > soffset + this_nob) {
554 cfs_kunmap(siov->kiov_page);
563 cfs_kunmap(diov->kiov_page);
565 cfs_kunmap(siov->kiov_page);
569 lnet_copy_kiov2iov (unsigned int niov, struct iovec *iov, unsigned int iovoffset,
570 unsigned int nkiov, lnet_kiov_t *kiov, unsigned int kiovoffset,
573 /* NB iov, kiov are READ-ONLY */
574 unsigned int this_nob;
580 LASSERT (!cfs_in_interrupt ());
583 while (iovoffset >= iov->iov_len) {
584 iovoffset -= iov->iov_len;
591 while (kiovoffset >= kiov->kiov_len) {
592 kiovoffset -= kiov->kiov_len;
601 this_nob = MIN(iov->iov_len - iovoffset,
602 kiov->kiov_len - kiovoffset);
603 this_nob = MIN(this_nob, nob);
606 addr = ((char *)cfs_kmap(kiov->kiov_page)) +
607 kiov->kiov_offset + kiovoffset;
609 memcpy ((char *)iov->iov_base + iovoffset, addr, this_nob);
612 if (iov->iov_len > iovoffset + this_nob) {
613 iovoffset += this_nob;
620 if (kiov->kiov_len > kiovoffset + this_nob) {
622 kiovoffset += this_nob;
624 cfs_kunmap(kiov->kiov_page);
634 cfs_kunmap(kiov->kiov_page);
638 lnet_copy_iov2kiov (unsigned int nkiov, lnet_kiov_t *kiov, unsigned int kiovoffset,
639 unsigned int niov, struct iovec *iov, unsigned int iovoffset,
642 /* NB kiov, iov are READ-ONLY */
643 unsigned int this_nob;
649 LASSERT (!cfs_in_interrupt ());
652 while (kiovoffset >= kiov->kiov_len) {
653 kiovoffset -= kiov->kiov_len;
660 while (iovoffset >= iov->iov_len) {
661 iovoffset -= iov->iov_len;
670 this_nob = MIN(kiov->kiov_len - kiovoffset,
671 iov->iov_len - iovoffset);
672 this_nob = MIN(this_nob, nob);
675 addr = ((char *)cfs_kmap(kiov->kiov_page)) +
676 kiov->kiov_offset + kiovoffset;
678 memcpy (addr, (char *)iov->iov_base + iovoffset, this_nob);
681 if (kiov->kiov_len > kiovoffset + this_nob) {
683 kiovoffset += this_nob;
685 cfs_kunmap(kiov->kiov_page);
692 if (iov->iov_len > iovoffset + this_nob) {
693 iovoffset += this_nob;
702 cfs_kunmap(kiov->kiov_page);
706 lnet_extract_kiov (int dst_niov, lnet_kiov_t *dst,
707 int src_niov, lnet_kiov_t *src,
708 unsigned int offset, unsigned int len)
710 /* Initialise 'dst' to the subset of 'src' starting at 'offset',
711 * for exactly 'len' bytes, and return the number of entries.
712 * NB not destructive to 'src' */
713 unsigned int frag_len;
716 if (len == 0) /* no data => */
717 return (0); /* no frags */
719 LASSERT (src_niov > 0);
720 while (offset >= src->kiov_len) { /* skip initial frags */
721 offset -= src->kiov_len;
724 LASSERT (src_niov > 0);
729 LASSERT (src_niov > 0);
730 LASSERT ((int)niov <= dst_niov);
732 frag_len = src->kiov_len - offset;
733 dst->kiov_page = src->kiov_page;
734 dst->kiov_offset = src->kiov_offset + offset;
736 if (len <= frag_len) {
738 LASSERT (dst->kiov_offset + dst->kiov_len <= CFS_PAGE_SIZE);
742 dst->kiov_len = frag_len;
743 LASSERT (dst->kiov_offset + dst->kiov_len <= CFS_PAGE_SIZE);
756 lnet_ni_recv(lnet_ni_t *ni, void *private, lnet_msg_t *msg, int delayed,
757 unsigned int offset, unsigned int mlen, unsigned int rlen)
759 unsigned int niov = 0;
760 struct iovec *iov = NULL;
761 lnet_kiov_t *kiov = NULL;
764 LASSERT (!cfs_in_interrupt ());
765 LASSERT (mlen == 0 || msg != NULL);
768 LASSERT(msg->msg_receiving);
769 LASSERT(!msg->msg_sending);
770 LASSERT(rlen == msg->msg_len);
771 LASSERT(mlen <= msg->msg_len);
773 msg->msg_wanted = mlen;
774 msg->msg_offset = offset;
775 msg->msg_receiving = 0;
778 niov = msg->msg_niov;
780 kiov = msg->msg_kiov;
783 LASSERT ((iov == NULL) != (kiov == NULL));
787 rc = (ni->ni_lnd->lnd_recv)(ni, private, msg, delayed,
788 niov, iov, kiov, offset, mlen, rlen);
790 lnet_finalize(ni, msg, rc);
794 lnet_compare_routes(lnet_route_t *r1, lnet_route_t *r2)
796 lnet_peer_t *p1 = r1->lr_gateway;
797 lnet_peer_t *p2 = r2->lr_gateway;
799 if (r1->lr_hops < r2->lr_hops)
802 if (r1->lr_hops > r2->lr_hops)
805 if (p1->lp_txqnob < p2->lp_txqnob)
808 if (p1->lp_txqnob > p2->lp_txqnob)
811 if (p1->lp_txcredits > p2->lp_txcredits)
814 if (p1->lp_txcredits < p2->lp_txcredits)
822 lnet_setpayloadbuffer(lnet_msg_t *msg)
824 lnet_libmd_t *md = msg->msg_md;
826 LASSERT (msg->msg_len > 0);
827 LASSERT (!msg->msg_routing);
828 LASSERT (md != NULL);
829 LASSERT (msg->msg_niov == 0);
830 LASSERT (msg->msg_iov == NULL);
831 LASSERT (msg->msg_kiov == NULL);
833 msg->msg_niov = md->md_niov;
834 if ((md->md_options & LNET_MD_KIOV) != 0)
835 msg->msg_kiov = md->md_iov.kiov;
837 msg->msg_iov = md->md_iov.iov;
841 lnet_prep_send(lnet_msg_t *msg, int type, lnet_process_id_t target,
842 unsigned int offset, unsigned int len)
844 msg->msg_type = type;
845 msg->msg_target = target;
847 msg->msg_offset = offset;
850 lnet_setpayloadbuffer(msg);
852 memset (&msg->msg_hdr, 0, sizeof (msg->msg_hdr));
853 msg->msg_hdr.type = cpu_to_le32(type);
854 msg->msg_hdr.dest_nid = cpu_to_le64(target.nid);
855 msg->msg_hdr.dest_pid = cpu_to_le32(target.pid);
856 /* src_nid will be set later */
857 msg->msg_hdr.src_pid = cpu_to_le32(the_lnet.ln_pid);
858 msg->msg_hdr.payload_length = cpu_to_le32(len);
862 lnet_ni_send(lnet_ni_t *ni, lnet_msg_t *msg)
864 void *priv = msg->msg_private;
867 LASSERT (!cfs_in_interrupt ());
868 LASSERT (LNET_NETTYP(LNET_NIDNET(ni->ni_nid)) == LOLND ||
869 (msg->msg_txcredit && msg->msg_peertxcredit));
871 rc = (ni->ni_lnd->lnd_send)(ni, priv, msg);
873 lnet_finalize(ni, msg, rc);
877 lnet_eager_recv_locked(lnet_msg_t *msg)
883 LASSERT (!msg->msg_delayed);
884 msg->msg_delayed = 1;
886 LASSERT (msg->msg_receiving);
887 LASSERT (!msg->msg_sending);
889 peer = msg->msg_rxpeer;
892 if (ni->ni_lnd->lnd_eager_recv != NULL) {
895 rc = (ni->ni_lnd->lnd_eager_recv)(ni, msg->msg_private, msg,
898 CERROR("recv from %s / send to %s aborted: "
899 "eager_recv failed %d\n",
900 libcfs_nid2str(peer->lp_nid),
901 libcfs_id2str(msg->msg_target), rc);
902 LASSERT (rc < 0); /* required by my callers */
911 /* NB: caller shall hold a ref on 'lp' as I'd drop LNET_LOCK */
913 lnet_ni_peer_alive(lnet_peer_t *lp)
915 cfs_time_t last_alive = 0;
916 lnet_ni_t *ni = lp->lp_ni;
918 LASSERT (lnet_peer_aliveness_enabled(lp));
919 LASSERT (ni->ni_lnd->lnd_query != NULL);
922 (ni->ni_lnd->lnd_query)(ni, lp->lp_nid, &last_alive);
925 lp->lp_last_query = cfs_time_current();
927 if (last_alive != 0) /* NI has updated timestamp */
928 lp->lp_last_alive = last_alive;
932 /* NB: always called with LNET_LOCK held */
934 lnet_peer_is_alive (lnet_peer_t *lp, cfs_time_t now)
939 LASSERT (lnet_peer_aliveness_enabled(lp));
941 /* Trust lnet_notify() if it has more recent aliveness news, but
942 * ignore the initial assumed death (see lnet_peers_start_down()).
944 if (!lp->lp_alive && lp->lp_alive_count > 0 &&
945 cfs_time_aftereq(lp->lp_timestamp, lp->lp_last_alive))
948 deadline = cfs_time_add(lp->lp_last_alive,
949 cfs_time_seconds(lp->lp_ni->ni_peertimeout));
950 alive = cfs_time_after(deadline, now);
952 /* Update obsolete lp_alive except for routers assumed to be dead
953 * initially, because router checker would update aliveness in this
954 * case, and moreover lp_last_alive at peer creation is assumed.
956 if (alive && !lp->lp_alive &&
957 !(lnet_isrouter(lp) && lp->lp_alive_count == 0))
958 lnet_notify_locked(lp, 0, 1, lp->lp_last_alive);
964 /* NB: returns 1 when alive, 0 when dead, negative when error;
965 * may drop the LNET_LOCK */
967 lnet_peer_alive_locked (lnet_peer_t *lp)
969 cfs_time_t now = cfs_time_current();
971 if (!lnet_peer_aliveness_enabled(lp))
974 if (lnet_peer_is_alive(lp, now))
977 /* Peer appears dead, but we should avoid frequent NI queries (at
978 * most once per lnet_queryinterval seconds). */
979 if (lp->lp_last_query != 0) {
980 static const int lnet_queryinterval = 1;
982 cfs_time_t next_query =
983 cfs_time_add(lp->lp_last_query,
984 cfs_time_seconds(lnet_queryinterval));
986 if (cfs_time_before(now, next_query)) {
988 CWARN("Unexpected aliveness of peer %s: "
990 libcfs_nid2str(lp->lp_nid),
991 (int)now, (int)next_query,
993 lp->lp_ni->ni_peertimeout);
998 /* query NI for latest aliveness news */
999 lnet_ni_peer_alive(lp);
1001 if (lnet_peer_is_alive(lp, now))
1004 lnet_notify_locked(lp, 0, 0, lp->lp_last_alive);
1009 lnet_post_send_locked (lnet_msg_t *msg, int do_send)
1011 /* lnet_send is going to LNET_UNLOCK immediately after this, so it sets
1012 * do_send FALSE and I don't do the unlock/send/lock bit. I return
1013 * EAGAIN if msg blocked, EHOSTUNREACH if msg_txpeer appears dead, and
1014 * 0 if sent or OK to send */
1015 lnet_peer_t *lp = msg->msg_txpeer;
1016 lnet_ni_t *ni = lp->lp_ni;
1018 /* non-lnet_send() callers have checked before */
1019 LASSERT (!do_send || msg->msg_delayed);
1020 LASSERT (!msg->msg_receiving);
1022 /* NB 'lp' is always the next hop */
1023 if ((msg->msg_target.pid & LNET_PID_USERFLAG) == 0 &&
1024 lnet_peer_alive_locked(lp) == 0) {
1027 CDEBUG(D_NETERROR, "Dropping message for %s: peer not alive\n",
1028 libcfs_id2str(msg->msg_target));
1030 lnet_finalize(ni, msg, -EHOSTUNREACH);
1033 return EHOSTUNREACH;
1036 if (!msg->msg_peertxcredit) {
1037 LASSERT ((lp->lp_txcredits < 0) ==
1038 !cfs_list_empty(&lp->lp_txq));
1040 msg->msg_peertxcredit = 1;
1041 lp->lp_txqnob += msg->msg_len + sizeof(lnet_hdr_t);
1044 if (lp->lp_txcredits < lp->lp_mintxcredits)
1045 lp->lp_mintxcredits = lp->lp_txcredits;
1047 if (lp->lp_txcredits < 0) {
1048 msg->msg_delayed = 1;
1049 cfs_list_add_tail(&msg->msg_list, &lp->lp_txq);
1054 if (!msg->msg_txcredit) {
1055 LASSERT ((ni->ni_txcredits < 0) ==
1056 !cfs_list_empty(&ni->ni_txq));
1058 msg->msg_txcredit = 1;
1061 if (ni->ni_txcredits < ni->ni_mintxcredits)
1062 ni->ni_mintxcredits = ni->ni_txcredits;
1064 if (ni->ni_txcredits < 0) {
1065 msg->msg_delayed = 1;
1066 cfs_list_add_tail(&msg->msg_list, &ni->ni_txq);
1073 lnet_ni_send(ni, msg);
1081 lnet_commit_routedmsg (lnet_msg_t *msg)
1083 /* ALWAYS called holding the LNET_LOCK */
1084 LASSERT (msg->msg_routing);
1086 the_lnet.ln_counters.msgs_alloc++;
1087 if (the_lnet.ln_counters.msgs_alloc >
1088 the_lnet.ln_counters.msgs_max)
1089 the_lnet.ln_counters.msgs_max =
1090 the_lnet.ln_counters.msgs_alloc;
1092 the_lnet.ln_counters.route_count++;
1093 the_lnet.ln_counters.route_length += msg->msg_len;
1095 LASSERT (!msg->msg_onactivelist);
1096 msg->msg_onactivelist = 1;
1097 cfs_list_add (&msg->msg_activelist, &the_lnet.ln_active_msgs);
1101 lnet_msg2bufpool(lnet_msg_t *msg)
1103 lnet_rtrbufpool_t *rbp = &the_lnet.ln_rtrpools[0];
1105 LASSERT (msg->msg_len <= LNET_MTU);
1106 while (msg->msg_len > (unsigned int)rbp->rbp_npages * CFS_PAGE_SIZE) {
1108 LASSERT (rbp < &the_lnet.ln_rtrpools[LNET_NRBPOOLS]);
1115 lnet_post_routed_recv_locked (lnet_msg_t *msg, int do_recv)
1117 /* lnet_parse is going to LNET_UNLOCK immediately after this, so it
1118 * sets do_recv FALSE and I don't do the unlock/send/lock bit. I
1119 * return EAGAIN if msg blocked and 0 if received or OK to receive */
1120 lnet_peer_t *lp = msg->msg_rxpeer;
1121 lnet_rtrbufpool_t *rbp;
1124 LASSERT (msg->msg_iov == NULL);
1125 LASSERT (msg->msg_kiov == NULL);
1126 LASSERT (msg->msg_niov == 0);
1127 LASSERT (msg->msg_routing);
1128 LASSERT (msg->msg_receiving);
1129 LASSERT (!msg->msg_sending);
1131 /* non-lnet_parse callers only send delayed messages */
1132 LASSERT (!do_recv || msg->msg_delayed);
1134 if (!msg->msg_peerrtrcredit) {
1135 LASSERT ((lp->lp_rtrcredits < 0) ==
1136 !cfs_list_empty(&lp->lp_rtrq));
1138 msg->msg_peerrtrcredit = 1;
1139 lp->lp_rtrcredits--;
1140 if (lp->lp_rtrcredits < lp->lp_minrtrcredits)
1141 lp->lp_minrtrcredits = lp->lp_rtrcredits;
1143 if (lp->lp_rtrcredits < 0) {
1144 /* must have checked eager_recv before here */
1145 LASSERT (msg->msg_delayed);
1146 cfs_list_add_tail(&msg->msg_list, &lp->lp_rtrq);
1151 rbp = lnet_msg2bufpool(msg);
1153 if (!msg->msg_rtrcredit) {
1154 LASSERT ((rbp->rbp_credits < 0) ==
1155 !cfs_list_empty(&rbp->rbp_msgs));
1157 msg->msg_rtrcredit = 1;
1159 if (rbp->rbp_credits < rbp->rbp_mincredits)
1160 rbp->rbp_mincredits = rbp->rbp_credits;
1162 if (rbp->rbp_credits < 0) {
1163 /* must have checked eager_recv before here */
1164 LASSERT (msg->msg_delayed);
1165 cfs_list_add_tail(&msg->msg_list, &rbp->rbp_msgs);
1170 LASSERT (!cfs_list_empty(&rbp->rbp_bufs));
1171 rb = cfs_list_entry(rbp->rbp_bufs.next, lnet_rtrbuf_t, rb_list);
1172 cfs_list_del(&rb->rb_list);
1174 msg->msg_niov = rbp->rbp_npages;
1175 msg->msg_kiov = &rb->rb_kiov[0];
1179 lnet_ni_recv(lp->lp_ni, msg->msg_private, msg, 1,
1180 0, msg->msg_len, msg->msg_len);
1188 lnet_return_credits_locked (lnet_msg_t *msg)
1190 lnet_peer_t *txpeer = msg->msg_txpeer;
1191 lnet_peer_t *rxpeer = msg->msg_rxpeer;
1195 if (msg->msg_txcredit) {
1196 /* give back NI txcredits */
1197 msg->msg_txcredit = 0;
1200 LASSERT((ni->ni_txcredits < 0) == !cfs_list_empty(&ni->ni_txq));
1203 if (ni->ni_txcredits <= 0) {
1204 msg2 = cfs_list_entry(ni->ni_txq.next, lnet_msg_t,
1206 cfs_list_del(&msg2->msg_list);
1208 LASSERT(msg2->msg_txpeer->lp_ni == ni);
1209 LASSERT(msg2->msg_delayed);
1211 (void) lnet_post_send_locked(msg2, 1);
1215 if (msg->msg_peertxcredit) {
1216 /* give back peer txcredits */
1217 msg->msg_peertxcredit = 0;
1219 LASSERT((txpeer->lp_txcredits < 0) ==
1220 !cfs_list_empty(&txpeer->lp_txq));
1222 txpeer->lp_txqnob -= msg->msg_len + sizeof(lnet_hdr_t);
1223 LASSERT (txpeer->lp_txqnob >= 0);
1225 txpeer->lp_txcredits++;
1226 if (txpeer->lp_txcredits <= 0) {
1227 msg2 = cfs_list_entry(txpeer->lp_txq.next,
1228 lnet_msg_t, msg_list);
1229 cfs_list_del(&msg2->msg_list);
1231 LASSERT (msg2->msg_txpeer == txpeer);
1232 LASSERT (msg2->msg_delayed);
1234 (void) lnet_post_send_locked(msg2, 1);
1238 if (txpeer != NULL) {
1239 msg->msg_txpeer = NULL;
1240 lnet_peer_decref_locked(txpeer);
1244 if (msg->msg_rtrcredit) {
1245 /* give back global router credits */
1247 lnet_rtrbufpool_t *rbp;
1249 /* NB If a msg ever blocks for a buffer in rbp_msgs, it stays
1250 * there until it gets one allocated, or aborts the wait
1252 LASSERT (msg->msg_kiov != NULL);
1254 rb = cfs_list_entry(msg->msg_kiov, lnet_rtrbuf_t, rb_kiov[0]);
1256 LASSERT (rbp == lnet_msg2bufpool(msg));
1258 msg->msg_kiov = NULL;
1259 msg->msg_rtrcredit = 0;
1261 LASSERT((rbp->rbp_credits < 0) ==
1262 !cfs_list_empty(&rbp->rbp_msgs));
1263 LASSERT((rbp->rbp_credits > 0) ==
1264 !cfs_list_empty(&rbp->rbp_bufs));
1266 cfs_list_add(&rb->rb_list, &rbp->rbp_bufs);
1268 if (rbp->rbp_credits <= 0) {
1269 msg2 = cfs_list_entry(rbp->rbp_msgs.next,
1270 lnet_msg_t, msg_list);
1271 cfs_list_del(&msg2->msg_list);
1273 (void) lnet_post_routed_recv_locked(msg2, 1);
1277 if (msg->msg_peerrtrcredit) {
1278 /* give back peer router credits */
1279 msg->msg_peerrtrcredit = 0;
1281 LASSERT((rxpeer->lp_rtrcredits < 0) ==
1282 !cfs_list_empty(&rxpeer->lp_rtrq));
1284 rxpeer->lp_rtrcredits++;
1285 if (rxpeer->lp_rtrcredits <= 0) {
1286 msg2 = cfs_list_entry(rxpeer->lp_rtrq.next,
1287 lnet_msg_t, msg_list);
1288 cfs_list_del(&msg2->msg_list);
1290 (void) lnet_post_routed_recv_locked(msg2, 1);
1294 LASSERT (!msg->msg_rtrcredit);
1295 LASSERT (!msg->msg_peerrtrcredit);
1297 if (rxpeer != NULL) {
1298 msg->msg_rxpeer = NULL;
1299 lnet_peer_decref_locked(rxpeer);
1304 lnet_send(lnet_nid_t src_nid, lnet_msg_t *msg)
1306 lnet_nid_t dst_nid = msg->msg_target.nid;
1308 lnet_ni_t *local_ni;
1309 lnet_remotenet_t *rnet;
1310 lnet_route_t *route;
1311 lnet_route_t *best_route;
1317 LASSERT (msg->msg_txpeer == NULL);
1318 LASSERT (!msg->msg_sending);
1319 LASSERT (!msg->msg_target_is_router);
1320 LASSERT (!msg->msg_receiving);
1322 msg->msg_sending = 1;
1324 /* NB! ni != NULL == interface pre-determined (ACK/REPLY) */
1328 if (the_lnet.ln_shutdown) {
1333 if (src_nid == LNET_NID_ANY) {
1336 src_ni = lnet_nid2ni_locked(src_nid);
1337 if (src_ni == NULL) {
1339 CERROR("Can't send to %s: src %s is not a local nid\n",
1340 libcfs_nid2str(dst_nid), libcfs_nid2str(src_nid));
1343 LASSERT (!msg->msg_routing);
1346 /* Is this for someone on a local network? */
1347 local_ni = lnet_net2ni_locked(LNET_NIDNET(dst_nid));
1349 if (local_ni != NULL) {
1350 if (src_ni == NULL) {
1352 src_nid = src_ni->ni_nid;
1353 } else if (src_ni == local_ni) {
1354 lnet_ni_decref_locked(local_ni);
1356 lnet_ni_decref_locked(local_ni);
1357 lnet_ni_decref_locked(src_ni);
1359 CERROR("No route to %s via from %s\n",
1360 libcfs_nid2str(dst_nid), libcfs_nid2str(src_nid));
1364 LASSERT (src_nid != LNET_NID_ANY);
1366 if (!msg->msg_routing)
1367 msg->msg_hdr.src_nid = cpu_to_le64(src_nid);
1369 if (src_ni == the_lnet.ln_loni) {
1370 /* No send credit hassles with LOLND */
1372 lnet_ni_send(src_ni, msg);
1373 lnet_ni_decref(src_ni);
1377 rc = lnet_nid2peer_locked(&lp, dst_nid);
1378 lnet_ni_decref_locked(src_ni); /* lp has ref on src_ni; lose mine */
1381 CERROR("Error %d finding peer %s\n", rc,
1382 libcfs_nid2str(dst_nid));
1383 /* ENOMEM or shutting down */
1386 LASSERT (lp->lp_ni == src_ni);
1392 * - once application finishes computation, check here to update
1393 * router states before it waits for pending IO in LNetEQPoll
1394 * - recursion breaker: router checker sends no message
1395 * to remote networks */
1396 if (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING)
1397 lnet_router_checker();
1401 /* sending to a remote network */
1402 rnet = lnet_find_net_locked(LNET_NIDNET(dst_nid));
1405 lnet_ni_decref_locked(src_ni);
1407 CERROR("No route to %s\n", libcfs_id2str(msg->msg_target));
1408 return -EHOSTUNREACH;
1411 /* Find the best gateway I can use */
1414 cfs_list_for_each(tmp, &rnet->lrn_routes) {
1415 route = cfs_list_entry(tmp, lnet_route_t, lr_list);
1416 lp2 = route->lr_gateway;
1418 if (lp2->lp_alive &&
1419 lnet_router_down_ni(lp2, rnet->lrn_net) <= 0 &&
1420 (src_ni == NULL || lp2->lp_ni == src_ni) &&
1422 lnet_compare_routes(route, best_route) > 0)) {
1430 lnet_ni_decref_locked(src_ni);
1433 CERROR("No route to %s via %s (all routers down)\n",
1434 libcfs_id2str(msg->msg_target),
1435 libcfs_nid2str(src_nid));
1436 return -EHOSTUNREACH;
1439 /* Place selected route at the end of the route list to ensure
1440 * fairness; everything else being equal... */
1441 cfs_list_del(&best_route->lr_list);
1442 cfs_list_add_tail(&best_route->lr_list, &rnet->lrn_routes);
1444 if (src_ni == NULL) {
1446 src_nid = src_ni->ni_nid;
1448 LASSERT (src_ni == lp->lp_ni);
1449 lnet_ni_decref_locked(src_ni);
1452 lnet_peer_addref_locked(lp);
1454 LASSERT (src_nid != LNET_NID_ANY);
1456 if (!msg->msg_routing) {
1457 /* I'm the source and now I know which NI to send on */
1458 msg->msg_hdr.src_nid = cpu_to_le64(src_nid);
1461 msg->msg_target_is_router = 1;
1462 msg->msg_target.nid = lp->lp_nid;
1463 msg->msg_target.pid = LUSTRE_SRV_LNET_PID;
1466 /* 'lp' is our best choice of peer */
1468 LASSERT (!msg->msg_peertxcredit);
1469 LASSERT (!msg->msg_txcredit);
1470 LASSERT (msg->msg_txpeer == NULL);
1472 msg->msg_txpeer = lp; /* msg takes my ref on lp */
1474 rc = lnet_post_send_locked(msg, 0);
1477 if (rc == EHOSTUNREACH)
1478 return -EHOSTUNREACH;
1481 lnet_ni_send(src_ni, msg);
1487 lnet_commit_md (lnet_libmd_t *md, lnet_msg_t *msg)
1489 /* ALWAYS called holding the LNET_LOCK */
1490 /* Here, we commit the MD to a network OP by marking it busy and
1491 * decrementing its threshold. Come what may, the network "owns"
1492 * the MD until a call to lnet_finalize() signals completion. */
1493 LASSERT (!msg->msg_routing);
1498 if (md->md_threshold != LNET_MD_THRESH_INF) {
1499 LASSERT (md->md_threshold > 0);
1503 the_lnet.ln_counters.msgs_alloc++;
1504 if (the_lnet.ln_counters.msgs_alloc >
1505 the_lnet.ln_counters.msgs_max)
1506 the_lnet.ln_counters.msgs_max =
1507 the_lnet.ln_counters.msgs_alloc;
1509 LASSERT (!msg->msg_onactivelist);
1510 msg->msg_onactivelist = 1;
1511 cfs_list_add (&msg->msg_activelist, &the_lnet.ln_active_msgs);
1515 lnet_drop_message (lnet_ni_t *ni, void *private, unsigned int nob)
1518 the_lnet.ln_counters.drop_count++;
1519 the_lnet.ln_counters.drop_length += nob;
1522 lnet_ni_recv(ni, private, NULL, 0, 0, 0, nob);
1526 lnet_drop_delayed_put(lnet_msg_t *msg, char *reason)
1528 lnet_process_id_t id = {0};
1530 id.nid = msg->msg_hdr.src_nid;
1531 id.pid = msg->msg_hdr.src_pid;
1533 LASSERT (msg->msg_md == NULL);
1534 LASSERT (msg->msg_delayed);
1535 LASSERT (msg->msg_rxpeer != NULL);
1536 LASSERT (msg->msg_hdr.type == LNET_MSG_PUT);
1538 CWARN("Dropping delayed PUT from %s portal %d match "LPU64
1539 " offset %d length %d: %s\n",
1541 msg->msg_hdr.msg.put.ptl_index,
1542 msg->msg_hdr.msg.put.match_bits,
1543 msg->msg_hdr.msg.put.offset,
1544 msg->msg_hdr.payload_length,
1547 /* NB I can't drop msg's ref on msg_rxpeer until after I've
1548 * called lnet_drop_message(), so I just hang onto msg as well
1549 * until that's done */
1551 lnet_drop_message(msg->msg_rxpeer->lp_ni,
1552 msg->msg_private, msg->msg_len);
1556 lnet_peer_decref_locked(msg->msg_rxpeer);
1557 msg->msg_rxpeer = NULL;
1565 LNetSetLazyPortal(int portal)
1567 lnet_portal_t *ptl = &the_lnet.ln_portals[portal];
1569 if (portal < 0 || portal >= the_lnet.ln_nportals)
1572 CDEBUG(D_NET, "Setting portal %d lazy\n", portal);
1576 ptl->ptl_options |= LNET_PTL_LAZY;
1584 LNetClearLazyPortal(int portal)
1587 lnet_portal_t *ptl = &the_lnet.ln_portals[portal];
1590 if (portal < 0 || portal >= the_lnet.ln_nportals)
1595 if ((ptl->ptl_options & LNET_PTL_LAZY) == 0) {
1600 if (the_lnet.ln_shutdown)
1601 CWARN ("Active lazy portal %d on exit\n", portal);
1603 CDEBUG (D_NET, "clearing portal %d lazy\n", portal);
1605 /* grab all the blocked messages atomically */
1606 cfs_list_add(&zombies, &ptl->ptl_msgq);
1607 cfs_list_del_init(&ptl->ptl_msgq);
1609 ptl->ptl_msgq_version++;
1610 ptl->ptl_options &= ~LNET_PTL_LAZY;
1614 while (!cfs_list_empty(&zombies)) {
1615 msg = cfs_list_entry(zombies.next, lnet_msg_t, msg_list);
1616 cfs_list_del(&msg->msg_list);
1618 lnet_drop_delayed_put(msg, "Clearing lazy portal attr");
1625 lnet_recv_put(lnet_libmd_t *md, lnet_msg_t *msg, int delayed,
1626 unsigned int offset, unsigned int mlength)
1628 lnet_hdr_t *hdr = &msg->msg_hdr;
1632 the_lnet.ln_counters.recv_count++;
1633 the_lnet.ln_counters.recv_length += mlength;
1638 lnet_setpayloadbuffer(msg);
1640 msg->msg_ev.type = LNET_EVENT_PUT;
1641 msg->msg_ev.target.pid = hdr->dest_pid;
1642 msg->msg_ev.target.nid = hdr->dest_nid;
1643 msg->msg_ev.hdr_data = hdr->msg.put.hdr_data;
1645 /* Must I ACK? If so I'll grab the ack_wmd out of the header and put
1646 * it back into the ACK during lnet_finalize() */
1647 msg->msg_ack = (!lnet_is_wire_handle_none(&hdr->msg.put.ack_wmd) &&
1648 (md->md_options & LNET_MD_ACK_DISABLE) == 0);
1650 lnet_ni_recv(msg->msg_rxpeer->lp_ni,
1652 msg, delayed, offset, mlength,
1653 hdr->payload_length);
1656 /* called with LNET_LOCK held */
1658 lnet_match_blocked_msg(lnet_libmd_t *md)
1660 CFS_LIST_HEAD (drops);
1661 CFS_LIST_HEAD (matches);
1665 lnet_me_t *me = md->md_me;
1666 lnet_portal_t *ptl = &the_lnet.ln_portals[me->me_portal];
1668 LASSERT (me->me_portal < (unsigned int)the_lnet.ln_nportals);
1670 if ((ptl->ptl_options & LNET_PTL_LAZY) == 0) {
1671 LASSERT (cfs_list_empty(&ptl->ptl_msgq));
1675 LASSERT (md->md_refcount == 0); /* a brand new MD */
1677 cfs_list_for_each_safe (entry, tmp, &ptl->ptl_msgq) {
1680 unsigned int mlength;
1681 unsigned int offset;
1683 lnet_process_id_t src;
1685 msg = cfs_list_entry(entry, lnet_msg_t, msg_list);
1687 LASSERT (msg->msg_delayed);
1689 hdr = &msg->msg_hdr;
1690 index = hdr->msg.put.ptl_index;
1692 src.nid = hdr->src_nid;
1693 src.pid = hdr->src_pid;
1695 rc = lnet_try_match_md(index, LNET_MD_OP_PUT, src,
1696 hdr->payload_length,
1697 hdr->msg.put.offset,
1698 hdr->msg.put.match_bits,
1699 md, msg, &mlength, &offset);
1701 if (rc == LNET_MATCHMD_NONE)
1704 /* Hurrah! This _is_ a match */
1705 cfs_list_del(&msg->msg_list);
1706 ptl->ptl_msgq_version++;
1708 if (rc == LNET_MATCHMD_OK) {
1709 cfs_list_add_tail(&msg->msg_list, &matches);
1711 CDEBUG(D_NET, "Resuming delayed PUT from %s portal %d "
1712 "match "LPU64" offset %d length %d.\n",
1714 hdr->msg.put.ptl_index,
1715 hdr->msg.put.match_bits,
1716 hdr->msg.put.offset,
1717 hdr->payload_length);
1719 LASSERT (rc == LNET_MATCHMD_DROP);
1721 cfs_list_add_tail(&msg->msg_list, &drops);
1724 if (lnet_md_exhausted(md))
1730 cfs_list_for_each_safe (entry, tmp, &drops) {
1731 msg = cfs_list_entry(entry, lnet_msg_t, msg_list);
1733 cfs_list_del(&msg->msg_list);
1735 lnet_drop_delayed_put(msg, "Bad match");
1738 cfs_list_for_each_safe (entry, tmp, &matches) {
1739 msg = cfs_list_entry(entry, lnet_msg_t, msg_list);
1741 cfs_list_del(&msg->msg_list);
1743 /* md won't disappear under me, since each msg
1744 * holds a ref on it */
1745 lnet_recv_put(md, msg, 1,
1747 msg->msg_ev.mlength);
1754 lnet_parse_put(lnet_ni_t *ni, lnet_msg_t *msg)
1759 lnet_hdr_t *hdr = &msg->msg_hdr;
1760 unsigned int rlength = hdr->payload_length;
1761 unsigned int mlength = 0;
1762 unsigned int offset = 0;
1763 lnet_process_id_t src= {0};
1767 src.nid = hdr->src_nid;
1768 src.pid = hdr->src_pid;
1770 /* Convert put fields to host byte order */
1771 hdr->msg.put.match_bits = le64_to_cpu(hdr->msg.put.match_bits);
1772 hdr->msg.put.ptl_index = le32_to_cpu(hdr->msg.put.ptl_index);
1773 hdr->msg.put.offset = le32_to_cpu(hdr->msg.put.offset);
1775 index = hdr->msg.put.ptl_index;
1776 ptl = &the_lnet.ln_portals[index];
1781 rc = lnet_match_md(index, LNET_MD_OP_PUT, src,
1782 rlength, hdr->msg.put.offset,
1783 hdr->msg.put.match_bits, msg,
1784 &mlength, &offset, &md);
1789 case LNET_MATCHMD_OK:
1791 lnet_recv_put(md, msg, msg->msg_delayed, offset, mlength);
1794 case LNET_MATCHMD_NONE:
1795 version = ptl->ptl_ml_version;
1798 if (!msg->msg_delayed)
1799 rc = lnet_eager_recv_locked(msg);
1802 !the_lnet.ln_shutdown &&
1803 ((ptl->ptl_options & LNET_PTL_LAZY) != 0)) {
1804 if (version != ptl->ptl_ml_version)
1807 cfs_list_add_tail(&msg->msg_list, &ptl->ptl_msgq);
1808 ptl->ptl_msgq_version++;
1811 CDEBUG(D_NET, "Delaying PUT from %s portal %d match "
1812 LPU64" offset %d length %d: no match \n",
1813 libcfs_id2str(src), index,
1814 hdr->msg.put.match_bits,
1815 hdr->msg.put.offset, rlength);
1820 case LNET_MATCHMD_DROP:
1822 "Dropping PUT from %s portal %d match "LPU64
1823 " offset %d length %d: %d\n",
1824 libcfs_id2str(src), index,
1825 hdr->msg.put.match_bits,
1826 hdr->msg.put.offset, rlength, rc);
1829 return ENOENT; /* +ve: OK but no match */
1834 lnet_parse_get(lnet_ni_t *ni, lnet_msg_t *msg, int rdma_get)
1836 lnet_hdr_t *hdr = &msg->msg_hdr;
1837 unsigned int mlength = 0;
1838 unsigned int offset = 0;
1839 lnet_process_id_t src = {0};
1840 lnet_handle_wire_t reply_wmd;
1844 src.nid = hdr->src_nid;
1845 src.pid = hdr->src_pid;
1847 /* Convert get fields to host byte order */
1848 hdr->msg.get.match_bits = le64_to_cpu(hdr->msg.get.match_bits);
1849 hdr->msg.get.ptl_index = le32_to_cpu(hdr->msg.get.ptl_index);
1850 hdr->msg.get.sink_length = le32_to_cpu(hdr->msg.get.sink_length);
1851 hdr->msg.get.src_offset = le32_to_cpu(hdr->msg.get.src_offset);
1855 rc = lnet_match_md(hdr->msg.get.ptl_index, LNET_MD_OP_GET, src,
1856 hdr->msg.get.sink_length, hdr->msg.get.src_offset,
1857 hdr->msg.get.match_bits, msg,
1858 &mlength, &offset, &md);
1859 if (rc == LNET_MATCHMD_DROP) {
1861 "Dropping GET from %s portal %d match "LPU64
1862 " offset %d length %d\n",
1864 hdr->msg.get.ptl_index,
1865 hdr->msg.get.match_bits,
1866 hdr->msg.get.src_offset,
1867 hdr->msg.get.sink_length);
1869 return ENOENT; /* +ve: OK but no match */
1872 LASSERT (rc == LNET_MATCHMD_OK);
1874 the_lnet.ln_counters.send_count++;
1875 the_lnet.ln_counters.send_length += mlength;
1879 msg->msg_ev.type = LNET_EVENT_GET;
1880 msg->msg_ev.target.pid = hdr->dest_pid;
1881 msg->msg_ev.target.nid = hdr->dest_nid;
1882 msg->msg_ev.hdr_data = 0;
1884 reply_wmd = hdr->msg.get.return_wmd;
1886 lnet_prep_send(msg, LNET_MSG_REPLY, src, offset, mlength);
1888 msg->msg_hdr.msg.reply.dst_wmd = reply_wmd;
1891 /* The LND completes the REPLY from her recv procedure */
1892 lnet_ni_recv(ni, msg->msg_private, msg, 0,
1893 msg->msg_offset, msg->msg_len, msg->msg_len);
1897 lnet_ni_recv(ni, msg->msg_private, NULL, 0, 0, 0, 0);
1898 msg->msg_receiving = 0;
1900 rc = lnet_send(ni->ni_nid, msg);
1902 /* didn't get as far as lnet_ni_send() */
1903 CERROR("%s: Unable to send REPLY for GET from %s: %d\n",
1904 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src), rc);
1906 lnet_finalize(ni, msg, rc);
1913 lnet_parse_reply(lnet_ni_t *ni, lnet_msg_t *msg)
1915 void *private = msg->msg_private;
1916 lnet_hdr_t *hdr = &msg->msg_hdr;
1917 lnet_process_id_t src = {0};
1924 src.nid = hdr->src_nid;
1925 src.pid = hdr->src_pid;
1927 /* NB handles only looked up by creator (no flips) */
1928 md = lnet_wire_handle2md(&hdr->msg.reply.dst_wmd);
1929 if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) {
1930 CDEBUG(D_NETERROR, "%s: Dropping REPLY from %s for %s "
1931 "MD "LPX64"."LPX64"\n",
1932 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
1933 (md == NULL) ? "invalid" : "inactive",
1934 hdr->msg.reply.dst_wmd.wh_interface_cookie,
1935 hdr->msg.reply.dst_wmd.wh_object_cookie);
1936 if (md != NULL && md->md_me != NULL)
1937 CERROR("REPLY MD also attached to portal %d\n",
1938 md->md_me->me_portal);
1941 return ENOENT; /* +ve: OK but no match */
1944 LASSERT (md->md_offset == 0);
1946 rlength = hdr->payload_length;
1947 mlength = MIN(rlength, (int)md->md_length);
1949 if (mlength < rlength &&
1950 (md->md_options & LNET_MD_TRUNCATE) == 0) {
1951 CDEBUG(D_NETERROR, "%s: Dropping REPLY from %s length %d "
1952 "for MD "LPX64" would overflow (%d)\n",
1953 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
1954 rlength, hdr->msg.reply.dst_wmd.wh_object_cookie,
1957 return ENOENT; /* +ve: OK but no match */
1960 CDEBUG(D_NET, "%s: Reply from %s of length %d/%d into md "LPX64"\n",
1961 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
1962 mlength, rlength, hdr->msg.reply.dst_wmd.wh_object_cookie);
1964 lnet_commit_md(md, msg);
1967 lnet_setpayloadbuffer(msg);
1969 msg->msg_ev.type = LNET_EVENT_REPLY;
1970 msg->msg_ev.target.pid = hdr->dest_pid;
1971 msg->msg_ev.target.nid = hdr->dest_nid;
1972 msg->msg_ev.initiator = src;
1973 msg->msg_ev.rlength = rlength;
1974 msg->msg_ev.mlength = mlength;
1975 msg->msg_ev.offset = 0;
1977 lnet_md_deconstruct(md, &msg->msg_ev.md);
1978 lnet_md2handle(&msg->msg_ev.md_handle, md);
1980 the_lnet.ln_counters.recv_count++;
1981 the_lnet.ln_counters.recv_length += mlength;
1985 lnet_ni_recv(ni, private, msg, 0, 0, mlength, rlength);
1990 lnet_parse_ack(lnet_ni_t *ni, lnet_msg_t *msg)
1992 lnet_hdr_t *hdr = &msg->msg_hdr;
1993 lnet_process_id_t src = {0};
1996 src.nid = hdr->src_nid;
1997 src.pid = hdr->src_pid;
1999 /* Convert ack fields to host byte order */
2000 hdr->msg.ack.match_bits = le64_to_cpu(hdr->msg.ack.match_bits);
2001 hdr->msg.ack.mlength = le32_to_cpu(hdr->msg.ack.mlength);
2005 /* NB handles only looked up by creator (no flips) */
2006 md = lnet_wire_handle2md(&hdr->msg.ack.dst_wmd);
2007 if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) {
2008 /* Don't moan; this is expected */
2010 "%s: Dropping ACK from %s to %s MD "LPX64"."LPX64"\n",
2011 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
2012 (md == NULL) ? "invalid" : "inactive",
2013 hdr->msg.ack.dst_wmd.wh_interface_cookie,
2014 hdr->msg.ack.dst_wmd.wh_object_cookie);
2015 if (md != NULL && md->md_me != NULL)
2016 CERROR("Source MD also attached to portal %d\n",
2017 md->md_me->me_portal);
2020 return ENOENT; /* +ve! */
2023 CDEBUG(D_NET, "%s: ACK from %s into md "LPX64"\n",
2024 libcfs_nid2str(ni->ni_nid), libcfs_id2str(src),
2025 hdr->msg.ack.dst_wmd.wh_object_cookie);
2027 lnet_commit_md(md, msg);
2029 msg->msg_ev.type = LNET_EVENT_ACK;
2030 msg->msg_ev.target.pid = hdr->dest_pid;
2031 msg->msg_ev.target.nid = hdr->dest_nid;
2032 msg->msg_ev.initiator = src;
2033 msg->msg_ev.mlength = hdr->msg.ack.mlength;
2034 msg->msg_ev.match_bits = hdr->msg.ack.match_bits;
2036 lnet_md_deconstruct(md, &msg->msg_ev.md);
2037 lnet_md2handle(&msg->msg_ev.md_handle, md);
2039 the_lnet.ln_counters.recv_count++;
2043 lnet_ni_recv(ni, msg->msg_private, msg, 0, 0, 0, msg->msg_len);
2048 lnet_msgtyp2str (int type)
2057 case LNET_MSG_REPLY:
2059 case LNET_MSG_HELLO:
2062 return ("<UNKNOWN>");
2067 lnet_print_hdr(lnet_hdr_t * hdr)
2069 lnet_process_id_t src = {0};
2070 lnet_process_id_t dst = {0};
2071 char *type_str = lnet_msgtyp2str (hdr->type);
2073 src.nid = hdr->src_nid;
2074 src.pid = hdr->src_pid;
2076 dst.nid = hdr->dest_nid;
2077 dst.pid = hdr->dest_pid;
2079 CWARN("P3 Header at %p of type %s\n", hdr, type_str);
2080 CWARN(" From %s\n", libcfs_id2str(src));
2081 CWARN(" To %s\n", libcfs_id2str(dst));
2083 switch (hdr->type) {
2088 CWARN(" Ptl index %d, ack md "LPX64"."LPX64", "
2089 "match bits "LPU64"\n",
2090 hdr->msg.put.ptl_index,
2091 hdr->msg.put.ack_wmd.wh_interface_cookie,
2092 hdr->msg.put.ack_wmd.wh_object_cookie,
2093 hdr->msg.put.match_bits);
2094 CWARN(" Length %d, offset %d, hdr data "LPX64"\n",
2095 hdr->payload_length, hdr->msg.put.offset,
2096 hdr->msg.put.hdr_data);
2100 CWARN(" Ptl index %d, return md "LPX64"."LPX64", "
2101 "match bits "LPU64"\n", hdr->msg.get.ptl_index,
2102 hdr->msg.get.return_wmd.wh_interface_cookie,
2103 hdr->msg.get.return_wmd.wh_object_cookie,
2104 hdr->msg.get.match_bits);
2105 CWARN(" Length %d, src offset %d\n",
2106 hdr->msg.get.sink_length,
2107 hdr->msg.get.src_offset);
2111 CWARN(" dst md "LPX64"."LPX64", "
2112 "manipulated length %d\n",
2113 hdr->msg.ack.dst_wmd.wh_interface_cookie,
2114 hdr->msg.ack.dst_wmd.wh_object_cookie,
2115 hdr->msg.ack.mlength);
2118 case LNET_MSG_REPLY:
2119 CWARN(" dst md "LPX64"."LPX64", "
2121 hdr->msg.reply.dst_wmd.wh_interface_cookie,
2122 hdr->msg.reply.dst_wmd.wh_object_cookie,
2123 hdr->payload_length);
2129 lnet_parse(lnet_ni_t *ni, lnet_hdr_t *hdr, lnet_nid_t from_nid,
2130 void *private, int rdma_req)
2135 lnet_pid_t dest_pid;
2136 lnet_nid_t dest_nid;
2138 __u32 payload_length;
2141 LASSERT (!cfs_in_interrupt ());
2143 type = le32_to_cpu(hdr->type);
2144 src_nid = le64_to_cpu(hdr->src_nid);
2145 dest_nid = le64_to_cpu(hdr->dest_nid);
2146 dest_pid = le32_to_cpu(hdr->dest_pid);
2147 payload_length = le32_to_cpu(hdr->payload_length);
2149 for_me = (ni->ni_nid == dest_nid);
2154 if (payload_length > 0) {
2155 CERROR("%s, src %s: bad %s payload %d (0 expected)\n",
2156 libcfs_nid2str(from_nid),
2157 libcfs_nid2str(src_nid),
2158 lnet_msgtyp2str(type), payload_length);
2164 case LNET_MSG_REPLY:
2165 if (payload_length > (__u32)(for_me ? LNET_MAX_PAYLOAD : LNET_MTU)) {
2166 CERROR("%s, src %s: bad %s payload %d "
2167 "(%d max expected)\n",
2168 libcfs_nid2str(from_nid),
2169 libcfs_nid2str(src_nid),
2170 lnet_msgtyp2str(type),
2172 for_me ? LNET_MAX_PAYLOAD : LNET_MTU);
2178 CERROR("%s, src %s: Bad message type 0x%x\n",
2179 libcfs_nid2str(from_nid),
2180 libcfs_nid2str(src_nid), type);
2184 if (the_lnet.ln_routing) {
2185 cfs_time_t now = cfs_time_current();
2189 ni->ni_last_alive = now;
2190 if (ni->ni_status != NULL &&
2191 ni->ni_status->ns_status == LNET_NI_STATUS_DOWN)
2192 ni->ni_status->ns_status = LNET_NI_STATUS_UP;
2197 /* Regard a bad destination NID as a protocol error. Senders should
2198 * know what they're doing; if they don't they're misconfigured, buggy
2199 * or malicious so we chop them off at the knees :) */
2202 if (LNET_NIDNET(dest_nid) == LNET_NIDNET(ni->ni_nid)) {
2203 /* should have gone direct */
2204 CERROR ("%s, src %s: Bad dest nid %s "
2205 "(should have been sent direct)\n",
2206 libcfs_nid2str(from_nid),
2207 libcfs_nid2str(src_nid),
2208 libcfs_nid2str(dest_nid));
2212 if (lnet_islocalnid(dest_nid)) {
2213 /* dest is another local NI; sender should have used
2214 * this node's NID on its own network */
2215 CERROR ("%s, src %s: Bad dest nid %s "
2216 "(it's my nid but on a different network)\n",
2217 libcfs_nid2str(from_nid),
2218 libcfs_nid2str(src_nid),
2219 libcfs_nid2str(dest_nid));
2223 if (rdma_req && type == LNET_MSG_GET) {
2224 CERROR ("%s, src %s: Bad optimized GET for %s "
2225 "(final destination must be me)\n",
2226 libcfs_nid2str(from_nid),
2227 libcfs_nid2str(src_nid),
2228 libcfs_nid2str(dest_nid));
2232 if (!the_lnet.ln_routing) {
2233 CERROR ("%s, src %s: Dropping message for %s "
2234 "(routing not enabled)\n",
2235 libcfs_nid2str(from_nid),
2236 libcfs_nid2str(src_nid),
2237 libcfs_nid2str(dest_nid));
2242 /* Message looks OK; we're not going to return an error, so we MUST
2243 * call back lnd_recv() come what may... */
2245 if (!cfs_list_empty (&the_lnet.ln_test_peers) && /* normally we don't */
2246 fail_peer (src_nid, 0)) /* shall we now? */
2248 CERROR("%s, src %s: Dropping %s to simulate failure\n",
2249 libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
2250 lnet_msgtyp2str(type));
2254 msg = lnet_msg_alloc();
2256 CERROR("%s, src %s: Dropping %s (out of memory)\n",
2257 libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
2258 lnet_msgtyp2str(type));
2262 /* msg zeroed in lnet_msg_alloc; i.e. flags all clear, pointers NULL etc */
2264 msg->msg_type = type;
2265 msg->msg_private = private;
2266 msg->msg_receiving = 1;
2267 msg->msg_len = msg->msg_wanted = payload_length;
2268 msg->msg_offset = 0;
2269 msg->msg_hdr = *hdr;
2272 rc = lnet_nid2peer_locked(&msg->msg_rxpeer, from_nid);
2275 CERROR("%s, src %s: Dropping %s "
2276 "(error %d looking up sender)\n",
2277 libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
2278 lnet_msgtyp2str(type), rc);
2287 msg->msg_target.pid = dest_pid;
2288 msg->msg_target.nid = dest_nid;
2289 msg->msg_routing = 1;
2290 msg->msg_offset = 0;
2293 if (msg->msg_rxpeer->lp_rtrcredits <= 0 ||
2294 lnet_msg2bufpool(msg)->rbp_credits <= 0) {
2295 rc = lnet_eager_recv_locked(msg);
2301 lnet_commit_routedmsg(msg);
2302 rc = lnet_post_routed_recv_locked(msg, 0);
2306 lnet_ni_recv(ni, msg->msg_private, msg, 0,
2307 0, payload_length, payload_length);
2311 /* convert common msg->hdr fields to host byteorder */
2312 msg->msg_hdr.type = type;
2313 msg->msg_hdr.src_nid = src_nid;
2314 msg->msg_hdr.src_pid = le32_to_cpu(msg->msg_hdr.src_pid);
2315 msg->msg_hdr.dest_nid = dest_nid;
2316 msg->msg_hdr.dest_pid = dest_pid;
2317 msg->msg_hdr.payload_length = payload_length;
2319 msg->msg_ev.sender = from_nid;
2323 rc = lnet_parse_ack(ni, msg);
2326 rc = lnet_parse_put(ni, msg);
2329 rc = lnet_parse_get(ni, msg, rdma_req);
2331 case LNET_MSG_REPLY:
2332 rc = lnet_parse_reply(ni, msg);
2336 goto free_drop; /* prevent an unused label if !kernel */
2342 LASSERT (rc == ENOENT);
2345 LASSERT (msg->msg_md == NULL);
2347 if (msg->msg_rxpeer != NULL) {
2348 lnet_peer_decref_locked(msg->msg_rxpeer);
2349 msg->msg_rxpeer = NULL;
2351 lnet_msg_free(msg); /* expects LNET_LOCK held */
2355 lnet_drop_message(ni, private, payload_length);
2360 LNetPut(lnet_nid_t self, lnet_handle_md_t mdh, lnet_ack_req_t ack,
2361 lnet_process_id_t target, unsigned int portal,
2362 __u64 match_bits, unsigned int offset,
2369 LASSERT (the_lnet.ln_init);
2370 LASSERT (the_lnet.ln_refcount > 0);
2372 if (!cfs_list_empty (&the_lnet.ln_test_peers) && /* normally we don't */
2373 fail_peer (target.nid, 1)) /* shall we now? */
2375 CERROR("Dropping PUT to %s: simulated failure\n",
2376 libcfs_id2str(target));
2380 msg = lnet_msg_alloc();
2382 CERROR("Dropping PUT to %s: ENOMEM on lnet_msg_t\n",
2383 libcfs_id2str(target));
2386 msg->msg_vmflush = !!cfs_memory_pressure_get();
2390 md = lnet_handle2md(&mdh);
2391 if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) {
2394 CERROR("Dropping PUT ("LPU64":%d:%s): MD (%d) invalid\n",
2395 match_bits, portal, libcfs_id2str(target),
2396 md == NULL ? -1 : md->md_threshold);
2397 if (md != NULL && md->md_me != NULL)
2398 CERROR("Source MD also attached to portal %d\n",
2399 md->md_me->me_portal);
2405 CDEBUG(D_NET, "LNetPut -> %s\n", libcfs_id2str(target));
2407 lnet_commit_md(md, msg);
2409 lnet_prep_send(msg, LNET_MSG_PUT, target, 0, md->md_length);
2411 msg->msg_hdr.msg.put.match_bits = cpu_to_le64(match_bits);
2412 msg->msg_hdr.msg.put.ptl_index = cpu_to_le32(portal);
2413 msg->msg_hdr.msg.put.offset = cpu_to_le32(offset);
2414 msg->msg_hdr.msg.put.hdr_data = hdr_data;
2416 /* NB handles only looked up by creator (no flips) */
2417 if (ack == LNET_ACK_REQ) {
2418 msg->msg_hdr.msg.put.ack_wmd.wh_interface_cookie =
2419 the_lnet.ln_interface_cookie;
2420 msg->msg_hdr.msg.put.ack_wmd.wh_object_cookie =
2421 md->md_lh.lh_cookie;
2423 msg->msg_hdr.msg.put.ack_wmd.wh_interface_cookie =
2424 LNET_WIRE_HANDLE_COOKIE_NONE;
2425 msg->msg_hdr.msg.put.ack_wmd.wh_object_cookie =
2426 LNET_WIRE_HANDLE_COOKIE_NONE;
2429 msg->msg_ev.type = LNET_EVENT_SEND;
2430 msg->msg_ev.initiator.nid = LNET_NID_ANY;
2431 msg->msg_ev.initiator.pid = the_lnet.ln_pid;
2432 msg->msg_ev.target = target;
2433 msg->msg_ev.sender = LNET_NID_ANY;
2434 msg->msg_ev.pt_index = portal;
2435 msg->msg_ev.match_bits = match_bits;
2436 msg->msg_ev.rlength = md->md_length;
2437 msg->msg_ev.mlength = md->md_length;
2438 msg->msg_ev.offset = offset;
2439 msg->msg_ev.hdr_data = hdr_data;
2441 lnet_md_deconstruct(md, &msg->msg_ev.md);
2442 lnet_md2handle(&msg->msg_ev.md_handle, md);
2444 the_lnet.ln_counters.send_count++;
2445 the_lnet.ln_counters.send_length += md->md_length;
2449 rc = lnet_send(self, msg);
2451 CERROR("Error sending PUT to %s: %d\n",
2452 libcfs_id2str(target), rc);
2453 lnet_finalize (NULL, msg, rc);
2456 /* completion will be signalled by an event */
2461 lnet_create_reply_msg (lnet_ni_t *ni, lnet_msg_t *getmsg)
2463 /* The LND can DMA direct to the GET md (i.e. no REPLY msg). This
2464 * returns a msg for the LND to pass to lnet_finalize() when the sink
2465 * data has been received.
2467 * CAVEAT EMPTOR: 'getmsg' is the original GET, which is freed when
2468 * lnet_finalize() is called on it, so the LND must call this first */
2470 lnet_msg_t *msg = lnet_msg_alloc();
2471 lnet_libmd_t *getmd = getmsg->msg_md;
2472 lnet_process_id_t peer_id = getmsg->msg_target;
2474 LASSERT (!getmsg->msg_target_is_router);
2475 LASSERT (!getmsg->msg_routing);
2479 LASSERT (getmd->md_refcount > 0);
2482 CERROR ("%s: Dropping REPLY from %s: can't allocate msg\n",
2483 libcfs_nid2str(ni->ni_nid), libcfs_id2str(peer_id));
2487 if (getmd->md_threshold == 0) {
2488 CERROR ("%s: Dropping REPLY from %s for inactive MD %p\n",
2489 libcfs_nid2str(ni->ni_nid), libcfs_id2str(peer_id),
2494 LASSERT (getmd->md_offset == 0);
2496 CDEBUG(D_NET, "%s: Reply from %s md %p\n",
2497 libcfs_nid2str(ni->ni_nid), libcfs_id2str(peer_id), getmd);
2499 lnet_commit_md (getmd, msg);
2501 msg->msg_type = LNET_MSG_GET; /* flag this msg as an "optimized" GET */
2503 msg->msg_ev.type = LNET_EVENT_REPLY;
2504 msg->msg_ev.initiator = peer_id;
2505 msg->msg_ev.sender = peer_id.nid; /* optimized GETs can't be routed */
2506 msg->msg_ev.rlength = msg->msg_ev.mlength = getmd->md_length;
2507 msg->msg_ev.offset = 0;
2509 lnet_md_deconstruct(getmd, &msg->msg_ev.md);
2510 lnet_md2handle(&msg->msg_ev.md_handle, getmd);
2512 the_lnet.ln_counters.recv_count++;
2513 the_lnet.ln_counters.recv_length += getmd->md_length;
2522 the_lnet.ln_counters.drop_count++;
2523 the_lnet.ln_counters.drop_length += getmd->md_length;
2531 lnet_set_reply_msg_len(lnet_ni_t *ni, lnet_msg_t *reply, unsigned int len)
2533 /* Set the REPLY length, now the RDMA that elides the REPLY message has
2534 * completed and I know it. */
2535 LASSERT (reply != NULL);
2536 LASSERT (reply->msg_type == LNET_MSG_GET);
2537 LASSERT (reply->msg_ev.type == LNET_EVENT_REPLY);
2539 /* NB I trusted my peer to RDMA. If she tells me she's written beyond
2540 * the end of my buffer, I might as well be dead. */
2541 LASSERT (len <= reply->msg_ev.mlength);
2543 reply->msg_ev.mlength = len;
2547 LNetGet(lnet_nid_t self, lnet_handle_md_t mdh,
2548 lnet_process_id_t target, unsigned int portal,
2549 __u64 match_bits, unsigned int offset)
2555 LASSERT (the_lnet.ln_init);
2556 LASSERT (the_lnet.ln_refcount > 0);
2558 if (!cfs_list_empty (&the_lnet.ln_test_peers) && /* normally we don't */
2559 fail_peer (target.nid, 1)) /* shall we now? */
2561 CERROR("Dropping GET to %s: simulated failure\n",
2562 libcfs_id2str(target));
2566 msg = lnet_msg_alloc();
2568 CERROR("Dropping GET to %s: ENOMEM on lnet_msg_t\n",
2569 libcfs_id2str(target));
2575 md = lnet_handle2md(&mdh);
2576 if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) {
2579 CERROR("Dropping GET ("LPU64":%d:%s): MD (%d) invalid\n",
2580 match_bits, portal, libcfs_id2str(target),
2581 md == NULL ? -1 : md->md_threshold);
2582 if (md != NULL && md->md_me != NULL)
2583 CERROR("REPLY MD also attached to portal %d\n",
2584 md->md_me->me_portal);
2590 CDEBUG(D_NET, "LNetGet -> %s\n", libcfs_id2str(target));
2592 lnet_commit_md(md, msg);
2594 lnet_prep_send(msg, LNET_MSG_GET, target, 0, 0);
2596 msg->msg_hdr.msg.get.match_bits = cpu_to_le64(match_bits);
2597 msg->msg_hdr.msg.get.ptl_index = cpu_to_le32(portal);
2598 msg->msg_hdr.msg.get.src_offset = cpu_to_le32(offset);
2599 msg->msg_hdr.msg.get.sink_length = cpu_to_le32(md->md_length);
2601 /* NB handles only looked up by creator (no flips) */
2602 msg->msg_hdr.msg.get.return_wmd.wh_interface_cookie =
2603 the_lnet.ln_interface_cookie;
2604 msg->msg_hdr.msg.get.return_wmd.wh_object_cookie =
2605 md->md_lh.lh_cookie;
2607 msg->msg_ev.type = LNET_EVENT_SEND;
2608 msg->msg_ev.initiator.nid = LNET_NID_ANY;
2609 msg->msg_ev.initiator.pid = the_lnet.ln_pid;
2610 msg->msg_ev.target = target;
2611 msg->msg_ev.sender = LNET_NID_ANY;
2612 msg->msg_ev.pt_index = portal;
2613 msg->msg_ev.match_bits = match_bits;
2614 msg->msg_ev.rlength = md->md_length;
2615 msg->msg_ev.mlength = md->md_length;
2616 msg->msg_ev.offset = offset;
2617 msg->msg_ev.hdr_data = 0;
2619 lnet_md_deconstruct(md, &msg->msg_ev.md);
2620 lnet_md2handle(&msg->msg_ev.md_handle, md);
2622 the_lnet.ln_counters.send_count++;
2626 rc = lnet_send(self, msg);
2628 CERROR("error sending GET to %s: %d\n",
2629 libcfs_id2str(target), rc);
2630 lnet_finalize (NULL, msg, rc);
2633 /* completion will be signalled by an event */
2638 LNetDist (lnet_nid_t dstnid, lnet_nid_t *srcnidp, __u32 *orderp)
2642 lnet_remotenet_t *rnet;
2643 __u32 dstnet = LNET_NIDNET(dstnid);
2647 /* if !local_nid_dist_zero, I don't return a distance of 0 ever
2648 * (when lustre sees a distance of 0, it substitutes 0@lo), so I
2649 * keep order 0 free for 0@lo and order 1 free for a local NID
2652 LASSERT (the_lnet.ln_init);
2653 LASSERT (the_lnet.ln_refcount > 0);
2657 cfs_list_for_each (e, &the_lnet.ln_nis) {
2658 ni = cfs_list_entry(e, lnet_ni_t, ni_list);
2660 if (ni->ni_nid == dstnid) {
2661 if (srcnidp != NULL)
2663 if (orderp != NULL) {
2664 if (LNET_NETTYP(LNET_NIDNET(dstnid)) == LOLND)
2671 return local_nid_dist_zero ? 0 : 1;
2674 if (LNET_NIDNET(ni->ni_nid) == dstnet) {
2675 if (srcnidp != NULL)
2676 *srcnidp = ni->ni_nid;
2686 cfs_list_for_each (e, &the_lnet.ln_remote_nets) {
2687 rnet = cfs_list_entry(e, lnet_remotenet_t, lrn_list);
2689 if (rnet->lrn_net == dstnet) {
2690 lnet_route_t *route;
2691 lnet_route_t *shortest = NULL;
2693 LASSERT (!cfs_list_empty(&rnet->lrn_routes));
2695 cfs_list_for_each_entry(route, &rnet->lrn_routes,
2697 if (shortest == NULL ||
2698 route->lr_hops < shortest->lr_hops)
2702 LASSERT (shortest != NULL);
2703 hops = shortest->lr_hops;
2704 if (srcnidp != NULL)
2705 *srcnidp = shortest->lr_gateway->lp_ni->ni_nid;
2715 return -EHOSTUNREACH;
2719 LNetSetAsync(lnet_process_id_t id, int nasync)
2725 lnet_remotenet_t *rnet;
2727 lnet_route_t *route;
2734 /* Target on a local network? */
2736 ni = lnet_net2ni(LNET_NIDNET(id.nid));
2738 if (ni->ni_lnd->lnd_setasync != NULL)
2739 rc = (ni->ni_lnd->lnd_setasync)(ni, id, nasync);
2744 /* Target on a remote network: apply to routers */
2746 LIBCFS_ALLOC(nids, maxnids * sizeof(*nids));
2751 /* Snapshot all the router NIDs */
2753 rnet = lnet_find_net_locked(LNET_NIDNET(id.nid));
2755 cfs_list_for_each(tmp, &rnet->lrn_routes) {
2756 if (nnids == maxnids) {
2758 LIBCFS_FREE(nids, maxnids * sizeof(*nids));
2763 route = cfs_list_entry(tmp, lnet_route_t, lr_list);
2764 nids[nnids++] = route->lr_gateway->lp_nid;
2769 /* set async on all the routers */
2770 while (nnids-- > 0) {
2771 id.pid = LUSTRE_SRV_LNET_PID;
2772 id.nid = nids[nnids];
2774 ni = lnet_net2ni(LNET_NIDNET(id.nid));
2778 if (ni->ni_lnd->lnd_setasync != NULL) {
2779 rc2 = (ni->ni_lnd->lnd_setasync)(ni, id, nasync);
2786 LIBCFS_FREE(nids, maxnids * sizeof(*nids));