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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
34 * Message decoding, parsing and finalizing routines
37 #define DEBUG_SUBSYSTEM S_LNET
39 #include <lnet/lib-lnet.h>
42 lnet_build_unlink_event(struct lnet_libmd *md, struct lnet_event *ev)
46 memset(ev, 0, sizeof(*ev));
50 ev->type = LNET_EVENT_UNLINK;
51 lnet_md_deconstruct(md, &ev->md);
52 lnet_md2handle(&ev->md_handle, md);
57 * Don't need any lock, must be called after lnet_commit_md
60 lnet_build_msg_event(struct lnet_msg *msg, enum lnet_event_kind ev_type)
62 struct lnet_hdr *hdr = &msg->msg_hdr;
63 struct lnet_event *ev = &msg->msg_ev;
65 LASSERT(!msg->msg_routing);
68 ev->msg_type = msg->msg_type;
70 if (ev_type == LNET_EVENT_SEND) {
71 /* event for active message */
72 ev->target.nid = le64_to_cpu(hdr->dest_nid);
73 ev->target.pid = le32_to_cpu(hdr->dest_pid);
74 ev->initiator.nid = LNET_NID_ANY;
75 ev->initiator.pid = the_lnet.ln_pid;
76 ev->source.nid = LNET_NID_ANY;
77 ev->source.pid = the_lnet.ln_pid;
78 ev->sender = LNET_NID_ANY;
80 /* event for passive message */
81 ev->target.pid = hdr->dest_pid;
82 ev->target.nid = hdr->dest_nid;
83 ev->initiator.pid = hdr->src_pid;
84 /* Multi-Rail: resolve src_nid to "primary" peer NID */
85 ev->initiator.nid = msg->msg_initiator;
86 /* Multi-Rail: track source NID. */
87 ev->source.pid = hdr->src_pid;
88 ev->source.nid = hdr->src_nid;
89 ev->rlength = hdr->payload_length;
90 ev->sender = msg->msg_from;
91 ev->mlength = msg->msg_wanted;
92 ev->offset = msg->msg_offset;
99 case LNET_EVENT_PUT: /* passive PUT */
100 ev->pt_index = hdr->msg.put.ptl_index;
101 ev->match_bits = hdr->msg.put.match_bits;
102 ev->hdr_data = hdr->msg.put.hdr_data;
105 case LNET_EVENT_GET: /* passive GET */
106 ev->pt_index = hdr->msg.get.ptl_index;
107 ev->match_bits = hdr->msg.get.match_bits;
111 case LNET_EVENT_ACK: /* ACK */
112 ev->match_bits = hdr->msg.ack.match_bits;
113 ev->mlength = hdr->msg.ack.mlength;
116 case LNET_EVENT_REPLY: /* REPLY */
119 case LNET_EVENT_SEND: /* active message */
120 if (msg->msg_type == LNET_MSG_PUT) {
121 ev->pt_index = le32_to_cpu(hdr->msg.put.ptl_index);
122 ev->match_bits = le64_to_cpu(hdr->msg.put.match_bits);
123 ev->offset = le32_to_cpu(hdr->msg.put.offset);
125 ev->rlength = le32_to_cpu(hdr->payload_length);
126 ev->hdr_data = le64_to_cpu(hdr->msg.put.hdr_data);
129 LASSERT(msg->msg_type == LNET_MSG_GET);
130 ev->pt_index = le32_to_cpu(hdr->msg.get.ptl_index);
131 ev->match_bits = le64_to_cpu(hdr->msg.get.match_bits);
133 ev->rlength = le32_to_cpu(hdr->msg.get.sink_length);
134 ev->offset = le32_to_cpu(hdr->msg.get.src_offset);
142 lnet_msg_commit(struct lnet_msg *msg, int cpt)
144 struct lnet_msg_container *container = the_lnet.ln_msg_containers[cpt];
145 struct lnet_counters *counters = the_lnet.ln_counters[cpt];
148 /* set the message deadline */
149 timeout_ns = lnet_transaction_timeout * NSEC_PER_SEC;
150 msg->msg_deadline = ktime_add_ns(ktime_get(), timeout_ns);
152 /* routed message can be committed for both receiving and sending */
153 LASSERT(!msg->msg_tx_committed);
155 if (msg->msg_sending) {
156 LASSERT(!msg->msg_receiving);
157 msg->msg_tx_cpt = cpt;
158 msg->msg_tx_committed = 1;
159 if (msg->msg_rx_committed) { /* routed message REPLY */
160 LASSERT(msg->msg_onactivelist);
164 LASSERT(!msg->msg_sending);
165 msg->msg_rx_cpt = cpt;
166 msg->msg_rx_committed = 1;
169 LASSERT(!msg->msg_onactivelist);
171 msg->msg_onactivelist = 1;
172 list_add_tail(&msg->msg_activelist, &container->msc_active);
174 counters->msgs_alloc++;
175 if (counters->msgs_alloc > counters->msgs_max)
176 counters->msgs_max = counters->msgs_alloc;
180 lnet_msg_decommit_tx(struct lnet_msg *msg, int status)
182 struct lnet_counters *counters;
183 struct lnet_event *ev = &msg->msg_ev;
185 LASSERT(msg->msg_tx_committed);
189 counters = the_lnet.ln_counters[msg->msg_tx_cpt];
191 default: /* routed message */
192 LASSERT(msg->msg_routing);
193 LASSERT(msg->msg_rx_committed);
194 LASSERT(ev->type == 0);
196 counters->route_length += msg->msg_len;
197 counters->route_count++;
201 /* should have been decommitted */
202 LASSERT(!msg->msg_rx_committed);
203 /* overwritten while sending ACK */
204 LASSERT(msg->msg_type == LNET_MSG_ACK);
205 msg->msg_type = LNET_MSG_PUT; /* fix type */
208 case LNET_EVENT_SEND:
209 LASSERT(!msg->msg_rx_committed);
210 if (msg->msg_type == LNET_MSG_PUT)
211 counters->send_length += msg->msg_len;
215 LASSERT(msg->msg_rx_committed);
216 /* overwritten while sending reply, we should never be
217 * here for optimized GET */
218 LASSERT(msg->msg_type == LNET_MSG_REPLY);
219 msg->msg_type = LNET_MSG_GET; /* fix type */
223 counters->send_count++;
227 lnet_incr_stats(&msg->msg_txpeer->lpni_stats,
229 LNET_STATS_TYPE_SEND);
231 lnet_incr_stats(&msg->msg_txni->ni_stats,
233 LNET_STATS_TYPE_SEND);
235 lnet_return_tx_credits_locked(msg);
236 msg->msg_tx_committed = 0;
240 lnet_msg_decommit_rx(struct lnet_msg *msg, int status)
242 struct lnet_counters *counters;
243 struct lnet_event *ev = &msg->msg_ev;
245 LASSERT(!msg->msg_tx_committed); /* decommitted or never committed */
246 LASSERT(msg->msg_rx_committed);
251 counters = the_lnet.ln_counters[msg->msg_rx_cpt];
254 LASSERT(ev->type == 0);
255 LASSERT(msg->msg_routing);
259 LASSERT(msg->msg_type == LNET_MSG_ACK);
263 /* type is "REPLY" if it's an optimized GET on passive side,
264 * because optimized GET will never be committed for sending,
265 * so message type wouldn't be changed back to "GET" by
266 * lnet_msg_decommit_tx(), see details in lnet_parse_get() */
267 LASSERT(msg->msg_type == LNET_MSG_REPLY ||
268 msg->msg_type == LNET_MSG_GET);
269 counters->send_length += msg->msg_wanted;
273 LASSERT(msg->msg_type == LNET_MSG_PUT);
276 case LNET_EVENT_REPLY:
277 /* type is "GET" if it's an optimized GET on active side,
278 * see details in lnet_create_reply_msg() */
279 LASSERT(msg->msg_type == LNET_MSG_GET ||
280 msg->msg_type == LNET_MSG_REPLY);
284 counters->recv_count++;
288 lnet_incr_stats(&msg->msg_rxpeer->lpni_stats,
290 LNET_STATS_TYPE_RECV);
292 lnet_incr_stats(&msg->msg_rxni->ni_stats,
294 LNET_STATS_TYPE_RECV);
295 if (ev->type == LNET_EVENT_PUT || ev->type == LNET_EVENT_REPLY)
296 counters->recv_length += msg->msg_wanted;
299 lnet_return_rx_credits_locked(msg);
300 msg->msg_rx_committed = 0;
304 lnet_msg_decommit(struct lnet_msg *msg, int cpt, int status)
308 LASSERT(msg->msg_tx_committed || msg->msg_rx_committed);
309 LASSERT(msg->msg_onactivelist);
311 if (msg->msg_tx_committed) { /* always decommit for sending first */
312 LASSERT(cpt == msg->msg_tx_cpt);
313 lnet_msg_decommit_tx(msg, status);
316 if (msg->msg_rx_committed) {
317 /* forwarding msg committed for both receiving and sending */
318 if (cpt != msg->msg_rx_cpt) {
319 lnet_net_unlock(cpt);
320 cpt2 = msg->msg_rx_cpt;
323 lnet_msg_decommit_rx(msg, status);
326 list_del(&msg->msg_activelist);
327 msg->msg_onactivelist = 0;
329 the_lnet.ln_counters[cpt2]->msgs_alloc--;
332 lnet_net_unlock(cpt2);
338 lnet_msg_attach_md(struct lnet_msg *msg, struct lnet_libmd *md,
339 unsigned int offset, unsigned int mlen)
341 /* NB: @offset and @len are only useful for receiving */
342 /* Here, we attach the MD on lnet_msg and mark it busy and
343 * decrementing its threshold. Come what may, the lnet_msg "owns"
344 * the MD until a call to lnet_msg_detach_md or lnet_finalize()
345 * signals completion. */
346 LASSERT(!msg->msg_routing);
349 if (msg->msg_receiving) { /* committed for receiving */
350 msg->msg_offset = offset;
351 msg->msg_wanted = mlen;
355 if (md->md_threshold != LNET_MD_THRESH_INF) {
356 LASSERT(md->md_threshold > 0);
360 /* build umd in event */
361 lnet_md2handle(&msg->msg_ev.md_handle, md);
362 lnet_md_deconstruct(md, &msg->msg_ev.md);
366 lnet_msg_detach_md(struct lnet_msg *msg, int status)
368 struct lnet_libmd *md = msg->msg_md;
371 /* Now it's safe to drop my caller's ref */
373 LASSERT(md->md_refcount >= 0);
375 unlink = lnet_md_unlinkable(md);
376 if (md->md_eq != NULL) {
377 msg->msg_ev.status = status;
378 msg->msg_ev.unlinked = unlink;
379 lnet_eq_enqueue_event(md->md_eq, &msg->msg_ev);
389 lnet_complete_msg_locked(struct lnet_msg *msg, int cpt)
391 struct lnet_handle_wire ack_wmd;
393 int status = msg->msg_ev.status;
395 LASSERT(msg->msg_onactivelist);
397 if (status == 0 && msg->msg_ack) {
398 /* Only send an ACK if the PUT completed successfully */
400 lnet_msg_decommit(msg, cpt, 0);
403 lnet_net_unlock(cpt);
405 LASSERT(msg->msg_ev.type == LNET_EVENT_PUT);
406 LASSERT(!msg->msg_routing);
408 ack_wmd = msg->msg_hdr.msg.put.ack_wmd;
410 lnet_prep_send(msg, LNET_MSG_ACK, msg->msg_ev.source, 0, 0);
412 msg->msg_hdr.msg.ack.dst_wmd = ack_wmd;
413 msg->msg_hdr.msg.ack.match_bits = msg->msg_ev.match_bits;
414 msg->msg_hdr.msg.ack.mlength = cpu_to_le32(msg->msg_ev.mlength);
416 /* NB: we probably want to use NID of msg::msg_from as 3rd
417 * parameter (router NID) if it's routed message */
418 rc = lnet_send(msg->msg_ev.target.nid, msg, LNET_NID_ANY);
422 * NB: message is committed for sending, we should return
423 * on success because LND will finalize this message later.
425 * Also, there is possibility that message is committed for
426 * sending and also failed before delivering to LND,
427 * i.e: ENOMEM, in that case we can't fall through either
428 * because CPT for sending can be different with CPT for
429 * receiving, so we should return back to lnet_finalize()
430 * to make sure we are locking the correct partition.
434 } else if (status == 0 && /* OK so far */
435 (msg->msg_routing && !msg->msg_sending)) {
437 LASSERT(!msg->msg_receiving); /* called back recv already */
438 lnet_net_unlock(cpt);
440 rc = lnet_send(LNET_NID_ANY, msg, LNET_NID_ANY);
444 * NB: message is committed for sending, we should return
445 * on success because LND will finalize this message later.
447 * Also, there is possibility that message is committed for
448 * sending and also failed before delivering to LND,
449 * i.e: ENOMEM, in that case we can't fall through either:
450 * - The rule is message must decommit for sending first if
451 * the it's committed for both sending and receiving
452 * - CPT for sending can be different with CPT for receiving,
453 * so we should return back to lnet_finalize() to make
454 * sure we are locking the correct partition.
459 lnet_msg_decommit(msg, cpt, status);
465 lnet_dec_healthv_locked(atomic_t *healthv)
467 int h = atomic_read(healthv);
469 if (h < lnet_health_sensitivity) {
470 atomic_set(healthv, 0);
472 h -= lnet_health_sensitivity;
473 atomic_set(healthv, h);
478 lnet_handle_local_failure(struct lnet_msg *msg)
480 struct lnet_ni *local_ni;
482 local_ni = msg->msg_txni;
485 * the lnet_net_lock(0) is used to protect the addref on the ni
486 * and the recovery queue.
489 /* the mt could've shutdown and cleaned up the queues */
490 if (the_lnet.ln_mt_state != LNET_MT_STATE_RUNNING) {
495 lnet_dec_healthv_locked(&local_ni->ni_healthv);
497 * add the NI to the recovery queue if it's not already there
498 * and it's health value is actually below the maximum. It's
499 * possible that the sensitivity might be set to 0, and the health
500 * value will not be reduced. In this case, there is no reason to
503 if (list_empty(&local_ni->ni_recovery) &&
504 atomic_read(&local_ni->ni_healthv) < LNET_MAX_HEALTH_VALUE) {
505 CERROR("ni %s added to recovery queue. Health = %d\n",
506 libcfs_nid2str(local_ni->ni_nid),
507 atomic_read(&local_ni->ni_healthv));
508 list_add_tail(&local_ni->ni_recovery,
509 &the_lnet.ln_mt_localNIRecovq);
510 lnet_ni_addref_locked(local_ni, 0);
516 lnet_handle_remote_failure(struct lnet_msg *msg)
518 struct lnet_peer_ni *lpni;
520 lpni = msg->msg_txpeer;
522 /* lpni could be NULL if we're in the LOLND case */
527 lnet_dec_healthv_locked(&lpni->lpni_healthv);
529 * add the peer NI to the recovery queue if it's not already there
530 * and it's health value is actually below the maximum. It's
531 * possible that the sensitivity might be set to 0, and the health
532 * value will not be reduced. In this case, there is no reason to
535 lnet_peer_ni_add_to_recoveryq_locked(lpni);
540 * Do a health check on the message:
541 * return -1 if we're not going to handle the error or
542 * if we've reached the maximum number of retries.
543 * success case will return -1 as well
544 * return 0 if it the message is requeued for send
547 lnet_health_check(struct lnet_msg *msg)
549 enum lnet_msg_hstatus hstatus = msg->msg_health_status;
552 /* TODO: lnet_incr_hstats(hstatus); */
554 LASSERT(msg->msg_txni);
557 * if we're sending to the LOLND then the msg_txpeer will not be
558 * set. So no need to sanity check it.
560 if (LNET_NETTYP(LNET_NIDNET(msg->msg_txni->ni_nid)) != LOLND)
561 LASSERT(msg->msg_txpeer);
565 if (hstatus != LNET_MSG_STATUS_OK &&
566 ktime_compare(ktime_get(), msg->msg_deadline) >= 0)
569 /* if we're shutting down no point in handling health. */
570 if (the_lnet.ln_state != LNET_STATE_RUNNING)
573 CDEBUG(D_NET, "health check: %s->%s: %s: %s\n",
574 libcfs_nid2str(msg->msg_txni->ni_nid),
575 (lo) ? "self" : libcfs_nid2str(msg->msg_txpeer->lpni_nid),
576 lnet_msgtyp2str(msg->msg_type),
577 lnet_health_error2str(hstatus));
580 case LNET_MSG_STATUS_OK:
581 lnet_inc_healthv(&msg->msg_txni->ni_healthv);
583 * It's possible msg_txpeer is NULL in the LOLND
587 lnet_inc_healthv(&msg->msg_txpeer->lpni_healthv);
589 /* we can finalize this message */
591 case LNET_MSG_STATUS_LOCAL_INTERRUPT:
592 case LNET_MSG_STATUS_LOCAL_DROPPED:
593 case LNET_MSG_STATUS_LOCAL_ABORTED:
594 case LNET_MSG_STATUS_LOCAL_NO_ROUTE:
595 case LNET_MSG_STATUS_LOCAL_TIMEOUT:
596 lnet_handle_local_failure(msg);
597 /* add to the re-send queue */
601 * These errors will not trigger a resend so simply
602 * finalize the message
604 case LNET_MSG_STATUS_LOCAL_ERROR:
605 lnet_handle_local_failure(msg);
609 * TODO: since the remote dropped the message we can
610 * attempt a resend safely.
612 case LNET_MSG_STATUS_REMOTE_DROPPED:
613 lnet_handle_remote_failure(msg);
616 case LNET_MSG_STATUS_REMOTE_ERROR:
617 case LNET_MSG_STATUS_REMOTE_TIMEOUT:
618 case LNET_MSG_STATUS_NETWORK_TIMEOUT:
619 lnet_handle_remote_failure(msg);
626 /* don't resend recovery messages */
627 if (msg->msg_recovery)
631 * if we explicitly indicated we don't want to resend then just
634 if (msg->msg_no_resend)
637 /* check if the message has exceeded the number of retries */
638 if (msg->msg_retry_count >= lnet_retry_count)
640 msg->msg_retry_count++;
642 lnet_net_lock(msg->msg_tx_cpt);
645 * remove message from the active list and reset it in preparation
646 * for a resend. Two exception to this
648 * 1. the router case, whe a message is committed for rx when
649 * received, then tx when it is sent. When committed to both tx and
650 * rx we don't want to remove it from the active list.
652 * 2. The REPLY case since it uses the same msg block for the GET
655 if (!msg->msg_routing && msg->msg_type != LNET_MSG_REPLY) {
656 list_del_init(&msg->msg_activelist);
657 msg->msg_onactivelist = 0;
660 * The msg_target.nid which was originally set
661 * when calling LNetGet() or LNetPut() might've
662 * been overwritten if we're routing this message.
663 * Call lnet_return_tx_credits_locked() to return
664 * the credit this message consumed. The message will
665 * consume another credit when it gets resent.
667 msg->msg_target.nid = msg->msg_hdr.dest_nid;
668 lnet_msg_decommit_tx(msg, -EAGAIN);
669 msg->msg_sending = 0;
670 msg->msg_receiving = 0;
671 msg->msg_target_is_router = 0;
673 CDEBUG(D_NET, "%s->%s:%s:%s - queuing for resend\n",
674 libcfs_nid2str(msg->msg_hdr.src_nid),
675 libcfs_nid2str(msg->msg_hdr.dest_nid),
676 lnet_msgtyp2str(msg->msg_type),
677 lnet_health_error2str(hstatus));
679 list_add_tail(&msg->msg_list, the_lnet.ln_mt_resendqs[msg->msg_tx_cpt]);
680 lnet_net_unlock(msg->msg_tx_cpt);
682 wake_up(&the_lnet.ln_mt_waitq);
687 lnet_detach_md(struct lnet_msg *msg, int status)
689 int cpt = lnet_cpt_of_cookie(msg->msg_md->md_lh.lh_cookie);
692 lnet_msg_detach_md(msg, status);
693 lnet_res_unlock(cpt);
697 lnet_is_health_check(struct lnet_msg *msg)
700 int status = msg->msg_ev.status;
703 * perform a health check for any message committed for transmit
705 hc = msg->msg_tx_committed;
707 /* Check for status inconsistencies */
709 ((!status && msg->msg_health_status != LNET_MSG_STATUS_OK) ||
710 (status && msg->msg_health_status == LNET_MSG_STATUS_OK))) {
711 CERROR("Msg is in inconsistent state, don't perform health "
712 "checking (%d, %d)\n", status, msg->msg_health_status);
716 CDEBUG(D_NET, "health check = %d, status = %d, hstatus = %d\n",
717 hc, status, msg->msg_health_status);
723 lnet_health_error2str(enum lnet_msg_hstatus hstatus)
726 case LNET_MSG_STATUS_LOCAL_INTERRUPT:
727 return "LOCAL_INTERRUPT";
728 case LNET_MSG_STATUS_LOCAL_DROPPED:
729 return "LOCAL_DROPPED";
730 case LNET_MSG_STATUS_LOCAL_ABORTED:
731 return "LOCAL_ABORTED";
732 case LNET_MSG_STATUS_LOCAL_NO_ROUTE:
733 return "LOCAL_NO_ROUTE";
734 case LNET_MSG_STATUS_LOCAL_TIMEOUT:
735 return "LOCAL_TIMEOUT";
736 case LNET_MSG_STATUS_LOCAL_ERROR:
737 return "LOCAL_ERROR";
738 case LNET_MSG_STATUS_REMOTE_DROPPED:
739 return "REMOTE_DROPPED";
740 case LNET_MSG_STATUS_REMOTE_ERROR:
741 return "REMOTE_ERROR";
742 case LNET_MSG_STATUS_REMOTE_TIMEOUT:
743 return "REMOTE_TIMEOUT";
744 case LNET_MSG_STATUS_NETWORK_TIMEOUT:
745 return "NETWORK_TIMEOUT";
746 case LNET_MSG_STATUS_OK:
754 lnet_finalize(struct lnet_msg *msg, int status)
756 struct lnet_msg_container *container;
763 LASSERT(!in_interrupt());
768 msg->msg_ev.status = status;
771 * if this is an ACK or a REPLY then make sure to remove the
774 if (msg->msg_ev.type == LNET_EVENT_REPLY ||
775 msg->msg_ev.type == LNET_EVENT_ACK) {
776 cpt = lnet_cpt_of_cookie(msg->msg_md->md_lh.lh_cookie);
777 lnet_detach_rsp_tracker(msg->msg_md, cpt);
780 /* if the message is successfully sent, no need to keep the MD around */
781 if (msg->msg_md != NULL && !status)
782 lnet_detach_md(msg, status);
785 hc = lnet_is_health_check(msg);
788 * the MD would've been detached from the message if it was
789 * successfully sent. However, if it wasn't successfully sent the
790 * MD would be around. And since we recalculate whether to
791 * health check or not, it's possible that we change our minds and
792 * we don't want to health check this message. In this case also
795 * If the message is successful we're going to
796 * go through the lnet_health_check() function, but that'll just
797 * increment the appropriate health value and return.
799 if (msg->msg_md != NULL && !hc)
800 lnet_detach_md(msg, status);
803 if (!msg->msg_tx_committed && !msg->msg_rx_committed) {
804 /* not committed to network yet */
805 LASSERT(!msg->msg_onactivelist);
812 * Check the health status of the message. If it has one
813 * of the errors that we're supposed to handle, and it has
814 * not timed out, then
815 * 1. Decrement the appropriate health_value
816 * 2. queue the message on the resend queue
818 * if the message send is success, timed out or failed in the
819 * health check for any reason then we'll just finalize the
820 * message. Otherwise just return since the message has been
821 * put on the resend queue.
823 if (!lnet_health_check(msg))
827 * if we get here then we need to clean up the md because we're
828 * finalizing the message.
830 if (msg->msg_md != NULL)
831 lnet_detach_md(msg, status);
835 * NB: routed message can be committed for both receiving and sending,
836 * we should finalize in LIFO order and keep counters correct.
837 * (finalize sending first then finalize receiving)
839 cpt = msg->msg_tx_committed ? msg->msg_tx_cpt : msg->msg_rx_cpt;
842 container = the_lnet.ln_msg_containers[cpt];
843 list_add_tail(&msg->msg_list, &container->msc_finalizing);
845 /* Recursion breaker. Don't complete the message here if I am (or
846 * enough other threads are) already completing messages */
849 for (i = 0; i < container->msc_nfinalizers; i++) {
850 if (container->msc_finalizers[i] == current)
853 if (my_slot < 0 && container->msc_finalizers[i] == NULL)
857 if (i < container->msc_nfinalizers || my_slot < 0) {
858 lnet_net_unlock(cpt);
862 container->msc_finalizers[my_slot] = current;
864 while (!list_empty(&container->msc_finalizing)) {
865 msg = list_entry(container->msc_finalizing.next,
866 struct lnet_msg, msg_list);
868 list_del_init(&msg->msg_list);
870 /* NB drops and regains the lnet lock if it actually does
871 * anything, so my finalizing friends can chomp along too */
872 rc = lnet_complete_msg_locked(msg, cpt);
877 if (unlikely(!list_empty(&the_lnet.ln_delay_rules))) {
878 lnet_net_unlock(cpt);
879 lnet_delay_rule_check();
883 container->msc_finalizers[my_slot] = NULL;
884 lnet_net_unlock(cpt);
889 EXPORT_SYMBOL(lnet_finalize);
892 lnet_msg_container_cleanup(struct lnet_msg_container *container)
896 if (container->msc_init == 0)
899 while (!list_empty(&container->msc_active)) {
900 struct lnet_msg *msg;
902 msg = list_entry(container->msc_active.next,
903 struct lnet_msg, msg_activelist);
904 LASSERT(msg->msg_onactivelist);
905 msg->msg_onactivelist = 0;
906 list_del_init(&msg->msg_activelist);
912 CERROR("%d active msg on exit\n", count);
914 if (container->msc_finalizers != NULL) {
915 LIBCFS_FREE(container->msc_finalizers,
916 container->msc_nfinalizers *
917 sizeof(*container->msc_finalizers));
918 container->msc_finalizers = NULL;
920 container->msc_init = 0;
924 lnet_msg_container_setup(struct lnet_msg_container *container, int cpt)
928 container->msc_init = 1;
930 INIT_LIST_HEAD(&container->msc_active);
931 INIT_LIST_HEAD(&container->msc_finalizing);
934 container->msc_nfinalizers = cfs_cpt_weight(lnet_cpt_table(), cpt);
935 if (container->msc_nfinalizers == 0)
936 container->msc_nfinalizers = 1;
938 LIBCFS_CPT_ALLOC(container->msc_finalizers, lnet_cpt_table(), cpt,
939 container->msc_nfinalizers *
940 sizeof(*container->msc_finalizers));
942 if (container->msc_finalizers == NULL) {
943 CERROR("Failed to allocate message finalizers\n");
944 lnet_msg_container_cleanup(container);
952 lnet_msg_containers_destroy(void)
954 struct lnet_msg_container *container;
957 if (the_lnet.ln_msg_containers == NULL)
960 cfs_percpt_for_each(container, i, the_lnet.ln_msg_containers)
961 lnet_msg_container_cleanup(container);
963 cfs_percpt_free(the_lnet.ln_msg_containers);
964 the_lnet.ln_msg_containers = NULL;
968 lnet_msg_containers_create(void)
970 struct lnet_msg_container *container;
974 the_lnet.ln_msg_containers = cfs_percpt_alloc(lnet_cpt_table(),
977 if (the_lnet.ln_msg_containers == NULL) {
978 CERROR("Failed to allocate cpu-partition data for network\n");
982 cfs_percpt_for_each(container, i, the_lnet.ln_msg_containers) {
983 rc = lnet_msg_container_setup(container, i);
985 lnet_msg_containers_destroy();