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, 2012, 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 <linux/lnet/lib-lnet.h>
45 static int local_nid_dist_zero
= 1;
46 CFS_MODULE_PARM(local_nid_dist_zero
, "i", int, 0444,
50 lnet_fail_nid(lnet_nid_t nid
, unsigned int threshold
)
54 struct list_head
*next
;
55 struct list_head cull
;
57 LASSERT(the_lnet
.ln_init
);
59 /* NB: use lnet_net_lock(0) to serialize operations on test peers */
61 /* Adding a new entry */
62 LIBCFS_ALLOC(tp
, sizeof(*tp
));
67 tp
->tp_threshold
= threshold
;
70 list_add_tail(&tp
->tp_list
, &the_lnet
.ln_test_peers
);
75 /* removing entries */
76 INIT_LIST_HEAD(&cull
);
80 list_for_each_safe(el
, next
, &the_lnet
.ln_test_peers
) {
81 tp
= list_entry(el
, lnet_test_peer_t
, tp_list
);
83 if (tp
->tp_threshold
== 0 || /* needs culling anyway */
84 nid
== LNET_NID_ANY
|| /* removing all entries */
85 tp
->tp_nid
== nid
) { /* matched this one */
86 list_del(&tp
->tp_list
);
87 list_add(&tp
->tp_list
, &cull
);
93 while (!list_empty(&cull
)) {
94 tp
= list_entry(cull
.next
, lnet_test_peer_t
, tp_list
);
96 list_del(&tp
->tp_list
);
97 LIBCFS_FREE(tp
, sizeof(*tp
));
103 fail_peer(lnet_nid_t nid
, int outgoing
)
105 lnet_test_peer_t
*tp
;
106 struct list_head
*el
;
107 struct list_head
*next
;
108 struct list_head cull
;
111 INIT_LIST_HEAD(&cull
);
113 /* NB: use lnet_net_lock(0) to serialize operations on test peers */
116 list_for_each_safe(el
, next
, &the_lnet
.ln_test_peers
) {
117 tp
= list_entry(el
, lnet_test_peer_t
, tp_list
);
119 if (tp
->tp_threshold
== 0) {
122 /* only cull zombies on outgoing tests,
123 * since we may be at interrupt priority on
124 * incoming messages. */
125 list_del(&tp
->tp_list
);
126 list_add(&tp
->tp_list
, &cull
);
131 if (tp
->tp_nid
== LNET_NID_ANY
|| /* fail every peer */
132 nid
== tp
->tp_nid
) { /* fail this peer */
135 if (tp
->tp_threshold
!= LNET_MD_THRESH_INF
) {
138 tp
->tp_threshold
== 0) {
140 list_del(&tp
->tp_list
);
141 list_add(&tp
->tp_list
, &cull
);
150 while (!list_empty(&cull
)) {
151 tp
= list_entry(cull
.next
, lnet_test_peer_t
, tp_list
);
152 list_del(&tp
->tp_list
);
154 LIBCFS_FREE(tp
, sizeof(*tp
));
161 lnet_iov_nob(unsigned int niov
, struct iovec
*iov
)
163 unsigned int nob
= 0;
166 nob
+= (iov
++)->iov_len
;
170 EXPORT_SYMBOL(lnet_iov_nob
);
173 lnet_copy_iov2iov(unsigned int ndiov
, struct iovec
*diov
, unsigned int doffset
,
174 unsigned int nsiov
, struct iovec
*siov
, unsigned int soffset
,
177 /* NB diov, siov are READ-ONLY */
178 unsigned int this_nob
;
183 /* skip complete frags before 'doffset' */
185 while (doffset
>= diov
->iov_len
) {
186 doffset
-= diov
->iov_len
;
192 /* skip complete frags before 'soffset' */
194 while (soffset
>= siov
->iov_len
) {
195 soffset
-= siov
->iov_len
;
204 this_nob
= MIN(diov
->iov_len
- doffset
,
205 siov
->iov_len
- soffset
);
206 this_nob
= MIN(this_nob
, nob
);
208 memcpy((char *)diov
->iov_base
+ doffset
,
209 (char *)siov
->iov_base
+ soffset
, this_nob
);
212 if (diov
->iov_len
> doffset
+ this_nob
) {
220 if (siov
->iov_len
> soffset
+ this_nob
) {
229 EXPORT_SYMBOL(lnet_copy_iov2iov
);
232 lnet_extract_iov(int dst_niov
, struct iovec
*dst
,
233 int src_niov
, struct iovec
*src
,
234 unsigned int offset
, unsigned int len
)
236 /* Initialise 'dst' to the subset of 'src' starting at 'offset',
237 * for exactly 'len' bytes, and return the number of entries.
238 * NB not destructive to 'src' */
239 unsigned int frag_len
;
242 if (len
== 0) /* no data => */
243 return 0; /* no frags */
245 LASSERT(src_niov
> 0);
246 while (offset
>= src
->iov_len
) { /* skip initial frags */
247 offset
-= src
->iov_len
;
250 LASSERT(src_niov
> 0);
255 LASSERT(src_niov
> 0);
256 LASSERT((int)niov
<= dst_niov
);
258 frag_len
= src
->iov_len
- offset
;
259 dst
->iov_base
= ((char *)src
->iov_base
) + offset
;
261 if (len
<= frag_len
) {
266 dst
->iov_len
= frag_len
;
276 EXPORT_SYMBOL(lnet_extract_iov
);
280 lnet_kiov_nob(unsigned int niov
, lnet_kiov_t
*kiov
)
282 unsigned int nob
= 0;
285 nob
+= (kiov
++)->kiov_len
;
289 EXPORT_SYMBOL(lnet_kiov_nob
);
292 lnet_copy_kiov2kiov(unsigned int ndiov
, lnet_kiov_t
*diov
, unsigned int doffset
,
293 unsigned int nsiov
, lnet_kiov_t
*siov
, unsigned int soffset
,
296 /* NB diov, siov are READ-ONLY */
297 unsigned int this_nob
;
304 LASSERT(!in_interrupt());
307 while (doffset
>= diov
->kiov_len
) {
308 doffset
-= diov
->kiov_len
;
315 while (soffset
>= siov
->kiov_len
) {
316 soffset
-= siov
->kiov_len
;
325 this_nob
= MIN(diov
->kiov_len
- doffset
,
326 siov
->kiov_len
- soffset
);
327 this_nob
= MIN(this_nob
, nob
);
330 daddr
= ((char *)kmap(diov
->kiov_page
)) +
331 diov
->kiov_offset
+ doffset
;
333 saddr
= ((char *)kmap(siov
->kiov_page
)) +
334 siov
->kiov_offset
+ soffset
;
336 /* Vanishing risk of kmap deadlock when mapping 2 pages.
337 * However in practice at least one of the kiovs will be mapped
338 * kernel pages and the map/unmap will be NOOPs */
340 memcpy(daddr
, saddr
, this_nob
);
343 if (diov
->kiov_len
> doffset
+ this_nob
) {
347 kunmap(diov
->kiov_page
);
354 if (siov
->kiov_len
> soffset
+ this_nob
) {
358 kunmap(siov
->kiov_page
);
367 kunmap(diov
->kiov_page
);
369 kunmap(siov
->kiov_page
);
371 EXPORT_SYMBOL(lnet_copy_kiov2kiov
);
374 lnet_copy_kiov2iov(unsigned int niov
, struct iovec
*iov
, unsigned int iovoffset
,
375 unsigned int nkiov
, lnet_kiov_t
*kiov
,
376 unsigned int kiovoffset
, unsigned int nob
)
378 /* NB iov, kiov are READ-ONLY */
379 unsigned int this_nob
;
385 LASSERT(!in_interrupt());
388 while (iovoffset
>= iov
->iov_len
) {
389 iovoffset
-= iov
->iov_len
;
396 while (kiovoffset
>= kiov
->kiov_len
) {
397 kiovoffset
-= kiov
->kiov_len
;
406 this_nob
= MIN(iov
->iov_len
- iovoffset
,
407 kiov
->kiov_len
- kiovoffset
);
408 this_nob
= MIN(this_nob
, nob
);
411 addr
= ((char *)kmap(kiov
->kiov_page
)) +
412 kiov
->kiov_offset
+ kiovoffset
;
414 memcpy((char *)iov
->iov_base
+ iovoffset
, addr
, this_nob
);
417 if (iov
->iov_len
> iovoffset
+ this_nob
) {
418 iovoffset
+= this_nob
;
425 if (kiov
->kiov_len
> kiovoffset
+ this_nob
) {
427 kiovoffset
+= this_nob
;
429 kunmap(kiov
->kiov_page
);
439 kunmap(kiov
->kiov_page
);
441 EXPORT_SYMBOL(lnet_copy_kiov2iov
);
444 lnet_copy_iov2kiov(unsigned int nkiov
, lnet_kiov_t
*kiov
,
445 unsigned int kiovoffset
, unsigned int niov
,
446 struct iovec
*iov
, unsigned int iovoffset
,
449 /* NB kiov, iov are READ-ONLY */
450 unsigned int this_nob
;
456 LASSERT(!in_interrupt());
459 while (kiovoffset
>= kiov
->kiov_len
) {
460 kiovoffset
-= kiov
->kiov_len
;
467 while (iovoffset
>= iov
->iov_len
) {
468 iovoffset
-= iov
->iov_len
;
477 this_nob
= MIN(kiov
->kiov_len
- kiovoffset
,
478 iov
->iov_len
- iovoffset
);
479 this_nob
= MIN(this_nob
, nob
);
482 addr
= ((char *)kmap(kiov
->kiov_page
)) +
483 kiov
->kiov_offset
+ kiovoffset
;
485 memcpy(addr
, (char *)iov
->iov_base
+ iovoffset
, this_nob
);
488 if (kiov
->kiov_len
> kiovoffset
+ this_nob
) {
490 kiovoffset
+= this_nob
;
492 kunmap(kiov
->kiov_page
);
499 if (iov
->iov_len
> iovoffset
+ this_nob
) {
500 iovoffset
+= this_nob
;
509 kunmap(kiov
->kiov_page
);
511 EXPORT_SYMBOL(lnet_copy_iov2kiov
);
514 lnet_extract_kiov(int dst_niov
, lnet_kiov_t
*dst
,
515 int src_niov
, lnet_kiov_t
*src
,
516 unsigned int offset
, unsigned int len
)
518 /* Initialise 'dst' to the subset of 'src' starting at 'offset',
519 * for exactly 'len' bytes, and return the number of entries.
520 * NB not destructive to 'src' */
521 unsigned int frag_len
;
524 if (len
== 0) /* no data => */
525 return 0; /* no frags */
527 LASSERT(src_niov
> 0);
528 while (offset
>= src
->kiov_len
) { /* skip initial frags */
529 offset
-= src
->kiov_len
;
532 LASSERT(src_niov
> 0);
537 LASSERT(src_niov
> 0);
538 LASSERT((int)niov
<= dst_niov
);
540 frag_len
= src
->kiov_len
- offset
;
541 dst
->kiov_page
= src
->kiov_page
;
542 dst
->kiov_offset
= src
->kiov_offset
+ offset
;
544 if (len
<= frag_len
) {
546 LASSERT(dst
->kiov_offset
+ dst
->kiov_len
551 dst
->kiov_len
= frag_len
;
552 LASSERT(dst
->kiov_offset
+ dst
->kiov_len
<= PAGE_CACHE_SIZE
);
562 EXPORT_SYMBOL(lnet_extract_kiov
);
565 lnet_ni_recv(lnet_ni_t
*ni
, void *private, lnet_msg_t
*msg
, int delayed
,
566 unsigned int offset
, unsigned int mlen
, unsigned int rlen
)
568 unsigned int niov
= 0;
569 struct iovec
*iov
= NULL
;
570 lnet_kiov_t
*kiov
= NULL
;
573 LASSERT(!in_interrupt());
574 LASSERT(mlen
== 0 || msg
!= NULL
);
577 LASSERT(msg
->msg_receiving
);
578 LASSERT(!msg
->msg_sending
);
579 LASSERT(rlen
== msg
->msg_len
);
580 LASSERT(mlen
<= msg
->msg_len
);
581 LASSERT(msg
->msg_offset
== offset
);
582 LASSERT(msg
->msg_wanted
== mlen
);
584 msg
->msg_receiving
= 0;
587 niov
= msg
->msg_niov
;
589 kiov
= msg
->msg_kiov
;
592 LASSERT((iov
== NULL
) != (kiov
== NULL
));
596 rc
= (ni
->ni_lnd
->lnd_recv
)(ni
, private, msg
, delayed
,
597 niov
, iov
, kiov
, offset
, mlen
, rlen
);
599 lnet_finalize(ni
, msg
, rc
);
603 lnet_setpayloadbuffer(lnet_msg_t
*msg
)
605 lnet_libmd_t
*md
= msg
->msg_md
;
607 LASSERT(msg
->msg_len
> 0);
608 LASSERT(!msg
->msg_routing
);
610 LASSERT(msg
->msg_niov
== 0);
611 LASSERT(msg
->msg_iov
== NULL
);
612 LASSERT(msg
->msg_kiov
== NULL
);
614 msg
->msg_niov
= md
->md_niov
;
615 if ((md
->md_options
& LNET_MD_KIOV
) != 0)
616 msg
->msg_kiov
= md
->md_iov
.kiov
;
618 msg
->msg_iov
= md
->md_iov
.iov
;
622 lnet_prep_send(lnet_msg_t
*msg
, int type
, lnet_process_id_t target
,
623 unsigned int offset
, unsigned int len
)
625 msg
->msg_type
= type
;
626 msg
->msg_target
= target
;
628 msg
->msg_offset
= offset
;
631 lnet_setpayloadbuffer(msg
);
633 memset(&msg
->msg_hdr
, 0, sizeof(msg
->msg_hdr
));
634 msg
->msg_hdr
.type
= cpu_to_le32(type
);
635 msg
->msg_hdr
.dest_nid
= cpu_to_le64(target
.nid
);
636 msg
->msg_hdr
.dest_pid
= cpu_to_le32(target
.pid
);
637 /* src_nid will be set later */
638 msg
->msg_hdr
.src_pid
= cpu_to_le32(the_lnet
.ln_pid
);
639 msg
->msg_hdr
.payload_length
= cpu_to_le32(len
);
643 lnet_ni_send(lnet_ni_t
*ni
, lnet_msg_t
*msg
)
645 void *priv
= msg
->msg_private
;
648 LASSERT(!in_interrupt());
649 LASSERT(LNET_NETTYP(LNET_NIDNET(ni
->ni_nid
)) == LOLND
||
650 (msg
->msg_txcredit
&& msg
->msg_peertxcredit
));
652 rc
= (ni
->ni_lnd
->lnd_send
)(ni
, priv
, msg
);
654 lnet_finalize(ni
, msg
, rc
);
658 lnet_ni_eager_recv(lnet_ni_t
*ni
, lnet_msg_t
*msg
)
662 LASSERT(!msg
->msg_sending
);
663 LASSERT(msg
->msg_receiving
);
664 LASSERT(!msg
->msg_rx_ready_delay
);
665 LASSERT(ni
->ni_lnd
->lnd_eager_recv
!= NULL
);
667 msg
->msg_rx_ready_delay
= 1;
668 rc
= (ni
->ni_lnd
->lnd_eager_recv
)(ni
, msg
->msg_private
, msg
,
671 CERROR("recv from %s / send to %s aborted: "
672 "eager_recv failed %d\n",
673 libcfs_nid2str(msg
->msg_rxpeer
->lp_nid
),
674 libcfs_id2str(msg
->msg_target
), rc
);
675 LASSERT(rc
< 0); /* required by my callers */
681 /* NB: caller shall hold a ref on 'lp' as I'd drop lnet_net_lock */
683 lnet_ni_query_locked(lnet_ni_t
*ni
, lnet_peer_t
*lp
)
685 cfs_time_t last_alive
= 0;
687 LASSERT(lnet_peer_aliveness_enabled(lp
));
688 LASSERT(ni
->ni_lnd
->lnd_query
!= NULL
);
690 lnet_net_unlock(lp
->lp_cpt
);
691 (ni
->ni_lnd
->lnd_query
)(ni
, lp
->lp_nid
, &last_alive
);
692 lnet_net_lock(lp
->lp_cpt
);
694 lp
->lp_last_query
= cfs_time_current();
696 if (last_alive
!= 0) /* NI has updated timestamp */
697 lp
->lp_last_alive
= last_alive
;
700 /* NB: always called with lnet_net_lock held */
702 lnet_peer_is_alive(lnet_peer_t
*lp
, cfs_time_t now
)
707 LASSERT(lnet_peer_aliveness_enabled(lp
));
709 /* Trust lnet_notify() if it has more recent aliveness news, but
710 * ignore the initial assumed death (see lnet_peers_start_down()).
712 if (!lp
->lp_alive
&& lp
->lp_alive_count
> 0 &&
713 cfs_time_aftereq(lp
->lp_timestamp
, lp
->lp_last_alive
))
716 deadline
= cfs_time_add(lp
->lp_last_alive
,
717 cfs_time_seconds(lp
->lp_ni
->ni_peertimeout
));
718 alive
= cfs_time_after(deadline
, now
);
720 /* Update obsolete lp_alive except for routers assumed to be dead
721 * initially, because router checker would update aliveness in this
722 * case, and moreover lp_last_alive at peer creation is assumed.
724 if (alive
&& !lp
->lp_alive
&&
725 !(lnet_isrouter(lp
) && lp
->lp_alive_count
== 0))
726 lnet_notify_locked(lp
, 0, 1, lp
->lp_last_alive
);
732 /* NB: returns 1 when alive, 0 when dead, negative when error;
733 * may drop the lnet_net_lock */
735 lnet_peer_alive_locked(lnet_peer_t
*lp
)
737 cfs_time_t now
= cfs_time_current();
739 if (!lnet_peer_aliveness_enabled(lp
))
742 if (lnet_peer_is_alive(lp
, now
))
745 /* Peer appears dead, but we should avoid frequent NI queries (at
746 * most once per lnet_queryinterval seconds). */
747 if (lp
->lp_last_query
!= 0) {
748 static const int lnet_queryinterval
= 1;
750 cfs_time_t next_query
=
751 cfs_time_add(lp
->lp_last_query
,
752 cfs_time_seconds(lnet_queryinterval
));
754 if (cfs_time_before(now
, next_query
)) {
756 CWARN("Unexpected aliveness of peer %s: "
758 libcfs_nid2str(lp
->lp_nid
),
759 (int)now
, (int)next_query
,
761 lp
->lp_ni
->ni_peertimeout
);
766 /* query NI for latest aliveness news */
767 lnet_ni_query_locked(lp
->lp_ni
, lp
);
769 if (lnet_peer_is_alive(lp
, now
))
772 lnet_notify_locked(lp
, 0, 0, lp
->lp_last_alive
);
777 lnet_post_send_locked(lnet_msg_t
*msg
, int do_send
)
779 /* lnet_send is going to lnet_net_unlock immediately after this,
780 * so it sets do_send FALSE and I don't do the unlock/send/lock bit.
781 * I return EAGAIN if msg blocked, EHOSTUNREACH if msg_txpeer
782 * appears dead, and 0 if sent or OK to send */
783 struct lnet_peer
*lp
= msg
->msg_txpeer
;
784 struct lnet_ni
*ni
= lp
->lp_ni
;
785 struct lnet_tx_queue
*tq
;
788 /* non-lnet_send() callers have checked before */
789 LASSERT(!do_send
|| msg
->msg_tx_delayed
);
790 LASSERT(!msg
->msg_receiving
);
791 LASSERT(msg
->msg_tx_committed
);
793 cpt
= msg
->msg_tx_cpt
;
794 tq
= ni
->ni_tx_queues
[cpt
];
796 /* NB 'lp' is always the next hop */
797 if ((msg
->msg_target
.pid
& LNET_PID_USERFLAG
) == 0 &&
798 lnet_peer_alive_locked(lp
) == 0) {
799 the_lnet
.ln_counters
[cpt
]->drop_count
++;
800 the_lnet
.ln_counters
[cpt
]->drop_length
+= msg
->msg_len
;
801 lnet_net_unlock(cpt
);
803 CNETERR("Dropping message for %s: peer not alive\n",
804 libcfs_id2str(msg
->msg_target
));
806 lnet_finalize(ni
, msg
, -EHOSTUNREACH
);
812 if (!msg
->msg_peertxcredit
) {
813 LASSERT((lp
->lp_txcredits
< 0) ==
814 !list_empty(&lp
->lp_txq
));
816 msg
->msg_peertxcredit
= 1;
817 lp
->lp_txqnob
+= msg
->msg_len
+ sizeof(lnet_hdr_t
);
820 if (lp
->lp_txcredits
< lp
->lp_mintxcredits
)
821 lp
->lp_mintxcredits
= lp
->lp_txcredits
;
823 if (lp
->lp_txcredits
< 0) {
824 msg
->msg_tx_delayed
= 1;
825 list_add_tail(&msg
->msg_list
, &lp
->lp_txq
);
830 if (!msg
->msg_txcredit
) {
831 LASSERT((tq
->tq_credits
< 0) ==
832 !list_empty(&tq
->tq_delayed
));
834 msg
->msg_txcredit
= 1;
837 if (tq
->tq_credits
< tq
->tq_credits_min
)
838 tq
->tq_credits_min
= tq
->tq_credits
;
840 if (tq
->tq_credits
< 0) {
841 msg
->msg_tx_delayed
= 1;
842 list_add_tail(&msg
->msg_list
, &tq
->tq_delayed
);
848 lnet_net_unlock(cpt
);
849 lnet_ni_send(ni
, msg
);
857 lnet_msg2bufpool(lnet_msg_t
*msg
)
859 lnet_rtrbufpool_t
*rbp
;
862 LASSERT(msg
->msg_rx_committed
);
864 cpt
= msg
->msg_rx_cpt
;
865 rbp
= &the_lnet
.ln_rtrpools
[cpt
][0];
867 LASSERT(msg
->msg_len
<= LNET_MTU
);
868 while (msg
->msg_len
> (unsigned int)rbp
->rbp_npages
* PAGE_CACHE_SIZE
) {
870 LASSERT(rbp
< &the_lnet
.ln_rtrpools
[cpt
][LNET_NRBPOOLS
]);
877 lnet_post_routed_recv_locked(lnet_msg_t
*msg
, int do_recv
)
879 /* lnet_parse is going to lnet_net_unlock immediately after this, so it
880 * sets do_recv FALSE and I don't do the unlock/send/lock bit. I
881 * return EAGAIN if msg blocked and 0 if received or OK to receive */
882 lnet_peer_t
*lp
= msg
->msg_rxpeer
;
883 lnet_rtrbufpool_t
*rbp
;
886 LASSERT(msg
->msg_iov
== NULL
);
887 LASSERT(msg
->msg_kiov
== NULL
);
888 LASSERT(msg
->msg_niov
== 0);
889 LASSERT(msg
->msg_routing
);
890 LASSERT(msg
->msg_receiving
);
891 LASSERT(!msg
->msg_sending
);
893 /* non-lnet_parse callers only receive delayed messages */
894 LASSERT(!do_recv
|| msg
->msg_rx_delayed
);
896 if (!msg
->msg_peerrtrcredit
) {
897 LASSERT((lp
->lp_rtrcredits
< 0) ==
898 !list_empty(&lp
->lp_rtrq
));
900 msg
->msg_peerrtrcredit
= 1;
902 if (lp
->lp_rtrcredits
< lp
->lp_minrtrcredits
)
903 lp
->lp_minrtrcredits
= lp
->lp_rtrcredits
;
905 if (lp
->lp_rtrcredits
< 0) {
906 /* must have checked eager_recv before here */
907 LASSERT(msg
->msg_rx_ready_delay
);
908 msg
->msg_rx_delayed
= 1;
909 list_add_tail(&msg
->msg_list
, &lp
->lp_rtrq
);
914 rbp
= lnet_msg2bufpool(msg
);
916 if (!msg
->msg_rtrcredit
) {
917 LASSERT((rbp
->rbp_credits
< 0) ==
918 !list_empty(&rbp
->rbp_msgs
));
920 msg
->msg_rtrcredit
= 1;
922 if (rbp
->rbp_credits
< rbp
->rbp_mincredits
)
923 rbp
->rbp_mincredits
= rbp
->rbp_credits
;
925 if (rbp
->rbp_credits
< 0) {
926 /* must have checked eager_recv before here */
927 LASSERT(msg
->msg_rx_ready_delay
);
928 msg
->msg_rx_delayed
= 1;
929 list_add_tail(&msg
->msg_list
, &rbp
->rbp_msgs
);
934 LASSERT(!list_empty(&rbp
->rbp_bufs
));
935 rb
= list_entry(rbp
->rbp_bufs
.next
, lnet_rtrbuf_t
, rb_list
);
936 list_del(&rb
->rb_list
);
938 msg
->msg_niov
= rbp
->rbp_npages
;
939 msg
->msg_kiov
= &rb
->rb_kiov
[0];
942 int cpt
= msg
->msg_rx_cpt
;
944 lnet_net_unlock(cpt
);
945 lnet_ni_recv(lp
->lp_ni
, msg
->msg_private
, msg
, 1,
946 0, msg
->msg_len
, msg
->msg_len
);
953 lnet_return_tx_credits_locked(lnet_msg_t
*msg
)
955 lnet_peer_t
*txpeer
= msg
->msg_txpeer
;
958 if (msg
->msg_txcredit
) {
959 struct lnet_ni
*ni
= txpeer
->lp_ni
;
960 struct lnet_tx_queue
*tq
= ni
->ni_tx_queues
[msg
->msg_tx_cpt
];
962 /* give back NI txcredits */
963 msg
->msg_txcredit
= 0;
965 LASSERT((tq
->tq_credits
< 0) ==
966 !list_empty(&tq
->tq_delayed
));
969 if (tq
->tq_credits
<= 0) {
970 msg2
= list_entry(tq
->tq_delayed
.next
,
971 lnet_msg_t
, msg_list
);
972 list_del(&msg2
->msg_list
);
974 LASSERT(msg2
->msg_txpeer
->lp_ni
== ni
);
975 LASSERT(msg2
->msg_tx_delayed
);
977 (void) lnet_post_send_locked(msg2
, 1);
981 if (msg
->msg_peertxcredit
) {
982 /* give back peer txcredits */
983 msg
->msg_peertxcredit
= 0;
985 LASSERT((txpeer
->lp_txcredits
< 0) ==
986 !list_empty(&txpeer
->lp_txq
));
988 txpeer
->lp_txqnob
-= msg
->msg_len
+ sizeof(lnet_hdr_t
);
989 LASSERT(txpeer
->lp_txqnob
>= 0);
991 txpeer
->lp_txcredits
++;
992 if (txpeer
->lp_txcredits
<= 0) {
993 msg2
= list_entry(txpeer
->lp_txq
.next
,
994 lnet_msg_t
, msg_list
);
995 list_del(&msg2
->msg_list
);
997 LASSERT(msg2
->msg_txpeer
== txpeer
);
998 LASSERT(msg2
->msg_tx_delayed
);
1000 (void) lnet_post_send_locked(msg2
, 1);
1004 if (txpeer
!= NULL
) {
1005 msg
->msg_txpeer
= NULL
;
1006 lnet_peer_decref_locked(txpeer
);
1011 lnet_return_rx_credits_locked(lnet_msg_t
*msg
)
1013 lnet_peer_t
*rxpeer
= msg
->msg_rxpeer
;
1016 if (msg
->msg_rtrcredit
) {
1017 /* give back global router credits */
1019 lnet_rtrbufpool_t
*rbp
;
1021 /* NB If a msg ever blocks for a buffer in rbp_msgs, it stays
1022 * there until it gets one allocated, or aborts the wait
1024 LASSERT(msg
->msg_kiov
!= NULL
);
1026 rb
= list_entry(msg
->msg_kiov
, lnet_rtrbuf_t
, rb_kiov
[0]);
1028 LASSERT(rbp
== lnet_msg2bufpool(msg
));
1030 msg
->msg_kiov
= NULL
;
1031 msg
->msg_rtrcredit
= 0;
1033 LASSERT((rbp
->rbp_credits
< 0) ==
1034 !list_empty(&rbp
->rbp_msgs
));
1035 LASSERT((rbp
->rbp_credits
> 0) ==
1036 !list_empty(&rbp
->rbp_bufs
));
1038 list_add(&rb
->rb_list
, &rbp
->rbp_bufs
);
1040 if (rbp
->rbp_credits
<= 0) {
1041 msg2
= list_entry(rbp
->rbp_msgs
.next
,
1042 lnet_msg_t
, msg_list
);
1043 list_del(&msg2
->msg_list
);
1045 (void) lnet_post_routed_recv_locked(msg2
, 1);
1049 if (msg
->msg_peerrtrcredit
) {
1050 /* give back peer router credits */
1051 msg
->msg_peerrtrcredit
= 0;
1053 LASSERT((rxpeer
->lp_rtrcredits
< 0) ==
1054 !list_empty(&rxpeer
->lp_rtrq
));
1056 rxpeer
->lp_rtrcredits
++;
1057 if (rxpeer
->lp_rtrcredits
<= 0) {
1058 msg2
= list_entry(rxpeer
->lp_rtrq
.next
,
1059 lnet_msg_t
, msg_list
);
1060 list_del(&msg2
->msg_list
);
1062 (void) lnet_post_routed_recv_locked(msg2
, 1);
1065 if (rxpeer
!= NULL
) {
1066 msg
->msg_rxpeer
= NULL
;
1067 lnet_peer_decref_locked(rxpeer
);
1072 lnet_compare_routes(lnet_route_t
*r1
, lnet_route_t
*r2
)
1074 lnet_peer_t
*p1
= r1
->lr_gateway
;
1075 lnet_peer_t
*p2
= r2
->lr_gateway
;
1077 if (r1
->lr_hops
< r2
->lr_hops
)
1080 if (r1
->lr_hops
> r2
->lr_hops
)
1083 if (p1
->lp_txqnob
< p2
->lp_txqnob
)
1086 if (p1
->lp_txqnob
> p2
->lp_txqnob
)
1089 if (p1
->lp_txcredits
> p2
->lp_txcredits
)
1092 if (p1
->lp_txcredits
< p2
->lp_txcredits
)
1095 if (r1
->lr_seq
- r2
->lr_seq
<= 0)
1101 static lnet_peer_t
*
1102 lnet_find_route_locked(lnet_ni_t
*ni
, lnet_nid_t target
, lnet_nid_t rtr_nid
)
1104 lnet_remotenet_t
*rnet
;
1106 lnet_route_t
*rtr_best
;
1107 lnet_route_t
*rtr_last
;
1108 struct lnet_peer
*lp_best
;
1109 struct lnet_peer
*lp
;
1112 /* If @rtr_nid is not LNET_NID_ANY, return the gateway with
1113 * rtr_nid nid, otherwise find the best gateway I can use */
1115 rnet
= lnet_find_net_locked(LNET_NIDNET(target
));
1120 rtr_best
= rtr_last
= NULL
;
1121 list_for_each_entry(rtr
, &rnet
->lrn_routes
, lr_list
) {
1122 lp
= rtr
->lr_gateway
;
1124 if (!lp
->lp_alive
|| /* gateway is down */
1125 ((lp
->lp_ping_feats
& LNET_PING_FEAT_NI_STATUS
) != 0 &&
1126 rtr
->lr_downis
!= 0)) /* NI to target is down */
1129 if (ni
!= NULL
&& lp
->lp_ni
!= ni
)
1132 if (lp
->lp_nid
== rtr_nid
) /* it's pre-determined router */
1135 if (lp_best
== NULL
) {
1136 rtr_best
= rtr_last
= rtr
;
1141 /* no protection on below fields, but it's harmless */
1142 if (rtr_last
->lr_seq
- rtr
->lr_seq
< 0)
1145 rc
= lnet_compare_routes(rtr
, rtr_best
);
1153 /* set sequence number on the best router to the latest sequence + 1
1154 * so we can round-robin all routers, it's race and inaccurate but
1155 * harmless and functional */
1156 if (rtr_best
!= NULL
)
1157 rtr_best
->lr_seq
= rtr_last
->lr_seq
+ 1;
1162 lnet_send(lnet_nid_t src_nid
, lnet_msg_t
*msg
, lnet_nid_t rtr_nid
)
1164 lnet_nid_t dst_nid
= msg
->msg_target
.nid
;
1165 struct lnet_ni
*src_ni
;
1166 struct lnet_ni
*local_ni
;
1167 struct lnet_peer
*lp
;
1172 /* NB: rtr_nid is set to LNET_NID_ANY for all current use-cases,
1173 * but we might want to use pre-determined router for ACK/REPLY
1175 /* NB: ni != NULL == interface pre-determined (ACK/REPLY) */
1176 LASSERT(msg
->msg_txpeer
== NULL
);
1177 LASSERT(!msg
->msg_sending
);
1178 LASSERT(!msg
->msg_target_is_router
);
1179 LASSERT(!msg
->msg_receiving
);
1181 msg
->msg_sending
= 1;
1183 LASSERT(!msg
->msg_tx_committed
);
1184 cpt
= lnet_cpt_of_nid(rtr_nid
== LNET_NID_ANY
? dst_nid
: rtr_nid
);
1188 if (the_lnet
.ln_shutdown
) {
1189 lnet_net_unlock(cpt
);
1193 if (src_nid
== LNET_NID_ANY
) {
1196 src_ni
= lnet_nid2ni_locked(src_nid
, cpt
);
1197 if (src_ni
== NULL
) {
1198 lnet_net_unlock(cpt
);
1199 LCONSOLE_WARN("Can't send to %s: src %s is not a "
1200 "local nid\n", libcfs_nid2str(dst_nid
),
1201 libcfs_nid2str(src_nid
));
1204 LASSERT(!msg
->msg_routing
);
1207 /* Is this for someone on a local network? */
1208 local_ni
= lnet_net2ni_locked(LNET_NIDNET(dst_nid
), cpt
);
1210 if (local_ni
!= NULL
) {
1211 if (src_ni
== NULL
) {
1213 src_nid
= src_ni
->ni_nid
;
1214 } else if (src_ni
== local_ni
) {
1215 lnet_ni_decref_locked(local_ni
, cpt
);
1217 lnet_ni_decref_locked(local_ni
, cpt
);
1218 lnet_ni_decref_locked(src_ni
, cpt
);
1219 lnet_net_unlock(cpt
);
1220 LCONSOLE_WARN("No route to %s via from %s\n",
1221 libcfs_nid2str(dst_nid
),
1222 libcfs_nid2str(src_nid
));
1226 LASSERT(src_nid
!= LNET_NID_ANY
);
1227 lnet_msg_commit(msg
, cpt
);
1229 if (!msg
->msg_routing
)
1230 msg
->msg_hdr
.src_nid
= cpu_to_le64(src_nid
);
1232 if (src_ni
== the_lnet
.ln_loni
) {
1233 /* No send credit hassles with LOLND */
1234 lnet_net_unlock(cpt
);
1235 lnet_ni_send(src_ni
, msg
);
1238 lnet_ni_decref_locked(src_ni
, cpt
);
1239 lnet_net_unlock(cpt
);
1243 rc
= lnet_nid2peer_locked(&lp
, dst_nid
, cpt
);
1244 /* lp has ref on src_ni; lose mine */
1245 lnet_ni_decref_locked(src_ni
, cpt
);
1247 lnet_net_unlock(cpt
);
1248 LCONSOLE_WARN("Error %d finding peer %s\n", rc
,
1249 libcfs_nid2str(dst_nid
));
1250 /* ENOMEM or shutting down */
1253 LASSERT(lp
->lp_ni
== src_ni
);
1255 /* sending to a remote network */
1256 lp
= lnet_find_route_locked(src_ni
, dst_nid
, rtr_nid
);
1259 lnet_ni_decref_locked(src_ni
, cpt
);
1260 lnet_net_unlock(cpt
);
1262 LCONSOLE_WARN("No route to %s via %s "
1263 "(all routers down)\n",
1264 libcfs_id2str(msg
->msg_target
),
1265 libcfs_nid2str(src_nid
));
1266 return -EHOSTUNREACH
;
1269 /* rtr_nid is LNET_NID_ANY or NID of pre-determined router,
1270 * it's possible that rtr_nid isn't LNET_NID_ANY and lp isn't
1271 * pre-determined router, this can happen if router table
1272 * was changed when we release the lock */
1273 if (rtr_nid
!= lp
->lp_nid
) {
1274 cpt2
= lnet_cpt_of_nid_locked(lp
->lp_nid
);
1277 lnet_ni_decref_locked(src_ni
, cpt
);
1278 lnet_net_unlock(cpt
);
1280 rtr_nid
= lp
->lp_nid
;
1286 CDEBUG(D_NET
, "Best route to %s via %s for %s %d\n",
1287 libcfs_nid2str(dst_nid
), libcfs_nid2str(lp
->lp_nid
),
1288 lnet_msgtyp2str(msg
->msg_type
), msg
->msg_len
);
1290 if (src_ni
== NULL
) {
1292 src_nid
= src_ni
->ni_nid
;
1294 LASSERT(src_ni
== lp
->lp_ni
);
1295 lnet_ni_decref_locked(src_ni
, cpt
);
1298 lnet_peer_addref_locked(lp
);
1300 LASSERT(src_nid
!= LNET_NID_ANY
);
1301 lnet_msg_commit(msg
, cpt
);
1303 if (!msg
->msg_routing
) {
1304 /* I'm the source and now I know which NI to send on */
1305 msg
->msg_hdr
.src_nid
= cpu_to_le64(src_nid
);
1308 msg
->msg_target_is_router
= 1;
1309 msg
->msg_target
.nid
= lp
->lp_nid
;
1310 msg
->msg_target
.pid
= LUSTRE_SRV_LNET_PID
;
1313 /* 'lp' is our best choice of peer */
1315 LASSERT(!msg
->msg_peertxcredit
);
1316 LASSERT(!msg
->msg_txcredit
);
1317 LASSERT(msg
->msg_txpeer
== NULL
);
1319 msg
->msg_txpeer
= lp
; /* msg takes my ref on lp */
1321 rc
= lnet_post_send_locked(msg
, 0);
1322 lnet_net_unlock(cpt
);
1324 if (rc
== EHOSTUNREACH
)
1325 return -EHOSTUNREACH
;
1328 lnet_ni_send(src_ni
, msg
);
1334 lnet_drop_message(lnet_ni_t
*ni
, int cpt
, void *private, unsigned int nob
)
1337 the_lnet
.ln_counters
[cpt
]->drop_count
++;
1338 the_lnet
.ln_counters
[cpt
]->drop_length
+= nob
;
1339 lnet_net_unlock(cpt
);
1341 lnet_ni_recv(ni
, private, NULL
, 0, 0, 0, nob
);
1345 lnet_recv_put(lnet_ni_t
*ni
, lnet_msg_t
*msg
)
1347 lnet_hdr_t
*hdr
= &msg
->msg_hdr
;
1349 if (msg
->msg_wanted
!= 0)
1350 lnet_setpayloadbuffer(msg
);
1352 lnet_build_msg_event(msg
, LNET_EVENT_PUT
);
1354 /* Must I ACK? If so I'll grab the ack_wmd out of the header and put
1355 * it back into the ACK during lnet_finalize() */
1356 msg
->msg_ack
= (!lnet_is_wire_handle_none(&hdr
->msg
.put
.ack_wmd
) &&
1357 (msg
->msg_md
->md_options
& LNET_MD_ACK_DISABLE
) == 0);
1359 lnet_ni_recv(ni
, msg
->msg_private
, msg
, msg
->msg_rx_delayed
,
1360 msg
->msg_offset
, msg
->msg_wanted
, hdr
->payload_length
);
1364 lnet_parse_put(lnet_ni_t
*ni
, lnet_msg_t
*msg
)
1366 lnet_hdr_t
*hdr
= &msg
->msg_hdr
;
1367 struct lnet_match_info info
;
1370 /* Convert put fields to host byte order */
1371 hdr
->msg
.put
.match_bits
= le64_to_cpu(hdr
->msg
.put
.match_bits
);
1372 hdr
->msg
.put
.ptl_index
= le32_to_cpu(hdr
->msg
.put
.ptl_index
);
1373 hdr
->msg
.put
.offset
= le32_to_cpu(hdr
->msg
.put
.offset
);
1375 info
.mi_id
.nid
= hdr
->src_nid
;
1376 info
.mi_id
.pid
= hdr
->src_pid
;
1377 info
.mi_opc
= LNET_MD_OP_PUT
;
1378 info
.mi_portal
= hdr
->msg
.put
.ptl_index
;
1379 info
.mi_rlength
= hdr
->payload_length
;
1380 info
.mi_roffset
= hdr
->msg
.put
.offset
;
1381 info
.mi_mbits
= hdr
->msg
.put
.match_bits
;
1383 msg
->msg_rx_ready_delay
= ni
->ni_lnd
->lnd_eager_recv
== NULL
;
1386 rc
= lnet_ptl_match_md(&info
, msg
);
1391 case LNET_MATCHMD_OK
:
1392 lnet_recv_put(ni
, msg
);
1395 case LNET_MATCHMD_NONE
:
1396 if (msg
->msg_rx_delayed
) /* attached on delayed list */
1399 rc
= lnet_ni_eager_recv(ni
, msg
);
1404 case LNET_MATCHMD_DROP
:
1405 CNETERR("Dropping PUT from %s portal %d match "LPU64
1406 " offset %d length %d: %d\n",
1407 libcfs_id2str(info
.mi_id
), info
.mi_portal
,
1408 info
.mi_mbits
, info
.mi_roffset
, info
.mi_rlength
, rc
);
1410 return ENOENT
; /* +ve: OK but no match */
1415 lnet_parse_get(lnet_ni_t
*ni
, lnet_msg_t
*msg
, int rdma_get
)
1417 struct lnet_match_info info
;
1418 lnet_hdr_t
*hdr
= &msg
->msg_hdr
;
1419 lnet_handle_wire_t reply_wmd
;
1422 /* Convert get fields to host byte order */
1423 hdr
->msg
.get
.match_bits
= le64_to_cpu(hdr
->msg
.get
.match_bits
);
1424 hdr
->msg
.get
.ptl_index
= le32_to_cpu(hdr
->msg
.get
.ptl_index
);
1425 hdr
->msg
.get
.sink_length
= le32_to_cpu(hdr
->msg
.get
.sink_length
);
1426 hdr
->msg
.get
.src_offset
= le32_to_cpu(hdr
->msg
.get
.src_offset
);
1428 info
.mi_id
.nid
= hdr
->src_nid
;
1429 info
.mi_id
.pid
= hdr
->src_pid
;
1430 info
.mi_opc
= LNET_MD_OP_GET
;
1431 info
.mi_portal
= hdr
->msg
.get
.ptl_index
;
1432 info
.mi_rlength
= hdr
->msg
.get
.sink_length
;
1433 info
.mi_roffset
= hdr
->msg
.get
.src_offset
;
1434 info
.mi_mbits
= hdr
->msg
.get
.match_bits
;
1436 rc
= lnet_ptl_match_md(&info
, msg
);
1437 if (rc
== LNET_MATCHMD_DROP
) {
1438 CNETERR("Dropping GET from %s portal %d match "LPU64
1439 " offset %d length %d\n",
1440 libcfs_id2str(info
.mi_id
), info
.mi_portal
,
1441 info
.mi_mbits
, info
.mi_roffset
, info
.mi_rlength
);
1442 return ENOENT
; /* +ve: OK but no match */
1445 LASSERT(rc
== LNET_MATCHMD_OK
);
1447 lnet_build_msg_event(msg
, LNET_EVENT_GET
);
1449 reply_wmd
= hdr
->msg
.get
.return_wmd
;
1451 lnet_prep_send(msg
, LNET_MSG_REPLY
, info
.mi_id
,
1452 msg
->msg_offset
, msg
->msg_wanted
);
1454 msg
->msg_hdr
.msg
.reply
.dst_wmd
= reply_wmd
;
1457 /* The LND completes the REPLY from her recv procedure */
1458 lnet_ni_recv(ni
, msg
->msg_private
, msg
, 0,
1459 msg
->msg_offset
, msg
->msg_len
, msg
->msg_len
);
1463 lnet_ni_recv(ni
, msg
->msg_private
, NULL
, 0, 0, 0, 0);
1464 msg
->msg_receiving
= 0;
1466 rc
= lnet_send(ni
->ni_nid
, msg
, LNET_NID_ANY
);
1468 /* didn't get as far as lnet_ni_send() */
1469 CERROR("%s: Unable to send REPLY for GET from %s: %d\n",
1470 libcfs_nid2str(ni
->ni_nid
),
1471 libcfs_id2str(info
.mi_id
), rc
);
1473 lnet_finalize(ni
, msg
, rc
);
1480 lnet_parse_reply(lnet_ni_t
*ni
, lnet_msg_t
*msg
)
1482 void *private = msg
->msg_private
;
1483 lnet_hdr_t
*hdr
= &msg
->msg_hdr
;
1484 lnet_process_id_t src
= {0};
1490 cpt
= lnet_cpt_of_cookie(hdr
->msg
.reply
.dst_wmd
.wh_object_cookie
);
1493 src
.nid
= hdr
->src_nid
;
1494 src
.pid
= hdr
->src_pid
;
1496 /* NB handles only looked up by creator (no flips) */
1497 md
= lnet_wire_handle2md(&hdr
->msg
.reply
.dst_wmd
);
1498 if (md
== NULL
|| md
->md_threshold
== 0 || md
->md_me
!= NULL
) {
1499 CNETERR("%s: Dropping REPLY from %s for %s "
1500 "MD "LPX64
"."LPX64
"\n",
1501 libcfs_nid2str(ni
->ni_nid
), libcfs_id2str(src
),
1502 (md
== NULL
) ? "invalid" : "inactive",
1503 hdr
->msg
.reply
.dst_wmd
.wh_interface_cookie
,
1504 hdr
->msg
.reply
.dst_wmd
.wh_object_cookie
);
1505 if (md
!= NULL
&& md
->md_me
!= NULL
)
1506 CERROR("REPLY MD also attached to portal %d\n",
1507 md
->md_me
->me_portal
);
1509 lnet_res_unlock(cpt
);
1510 return ENOENT
; /* +ve: OK but no match */
1513 LASSERT(md
->md_offset
== 0);
1515 rlength
= hdr
->payload_length
;
1516 mlength
= MIN(rlength
, (int)md
->md_length
);
1518 if (mlength
< rlength
&&
1519 (md
->md_options
& LNET_MD_TRUNCATE
) == 0) {
1520 CNETERR("%s: Dropping REPLY from %s length %d "
1521 "for MD "LPX64
" would overflow (%d)\n",
1522 libcfs_nid2str(ni
->ni_nid
), libcfs_id2str(src
),
1523 rlength
, hdr
->msg
.reply
.dst_wmd
.wh_object_cookie
,
1525 lnet_res_unlock(cpt
);
1526 return ENOENT
; /* +ve: OK but no match */
1529 CDEBUG(D_NET
, "%s: Reply from %s of length %d/%d into md "LPX64
"\n",
1530 libcfs_nid2str(ni
->ni_nid
), libcfs_id2str(src
),
1531 mlength
, rlength
, hdr
->msg
.reply
.dst_wmd
.wh_object_cookie
);
1533 lnet_msg_attach_md(msg
, md
, 0, mlength
);
1536 lnet_setpayloadbuffer(msg
);
1538 lnet_res_unlock(cpt
);
1540 lnet_build_msg_event(msg
, LNET_EVENT_REPLY
);
1542 lnet_ni_recv(ni
, private, msg
, 0, 0, mlength
, rlength
);
1547 lnet_parse_ack(lnet_ni_t
*ni
, lnet_msg_t
*msg
)
1549 lnet_hdr_t
*hdr
= &msg
->msg_hdr
;
1550 lnet_process_id_t src
= {0};
1554 src
.nid
= hdr
->src_nid
;
1555 src
.pid
= hdr
->src_pid
;
1557 /* Convert ack fields to host byte order */
1558 hdr
->msg
.ack
.match_bits
= le64_to_cpu(hdr
->msg
.ack
.match_bits
);
1559 hdr
->msg
.ack
.mlength
= le32_to_cpu(hdr
->msg
.ack
.mlength
);
1561 cpt
= lnet_cpt_of_cookie(hdr
->msg
.ack
.dst_wmd
.wh_object_cookie
);
1564 /* NB handles only looked up by creator (no flips) */
1565 md
= lnet_wire_handle2md(&hdr
->msg
.ack
.dst_wmd
);
1566 if (md
== NULL
|| md
->md_threshold
== 0 || md
->md_me
!= NULL
) {
1567 /* Don't moan; this is expected */
1569 "%s: Dropping ACK from %s to %s MD "LPX64
"."LPX64
"\n",
1570 libcfs_nid2str(ni
->ni_nid
), libcfs_id2str(src
),
1571 (md
== NULL
) ? "invalid" : "inactive",
1572 hdr
->msg
.ack
.dst_wmd
.wh_interface_cookie
,
1573 hdr
->msg
.ack
.dst_wmd
.wh_object_cookie
);
1574 if (md
!= NULL
&& md
->md_me
!= NULL
)
1575 CERROR("Source MD also attached to portal %d\n",
1576 md
->md_me
->me_portal
);
1578 lnet_res_unlock(cpt
);
1579 return ENOENT
; /* +ve! */
1582 CDEBUG(D_NET
, "%s: ACK from %s into md "LPX64
"\n",
1583 libcfs_nid2str(ni
->ni_nid
), libcfs_id2str(src
),
1584 hdr
->msg
.ack
.dst_wmd
.wh_object_cookie
);
1586 lnet_msg_attach_md(msg
, md
, 0, 0);
1588 lnet_res_unlock(cpt
);
1590 lnet_build_msg_event(msg
, LNET_EVENT_ACK
);
1592 lnet_ni_recv(ni
, msg
->msg_private
, msg
, 0, 0, 0, msg
->msg_len
);
1597 lnet_parse_forward_locked(lnet_ni_t
*ni
, lnet_msg_t
*msg
)
1601 if (msg
->msg_rxpeer
->lp_rtrcredits
<= 0 ||
1602 lnet_msg2bufpool(msg
)->rbp_credits
<= 0) {
1603 if (ni
->ni_lnd
->lnd_eager_recv
== NULL
) {
1604 msg
->msg_rx_ready_delay
= 1;
1606 lnet_net_unlock(msg
->msg_rx_cpt
);
1607 rc
= lnet_ni_eager_recv(ni
, msg
);
1608 lnet_net_lock(msg
->msg_rx_cpt
);
1613 rc
= lnet_post_routed_recv_locked(msg
, 0);
1618 lnet_msgtyp2str(int type
)
1627 case LNET_MSG_REPLY
:
1629 case LNET_MSG_HELLO
:
1635 EXPORT_SYMBOL(lnet_msgtyp2str
);
1638 lnet_print_hdr(lnet_hdr_t
*hdr
)
1640 lnet_process_id_t src
= {0};
1641 lnet_process_id_t dst
= {0};
1642 char *type_str
= lnet_msgtyp2str(hdr
->type
);
1644 src
.nid
= hdr
->src_nid
;
1645 src
.pid
= hdr
->src_pid
;
1647 dst
.nid
= hdr
->dest_nid
;
1648 dst
.pid
= hdr
->dest_pid
;
1650 CWARN("P3 Header at %p of type %s\n", hdr
, type_str
);
1651 CWARN(" From %s\n", libcfs_id2str(src
));
1652 CWARN(" To %s\n", libcfs_id2str(dst
));
1654 switch (hdr
->type
) {
1659 CWARN(" Ptl index %d, ack md "LPX64
"."LPX64
", "
1660 "match bits "LPU64
"\n",
1661 hdr
->msg
.put
.ptl_index
,
1662 hdr
->msg
.put
.ack_wmd
.wh_interface_cookie
,
1663 hdr
->msg
.put
.ack_wmd
.wh_object_cookie
,
1664 hdr
->msg
.put
.match_bits
);
1665 CWARN(" Length %d, offset %d, hdr data "LPX64
"\n",
1666 hdr
->payload_length
, hdr
->msg
.put
.offset
,
1667 hdr
->msg
.put
.hdr_data
);
1671 CWARN(" Ptl index %d, return md "LPX64
"."LPX64
", "
1672 "match bits "LPU64
"\n", hdr
->msg
.get
.ptl_index
,
1673 hdr
->msg
.get
.return_wmd
.wh_interface_cookie
,
1674 hdr
->msg
.get
.return_wmd
.wh_object_cookie
,
1675 hdr
->msg
.get
.match_bits
);
1676 CWARN(" Length %d, src offset %d\n",
1677 hdr
->msg
.get
.sink_length
,
1678 hdr
->msg
.get
.src_offset
);
1682 CWARN(" dst md "LPX64
"."LPX64
", "
1683 "manipulated length %d\n",
1684 hdr
->msg
.ack
.dst_wmd
.wh_interface_cookie
,
1685 hdr
->msg
.ack
.dst_wmd
.wh_object_cookie
,
1686 hdr
->msg
.ack
.mlength
);
1689 case LNET_MSG_REPLY
:
1690 CWARN(" dst md "LPX64
"."LPX64
", "
1692 hdr
->msg
.reply
.dst_wmd
.wh_interface_cookie
,
1693 hdr
->msg
.reply
.dst_wmd
.wh_object_cookie
,
1694 hdr
->payload_length
);
1700 lnet_parse(lnet_ni_t
*ni
, lnet_hdr_t
*hdr
, lnet_nid_t from_nid
,
1701 void *private, int rdma_req
)
1706 struct lnet_msg
*msg
;
1707 lnet_pid_t dest_pid
;
1708 lnet_nid_t dest_nid
;
1710 __u32 payload_length
;
1713 LASSERT(!in_interrupt());
1715 type
= le32_to_cpu(hdr
->type
);
1716 src_nid
= le64_to_cpu(hdr
->src_nid
);
1717 dest_nid
= le64_to_cpu(hdr
->dest_nid
);
1718 dest_pid
= le32_to_cpu(hdr
->dest_pid
);
1719 payload_length
= le32_to_cpu(hdr
->payload_length
);
1721 for_me
= (ni
->ni_nid
== dest_nid
);
1722 cpt
= lnet_cpt_of_nid(from_nid
);
1727 if (payload_length
> 0) {
1728 CERROR("%s, src %s: bad %s payload %d (0 expected)\n",
1729 libcfs_nid2str(from_nid
),
1730 libcfs_nid2str(src_nid
),
1731 lnet_msgtyp2str(type
), payload_length
);
1737 case LNET_MSG_REPLY
:
1738 if (payload_length
>
1739 (__u32
)(for_me
? LNET_MAX_PAYLOAD
: LNET_MTU
)) {
1740 CERROR("%s, src %s: bad %s payload %d "
1741 "(%d max expected)\n",
1742 libcfs_nid2str(from_nid
),
1743 libcfs_nid2str(src_nid
),
1744 lnet_msgtyp2str(type
),
1746 for_me
? LNET_MAX_PAYLOAD
: LNET_MTU
);
1752 CERROR("%s, src %s: Bad message type 0x%x\n",
1753 libcfs_nid2str(from_nid
),
1754 libcfs_nid2str(src_nid
), type
);
1758 if (the_lnet
.ln_routing
&&
1759 ni
->ni_last_alive
!= cfs_time_current_sec()) {
1762 /* NB: so far here is the only place to set NI status to "up */
1763 ni
->ni_last_alive
= cfs_time_current_sec();
1764 if (ni
->ni_status
!= NULL
&&
1765 ni
->ni_status
->ns_status
== LNET_NI_STATUS_DOWN
)
1766 ni
->ni_status
->ns_status
= LNET_NI_STATUS_UP
;
1770 /* Regard a bad destination NID as a protocol error. Senders should
1771 * know what they're doing; if they don't they're misconfigured, buggy
1772 * or malicious so we chop them off at the knees :) */
1775 if (LNET_NIDNET(dest_nid
) == LNET_NIDNET(ni
->ni_nid
)) {
1776 /* should have gone direct */
1777 CERROR("%s, src %s: Bad dest nid %s "
1778 "(should have been sent direct)\n",
1779 libcfs_nid2str(from_nid
),
1780 libcfs_nid2str(src_nid
),
1781 libcfs_nid2str(dest_nid
));
1785 if (lnet_islocalnid(dest_nid
)) {
1786 /* dest is another local NI; sender should have used
1787 * this node's NID on its own network */
1788 CERROR("%s, src %s: Bad dest nid %s "
1789 "(it's my nid but on a different network)\n",
1790 libcfs_nid2str(from_nid
),
1791 libcfs_nid2str(src_nid
),
1792 libcfs_nid2str(dest_nid
));
1796 if (rdma_req
&& type
== LNET_MSG_GET
) {
1797 CERROR("%s, src %s: Bad optimized GET for %s "
1798 "(final destination must be me)\n",
1799 libcfs_nid2str(from_nid
),
1800 libcfs_nid2str(src_nid
),
1801 libcfs_nid2str(dest_nid
));
1805 if (!the_lnet
.ln_routing
) {
1806 CERROR("%s, src %s: Dropping message for %s "
1807 "(routing not enabled)\n",
1808 libcfs_nid2str(from_nid
),
1809 libcfs_nid2str(src_nid
),
1810 libcfs_nid2str(dest_nid
));
1815 /* Message looks OK; we're not going to return an error, so we MUST
1816 * call back lnd_recv() come what may... */
1818 if (!list_empty(&the_lnet
.ln_test_peers
) && /* normally we don't */
1819 fail_peer(src_nid
, 0)) { /* shall we now? */
1820 CERROR("%s, src %s: Dropping %s to simulate failure\n",
1821 libcfs_nid2str(from_nid
), libcfs_nid2str(src_nid
),
1822 lnet_msgtyp2str(type
));
1826 msg
= lnet_msg_alloc();
1828 CERROR("%s, src %s: Dropping %s (out of memory)\n",
1829 libcfs_nid2str(from_nid
), libcfs_nid2str(src_nid
),
1830 lnet_msgtyp2str(type
));
1834 /* msg zeroed in lnet_msg_alloc;
1835 * i.e. flags all clear, pointers NULL etc
1838 msg
->msg_type
= type
;
1839 msg
->msg_private
= private;
1840 msg
->msg_receiving
= 1;
1841 msg
->msg_len
= msg
->msg_wanted
= payload_length
;
1842 msg
->msg_offset
= 0;
1843 msg
->msg_hdr
= *hdr
;
1844 /* for building message event */
1845 msg
->msg_from
= from_nid
;
1847 msg
->msg_target
.pid
= dest_pid
;
1848 msg
->msg_target
.nid
= dest_nid
;
1849 msg
->msg_routing
= 1;
1852 /* convert common msg->hdr fields to host byteorder */
1853 msg
->msg_hdr
.type
= type
;
1854 msg
->msg_hdr
.src_nid
= src_nid
;
1855 msg
->msg_hdr
.src_pid
= le32_to_cpu(msg
->msg_hdr
.src_pid
);
1856 msg
->msg_hdr
.dest_nid
= dest_nid
;
1857 msg
->msg_hdr
.dest_pid
= dest_pid
;
1858 msg
->msg_hdr
.payload_length
= payload_length
;
1862 rc
= lnet_nid2peer_locked(&msg
->msg_rxpeer
, from_nid
, cpt
);
1864 lnet_net_unlock(cpt
);
1865 CERROR("%s, src %s: Dropping %s "
1866 "(error %d looking up sender)\n",
1867 libcfs_nid2str(from_nid
), libcfs_nid2str(src_nid
),
1868 lnet_msgtyp2str(type
), rc
);
1873 lnet_msg_commit(msg
, cpt
);
1876 rc
= lnet_parse_forward_locked(ni
, msg
);
1877 lnet_net_unlock(cpt
);
1882 lnet_ni_recv(ni
, msg
->msg_private
, msg
, 0,
1883 0, payload_length
, payload_length
);
1888 lnet_net_unlock(cpt
);
1892 rc
= lnet_parse_ack(ni
, msg
);
1895 rc
= lnet_parse_put(ni
, msg
);
1898 rc
= lnet_parse_get(ni
, msg
, rdma_req
);
1900 case LNET_MSG_REPLY
:
1901 rc
= lnet_parse_reply(ni
, msg
);
1906 goto free_drop
; /* prevent an unused label if !kernel */
1912 LASSERT(rc
== ENOENT
);
1915 LASSERT(msg
->msg_md
== NULL
);
1916 lnet_finalize(ni
, msg
, rc
);
1919 lnet_drop_message(ni
, cpt
, private, payload_length
);
1922 EXPORT_SYMBOL(lnet_parse
);
1925 lnet_drop_delayed_msg_list(struct list_head
*head
, char *reason
)
1927 while (!list_empty(head
)) {
1928 lnet_process_id_t id
= {0};
1931 msg
= list_entry(head
->next
, lnet_msg_t
, msg_list
);
1932 list_del(&msg
->msg_list
);
1934 id
.nid
= msg
->msg_hdr
.src_nid
;
1935 id
.pid
= msg
->msg_hdr
.src_pid
;
1937 LASSERT(msg
->msg_md
== NULL
);
1938 LASSERT(msg
->msg_rx_delayed
);
1939 LASSERT(msg
->msg_rxpeer
!= NULL
);
1940 LASSERT(msg
->msg_hdr
.type
== LNET_MSG_PUT
);
1942 CWARN("Dropping delayed PUT from %s portal %d match "LPU64
1943 " offset %d length %d: %s\n",
1945 msg
->msg_hdr
.msg
.put
.ptl_index
,
1946 msg
->msg_hdr
.msg
.put
.match_bits
,
1947 msg
->msg_hdr
.msg
.put
.offset
,
1948 msg
->msg_hdr
.payload_length
, reason
);
1950 /* NB I can't drop msg's ref on msg_rxpeer until after I've
1951 * called lnet_drop_message(), so I just hang onto msg as well
1952 * until that's done */
1954 lnet_drop_message(msg
->msg_rxpeer
->lp_ni
,
1955 msg
->msg_rxpeer
->lp_cpt
,
1956 msg
->msg_private
, msg
->msg_len
);
1958 * NB: message will not generate event because w/o attached MD,
1959 * but we still should give error code so lnet_msg_decommit()
1960 * can skip counters operations and other checks.
1962 lnet_finalize(msg
->msg_rxpeer
->lp_ni
, msg
, -ENOENT
);
1967 lnet_recv_delayed_msg_list(struct list_head
*head
)
1969 while (!list_empty(head
)) {
1971 lnet_process_id_t id
;
1973 msg
= list_entry(head
->next
, lnet_msg_t
, msg_list
);
1974 list_del(&msg
->msg_list
);
1976 /* md won't disappear under me, since each msg
1977 * holds a ref on it */
1979 id
.nid
= msg
->msg_hdr
.src_nid
;
1980 id
.pid
= msg
->msg_hdr
.src_pid
;
1982 LASSERT(msg
->msg_rx_delayed
);
1983 LASSERT(msg
->msg_md
!= NULL
);
1984 LASSERT(msg
->msg_rxpeer
!= NULL
);
1985 LASSERT(msg
->msg_hdr
.type
== LNET_MSG_PUT
);
1987 CDEBUG(D_NET
, "Resuming delayed PUT from %s portal %d "
1988 "match "LPU64
" offset %d length %d.\n",
1989 libcfs_id2str(id
), msg
->msg_hdr
.msg
.put
.ptl_index
,
1990 msg
->msg_hdr
.msg
.put
.match_bits
,
1991 msg
->msg_hdr
.msg
.put
.offset
,
1992 msg
->msg_hdr
.payload_length
);
1994 lnet_recv_put(msg
->msg_rxpeer
->lp_ni
, msg
);
1999 * Initiate an asynchronous PUT operation.
2001 * There are several events associated with a PUT: completion of the send on
2002 * the initiator node (LNET_EVENT_SEND), and when the send completes
2003 * successfully, the receipt of an acknowledgment (LNET_EVENT_ACK) indicating
2004 * that the operation was accepted by the target. The event LNET_EVENT_PUT is
2005 * used at the target node to indicate the completion of incoming data
2008 * The local events will be logged in the EQ associated with the MD pointed to
2009 * by \a mdh handle. Using a MD without an associated EQ results in these
2010 * events being discarded. In this case, the caller must have another
2011 * mechanism (e.g., a higher level protocol) for determining when it is safe
2012 * to modify the memory region associated with the MD.
2014 * Note that LNet does not guarantee the order of LNET_EVENT_SEND and
2015 * LNET_EVENT_ACK, though intuitively ACK should happen after SEND.
2017 * \param self Indicates the NID of a local interface through which to send
2018 * the PUT request. Use LNET_NID_ANY to let LNet choose one by itself.
2019 * \param mdh A handle for the MD that describes the memory to be sent. The MD
2020 * must be "free floating" (See LNetMDBind()).
2021 * \param ack Controls whether an acknowledgment is requested.
2022 * Acknowledgments are only sent when they are requested by the initiating
2023 * process and the target MD enables them.
2024 * \param target A process identifier for the target process.
2025 * \param portal The index in the \a target's portal table.
2026 * \param match_bits The match bits to use for MD selection at the target
2028 * \param offset The offset into the target MD (only used when the target
2029 * MD has the LNET_MD_MANAGE_REMOTE option set).
2030 * \param hdr_data 64 bits of user data that can be included in the message
2031 * header. This data is written to an event queue entry at the target if an
2032 * EQ is present on the matching MD.
2034 * \retval 0 Success, and only in this case events will be generated
2035 * and logged to EQ (if it exists).
2036 * \retval -EIO Simulated failure.
2037 * \retval -ENOMEM Memory allocation failure.
2038 * \retval -ENOENT Invalid MD object.
2040 * \see lnet_event_t::hdr_data and lnet_event_kind_t.
2043 LNetPut(lnet_nid_t self
, lnet_handle_md_t mdh
, lnet_ack_req_t ack
,
2044 lnet_process_id_t target
, unsigned int portal
,
2045 __u64 match_bits
, unsigned int offset
,
2048 struct lnet_msg
*msg
;
2049 struct lnet_libmd
*md
;
2053 LASSERT(the_lnet
.ln_init
);
2054 LASSERT(the_lnet
.ln_refcount
> 0);
2056 if (!list_empty(&the_lnet
.ln_test_peers
) && /* normally we don't */
2057 fail_peer(target
.nid
, 1)) { /* shall we now? */
2058 CERROR("Dropping PUT to %s: simulated failure\n",
2059 libcfs_id2str(target
));
2063 msg
= lnet_msg_alloc();
2065 CERROR("Dropping PUT to %s: ENOMEM on lnet_msg_t\n",
2066 libcfs_id2str(target
));
2069 msg
->msg_vmflush
= !!memory_pressure_get();
2071 cpt
= lnet_cpt_of_cookie(mdh
.cookie
);
2074 md
= lnet_handle2md(&mdh
);
2075 if (md
== NULL
|| md
->md_threshold
== 0 || md
->md_me
!= NULL
) {
2076 CERROR("Dropping PUT ("LPU64
":%d:%s): MD (%d) invalid\n",
2077 match_bits
, portal
, libcfs_id2str(target
),
2078 md
== NULL
? -1 : md
->md_threshold
);
2079 if (md
!= NULL
&& md
->md_me
!= NULL
)
2080 CERROR("Source MD also attached to portal %d\n",
2081 md
->md_me
->me_portal
);
2082 lnet_res_unlock(cpt
);
2088 CDEBUG(D_NET
, "LNetPut -> %s\n", libcfs_id2str(target
));
2090 lnet_msg_attach_md(msg
, md
, 0, 0);
2092 lnet_prep_send(msg
, LNET_MSG_PUT
, target
, 0, md
->md_length
);
2094 msg
->msg_hdr
.msg
.put
.match_bits
= cpu_to_le64(match_bits
);
2095 msg
->msg_hdr
.msg
.put
.ptl_index
= cpu_to_le32(portal
);
2096 msg
->msg_hdr
.msg
.put
.offset
= cpu_to_le32(offset
);
2097 msg
->msg_hdr
.msg
.put
.hdr_data
= hdr_data
;
2099 /* NB handles only looked up by creator (no flips) */
2100 if (ack
== LNET_ACK_REQ
) {
2101 msg
->msg_hdr
.msg
.put
.ack_wmd
.wh_interface_cookie
=
2102 the_lnet
.ln_interface_cookie
;
2103 msg
->msg_hdr
.msg
.put
.ack_wmd
.wh_object_cookie
=
2104 md
->md_lh
.lh_cookie
;
2106 msg
->msg_hdr
.msg
.put
.ack_wmd
.wh_interface_cookie
=
2107 LNET_WIRE_HANDLE_COOKIE_NONE
;
2108 msg
->msg_hdr
.msg
.put
.ack_wmd
.wh_object_cookie
=
2109 LNET_WIRE_HANDLE_COOKIE_NONE
;
2112 lnet_res_unlock(cpt
);
2114 lnet_build_msg_event(msg
, LNET_EVENT_SEND
);
2116 rc
= lnet_send(self
, msg
, LNET_NID_ANY
);
2118 CNETERR("Error sending PUT to %s: %d\n",
2119 libcfs_id2str(target
), rc
);
2120 lnet_finalize(NULL
, msg
, rc
);
2123 /* completion will be signalled by an event */
2126 EXPORT_SYMBOL(LNetPut
);
2129 lnet_create_reply_msg(lnet_ni_t
*ni
, lnet_msg_t
*getmsg
)
2131 /* The LND can DMA direct to the GET md (i.e. no REPLY msg). This
2132 * returns a msg for the LND to pass to lnet_finalize() when the sink
2133 * data has been received.
2135 * CAVEAT EMPTOR: 'getmsg' is the original GET, which is freed when
2136 * lnet_finalize() is called on it, so the LND must call this first */
2138 struct lnet_msg
*msg
= lnet_msg_alloc();
2139 struct lnet_libmd
*getmd
= getmsg
->msg_md
;
2140 lnet_process_id_t peer_id
= getmsg
->msg_target
;
2143 LASSERT(!getmsg
->msg_target_is_router
);
2144 LASSERT(!getmsg
->msg_routing
);
2146 cpt
= lnet_cpt_of_cookie(getmd
->md_lh
.lh_cookie
);
2149 LASSERT(getmd
->md_refcount
> 0);
2152 CERROR("%s: Dropping REPLY from %s: can't allocate msg\n",
2153 libcfs_nid2str(ni
->ni_nid
), libcfs_id2str(peer_id
));
2157 if (getmd
->md_threshold
== 0) {
2158 CERROR("%s: Dropping REPLY from %s for inactive MD %p\n",
2159 libcfs_nid2str(ni
->ni_nid
), libcfs_id2str(peer_id
),
2161 lnet_res_unlock(cpt
);
2165 LASSERT(getmd
->md_offset
== 0);
2167 CDEBUG(D_NET
, "%s: Reply from %s md %p\n",
2168 libcfs_nid2str(ni
->ni_nid
), libcfs_id2str(peer_id
), getmd
);
2170 /* setup information for lnet_build_msg_event */
2171 msg
->msg_from
= peer_id
.nid
;
2172 msg
->msg_type
= LNET_MSG_GET
; /* flag this msg as an "optimized" GET */
2173 msg
->msg_hdr
.src_nid
= peer_id
.nid
;
2174 msg
->msg_hdr
.payload_length
= getmd
->md_length
;
2175 msg
->msg_receiving
= 1; /* required by lnet_msg_attach_md */
2177 lnet_msg_attach_md(msg
, getmd
, getmd
->md_offset
, getmd
->md_length
);
2178 lnet_res_unlock(cpt
);
2180 cpt
= lnet_cpt_of_nid(peer_id
.nid
);
2183 lnet_msg_commit(msg
, cpt
);
2184 lnet_net_unlock(cpt
);
2186 lnet_build_msg_event(msg
, LNET_EVENT_REPLY
);
2191 cpt
= lnet_cpt_of_nid(peer_id
.nid
);
2194 the_lnet
.ln_counters
[cpt
]->drop_count
++;
2195 the_lnet
.ln_counters
[cpt
]->drop_length
+= getmd
->md_length
;
2196 lnet_net_unlock(cpt
);
2203 EXPORT_SYMBOL(lnet_create_reply_msg
);
2206 lnet_set_reply_msg_len(lnet_ni_t
*ni
, lnet_msg_t
*reply
, unsigned int len
)
2208 /* Set the REPLY length, now the RDMA that elides the REPLY message has
2209 * completed and I know it. */
2210 LASSERT(reply
!= NULL
);
2211 LASSERT(reply
->msg_type
== LNET_MSG_GET
);
2212 LASSERT(reply
->msg_ev
.type
== LNET_EVENT_REPLY
);
2214 /* NB I trusted my peer to RDMA. If she tells me she's written beyond
2215 * the end of my buffer, I might as well be dead. */
2216 LASSERT(len
<= reply
->msg_ev
.mlength
);
2218 reply
->msg_ev
.mlength
= len
;
2220 EXPORT_SYMBOL(lnet_set_reply_msg_len
);
2223 * Initiate an asynchronous GET operation.
2225 * On the initiator node, an LNET_EVENT_SEND is logged when the GET request
2226 * is sent, and an LNET_EVENT_REPLY is logged when the data returned from
2227 * the target node in the REPLY has been written to local MD.
2229 * On the target node, an LNET_EVENT_GET is logged when the GET request
2230 * arrives and is accepted into a MD.
2232 * \param self,target,portal,match_bits,offset See the discussion in LNetPut().
2233 * \param mdh A handle for the MD that describes the memory into which the
2234 * requested data will be received. The MD must be "free floating"
2235 * (See LNetMDBind()).
2237 * \retval 0 Success, and only in this case events will be generated
2238 * and logged to EQ (if it exists) of the MD.
2239 * \retval -EIO Simulated failure.
2240 * \retval -ENOMEM Memory allocation failure.
2241 * \retval -ENOENT Invalid MD object.
2244 LNetGet(lnet_nid_t self
, lnet_handle_md_t mdh
,
2245 lnet_process_id_t target
, unsigned int portal
,
2246 __u64 match_bits
, unsigned int offset
)
2248 struct lnet_msg
*msg
;
2249 struct lnet_libmd
*md
;
2253 LASSERT(the_lnet
.ln_init
);
2254 LASSERT(the_lnet
.ln_refcount
> 0);
2256 if (!list_empty(&the_lnet
.ln_test_peers
) && /* normally we don't */
2257 fail_peer(target
.nid
, 1)) { /* shall we now? */
2258 CERROR("Dropping GET to %s: simulated failure\n",
2259 libcfs_id2str(target
));
2263 msg
= lnet_msg_alloc();
2265 CERROR("Dropping GET to %s: ENOMEM on lnet_msg_t\n",
2266 libcfs_id2str(target
));
2270 cpt
= lnet_cpt_of_cookie(mdh
.cookie
);
2273 md
= lnet_handle2md(&mdh
);
2274 if (md
== NULL
|| md
->md_threshold
== 0 || md
->md_me
!= NULL
) {
2275 CERROR("Dropping GET ("LPU64
":%d:%s): MD (%d) invalid\n",
2276 match_bits
, portal
, libcfs_id2str(target
),
2277 md
== NULL
? -1 : md
->md_threshold
);
2278 if (md
!= NULL
&& md
->md_me
!= NULL
)
2279 CERROR("REPLY MD also attached to portal %d\n",
2280 md
->md_me
->me_portal
);
2282 lnet_res_unlock(cpt
);
2289 CDEBUG(D_NET
, "LNetGet -> %s\n", libcfs_id2str(target
));
2291 lnet_msg_attach_md(msg
, md
, 0, 0);
2293 lnet_prep_send(msg
, LNET_MSG_GET
, target
, 0, 0);
2295 msg
->msg_hdr
.msg
.get
.match_bits
= cpu_to_le64(match_bits
);
2296 msg
->msg_hdr
.msg
.get
.ptl_index
= cpu_to_le32(portal
);
2297 msg
->msg_hdr
.msg
.get
.src_offset
= cpu_to_le32(offset
);
2298 msg
->msg_hdr
.msg
.get
.sink_length
= cpu_to_le32(md
->md_length
);
2300 /* NB handles only looked up by creator (no flips) */
2301 msg
->msg_hdr
.msg
.get
.return_wmd
.wh_interface_cookie
=
2302 the_lnet
.ln_interface_cookie
;
2303 msg
->msg_hdr
.msg
.get
.return_wmd
.wh_object_cookie
=
2304 md
->md_lh
.lh_cookie
;
2306 lnet_res_unlock(cpt
);
2308 lnet_build_msg_event(msg
, LNET_EVENT_SEND
);
2310 rc
= lnet_send(self
, msg
, LNET_NID_ANY
);
2312 CNETERR("Error sending GET to %s: %d\n",
2313 libcfs_id2str(target
), rc
);
2314 lnet_finalize(NULL
, msg
, rc
);
2317 /* completion will be signalled by an event */
2320 EXPORT_SYMBOL(LNetGet
);
2323 * Calculate distance to node at \a dstnid.
2325 * \param dstnid Target NID.
2326 * \param srcnidp If not NULL, NID of the local interface to reach \a dstnid
2328 * \param orderp If not NULL, order of the route to reach \a dstnid is saved
2331 * \retval 0 If \a dstnid belongs to a local interface, and reserved option
2332 * local_nid_dist_zero is set, which is the default.
2333 * \retval positives Distance to target NID, i.e. number of hops plus one.
2334 * \retval -EHOSTUNREACH If \a dstnid is not reachable.
2337 LNetDist(lnet_nid_t dstnid
, lnet_nid_t
*srcnidp
, __u32
*orderp
)
2339 struct list_head
*e
;
2341 lnet_remotenet_t
*rnet
;
2342 __u32 dstnet
= LNET_NIDNET(dstnid
);
2346 struct list_head
*rn_list
;
2348 /* if !local_nid_dist_zero, I don't return a distance of 0 ever
2349 * (when lustre sees a distance of 0, it substitutes 0@lo), so I
2350 * keep order 0 free for 0@lo and order 1 free for a local NID
2353 LASSERT(the_lnet
.ln_init
);
2354 LASSERT(the_lnet
.ln_refcount
> 0);
2356 cpt
= lnet_net_lock_current();
2358 list_for_each(e
, &the_lnet
.ln_nis
) {
2359 ni
= list_entry(e
, lnet_ni_t
, ni_list
);
2361 if (ni
->ni_nid
== dstnid
) {
2362 if (srcnidp
!= NULL
)
2364 if (orderp
!= NULL
) {
2365 if (LNET_NETTYP(LNET_NIDNET(dstnid
)) == LOLND
)
2370 lnet_net_unlock(cpt
);
2372 return local_nid_dist_zero
? 0 : 1;
2375 if (LNET_NIDNET(ni
->ni_nid
) == dstnet
) {
2376 if (srcnidp
!= NULL
)
2377 *srcnidp
= ni
->ni_nid
;
2380 lnet_net_unlock(cpt
);
2387 rn_list
= lnet_net2rnethash(dstnet
);
2388 list_for_each(e
, rn_list
) {
2389 rnet
= list_entry(e
, lnet_remotenet_t
, lrn_list
);
2391 if (rnet
->lrn_net
== dstnet
) {
2392 lnet_route_t
*route
;
2393 lnet_route_t
*shortest
= NULL
;
2395 LASSERT(!list_empty(&rnet
->lrn_routes
));
2397 list_for_each_entry(route
, &rnet
->lrn_routes
,
2399 if (shortest
== NULL
||
2400 route
->lr_hops
< shortest
->lr_hops
)
2404 LASSERT(shortest
!= NULL
);
2405 hops
= shortest
->lr_hops
;
2406 if (srcnidp
!= NULL
)
2407 *srcnidp
= shortest
->lr_gateway
->lp_ni
->ni_nid
;
2410 lnet_net_unlock(cpt
);
2416 lnet_net_unlock(cpt
);
2417 return -EHOSTUNREACH
;
2419 EXPORT_SYMBOL(LNetDist
);
2422 * Set the number of asynchronous messages expected from a target process.
2424 * This function is only meaningful for userspace callers. It's a no-op when
2425 * called from kernel.
2427 * Asynchronous messages are those that can come from a target when the
2428 * userspace process is not waiting for IO to complete; e.g., AST callbacks
2429 * from Lustre servers. Specifying the expected number of such messages
2430 * allows them to be eagerly received when user process is not running in
2431 * LNet; otherwise network errors may occur.
2433 * \param id Process ID of the target process.
2434 * \param nasync Number of asynchronous messages expected from the target.
2436 * \return 0 on success, and an error code otherwise.
2439 LNetSetAsync(lnet_process_id_t id
, int nasync
)
2443 EXPORT_SYMBOL(LNetSetAsync
);