4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2015, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lnet/lnet/lib-move.c
38 * Data movement routines
41 #define DEBUG_SUBSYSTEM S_LNET
43 #include "../../include/linux/lnet/lib-lnet.h"
45 /** lnet message has credit and can be submitted to lnd for send/receive */
46 #define LNET_CREDIT_OK 0
47 /** lnet message is waiting for credit */
48 #define LNET_CREDIT_WAIT 1
50 static int local_nid_dist_zero
= 1;
51 module_param(local_nid_dist_zero
, int, 0444);
52 MODULE_PARM_DESC(local_nid_dist_zero
, "Reserved");
55 lnet_fail_nid(lnet_nid_t nid
, unsigned int threshold
)
59 struct list_head
*next
;
60 struct list_head cull
;
62 /* NB: use lnet_net_lock(0) to serialize operations on test peers */
64 /* Adding a new entry */
65 LIBCFS_ALLOC(tp
, sizeof(*tp
));
70 tp
->tp_threshold
= threshold
;
73 list_add_tail(&tp
->tp_list
, &the_lnet
.ln_test_peers
);
78 /* removing entries */
79 INIT_LIST_HEAD(&cull
);
83 list_for_each_safe(el
, next
, &the_lnet
.ln_test_peers
) {
84 tp
= list_entry(el
, lnet_test_peer_t
, tp_list
);
86 if (!tp
->tp_threshold
|| /* needs culling anyway */
87 nid
== LNET_NID_ANY
|| /* removing all entries */
88 tp
->tp_nid
== nid
) { /* matched this one */
89 list_del(&tp
->tp_list
);
90 list_add(&tp
->tp_list
, &cull
);
96 while (!list_empty(&cull
)) {
97 tp
= list_entry(cull
.next
, lnet_test_peer_t
, tp_list
);
99 list_del(&tp
->tp_list
);
100 LIBCFS_FREE(tp
, sizeof(*tp
));
106 fail_peer(lnet_nid_t nid
, int outgoing
)
108 lnet_test_peer_t
*tp
;
109 struct list_head
*el
;
110 struct list_head
*next
;
111 struct list_head cull
;
114 INIT_LIST_HEAD(&cull
);
116 /* NB: use lnet_net_lock(0) to serialize operations on test peers */
119 list_for_each_safe(el
, next
, &the_lnet
.ln_test_peers
) {
120 tp
= list_entry(el
, lnet_test_peer_t
, tp_list
);
122 if (!tp
->tp_threshold
) {
126 * only cull zombies on outgoing tests,
127 * since we may be at interrupt priority on
130 list_del(&tp
->tp_list
);
131 list_add(&tp
->tp_list
, &cull
);
136 if (tp
->tp_nid
== LNET_NID_ANY
|| /* fail every peer */
137 nid
== tp
->tp_nid
) { /* fail this peer */
140 if (tp
->tp_threshold
!= LNET_MD_THRESH_INF
) {
145 list_del(&tp
->tp_list
);
146 list_add(&tp
->tp_list
, &cull
);
155 while (!list_empty(&cull
)) {
156 tp
= list_entry(cull
.next
, lnet_test_peer_t
, tp_list
);
157 list_del(&tp
->tp_list
);
159 LIBCFS_FREE(tp
, sizeof(*tp
));
166 lnet_iov_nob(unsigned int niov
, struct kvec
*iov
)
168 unsigned int nob
= 0;
171 nob
+= (iov
++)->iov_len
;
175 EXPORT_SYMBOL(lnet_iov_nob
);
178 lnet_copy_iov2iov(unsigned int ndiov
, struct kvec
*diov
, unsigned int doffset
,
179 unsigned int nsiov
, struct kvec
*siov
, unsigned int soffset
,
182 /* NB diov, siov are READ-ONLY */
183 unsigned int this_nob
;
188 /* skip complete frags before 'doffset' */
190 while (doffset
>= diov
->iov_len
) {
191 doffset
-= diov
->iov_len
;
197 /* skip complete frags before 'soffset' */
199 while (soffset
>= siov
->iov_len
) {
200 soffset
-= siov
->iov_len
;
209 this_nob
= min(diov
->iov_len
- doffset
,
210 siov
->iov_len
- soffset
);
211 this_nob
= min(this_nob
, nob
);
213 memcpy((char *)diov
->iov_base
+ doffset
,
214 (char *)siov
->iov_base
+ soffset
, this_nob
);
217 if (diov
->iov_len
> doffset
+ this_nob
) {
225 if (siov
->iov_len
> soffset
+ this_nob
) {
234 EXPORT_SYMBOL(lnet_copy_iov2iov
);
237 lnet_extract_iov(int dst_niov
, struct kvec
*dst
,
238 int src_niov
, struct kvec
*src
,
239 unsigned int offset
, unsigned int len
)
242 * Initialise 'dst' to the subset of 'src' starting at 'offset',
243 * for exactly 'len' bytes, and return the number of entries.
244 * NB not destructive to 'src'
246 unsigned int frag_len
;
249 if (!len
) /* no data => */
250 return 0; /* no frags */
252 LASSERT(src_niov
> 0);
253 while (offset
>= src
->iov_len
) { /* skip initial frags */
254 offset
-= src
->iov_len
;
257 LASSERT(src_niov
> 0);
262 LASSERT(src_niov
> 0);
263 LASSERT((int)niov
<= dst_niov
);
265 frag_len
= src
->iov_len
- offset
;
266 dst
->iov_base
= ((char *)src
->iov_base
) + offset
;
268 if (len
<= frag_len
) {
273 dst
->iov_len
= frag_len
;
283 EXPORT_SYMBOL(lnet_extract_iov
);
286 lnet_kiov_nob(unsigned int niov
, lnet_kiov_t
*kiov
)
288 unsigned int nob
= 0;
291 nob
+= (kiov
++)->kiov_len
;
295 EXPORT_SYMBOL(lnet_kiov_nob
);
298 lnet_copy_kiov2kiov(unsigned int ndiov
, lnet_kiov_t
*diov
, unsigned int doffset
,
299 unsigned int nsiov
, lnet_kiov_t
*siov
, unsigned int soffset
,
302 /* NB diov, siov are READ-ONLY */
303 unsigned int this_nob
;
310 LASSERT(!in_interrupt());
313 while (doffset
>= diov
->kiov_len
) {
314 doffset
-= diov
->kiov_len
;
321 while (soffset
>= siov
->kiov_len
) {
322 soffset
-= siov
->kiov_len
;
331 this_nob
= min(diov
->kiov_len
- doffset
,
332 siov
->kiov_len
- soffset
);
333 this_nob
= min(this_nob
, nob
);
336 daddr
= ((char *)kmap(diov
->kiov_page
)) +
337 diov
->kiov_offset
+ doffset
;
339 saddr
= ((char *)kmap(siov
->kiov_page
)) +
340 siov
->kiov_offset
+ soffset
;
343 * Vanishing risk of kmap deadlock when mapping 2 pages.
344 * However in practice at least one of the kiovs will be mapped
345 * kernel pages and the map/unmap will be NOOPs
347 memcpy(daddr
, saddr
, this_nob
);
350 if (diov
->kiov_len
> doffset
+ this_nob
) {
354 kunmap(diov
->kiov_page
);
361 if (siov
->kiov_len
> soffset
+ this_nob
) {
365 kunmap(siov
->kiov_page
);
374 kunmap(diov
->kiov_page
);
376 kunmap(siov
->kiov_page
);
378 EXPORT_SYMBOL(lnet_copy_kiov2kiov
);
381 lnet_copy_kiov2iov(unsigned int niov
, struct kvec
*iov
, unsigned int iovoffset
,
382 unsigned int nkiov
, lnet_kiov_t
*kiov
,
383 unsigned int kiovoffset
, unsigned int nob
)
385 /* NB iov, kiov are READ-ONLY */
386 unsigned int this_nob
;
392 LASSERT(!in_interrupt());
395 while (iovoffset
>= iov
->iov_len
) {
396 iovoffset
-= iov
->iov_len
;
403 while (kiovoffset
>= kiov
->kiov_len
) {
404 kiovoffset
-= kiov
->kiov_len
;
413 this_nob
= min(iov
->iov_len
- iovoffset
,
414 (__kernel_size_t
) kiov
->kiov_len
- kiovoffset
);
415 this_nob
= min(this_nob
, nob
);
418 addr
= ((char *)kmap(kiov
->kiov_page
)) +
419 kiov
->kiov_offset
+ kiovoffset
;
421 memcpy((char *)iov
->iov_base
+ iovoffset
, addr
, this_nob
);
424 if (iov
->iov_len
> iovoffset
+ this_nob
) {
425 iovoffset
+= this_nob
;
432 if (kiov
->kiov_len
> kiovoffset
+ this_nob
) {
434 kiovoffset
+= this_nob
;
436 kunmap(kiov
->kiov_page
);
446 kunmap(kiov
->kiov_page
);
448 EXPORT_SYMBOL(lnet_copy_kiov2iov
);
451 lnet_copy_iov2kiov(unsigned int nkiov
, lnet_kiov_t
*kiov
,
452 unsigned int kiovoffset
, unsigned int niov
,
453 struct kvec
*iov
, unsigned int iovoffset
,
456 /* NB kiov, iov are READ-ONLY */
457 unsigned int this_nob
;
463 LASSERT(!in_interrupt());
466 while (kiovoffset
>= kiov
->kiov_len
) {
467 kiovoffset
-= kiov
->kiov_len
;
474 while (iovoffset
>= iov
->iov_len
) {
475 iovoffset
-= iov
->iov_len
;
484 this_nob
= min((__kernel_size_t
) kiov
->kiov_len
- kiovoffset
,
485 iov
->iov_len
- iovoffset
);
486 this_nob
= min(this_nob
, nob
);
489 addr
= ((char *)kmap(kiov
->kiov_page
)) +
490 kiov
->kiov_offset
+ kiovoffset
;
492 memcpy(addr
, (char *)iov
->iov_base
+ iovoffset
, this_nob
);
495 if (kiov
->kiov_len
> kiovoffset
+ this_nob
) {
497 kiovoffset
+= this_nob
;
499 kunmap(kiov
->kiov_page
);
506 if (iov
->iov_len
> iovoffset
+ this_nob
) {
507 iovoffset
+= this_nob
;
516 kunmap(kiov
->kiov_page
);
518 EXPORT_SYMBOL(lnet_copy_iov2kiov
);
521 lnet_extract_kiov(int dst_niov
, lnet_kiov_t
*dst
,
522 int src_niov
, lnet_kiov_t
*src
,
523 unsigned int offset
, unsigned int len
)
526 * Initialise 'dst' to the subset of 'src' starting at 'offset',
527 * for exactly 'len' bytes, and return the number of entries.
528 * NB not destructive to 'src'
530 unsigned int frag_len
;
533 if (!len
) /* no data => */
534 return 0; /* no frags */
536 LASSERT(src_niov
> 0);
537 while (offset
>= src
->kiov_len
) { /* skip initial frags */
538 offset
-= src
->kiov_len
;
541 LASSERT(src_niov
> 0);
546 LASSERT(src_niov
> 0);
547 LASSERT((int)niov
<= dst_niov
);
549 frag_len
= src
->kiov_len
- offset
;
550 dst
->kiov_page
= src
->kiov_page
;
551 dst
->kiov_offset
= src
->kiov_offset
+ offset
;
553 if (len
<= frag_len
) {
555 LASSERT(dst
->kiov_offset
+ dst
->kiov_len
560 dst
->kiov_len
= frag_len
;
561 LASSERT(dst
->kiov_offset
+ dst
->kiov_len
<= PAGE_CACHE_SIZE
);
571 EXPORT_SYMBOL(lnet_extract_kiov
);
574 lnet_ni_recv(lnet_ni_t
*ni
, void *private, lnet_msg_t
*msg
, int delayed
,
575 unsigned int offset
, unsigned int mlen
, unsigned int rlen
)
577 unsigned int niov
= 0;
578 struct kvec
*iov
= NULL
;
579 lnet_kiov_t
*kiov
= NULL
;
582 LASSERT(!in_interrupt());
583 LASSERT(!mlen
|| msg
);
586 LASSERT(msg
->msg_receiving
);
587 LASSERT(!msg
->msg_sending
);
588 LASSERT(rlen
== msg
->msg_len
);
589 LASSERT(mlen
<= msg
->msg_len
);
590 LASSERT(msg
->msg_offset
== offset
);
591 LASSERT(msg
->msg_wanted
== mlen
);
593 msg
->msg_receiving
= 0;
596 niov
= msg
->msg_niov
;
598 kiov
= msg
->msg_kiov
;
601 LASSERT(!iov
!= !kiov
);
605 rc
= ni
->ni_lnd
->lnd_recv(ni
, private, msg
, delayed
,
606 niov
, iov
, kiov
, offset
, mlen
, rlen
);
608 lnet_finalize(ni
, msg
, rc
);
612 lnet_setpayloadbuffer(lnet_msg_t
*msg
)
614 lnet_libmd_t
*md
= msg
->msg_md
;
616 LASSERT(msg
->msg_len
> 0);
617 LASSERT(!msg
->msg_routing
);
619 LASSERT(!msg
->msg_niov
);
620 LASSERT(!msg
->msg_iov
);
621 LASSERT(!msg
->msg_kiov
);
623 msg
->msg_niov
= md
->md_niov
;
624 if (md
->md_options
& LNET_MD_KIOV
)
625 msg
->msg_kiov
= md
->md_iov
.kiov
;
627 msg
->msg_iov
= md
->md_iov
.iov
;
631 lnet_prep_send(lnet_msg_t
*msg
, int type
, lnet_process_id_t target
,
632 unsigned int offset
, unsigned int len
)
634 msg
->msg_type
= type
;
635 msg
->msg_target
= target
;
637 msg
->msg_offset
= offset
;
640 lnet_setpayloadbuffer(msg
);
642 memset(&msg
->msg_hdr
, 0, sizeof(msg
->msg_hdr
));
643 msg
->msg_hdr
.type
= cpu_to_le32(type
);
644 msg
->msg_hdr
.dest_nid
= cpu_to_le64(target
.nid
);
645 msg
->msg_hdr
.dest_pid
= cpu_to_le32(target
.pid
);
646 /* src_nid will be set later */
647 msg
->msg_hdr
.src_pid
= cpu_to_le32(the_lnet
.ln_pid
);
648 msg
->msg_hdr
.payload_length
= cpu_to_le32(len
);
652 lnet_ni_send(lnet_ni_t
*ni
, lnet_msg_t
*msg
)
654 void *priv
= msg
->msg_private
;
657 LASSERT(!in_interrupt());
658 LASSERT(LNET_NETTYP(LNET_NIDNET(ni
->ni_nid
)) == LOLND
||
659 (msg
->msg_txcredit
&& msg
->msg_peertxcredit
));
661 rc
= ni
->ni_lnd
->lnd_send(ni
, priv
, msg
);
663 lnet_finalize(ni
, msg
, rc
);
667 lnet_ni_eager_recv(lnet_ni_t
*ni
, lnet_msg_t
*msg
)
671 LASSERT(!msg
->msg_sending
);
672 LASSERT(msg
->msg_receiving
);
673 LASSERT(!msg
->msg_rx_ready_delay
);
674 LASSERT(ni
->ni_lnd
->lnd_eager_recv
);
676 msg
->msg_rx_ready_delay
= 1;
677 rc
= ni
->ni_lnd
->lnd_eager_recv(ni
, msg
->msg_private
, msg
,
680 CERROR("recv from %s / send to %s aborted: eager_recv failed %d\n",
681 libcfs_nid2str(msg
->msg_rxpeer
->lp_nid
),
682 libcfs_id2str(msg
->msg_target
), rc
);
683 LASSERT(rc
< 0); /* required by my callers */
689 /* NB: caller shall hold a ref on 'lp' as I'd drop lnet_net_lock */
691 lnet_ni_query_locked(lnet_ni_t
*ni
, lnet_peer_t
*lp
)
693 unsigned long last_alive
= 0;
695 LASSERT(lnet_peer_aliveness_enabled(lp
));
696 LASSERT(ni
->ni_lnd
->lnd_query
);
698 lnet_net_unlock(lp
->lp_cpt
);
699 ni
->ni_lnd
->lnd_query(ni
, lp
->lp_nid
, &last_alive
);
700 lnet_net_lock(lp
->lp_cpt
);
702 lp
->lp_last_query
= cfs_time_current();
704 if (last_alive
) /* NI has updated timestamp */
705 lp
->lp_last_alive
= last_alive
;
708 /* NB: always called with lnet_net_lock held */
710 lnet_peer_is_alive(lnet_peer_t
*lp
, unsigned long now
)
713 unsigned long deadline
;
715 LASSERT(lnet_peer_aliveness_enabled(lp
));
717 /* Trust lnet_notify() if it has more recent aliveness news, but
718 * ignore the initial assumed death (see lnet_peers_start_down()).
720 if (!lp
->lp_alive
&& lp
->lp_alive_count
> 0 &&
721 cfs_time_aftereq(lp
->lp_timestamp
, lp
->lp_last_alive
))
724 deadline
= cfs_time_add(lp
->lp_last_alive
,
725 cfs_time_seconds(lp
->lp_ni
->ni_peertimeout
));
726 alive
= cfs_time_after(deadline
, now
);
728 /* Update obsolete lp_alive except for routers assumed to be dead
729 * initially, because router checker would update aliveness in this
730 * case, and moreover lp_last_alive at peer creation is assumed.
732 if (alive
&& !lp
->lp_alive
&&
733 !(lnet_isrouter(lp
) && !lp
->lp_alive_count
))
734 lnet_notify_locked(lp
, 0, 1, lp
->lp_last_alive
);
740 * NB: returns 1 when alive, 0 when dead, negative when error;
741 * may drop the lnet_net_lock
744 lnet_peer_alive_locked(lnet_peer_t
*lp
)
746 unsigned long now
= cfs_time_current();
748 if (!lnet_peer_aliveness_enabled(lp
))
751 if (lnet_peer_is_alive(lp
, now
))
755 * Peer appears dead, but we should avoid frequent NI queries (at
756 * most once per lnet_queryinterval seconds).
758 if (lp
->lp_last_query
) {
759 static const int lnet_queryinterval
= 1;
761 unsigned long next_query
=
762 cfs_time_add(lp
->lp_last_query
,
763 cfs_time_seconds(lnet_queryinterval
));
765 if (time_before(now
, next_query
)) {
767 CWARN("Unexpected aliveness of peer %s: %d < %d (%d/%d)\n",
768 libcfs_nid2str(lp
->lp_nid
),
769 (int)now
, (int)next_query
,
771 lp
->lp_ni
->ni_peertimeout
);
776 /* query NI for latest aliveness news */
777 lnet_ni_query_locked(lp
->lp_ni
, lp
);
779 if (lnet_peer_is_alive(lp
, now
))
782 lnet_notify_locked(lp
, 0, 0, lp
->lp_last_alive
);
787 * \param msg The message to be sent.
788 * \param do_send True if lnet_ni_send() should be called in this function.
789 * lnet_send() is going to lnet_net_unlock immediately after this, so
790 * it sets do_send FALSE and I don't do the unlock/send/lock bit.
792 * \retval LNET_CREDIT_OK If \a msg sent or OK to send.
793 * \retval LNET_CREDIT_WAIT If \a msg blocked for credit.
794 * \retval -EHOSTUNREACH If the next hop of the message appears dead.
795 * \retval -ECANCELED If the MD of the message has been unlinked.
798 lnet_post_send_locked(lnet_msg_t
*msg
, int do_send
)
800 lnet_peer_t
*lp
= msg
->msg_txpeer
;
801 lnet_ni_t
*ni
= lp
->lp_ni
;
802 int cpt
= msg
->msg_tx_cpt
;
803 struct lnet_tx_queue
*tq
= ni
->ni_tx_queues
[cpt
];
805 /* non-lnet_send() callers have checked before */
806 LASSERT(!do_send
|| msg
->msg_tx_delayed
);
807 LASSERT(!msg
->msg_receiving
);
808 LASSERT(msg
->msg_tx_committed
);
810 /* NB 'lp' is always the next hop */
811 if (!(msg
->msg_target
.pid
& LNET_PID_USERFLAG
) &&
812 !lnet_peer_alive_locked(lp
)) {
813 the_lnet
.ln_counters
[cpt
]->drop_count
++;
814 the_lnet
.ln_counters
[cpt
]->drop_length
+= msg
->msg_len
;
815 lnet_net_unlock(cpt
);
817 CNETERR("Dropping message for %s: peer not alive\n",
818 libcfs_id2str(msg
->msg_target
));
820 lnet_finalize(ni
, msg
, -EHOSTUNREACH
);
823 return -EHOSTUNREACH
;
827 (msg
->msg_md
->md_flags
& LNET_MD_FLAG_ABORTED
)) {
828 lnet_net_unlock(cpt
);
830 CNETERR("Aborting message for %s: LNetM[DE]Unlink() already called on the MD/ME.\n",
831 libcfs_id2str(msg
->msg_target
));
833 lnet_finalize(ni
, msg
, -ECANCELED
);
839 if (!msg
->msg_peertxcredit
) {
840 LASSERT((lp
->lp_txcredits
< 0) ==
841 !list_empty(&lp
->lp_txq
));
843 msg
->msg_peertxcredit
= 1;
844 lp
->lp_txqnob
+= msg
->msg_len
+ sizeof(lnet_hdr_t
);
847 if (lp
->lp_txcredits
< lp
->lp_mintxcredits
)
848 lp
->lp_mintxcredits
= lp
->lp_txcredits
;
850 if (lp
->lp_txcredits
< 0) {
851 msg
->msg_tx_delayed
= 1;
852 list_add_tail(&msg
->msg_list
, &lp
->lp_txq
);
853 return LNET_CREDIT_WAIT
;
857 if (!msg
->msg_txcredit
) {
858 LASSERT((tq
->tq_credits
< 0) ==
859 !list_empty(&tq
->tq_delayed
));
861 msg
->msg_txcredit
= 1;
864 if (tq
->tq_credits
< tq
->tq_credits_min
)
865 tq
->tq_credits_min
= tq
->tq_credits
;
867 if (tq
->tq_credits
< 0) {
868 msg
->msg_tx_delayed
= 1;
869 list_add_tail(&msg
->msg_list
, &tq
->tq_delayed
);
870 return LNET_CREDIT_WAIT
;
875 lnet_net_unlock(cpt
);
876 lnet_ni_send(ni
, msg
);
879 return LNET_CREDIT_OK
;
882 static lnet_rtrbufpool_t
*
883 lnet_msg2bufpool(lnet_msg_t
*msg
)
885 lnet_rtrbufpool_t
*rbp
;
888 LASSERT(msg
->msg_rx_committed
);
890 cpt
= msg
->msg_rx_cpt
;
891 rbp
= &the_lnet
.ln_rtrpools
[cpt
][0];
893 LASSERT(msg
->msg_len
<= LNET_MTU
);
894 while (msg
->msg_len
> (unsigned int)rbp
->rbp_npages
* PAGE_CACHE_SIZE
) {
896 LASSERT(rbp
< &the_lnet
.ln_rtrpools
[cpt
][LNET_NRBPOOLS
]);
903 lnet_post_routed_recv_locked(lnet_msg_t
*msg
, int do_recv
)
906 * lnet_parse is going to lnet_net_unlock immediately after this, so it
907 * sets do_recv FALSE and I don't do the unlock/send/lock bit.
908 * I return LNET_CREDIT_WAIT if msg blocked and LNET_CREDIT_OK if
909 * received or OK to receive
911 lnet_peer_t
*lp
= msg
->msg_rxpeer
;
912 lnet_rtrbufpool_t
*rbp
;
915 LASSERT(!msg
->msg_iov
);
916 LASSERT(!msg
->msg_kiov
);
917 LASSERT(!msg
->msg_niov
);
918 LASSERT(msg
->msg_routing
);
919 LASSERT(msg
->msg_receiving
);
920 LASSERT(!msg
->msg_sending
);
922 /* non-lnet_parse callers only receive delayed messages */
923 LASSERT(!do_recv
|| msg
->msg_rx_delayed
);
925 if (!msg
->msg_peerrtrcredit
) {
926 LASSERT((lp
->lp_rtrcredits
< 0) ==
927 !list_empty(&lp
->lp_rtrq
));
929 msg
->msg_peerrtrcredit
= 1;
931 if (lp
->lp_rtrcredits
< lp
->lp_minrtrcredits
)
932 lp
->lp_minrtrcredits
= lp
->lp_rtrcredits
;
934 if (lp
->lp_rtrcredits
< 0) {
935 /* must have checked eager_recv before here */
936 LASSERT(msg
->msg_rx_ready_delay
);
937 msg
->msg_rx_delayed
= 1;
938 list_add_tail(&msg
->msg_list
, &lp
->lp_rtrq
);
939 return LNET_CREDIT_WAIT
;
943 rbp
= lnet_msg2bufpool(msg
);
945 if (!msg
->msg_rtrcredit
) {
946 msg
->msg_rtrcredit
= 1;
948 if (rbp
->rbp_credits
< rbp
->rbp_mincredits
)
949 rbp
->rbp_mincredits
= rbp
->rbp_credits
;
951 if (rbp
->rbp_credits
< 0) {
952 /* must have checked eager_recv before here */
953 LASSERT(msg
->msg_rx_ready_delay
);
954 msg
->msg_rx_delayed
= 1;
955 list_add_tail(&msg
->msg_list
, &rbp
->rbp_msgs
);
956 return LNET_CREDIT_WAIT
;
960 LASSERT(!list_empty(&rbp
->rbp_bufs
));
961 rb
= list_entry(rbp
->rbp_bufs
.next
, lnet_rtrbuf_t
, rb_list
);
962 list_del(&rb
->rb_list
);
964 msg
->msg_niov
= rbp
->rbp_npages
;
965 msg
->msg_kiov
= &rb
->rb_kiov
[0];
968 int cpt
= msg
->msg_rx_cpt
;
970 lnet_net_unlock(cpt
);
971 lnet_ni_recv(lp
->lp_ni
, msg
->msg_private
, msg
, 1,
972 0, msg
->msg_len
, msg
->msg_len
);
975 return LNET_CREDIT_OK
;
979 lnet_return_tx_credits_locked(lnet_msg_t
*msg
)
981 lnet_peer_t
*txpeer
= msg
->msg_txpeer
;
984 if (msg
->msg_txcredit
) {
985 struct lnet_ni
*ni
= txpeer
->lp_ni
;
986 struct lnet_tx_queue
*tq
= ni
->ni_tx_queues
[msg
->msg_tx_cpt
];
988 /* give back NI txcredits */
989 msg
->msg_txcredit
= 0;
991 LASSERT((tq
->tq_credits
< 0) ==
992 !list_empty(&tq
->tq_delayed
));
995 if (tq
->tq_credits
<= 0) {
996 msg2
= list_entry(tq
->tq_delayed
.next
,
997 lnet_msg_t
, msg_list
);
998 list_del(&msg2
->msg_list
);
1000 LASSERT(msg2
->msg_txpeer
->lp_ni
== ni
);
1001 LASSERT(msg2
->msg_tx_delayed
);
1003 (void) lnet_post_send_locked(msg2
, 1);
1007 if (msg
->msg_peertxcredit
) {
1008 /* give back peer txcredits */
1009 msg
->msg_peertxcredit
= 0;
1011 LASSERT((txpeer
->lp_txcredits
< 0) ==
1012 !list_empty(&txpeer
->lp_txq
));
1014 txpeer
->lp_txqnob
-= msg
->msg_len
+ sizeof(lnet_hdr_t
);
1015 LASSERT(txpeer
->lp_txqnob
>= 0);
1017 txpeer
->lp_txcredits
++;
1018 if (txpeer
->lp_txcredits
<= 0) {
1019 msg2
= list_entry(txpeer
->lp_txq
.next
,
1020 lnet_msg_t
, msg_list
);
1021 list_del(&msg2
->msg_list
);
1023 LASSERT(msg2
->msg_txpeer
== txpeer
);
1024 LASSERT(msg2
->msg_tx_delayed
);
1026 (void) lnet_post_send_locked(msg2
, 1);
1031 msg
->msg_txpeer
= NULL
;
1032 lnet_peer_decref_locked(txpeer
);
1037 lnet_schedule_blocked_locked(lnet_rtrbufpool_t
*rbp
)
1041 if (list_empty(&rbp
->rbp_msgs
))
1043 msg
= list_entry(rbp
->rbp_msgs
.next
,
1044 lnet_msg_t
, msg_list
);
1045 list_del(&msg
->msg_list
);
1047 (void)lnet_post_routed_recv_locked(msg
, 1);
1051 lnet_drop_routed_msgs_locked(struct list_head
*list
, int cpt
)
1053 struct list_head drop
;
1057 INIT_LIST_HEAD(&drop
);
1059 list_splice_init(list
, &drop
);
1061 lnet_net_unlock(cpt
);
1063 list_for_each_entry_safe(msg
, tmp
, &drop
, msg_list
) {
1064 lnet_ni_recv(msg
->msg_rxpeer
->lp_ni
, msg
->msg_private
, NULL
,
1065 0, 0, 0, msg
->msg_hdr
.payload_length
);
1066 list_del_init(&msg
->msg_list
);
1067 lnet_finalize(NULL
, msg
, -ECANCELED
);
1074 lnet_return_rx_credits_locked(lnet_msg_t
*msg
)
1076 lnet_peer_t
*rxpeer
= msg
->msg_rxpeer
;
1079 if (msg
->msg_rtrcredit
) {
1080 /* give back global router credits */
1082 lnet_rtrbufpool_t
*rbp
;
1085 * NB If a msg ever blocks for a buffer in rbp_msgs, it stays
1086 * there until it gets one allocated, or aborts the wait
1089 LASSERT(msg
->msg_kiov
);
1091 rb
= list_entry(msg
->msg_kiov
, lnet_rtrbuf_t
, rb_kiov
[0]);
1094 msg
->msg_kiov
= NULL
;
1095 msg
->msg_rtrcredit
= 0;
1097 LASSERT(rbp
== lnet_msg2bufpool(msg
));
1099 LASSERT((rbp
->rbp_credits
> 0) ==
1100 !list_empty(&rbp
->rbp_bufs
));
1103 * If routing is now turned off, we just drop this buffer and
1104 * don't bother trying to return credits.
1106 if (!the_lnet
.ln_routing
) {
1107 lnet_destroy_rtrbuf(rb
, rbp
->rbp_npages
);
1112 * It is possible that a user has lowered the desired number of
1113 * buffers in this pool. Make sure we never put back
1114 * more buffers than the stated number.
1116 if (rbp
->rbp_credits
>= rbp
->rbp_nbuffers
) {
1117 /* Discard this buffer so we don't have too many. */
1118 lnet_destroy_rtrbuf(rb
, rbp
->rbp_npages
);
1120 list_add(&rb
->rb_list
, &rbp
->rbp_bufs
);
1122 if (rbp
->rbp_credits
<= 0)
1123 lnet_schedule_blocked_locked(rbp
);
1128 if (msg
->msg_peerrtrcredit
) {
1129 /* give back peer router credits */
1130 msg
->msg_peerrtrcredit
= 0;
1132 LASSERT((rxpeer
->lp_rtrcredits
< 0) ==
1133 !list_empty(&rxpeer
->lp_rtrq
));
1135 rxpeer
->lp_rtrcredits
++;
1137 * drop all messages which are queued to be routed on that
1140 if (!the_lnet
.ln_routing
) {
1141 lnet_drop_routed_msgs_locked(&rxpeer
->lp_rtrq
,
1143 } else if (rxpeer
->lp_rtrcredits
<= 0) {
1144 msg2
= list_entry(rxpeer
->lp_rtrq
.next
,
1145 lnet_msg_t
, msg_list
);
1146 list_del(&msg2
->msg_list
);
1148 (void) lnet_post_routed_recv_locked(msg2
, 1);
1152 msg
->msg_rxpeer
= NULL
;
1153 lnet_peer_decref_locked(rxpeer
);
1158 lnet_compare_routes(lnet_route_t
*r1
, lnet_route_t
*r2
)
1160 lnet_peer_t
*p1
= r1
->lr_gateway
;
1161 lnet_peer_t
*p2
= r2
->lr_gateway
;
1163 if (r1
->lr_priority
< r2
->lr_priority
)
1166 if (r1
->lr_priority
> r2
->lr_priority
)
1169 if (r1
->lr_hops
< r2
->lr_hops
)
1172 if (r1
->lr_hops
> r2
->lr_hops
)
1175 if (p1
->lp_txqnob
< p2
->lp_txqnob
)
1178 if (p1
->lp_txqnob
> p2
->lp_txqnob
)
1181 if (p1
->lp_txcredits
> p2
->lp_txcredits
)
1184 if (p1
->lp_txcredits
< p2
->lp_txcredits
)
1187 if (r1
->lr_seq
- r2
->lr_seq
<= 0)
1193 static lnet_peer_t
*
1194 lnet_find_route_locked(lnet_ni_t
*ni
, lnet_nid_t target
, lnet_nid_t rtr_nid
)
1196 lnet_remotenet_t
*rnet
;
1197 lnet_route_t
*route
;
1198 lnet_route_t
*best_route
;
1199 lnet_route_t
*last_route
;
1200 struct lnet_peer
*lp_best
;
1201 struct lnet_peer
*lp
;
1205 * If @rtr_nid is not LNET_NID_ANY, return the gateway with
1206 * rtr_nid nid, otherwise find the best gateway I can use
1208 rnet
= lnet_find_net_locked(LNET_NIDNET(target
));
1215 list_for_each_entry(route
, &rnet
->lrn_routes
, lr_list
) {
1216 lp
= route
->lr_gateway
;
1218 if (!lnet_is_route_alive(route
))
1221 if (ni
&& lp
->lp_ni
!= ni
)
1224 if (lp
->lp_nid
== rtr_nid
) /* it's pre-determined router */
1234 /* no protection on below fields, but it's harmless */
1235 if (last_route
->lr_seq
- route
->lr_seq
< 0)
1238 rc
= lnet_compare_routes(route
, best_route
);
1247 * set sequence number on the best router to the latest sequence + 1
1248 * so we can round-robin all routers, it's race and inaccurate but
1249 * harmless and functional
1252 best_route
->lr_seq
= last_route
->lr_seq
+ 1;
1257 lnet_send(lnet_nid_t src_nid
, lnet_msg_t
*msg
, lnet_nid_t rtr_nid
)
1259 lnet_nid_t dst_nid
= msg
->msg_target
.nid
;
1260 struct lnet_ni
*src_ni
;
1261 struct lnet_ni
*local_ni
;
1262 struct lnet_peer
*lp
;
1268 * NB: rtr_nid is set to LNET_NID_ANY for all current use-cases,
1269 * but we might want to use pre-determined router for ACK/REPLY
1272 /* NB: ni == interface pre-determined (ACK/REPLY) */
1273 LASSERT(!msg
->msg_txpeer
);
1274 LASSERT(!msg
->msg_sending
);
1275 LASSERT(!msg
->msg_target_is_router
);
1276 LASSERT(!msg
->msg_receiving
);
1278 msg
->msg_sending
= 1;
1280 LASSERT(!msg
->msg_tx_committed
);
1281 cpt
= lnet_cpt_of_nid(rtr_nid
== LNET_NID_ANY
? dst_nid
: rtr_nid
);
1285 if (the_lnet
.ln_shutdown
) {
1286 lnet_net_unlock(cpt
);
1290 if (src_nid
== LNET_NID_ANY
) {
1293 src_ni
= lnet_nid2ni_locked(src_nid
, cpt
);
1295 lnet_net_unlock(cpt
);
1296 LCONSOLE_WARN("Can't send to %s: src %s is not a local nid\n",
1297 libcfs_nid2str(dst_nid
),
1298 libcfs_nid2str(src_nid
));
1301 LASSERT(!msg
->msg_routing
);
1304 /* Is this for someone on a local network? */
1305 local_ni
= lnet_net2ni_locked(LNET_NIDNET(dst_nid
), cpt
);
1310 src_nid
= src_ni
->ni_nid
;
1311 } else if (src_ni
== local_ni
) {
1312 lnet_ni_decref_locked(local_ni
, cpt
);
1314 lnet_ni_decref_locked(local_ni
, cpt
);
1315 lnet_ni_decref_locked(src_ni
, cpt
);
1316 lnet_net_unlock(cpt
);
1317 LCONSOLE_WARN("No route to %s via from %s\n",
1318 libcfs_nid2str(dst_nid
),
1319 libcfs_nid2str(src_nid
));
1323 LASSERT(src_nid
!= LNET_NID_ANY
);
1324 lnet_msg_commit(msg
, cpt
);
1326 if (!msg
->msg_routing
)
1327 msg
->msg_hdr
.src_nid
= cpu_to_le64(src_nid
);
1329 if (src_ni
== the_lnet
.ln_loni
) {
1330 /* No send credit hassles with LOLND */
1331 lnet_net_unlock(cpt
);
1332 lnet_ni_send(src_ni
, msg
);
1335 lnet_ni_decref_locked(src_ni
, cpt
);
1336 lnet_net_unlock(cpt
);
1340 rc
= lnet_nid2peer_locked(&lp
, dst_nid
, cpt
);
1341 /* lp has ref on src_ni; lose mine */
1342 lnet_ni_decref_locked(src_ni
, cpt
);
1344 lnet_net_unlock(cpt
);
1345 LCONSOLE_WARN("Error %d finding peer %s\n", rc
,
1346 libcfs_nid2str(dst_nid
));
1347 /* ENOMEM or shutting down */
1350 LASSERT(lp
->lp_ni
== src_ni
);
1352 /* sending to a remote network */
1353 lp
= lnet_find_route_locked(src_ni
, dst_nid
, rtr_nid
);
1356 lnet_ni_decref_locked(src_ni
, cpt
);
1357 lnet_net_unlock(cpt
);
1359 LCONSOLE_WARN("No route to %s via %s (all routers down)\n",
1360 libcfs_id2str(msg
->msg_target
),
1361 libcfs_nid2str(src_nid
));
1362 return -EHOSTUNREACH
;
1366 * rtr_nid is LNET_NID_ANY or NID of pre-determined router,
1367 * it's possible that rtr_nid isn't LNET_NID_ANY and lp isn't
1368 * pre-determined router, this can happen if router table
1369 * was changed when we release the lock
1371 if (rtr_nid
!= lp
->lp_nid
) {
1372 cpt2
= lnet_cpt_of_nid_locked(lp
->lp_nid
);
1375 lnet_ni_decref_locked(src_ni
, cpt
);
1376 lnet_net_unlock(cpt
);
1378 rtr_nid
= lp
->lp_nid
;
1384 CDEBUG(D_NET
, "Best route to %s via %s for %s %d\n",
1385 libcfs_nid2str(dst_nid
), libcfs_nid2str(lp
->lp_nid
),
1386 lnet_msgtyp2str(msg
->msg_type
), msg
->msg_len
);
1390 src_nid
= src_ni
->ni_nid
;
1392 LASSERT(src_ni
== lp
->lp_ni
);
1393 lnet_ni_decref_locked(src_ni
, cpt
);
1396 lnet_peer_addref_locked(lp
);
1398 LASSERT(src_nid
!= LNET_NID_ANY
);
1399 lnet_msg_commit(msg
, cpt
);
1401 if (!msg
->msg_routing
) {
1402 /* I'm the source and now I know which NI to send on */
1403 msg
->msg_hdr
.src_nid
= cpu_to_le64(src_nid
);
1406 msg
->msg_target_is_router
= 1;
1407 msg
->msg_target
.nid
= lp
->lp_nid
;
1408 msg
->msg_target
.pid
= LNET_PID_LUSTRE
;
1411 /* 'lp' is our best choice of peer */
1413 LASSERT(!msg
->msg_peertxcredit
);
1414 LASSERT(!msg
->msg_txcredit
);
1415 LASSERT(!msg
->msg_txpeer
);
1417 msg
->msg_txpeer
= lp
; /* msg takes my ref on lp */
1419 rc
= lnet_post_send_locked(msg
, 0);
1420 lnet_net_unlock(cpt
);
1425 if (rc
== LNET_CREDIT_OK
)
1426 lnet_ni_send(src_ni
, msg
);
1428 return 0; /* rc == LNET_CREDIT_OK or LNET_CREDIT_WAIT */
1432 lnet_drop_message(lnet_ni_t
*ni
, int cpt
, void *private, unsigned int nob
)
1435 the_lnet
.ln_counters
[cpt
]->drop_count
++;
1436 the_lnet
.ln_counters
[cpt
]->drop_length
+= nob
;
1437 lnet_net_unlock(cpt
);
1439 lnet_ni_recv(ni
, private, NULL
, 0, 0, 0, nob
);
1443 lnet_recv_put(lnet_ni_t
*ni
, lnet_msg_t
*msg
)
1445 lnet_hdr_t
*hdr
= &msg
->msg_hdr
;
1447 if (msg
->msg_wanted
)
1448 lnet_setpayloadbuffer(msg
);
1450 lnet_build_msg_event(msg
, LNET_EVENT_PUT
);
1453 * Must I ACK? If so I'll grab the ack_wmd out of the header and put
1454 * it back into the ACK during lnet_finalize()
1456 msg
->msg_ack
= !lnet_is_wire_handle_none(&hdr
->msg
.put
.ack_wmd
) &&
1457 !(msg
->msg_md
->md_options
& LNET_MD_ACK_DISABLE
);
1459 lnet_ni_recv(ni
, msg
->msg_private
, msg
, msg
->msg_rx_delayed
,
1460 msg
->msg_offset
, msg
->msg_wanted
, hdr
->payload_length
);
1464 lnet_parse_put(lnet_ni_t
*ni
, lnet_msg_t
*msg
)
1466 lnet_hdr_t
*hdr
= &msg
->msg_hdr
;
1467 struct lnet_match_info info
;
1470 /* Convert put fields to host byte order */
1471 hdr
->msg
.put
.match_bits
= le64_to_cpu(hdr
->msg
.put
.match_bits
);
1472 hdr
->msg
.put
.ptl_index
= le32_to_cpu(hdr
->msg
.put
.ptl_index
);
1473 hdr
->msg
.put
.offset
= le32_to_cpu(hdr
->msg
.put
.offset
);
1475 info
.mi_id
.nid
= hdr
->src_nid
;
1476 info
.mi_id
.pid
= hdr
->src_pid
;
1477 info
.mi_opc
= LNET_MD_OP_PUT
;
1478 info
.mi_portal
= hdr
->msg
.put
.ptl_index
;
1479 info
.mi_rlength
= hdr
->payload_length
;
1480 info
.mi_roffset
= hdr
->msg
.put
.offset
;
1481 info
.mi_mbits
= hdr
->msg
.put
.match_bits
;
1483 msg
->msg_rx_ready_delay
= !ni
->ni_lnd
->lnd_eager_recv
;
1486 rc
= lnet_ptl_match_md(&info
, msg
);
1491 case LNET_MATCHMD_OK
:
1492 lnet_recv_put(ni
, msg
);
1495 case LNET_MATCHMD_NONE
:
1496 if (msg
->msg_rx_delayed
) /* attached on delayed list */
1499 rc
= lnet_ni_eager_recv(ni
, msg
);
1504 case LNET_MATCHMD_DROP
:
1505 CNETERR("Dropping PUT from %s portal %d match %llu offset %d length %d: %d\n",
1506 libcfs_id2str(info
.mi_id
), info
.mi_portal
,
1507 info
.mi_mbits
, info
.mi_roffset
, info
.mi_rlength
, rc
);
1509 return ENOENT
; /* +ve: OK but no match */
1514 lnet_parse_get(lnet_ni_t
*ni
, lnet_msg_t
*msg
, int rdma_get
)
1516 struct lnet_match_info info
;
1517 lnet_hdr_t
*hdr
= &msg
->msg_hdr
;
1518 lnet_handle_wire_t reply_wmd
;
1521 /* Convert get fields to host byte order */
1522 hdr
->msg
.get
.match_bits
= le64_to_cpu(hdr
->msg
.get
.match_bits
);
1523 hdr
->msg
.get
.ptl_index
= le32_to_cpu(hdr
->msg
.get
.ptl_index
);
1524 hdr
->msg
.get
.sink_length
= le32_to_cpu(hdr
->msg
.get
.sink_length
);
1525 hdr
->msg
.get
.src_offset
= le32_to_cpu(hdr
->msg
.get
.src_offset
);
1527 info
.mi_id
.nid
= hdr
->src_nid
;
1528 info
.mi_id
.pid
= hdr
->src_pid
;
1529 info
.mi_opc
= LNET_MD_OP_GET
;
1530 info
.mi_portal
= hdr
->msg
.get
.ptl_index
;
1531 info
.mi_rlength
= hdr
->msg
.get
.sink_length
;
1532 info
.mi_roffset
= hdr
->msg
.get
.src_offset
;
1533 info
.mi_mbits
= hdr
->msg
.get
.match_bits
;
1535 rc
= lnet_ptl_match_md(&info
, msg
);
1536 if (rc
== LNET_MATCHMD_DROP
) {
1537 CNETERR("Dropping GET from %s portal %d match %llu offset %d length %d\n",
1538 libcfs_id2str(info
.mi_id
), info
.mi_portal
,
1539 info
.mi_mbits
, info
.mi_roffset
, info
.mi_rlength
);
1540 return ENOENT
; /* +ve: OK but no match */
1543 LASSERT(rc
== LNET_MATCHMD_OK
);
1545 lnet_build_msg_event(msg
, LNET_EVENT_GET
);
1547 reply_wmd
= hdr
->msg
.get
.return_wmd
;
1549 lnet_prep_send(msg
, LNET_MSG_REPLY
, info
.mi_id
,
1550 msg
->msg_offset
, msg
->msg_wanted
);
1552 msg
->msg_hdr
.msg
.reply
.dst_wmd
= reply_wmd
;
1555 /* The LND completes the REPLY from her recv procedure */
1556 lnet_ni_recv(ni
, msg
->msg_private
, msg
, 0,
1557 msg
->msg_offset
, msg
->msg_len
, msg
->msg_len
);
1561 lnet_ni_recv(ni
, msg
->msg_private
, NULL
, 0, 0, 0, 0);
1562 msg
->msg_receiving
= 0;
1564 rc
= lnet_send(ni
->ni_nid
, msg
, LNET_NID_ANY
);
1566 /* didn't get as far as lnet_ni_send() */
1567 CERROR("%s: Unable to send REPLY for GET from %s: %d\n",
1568 libcfs_nid2str(ni
->ni_nid
),
1569 libcfs_id2str(info
.mi_id
), rc
);
1571 lnet_finalize(ni
, msg
, rc
);
1578 lnet_parse_reply(lnet_ni_t
*ni
, lnet_msg_t
*msg
)
1580 void *private = msg
->msg_private
;
1581 lnet_hdr_t
*hdr
= &msg
->msg_hdr
;
1582 lnet_process_id_t src
= {0};
1588 cpt
= lnet_cpt_of_cookie(hdr
->msg
.reply
.dst_wmd
.wh_object_cookie
);
1591 src
.nid
= hdr
->src_nid
;
1592 src
.pid
= hdr
->src_pid
;
1594 /* NB handles only looked up by creator (no flips) */
1595 md
= lnet_wire_handle2md(&hdr
->msg
.reply
.dst_wmd
);
1596 if (!md
|| !md
->md_threshold
|| md
->md_me
) {
1597 CNETERR("%s: Dropping REPLY from %s for %s MD %#llx.%#llx\n",
1598 libcfs_nid2str(ni
->ni_nid
), libcfs_id2str(src
),
1599 !md
? "invalid" : "inactive",
1600 hdr
->msg
.reply
.dst_wmd
.wh_interface_cookie
,
1601 hdr
->msg
.reply
.dst_wmd
.wh_object_cookie
);
1602 if (md
&& md
->md_me
)
1603 CERROR("REPLY MD also attached to portal %d\n",
1604 md
->md_me
->me_portal
);
1606 lnet_res_unlock(cpt
);
1607 return ENOENT
; /* +ve: OK but no match */
1610 LASSERT(!md
->md_offset
);
1612 rlength
= hdr
->payload_length
;
1613 mlength
= min_t(uint
, rlength
, md
->md_length
);
1615 if (mlength
< rlength
&&
1616 !(md
->md_options
& LNET_MD_TRUNCATE
)) {
1617 CNETERR("%s: Dropping REPLY from %s length %d for MD %#llx would overflow (%d)\n",
1618 libcfs_nid2str(ni
->ni_nid
), libcfs_id2str(src
),
1619 rlength
, hdr
->msg
.reply
.dst_wmd
.wh_object_cookie
,
1621 lnet_res_unlock(cpt
);
1622 return ENOENT
; /* +ve: OK but no match */
1625 CDEBUG(D_NET
, "%s: Reply from %s of length %d/%d into md %#llx\n",
1626 libcfs_nid2str(ni
->ni_nid
), libcfs_id2str(src
),
1627 mlength
, rlength
, hdr
->msg
.reply
.dst_wmd
.wh_object_cookie
);
1629 lnet_msg_attach_md(msg
, md
, 0, mlength
);
1632 lnet_setpayloadbuffer(msg
);
1634 lnet_res_unlock(cpt
);
1636 lnet_build_msg_event(msg
, LNET_EVENT_REPLY
);
1638 lnet_ni_recv(ni
, private, msg
, 0, 0, mlength
, rlength
);
1643 lnet_parse_ack(lnet_ni_t
*ni
, lnet_msg_t
*msg
)
1645 lnet_hdr_t
*hdr
= &msg
->msg_hdr
;
1646 lnet_process_id_t src
= {0};
1650 src
.nid
= hdr
->src_nid
;
1651 src
.pid
= hdr
->src_pid
;
1653 /* Convert ack fields to host byte order */
1654 hdr
->msg
.ack
.match_bits
= le64_to_cpu(hdr
->msg
.ack
.match_bits
);
1655 hdr
->msg
.ack
.mlength
= le32_to_cpu(hdr
->msg
.ack
.mlength
);
1657 cpt
= lnet_cpt_of_cookie(hdr
->msg
.ack
.dst_wmd
.wh_object_cookie
);
1660 /* NB handles only looked up by creator (no flips) */
1661 md
= lnet_wire_handle2md(&hdr
->msg
.ack
.dst_wmd
);
1662 if (!md
|| !md
->md_threshold
|| md
->md_me
) {
1663 /* Don't moan; this is expected */
1665 "%s: Dropping ACK from %s to %s MD %#llx.%#llx\n",
1666 libcfs_nid2str(ni
->ni_nid
), libcfs_id2str(src
),
1667 !md
? "invalid" : "inactive",
1668 hdr
->msg
.ack
.dst_wmd
.wh_interface_cookie
,
1669 hdr
->msg
.ack
.dst_wmd
.wh_object_cookie
);
1670 if (md
&& md
->md_me
)
1671 CERROR("Source MD also attached to portal %d\n",
1672 md
->md_me
->me_portal
);
1674 lnet_res_unlock(cpt
);
1675 return ENOENT
; /* +ve! */
1678 CDEBUG(D_NET
, "%s: ACK from %s into md %#llx\n",
1679 libcfs_nid2str(ni
->ni_nid
), libcfs_id2str(src
),
1680 hdr
->msg
.ack
.dst_wmd
.wh_object_cookie
);
1682 lnet_msg_attach_md(msg
, md
, 0, 0);
1684 lnet_res_unlock(cpt
);
1686 lnet_build_msg_event(msg
, LNET_EVENT_ACK
);
1688 lnet_ni_recv(ni
, msg
->msg_private
, msg
, 0, 0, 0, msg
->msg_len
);
1693 * \retval LNET_CREDIT_OK If \a msg is forwarded
1694 * \retval LNET_CREDIT_WAIT If \a msg is blocked because w/o buffer
1695 * \retval -ve error code
1698 lnet_parse_forward_locked(lnet_ni_t
*ni
, lnet_msg_t
*msg
)
1702 if (!the_lnet
.ln_routing
)
1705 if (msg
->msg_rxpeer
->lp_rtrcredits
<= 0 ||
1706 lnet_msg2bufpool(msg
)->rbp_credits
<= 0) {
1707 if (!ni
->ni_lnd
->lnd_eager_recv
) {
1708 msg
->msg_rx_ready_delay
= 1;
1710 lnet_net_unlock(msg
->msg_rx_cpt
);
1711 rc
= lnet_ni_eager_recv(ni
, msg
);
1712 lnet_net_lock(msg
->msg_rx_cpt
);
1717 rc
= lnet_post_routed_recv_locked(msg
, 0);
1722 lnet_msgtyp2str(int type
)
1731 case LNET_MSG_REPLY
:
1733 case LNET_MSG_HELLO
:
1741 lnet_print_hdr(lnet_hdr_t
*hdr
)
1743 lnet_process_id_t src
= {0};
1744 lnet_process_id_t dst
= {0};
1745 char *type_str
= lnet_msgtyp2str(hdr
->type
);
1747 src
.nid
= hdr
->src_nid
;
1748 src
.pid
= hdr
->src_pid
;
1750 dst
.nid
= hdr
->dest_nid
;
1751 dst
.pid
= hdr
->dest_pid
;
1753 CWARN("P3 Header at %p of type %s\n", hdr
, type_str
);
1754 CWARN(" From %s\n", libcfs_id2str(src
));
1755 CWARN(" To %s\n", libcfs_id2str(dst
));
1757 switch (hdr
->type
) {
1762 CWARN(" Ptl index %d, ack md %#llx.%#llx, match bits %llu\n",
1763 hdr
->msg
.put
.ptl_index
,
1764 hdr
->msg
.put
.ack_wmd
.wh_interface_cookie
,
1765 hdr
->msg
.put
.ack_wmd
.wh_object_cookie
,
1766 hdr
->msg
.put
.match_bits
);
1767 CWARN(" Length %d, offset %d, hdr data %#llx\n",
1768 hdr
->payload_length
, hdr
->msg
.put
.offset
,
1769 hdr
->msg
.put
.hdr_data
);
1773 CWARN(" Ptl index %d, return md %#llx.%#llx, match bits %llu\n",
1774 hdr
->msg
.get
.ptl_index
,
1775 hdr
->msg
.get
.return_wmd
.wh_interface_cookie
,
1776 hdr
->msg
.get
.return_wmd
.wh_object_cookie
,
1777 hdr
->msg
.get
.match_bits
);
1778 CWARN(" Length %d, src offset %d\n",
1779 hdr
->msg
.get
.sink_length
,
1780 hdr
->msg
.get
.src_offset
);
1784 CWARN(" dst md %#llx.%#llx, manipulated length %d\n",
1785 hdr
->msg
.ack
.dst_wmd
.wh_interface_cookie
,
1786 hdr
->msg
.ack
.dst_wmd
.wh_object_cookie
,
1787 hdr
->msg
.ack
.mlength
);
1790 case LNET_MSG_REPLY
:
1791 CWARN(" dst md %#llx.%#llx, length %d\n",
1792 hdr
->msg
.reply
.dst_wmd
.wh_interface_cookie
,
1793 hdr
->msg
.reply
.dst_wmd
.wh_object_cookie
,
1794 hdr
->payload_length
);
1799 lnet_parse(lnet_ni_t
*ni
, lnet_hdr_t
*hdr
, lnet_nid_t from_nid
,
1800 void *private, int rdma_req
)
1805 struct lnet_msg
*msg
;
1806 lnet_pid_t dest_pid
;
1807 lnet_nid_t dest_nid
;
1809 __u32 payload_length
;
1812 LASSERT(!in_interrupt());
1814 type
= le32_to_cpu(hdr
->type
);
1815 src_nid
= le64_to_cpu(hdr
->src_nid
);
1816 dest_nid
= le64_to_cpu(hdr
->dest_nid
);
1817 dest_pid
= le32_to_cpu(hdr
->dest_pid
);
1818 payload_length
= le32_to_cpu(hdr
->payload_length
);
1820 for_me
= (ni
->ni_nid
== dest_nid
);
1821 cpt
= lnet_cpt_of_nid(from_nid
);
1826 if (payload_length
> 0) {
1827 CERROR("%s, src %s: bad %s payload %d (0 expected)\n",
1828 libcfs_nid2str(from_nid
),
1829 libcfs_nid2str(src_nid
),
1830 lnet_msgtyp2str(type
), payload_length
);
1836 case LNET_MSG_REPLY
:
1837 if (payload_length
>
1838 (__u32
)(for_me
? LNET_MAX_PAYLOAD
: LNET_MTU
)) {
1839 CERROR("%s, src %s: bad %s payload %d (%d max expected)\n",
1840 libcfs_nid2str(from_nid
),
1841 libcfs_nid2str(src_nid
),
1842 lnet_msgtyp2str(type
),
1844 for_me
? LNET_MAX_PAYLOAD
: LNET_MTU
);
1850 CERROR("%s, src %s: Bad message type 0x%x\n",
1851 libcfs_nid2str(from_nid
),
1852 libcfs_nid2str(src_nid
), type
);
1856 if (the_lnet
.ln_routing
&&
1857 ni
->ni_last_alive
!= ktime_get_real_seconds()) {
1858 /* NB: so far here is the only place to set NI status to "up */
1860 ni
->ni_last_alive
= ktime_get_real_seconds();
1861 if (ni
->ni_status
&&
1862 ni
->ni_status
->ns_status
== LNET_NI_STATUS_DOWN
)
1863 ni
->ni_status
->ns_status
= LNET_NI_STATUS_UP
;
1868 * Regard a bad destination NID as a protocol error. Senders should
1869 * know what they're doing; if they don't they're misconfigured, buggy
1870 * or malicious so we chop them off at the knees :)
1873 if (LNET_NIDNET(dest_nid
) == LNET_NIDNET(ni
->ni_nid
)) {
1874 /* should have gone direct */
1875 CERROR("%s, src %s: Bad dest nid %s (should have been sent direct)\n",
1876 libcfs_nid2str(from_nid
),
1877 libcfs_nid2str(src_nid
),
1878 libcfs_nid2str(dest_nid
));
1882 if (lnet_islocalnid(dest_nid
)) {
1884 * dest is another local NI; sender should have used
1885 * this node's NID on its own network
1887 CERROR("%s, src %s: Bad dest nid %s (it's my nid but on a different network)\n",
1888 libcfs_nid2str(from_nid
),
1889 libcfs_nid2str(src_nid
),
1890 libcfs_nid2str(dest_nid
));
1894 if (rdma_req
&& type
== LNET_MSG_GET
) {
1895 CERROR("%s, src %s: Bad optimized GET for %s (final destination must be me)\n",
1896 libcfs_nid2str(from_nid
),
1897 libcfs_nid2str(src_nid
),
1898 libcfs_nid2str(dest_nid
));
1902 if (!the_lnet
.ln_routing
) {
1903 CERROR("%s, src %s: Dropping message for %s (routing not enabled)\n",
1904 libcfs_nid2str(from_nid
),
1905 libcfs_nid2str(src_nid
),
1906 libcfs_nid2str(dest_nid
));
1912 * Message looks OK; we're not going to return an error, so we MUST
1913 * call back lnd_recv() come what may...
1915 if (!list_empty(&the_lnet
.ln_test_peers
) && /* normally we don't */
1916 fail_peer(src_nid
, 0)) { /* shall we now? */
1917 CERROR("%s, src %s: Dropping %s to simulate failure\n",
1918 libcfs_nid2str(from_nid
), libcfs_nid2str(src_nid
),
1919 lnet_msgtyp2str(type
));
1923 msg
= lnet_msg_alloc();
1925 CERROR("%s, src %s: Dropping %s (out of memory)\n",
1926 libcfs_nid2str(from_nid
), libcfs_nid2str(src_nid
),
1927 lnet_msgtyp2str(type
));
1931 /* msg zeroed in lnet_msg_alloc;
1932 * i.e. flags all clear, pointers NULL etc
1934 msg
->msg_type
= type
;
1935 msg
->msg_private
= private;
1936 msg
->msg_receiving
= 1;
1937 msg
->msg_wanted
= payload_length
;
1938 msg
->msg_len
= payload_length
;
1939 msg
->msg_offset
= 0;
1940 msg
->msg_hdr
= *hdr
;
1941 /* for building message event */
1942 msg
->msg_from
= from_nid
;
1944 msg
->msg_target
.pid
= dest_pid
;
1945 msg
->msg_target
.nid
= dest_nid
;
1946 msg
->msg_routing
= 1;
1949 /* convert common msg->hdr fields to host byteorder */
1950 msg
->msg_hdr
.type
= type
;
1951 msg
->msg_hdr
.src_nid
= src_nid
;
1952 msg
->msg_hdr
.src_pid
= le32_to_cpu(msg
->msg_hdr
.src_pid
);
1953 msg
->msg_hdr
.dest_nid
= dest_nid
;
1954 msg
->msg_hdr
.dest_pid
= dest_pid
;
1955 msg
->msg_hdr
.payload_length
= payload_length
;
1959 rc
= lnet_nid2peer_locked(&msg
->msg_rxpeer
, from_nid
, cpt
);
1961 lnet_net_unlock(cpt
);
1962 CERROR("%s, src %s: Dropping %s (error %d looking up sender)\n",
1963 libcfs_nid2str(from_nid
), libcfs_nid2str(src_nid
),
1964 lnet_msgtyp2str(type
), rc
);
1969 if (lnet_isrouter(msg
->msg_rxpeer
)) {
1970 lnet_peer_set_alive(msg
->msg_rxpeer
);
1971 if (avoid_asym_router_failure
&&
1972 LNET_NIDNET(src_nid
) != LNET_NIDNET(from_nid
)) {
1973 /* received a remote message from router, update
1974 * remote NI status on this router.
1975 * NB: multi-hop routed message will be ignored.
1977 lnet_router_ni_update_locked(msg
->msg_rxpeer
,
1978 LNET_NIDNET(src_nid
));
1982 lnet_msg_commit(msg
, cpt
);
1985 rc
= lnet_parse_forward_locked(ni
, msg
);
1986 lnet_net_unlock(cpt
);
1991 if (rc
== LNET_CREDIT_OK
) {
1992 lnet_ni_recv(ni
, msg
->msg_private
, msg
, 0,
1993 0, payload_length
, payload_length
);
1998 lnet_net_unlock(cpt
);
2002 rc
= lnet_parse_ack(ni
, msg
);
2005 rc
= lnet_parse_put(ni
, msg
);
2008 rc
= lnet_parse_get(ni
, msg
, rdma_req
);
2010 case LNET_MSG_REPLY
:
2011 rc
= lnet_parse_reply(ni
, msg
);
2016 goto free_drop
; /* prevent an unused label if !kernel */
2022 LASSERT(rc
== ENOENT
);
2025 LASSERT(!msg
->msg_md
);
2026 lnet_finalize(ni
, msg
, rc
);
2029 lnet_drop_message(ni
, cpt
, private, payload_length
);
2032 EXPORT_SYMBOL(lnet_parse
);
2035 lnet_drop_delayed_msg_list(struct list_head
*head
, char *reason
)
2037 while (!list_empty(head
)) {
2038 lnet_process_id_t id
= {0};
2041 msg
= list_entry(head
->next
, lnet_msg_t
, msg_list
);
2042 list_del(&msg
->msg_list
);
2044 id
.nid
= msg
->msg_hdr
.src_nid
;
2045 id
.pid
= msg
->msg_hdr
.src_pid
;
2047 LASSERT(!msg
->msg_md
);
2048 LASSERT(msg
->msg_rx_delayed
);
2049 LASSERT(msg
->msg_rxpeer
);
2050 LASSERT(msg
->msg_hdr
.type
== LNET_MSG_PUT
);
2052 CWARN("Dropping delayed PUT from %s portal %d match %llu offset %d length %d: %s\n",
2054 msg
->msg_hdr
.msg
.put
.ptl_index
,
2055 msg
->msg_hdr
.msg
.put
.match_bits
,
2056 msg
->msg_hdr
.msg
.put
.offset
,
2057 msg
->msg_hdr
.payload_length
, reason
);
2060 * NB I can't drop msg's ref on msg_rxpeer until after I've
2061 * called lnet_drop_message(), so I just hang onto msg as well
2064 lnet_drop_message(msg
->msg_rxpeer
->lp_ni
,
2065 msg
->msg_rxpeer
->lp_cpt
,
2066 msg
->msg_private
, msg
->msg_len
);
2068 * NB: message will not generate event because w/o attached MD,
2069 * but we still should give error code so lnet_msg_decommit()
2070 * can skip counters operations and other checks.
2072 lnet_finalize(msg
->msg_rxpeer
->lp_ni
, msg
, -ENOENT
);
2077 lnet_recv_delayed_msg_list(struct list_head
*head
)
2079 while (!list_empty(head
)) {
2081 lnet_process_id_t id
;
2083 msg
= list_entry(head
->next
, lnet_msg_t
, msg_list
);
2084 list_del(&msg
->msg_list
);
2087 * md won't disappear under me, since each msg
2090 id
.nid
= msg
->msg_hdr
.src_nid
;
2091 id
.pid
= msg
->msg_hdr
.src_pid
;
2093 LASSERT(msg
->msg_rx_delayed
);
2094 LASSERT(msg
->msg_md
);
2095 LASSERT(msg
->msg_rxpeer
);
2096 LASSERT(msg
->msg_hdr
.type
== LNET_MSG_PUT
);
2098 CDEBUG(D_NET
, "Resuming delayed PUT from %s portal %d match %llu offset %d length %d.\n",
2099 libcfs_id2str(id
), msg
->msg_hdr
.msg
.put
.ptl_index
,
2100 msg
->msg_hdr
.msg
.put
.match_bits
,
2101 msg
->msg_hdr
.msg
.put
.offset
,
2102 msg
->msg_hdr
.payload_length
);
2104 lnet_recv_put(msg
->msg_rxpeer
->lp_ni
, msg
);
2109 * Initiate an asynchronous PUT operation.
2111 * There are several events associated with a PUT: completion of the send on
2112 * the initiator node (LNET_EVENT_SEND), and when the send completes
2113 * successfully, the receipt of an acknowledgment (LNET_EVENT_ACK) indicating
2114 * that the operation was accepted by the target. The event LNET_EVENT_PUT is
2115 * used at the target node to indicate the completion of incoming data
2118 * The local events will be logged in the EQ associated with the MD pointed to
2119 * by \a mdh handle. Using a MD without an associated EQ results in these
2120 * events being discarded. In this case, the caller must have another
2121 * mechanism (e.g., a higher level protocol) for determining when it is safe
2122 * to modify the memory region associated with the MD.
2124 * Note that LNet does not guarantee the order of LNET_EVENT_SEND and
2125 * LNET_EVENT_ACK, though intuitively ACK should happen after SEND.
2127 * \param self Indicates the NID of a local interface through which to send
2128 * the PUT request. Use LNET_NID_ANY to let LNet choose one by itself.
2129 * \param mdh A handle for the MD that describes the memory to be sent. The MD
2130 * must be "free floating" (See LNetMDBind()).
2131 * \param ack Controls whether an acknowledgment is requested.
2132 * Acknowledgments are only sent when they are requested by the initiating
2133 * process and the target MD enables them.
2134 * \param target A process identifier for the target process.
2135 * \param portal The index in the \a target's portal table.
2136 * \param match_bits The match bits to use for MD selection at the target
2138 * \param offset The offset into the target MD (only used when the target
2139 * MD has the LNET_MD_MANAGE_REMOTE option set).
2140 * \param hdr_data 64 bits of user data that can be included in the message
2141 * header. This data is written to an event queue entry at the target if an
2142 * EQ is present on the matching MD.
2144 * \retval 0 Success, and only in this case events will be generated
2145 * and logged to EQ (if it exists).
2146 * \retval -EIO Simulated failure.
2147 * \retval -ENOMEM Memory allocation failure.
2148 * \retval -ENOENT Invalid MD object.
2150 * \see lnet_event_t::hdr_data and lnet_event_kind_t.
2153 LNetPut(lnet_nid_t self
, lnet_handle_md_t mdh
, lnet_ack_req_t ack
,
2154 lnet_process_id_t target
, unsigned int portal
,
2155 __u64 match_bits
, unsigned int offset
,
2158 struct lnet_msg
*msg
;
2159 struct lnet_libmd
*md
;
2163 LASSERT(the_lnet
.ln_refcount
> 0);
2165 if (!list_empty(&the_lnet
.ln_test_peers
) && /* normally we don't */
2166 fail_peer(target
.nid
, 1)) { /* shall we now? */
2167 CERROR("Dropping PUT to %s: simulated failure\n",
2168 libcfs_id2str(target
));
2172 msg
= lnet_msg_alloc();
2174 CERROR("Dropping PUT to %s: ENOMEM on lnet_msg_t\n",
2175 libcfs_id2str(target
));
2178 msg
->msg_vmflush
= !!memory_pressure_get();
2180 cpt
= lnet_cpt_of_cookie(mdh
.cookie
);
2183 md
= lnet_handle2md(&mdh
);
2184 if (!md
|| !md
->md_threshold
|| md
->md_me
) {
2185 CERROR("Dropping PUT (%llu:%d:%s): MD (%d) invalid\n",
2186 match_bits
, portal
, libcfs_id2str(target
),
2187 !md
? -1 : md
->md_threshold
);
2188 if (md
&& md
->md_me
)
2189 CERROR("Source MD also attached to portal %d\n",
2190 md
->md_me
->me_portal
);
2191 lnet_res_unlock(cpt
);
2197 CDEBUG(D_NET
, "LNetPut -> %s\n", libcfs_id2str(target
));
2199 lnet_msg_attach_md(msg
, md
, 0, 0);
2201 lnet_prep_send(msg
, LNET_MSG_PUT
, target
, 0, md
->md_length
);
2203 msg
->msg_hdr
.msg
.put
.match_bits
= cpu_to_le64(match_bits
);
2204 msg
->msg_hdr
.msg
.put
.ptl_index
= cpu_to_le32(portal
);
2205 msg
->msg_hdr
.msg
.put
.offset
= cpu_to_le32(offset
);
2206 msg
->msg_hdr
.msg
.put
.hdr_data
= hdr_data
;
2208 /* NB handles only looked up by creator (no flips) */
2209 if (ack
== LNET_ACK_REQ
) {
2210 msg
->msg_hdr
.msg
.put
.ack_wmd
.wh_interface_cookie
=
2211 the_lnet
.ln_interface_cookie
;
2212 msg
->msg_hdr
.msg
.put
.ack_wmd
.wh_object_cookie
=
2213 md
->md_lh
.lh_cookie
;
2215 msg
->msg_hdr
.msg
.put
.ack_wmd
.wh_interface_cookie
=
2216 LNET_WIRE_HANDLE_COOKIE_NONE
;
2217 msg
->msg_hdr
.msg
.put
.ack_wmd
.wh_object_cookie
=
2218 LNET_WIRE_HANDLE_COOKIE_NONE
;
2221 lnet_res_unlock(cpt
);
2223 lnet_build_msg_event(msg
, LNET_EVENT_SEND
);
2225 rc
= lnet_send(self
, msg
, LNET_NID_ANY
);
2227 CNETERR("Error sending PUT to %s: %d\n",
2228 libcfs_id2str(target
), rc
);
2229 lnet_finalize(NULL
, msg
, rc
);
2232 /* completion will be signalled by an event */
2235 EXPORT_SYMBOL(LNetPut
);
2238 lnet_create_reply_msg(lnet_ni_t
*ni
, lnet_msg_t
*getmsg
)
2241 * The LND can DMA direct to the GET md (i.e. no REPLY msg). This
2242 * returns a msg for the LND to pass to lnet_finalize() when the sink
2243 * data has been received.
2245 * CAVEAT EMPTOR: 'getmsg' is the original GET, which is freed when
2246 * lnet_finalize() is called on it, so the LND must call this first
2248 struct lnet_msg
*msg
= lnet_msg_alloc();
2249 struct lnet_libmd
*getmd
= getmsg
->msg_md
;
2250 lnet_process_id_t peer_id
= getmsg
->msg_target
;
2253 LASSERT(!getmsg
->msg_target_is_router
);
2254 LASSERT(!getmsg
->msg_routing
);
2257 CERROR("%s: Dropping REPLY from %s: can't allocate msg\n",
2258 libcfs_nid2str(ni
->ni_nid
), libcfs_id2str(peer_id
));
2262 cpt
= lnet_cpt_of_cookie(getmd
->md_lh
.lh_cookie
);
2265 LASSERT(getmd
->md_refcount
> 0);
2267 if (!getmd
->md_threshold
) {
2268 CERROR("%s: Dropping REPLY from %s for inactive MD %p\n",
2269 libcfs_nid2str(ni
->ni_nid
), libcfs_id2str(peer_id
),
2271 lnet_res_unlock(cpt
);
2275 LASSERT(!getmd
->md_offset
);
2277 CDEBUG(D_NET
, "%s: Reply from %s md %p\n",
2278 libcfs_nid2str(ni
->ni_nid
), libcfs_id2str(peer_id
), getmd
);
2280 /* setup information for lnet_build_msg_event */
2281 msg
->msg_from
= peer_id
.nid
;
2282 msg
->msg_type
= LNET_MSG_GET
; /* flag this msg as an "optimized" GET */
2283 msg
->msg_hdr
.src_nid
= peer_id
.nid
;
2284 msg
->msg_hdr
.payload_length
= getmd
->md_length
;
2285 msg
->msg_receiving
= 1; /* required by lnet_msg_attach_md */
2287 lnet_msg_attach_md(msg
, getmd
, getmd
->md_offset
, getmd
->md_length
);
2288 lnet_res_unlock(cpt
);
2290 cpt
= lnet_cpt_of_nid(peer_id
.nid
);
2293 lnet_msg_commit(msg
, cpt
);
2294 lnet_net_unlock(cpt
);
2296 lnet_build_msg_event(msg
, LNET_EVENT_REPLY
);
2301 cpt
= lnet_cpt_of_nid(peer_id
.nid
);
2304 the_lnet
.ln_counters
[cpt
]->drop_count
++;
2305 the_lnet
.ln_counters
[cpt
]->drop_length
+= getmd
->md_length
;
2306 lnet_net_unlock(cpt
);
2313 EXPORT_SYMBOL(lnet_create_reply_msg
);
2316 lnet_set_reply_msg_len(lnet_ni_t
*ni
, lnet_msg_t
*reply
, unsigned int len
)
2319 * Set the REPLY length, now the RDMA that elides the REPLY message has
2320 * completed and I know it.
2323 LASSERT(reply
->msg_type
== LNET_MSG_GET
);
2324 LASSERT(reply
->msg_ev
.type
== LNET_EVENT_REPLY
);
2327 * NB I trusted my peer to RDMA. If she tells me she's written beyond
2328 * the end of my buffer, I might as well be dead.
2330 LASSERT(len
<= reply
->msg_ev
.mlength
);
2332 reply
->msg_ev
.mlength
= len
;
2334 EXPORT_SYMBOL(lnet_set_reply_msg_len
);
2337 * Initiate an asynchronous GET operation.
2339 * On the initiator node, an LNET_EVENT_SEND is logged when the GET request
2340 * is sent, and an LNET_EVENT_REPLY is logged when the data returned from
2341 * the target node in the REPLY has been written to local MD.
2343 * On the target node, an LNET_EVENT_GET is logged when the GET request
2344 * arrives and is accepted into a MD.
2346 * \param self,target,portal,match_bits,offset See the discussion in LNetPut().
2347 * \param mdh A handle for the MD that describes the memory into which the
2348 * requested data will be received. The MD must be "free floating"
2349 * (See LNetMDBind()).
2351 * \retval 0 Success, and only in this case events will be generated
2352 * and logged to EQ (if it exists) of the MD.
2353 * \retval -EIO Simulated failure.
2354 * \retval -ENOMEM Memory allocation failure.
2355 * \retval -ENOENT Invalid MD object.
2358 LNetGet(lnet_nid_t self
, lnet_handle_md_t mdh
,
2359 lnet_process_id_t target
, unsigned int portal
,
2360 __u64 match_bits
, unsigned int offset
)
2362 struct lnet_msg
*msg
;
2363 struct lnet_libmd
*md
;
2367 LASSERT(the_lnet
.ln_refcount
> 0);
2369 if (!list_empty(&the_lnet
.ln_test_peers
) && /* normally we don't */
2370 fail_peer(target
.nid
, 1)) { /* shall we now? */
2371 CERROR("Dropping GET to %s: simulated failure\n",
2372 libcfs_id2str(target
));
2376 msg
= lnet_msg_alloc();
2378 CERROR("Dropping GET to %s: ENOMEM on lnet_msg_t\n",
2379 libcfs_id2str(target
));
2383 cpt
= lnet_cpt_of_cookie(mdh
.cookie
);
2386 md
= lnet_handle2md(&mdh
);
2387 if (!md
|| !md
->md_threshold
|| md
->md_me
) {
2388 CERROR("Dropping GET (%llu:%d:%s): MD (%d) invalid\n",
2389 match_bits
, portal
, libcfs_id2str(target
),
2390 !md
? -1 : md
->md_threshold
);
2391 if (md
&& md
->md_me
)
2392 CERROR("REPLY MD also attached to portal %d\n",
2393 md
->md_me
->me_portal
);
2395 lnet_res_unlock(cpt
);
2401 CDEBUG(D_NET
, "LNetGet -> %s\n", libcfs_id2str(target
));
2403 lnet_msg_attach_md(msg
, md
, 0, 0);
2405 lnet_prep_send(msg
, LNET_MSG_GET
, target
, 0, 0);
2407 msg
->msg_hdr
.msg
.get
.match_bits
= cpu_to_le64(match_bits
);
2408 msg
->msg_hdr
.msg
.get
.ptl_index
= cpu_to_le32(portal
);
2409 msg
->msg_hdr
.msg
.get
.src_offset
= cpu_to_le32(offset
);
2410 msg
->msg_hdr
.msg
.get
.sink_length
= cpu_to_le32(md
->md_length
);
2412 /* NB handles only looked up by creator (no flips) */
2413 msg
->msg_hdr
.msg
.get
.return_wmd
.wh_interface_cookie
=
2414 the_lnet
.ln_interface_cookie
;
2415 msg
->msg_hdr
.msg
.get
.return_wmd
.wh_object_cookie
=
2416 md
->md_lh
.lh_cookie
;
2418 lnet_res_unlock(cpt
);
2420 lnet_build_msg_event(msg
, LNET_EVENT_SEND
);
2422 rc
= lnet_send(self
, msg
, LNET_NID_ANY
);
2424 CNETERR("Error sending GET to %s: %d\n",
2425 libcfs_id2str(target
), rc
);
2426 lnet_finalize(NULL
, msg
, rc
);
2429 /* completion will be signalled by an event */
2432 EXPORT_SYMBOL(LNetGet
);
2435 * Calculate distance to node at \a dstnid.
2437 * \param dstnid Target NID.
2438 * \param srcnidp If not NULL, NID of the local interface to reach \a dstnid
2440 * \param orderp If not NULL, order of the route to reach \a dstnid is saved
2443 * \retval 0 If \a dstnid belongs to a local interface, and reserved option
2444 * local_nid_dist_zero is set, which is the default.
2445 * \retval positives Distance to target NID, i.e. number of hops plus one.
2446 * \retval -EHOSTUNREACH If \a dstnid is not reachable.
2449 LNetDist(lnet_nid_t dstnid
, lnet_nid_t
*srcnidp
, __u32
*orderp
)
2451 struct list_head
*e
;
2453 lnet_remotenet_t
*rnet
;
2454 __u32 dstnet
= LNET_NIDNET(dstnid
);
2458 struct list_head
*rn_list
;
2461 * if !local_nid_dist_zero, I don't return a distance of 0 ever
2462 * (when lustre sees a distance of 0, it substitutes 0@lo), so I
2463 * keep order 0 free for 0@lo and order 1 free for a local NID
2466 LASSERT(the_lnet
.ln_refcount
> 0);
2468 cpt
= lnet_net_lock_current();
2470 list_for_each(e
, &the_lnet
.ln_nis
) {
2471 ni
= list_entry(e
, lnet_ni_t
, ni_list
);
2473 if (ni
->ni_nid
== dstnid
) {
2477 if (LNET_NETTYP(LNET_NIDNET(dstnid
)) == LOLND
)
2482 lnet_net_unlock(cpt
);
2484 return local_nid_dist_zero
? 0 : 1;
2487 if (LNET_NIDNET(ni
->ni_nid
) == dstnet
) {
2489 *srcnidp
= ni
->ni_nid
;
2492 lnet_net_unlock(cpt
);
2499 rn_list
= lnet_net2rnethash(dstnet
);
2500 list_for_each(e
, rn_list
) {
2501 rnet
= list_entry(e
, lnet_remotenet_t
, lrn_list
);
2503 if (rnet
->lrn_net
== dstnet
) {
2504 lnet_route_t
*route
;
2505 lnet_route_t
*shortest
= NULL
;
2507 LASSERT(!list_empty(&rnet
->lrn_routes
));
2509 list_for_each_entry(route
, &rnet
->lrn_routes
,
2512 route
->lr_hops
< shortest
->lr_hops
)
2517 hops
= shortest
->lr_hops
;
2519 *srcnidp
= shortest
->lr_gateway
->lp_ni
->ni_nid
;
2522 lnet_net_unlock(cpt
);
2528 lnet_net_unlock(cpt
);
2529 return -EHOSTUNREACH
;
2531 EXPORT_SYMBOL(LNetDist
);