2 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
4 * Copyright (c) 2011, 2017, Intel Corporation.
6 * This file is part of Lustre, https://wiki.whamcloud.com/
8 * Portals is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Portals is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Portals; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #define DEBUG_SUBSYSTEM S_LNET
25 #include <linux/random.h>
26 #include <lnet/lib-lnet.h>
28 #define LNET_NRB_TINY_MIN 512 /* min value for each CPT */
29 #define LNET_NRB_TINY (LNET_NRB_TINY_MIN * 4)
30 #define LNET_NRB_SMALL_MIN 4096 /* min value for each CPT */
31 #define LNET_NRB_SMALL (LNET_NRB_SMALL_MIN * 4)
32 #define LNET_NRB_SMALL_PAGES 1
33 #define LNET_NRB_LARGE_MIN 256 /* min value for each CPT */
34 #define LNET_NRB_LARGE (LNET_NRB_LARGE_MIN * 4)
35 #define LNET_NRB_LARGE_PAGES ((LNET_MTU + PAGE_SIZE - 1) >> \
38 static char *forwarding = "";
39 module_param(forwarding, charp, 0444);
40 MODULE_PARM_DESC(forwarding, "Explicitly enable/disable forwarding between networks");
42 static int tiny_router_buffers;
43 module_param(tiny_router_buffers, int, 0444);
44 MODULE_PARM_DESC(tiny_router_buffers, "# of 0 payload messages to buffer in the router");
45 static int small_router_buffers;
46 module_param(small_router_buffers, int, 0444);
47 MODULE_PARM_DESC(small_router_buffers, "# of small (1 page) messages to buffer in the router");
48 static int large_router_buffers;
49 module_param(large_router_buffers, int, 0444);
50 MODULE_PARM_DESC(large_router_buffers, "# of large messages to buffer in the router");
51 static int peer_buffer_credits;
52 module_param(peer_buffer_credits, int, 0444);
53 MODULE_PARM_DESC(peer_buffer_credits, "# router buffer credits per peer");
55 static int auto_down = 1;
56 module_param(auto_down, int, 0444);
57 MODULE_PARM_DESC(auto_down, "Automatically mark peers down on comms error");
60 lnet_peer_buffer_credits(struct lnet_net *net)
62 /* NI option overrides LNet default */
63 if (net->net_tunables.lct_peer_rtr_credits > 0)
64 return net->net_tunables.lct_peer_rtr_credits;
65 if (peer_buffer_credits > 0)
66 return peer_buffer_credits;
68 /* As an approximation, allow this peer the same number of router
69 * buffers as it is allowed outstanding sends */
70 return net->net_tunables.lct_peer_tx_credits;
73 static int check_routers_before_use;
74 module_param(check_routers_before_use, int, 0444);
75 MODULE_PARM_DESC(check_routers_before_use, "Assume routers are down and ping them before use");
77 int avoid_asym_router_failure = 1;
78 module_param(avoid_asym_router_failure, int, 0644);
79 MODULE_PARM_DESC(avoid_asym_router_failure, "Avoid asymmetrical router failures (0 to disable)");
81 static int dead_router_check_interval = 60;
82 module_param(dead_router_check_interval, int, 0644);
83 MODULE_PARM_DESC(dead_router_check_interval, "Seconds between dead router health checks (<= 0 to disable)");
85 static int live_router_check_interval = 60;
86 module_param(live_router_check_interval, int, 0644);
87 MODULE_PARM_DESC(live_router_check_interval, "Seconds between live router health checks (<= 0 to disable)");
89 static int router_ping_timeout = 50;
90 module_param(router_ping_timeout, int, 0644);
91 MODULE_PARM_DESC(router_ping_timeout, "Seconds to wait for the reply to a router health query");
94 lnet_peers_start_down(void)
96 return check_routers_before_use;
100 lnet_notify_locked(struct lnet_peer_ni *lp, int notifylnd, int alive,
103 if (lp->lpni_timestamp > when) { /* out of date information */
104 CDEBUG(D_NET, "Out of date\n");
109 * This function can be called with different cpt locks being
110 * held. lpni_alive_count modification needs to be properly protected.
111 * Significant reads to lpni_alive_count are also protected with
114 spin_lock(&lp->lpni_lock);
116 lp->lpni_timestamp = when; /* update timestamp */
117 lp->lpni_ping_deadline = 0; /* disable ping timeout */
119 if (lp->lpni_alive_count != 0 && /* got old news */
120 (!lp->lpni_alive) == (!alive)) { /* new date for old news */
121 spin_unlock(&lp->lpni_lock);
122 CDEBUG(D_NET, "Old news\n");
126 /* Flag that notification is outstanding */
128 lp->lpni_alive_count++;
129 lp->lpni_alive = (alive) ? 1 : 0;
131 lp->lpni_notifylnd = notifylnd;
133 lp->lpni_ping_feats = LNET_PING_FEAT_INVAL; /* reset */
135 spin_unlock(&lp->lpni_lock);
137 CDEBUG(D_NET, "set %s %d\n", libcfs_nid2str(lp->lpni_nid), alive);
141 * This function will always be called with lp->lpni_cpt lock held.
144 lnet_ni_notify_locked(struct lnet_ni *ni, struct lnet_peer_ni *lp)
149 /* Notify only in 1 thread at any time to ensure ordered notification.
150 * NB individual events can be missed; the only guarantee is that you
151 * always get the most recent news */
153 spin_lock(&lp->lpni_lock);
155 if (lp->lpni_notifying || ni == NULL) {
156 spin_unlock(&lp->lpni_lock);
160 lp->lpni_notifying = 1;
163 * lp->lpni_notify needs to be protected because it can be set in
164 * lnet_notify_locked().
166 while (lp->lpni_notify) {
167 alive = lp->lpni_alive;
168 notifylnd = lp->lpni_notifylnd;
170 lp->lpni_notifylnd = 0;
173 if (notifylnd && ni->ni_net->net_lnd->lnd_notify != NULL) {
174 spin_unlock(&lp->lpni_lock);
175 lnet_net_unlock(lp->lpni_cpt);
177 /* A new notification could happen now; I'll handle it
178 * when control returns to me */
180 (ni->ni_net->net_lnd->lnd_notify)(ni, lp->lpni_nid,
183 lnet_net_lock(lp->lpni_cpt);
184 spin_lock(&lp->lpni_lock);
188 lp->lpni_notifying = 0;
189 spin_unlock(&lp->lpni_lock);
193 lnet_rtr_addref_locked(struct lnet_peer_ni *lp)
195 LASSERT(atomic_read(&lp->lpni_refcount) > 0);
196 LASSERT(lp->lpni_rtr_refcount >= 0);
198 /* lnet_net_lock must be exclusively locked */
199 lp->lpni_rtr_refcount++;
200 if (lp->lpni_rtr_refcount == 1) {
201 struct list_head *pos;
203 /* a simple insertion sort */
204 list_for_each_prev(pos, &the_lnet.ln_routers) {
205 struct lnet_peer_ni *rtr;
207 rtr = list_entry(pos, struct lnet_peer_ni,
209 if (rtr->lpni_nid < lp->lpni_nid)
213 list_add(&lp->lpni_rtr_list, pos);
214 /* addref for the_lnet.ln_routers */
215 lnet_peer_ni_addref_locked(lp);
216 the_lnet.ln_routers_version++;
221 lnet_rtr_decref_locked(struct lnet_peer_ni *lp)
223 LASSERT(atomic_read(&lp->lpni_refcount) > 0);
224 LASSERT(lp->lpni_rtr_refcount > 0);
226 /* lnet_net_lock must be exclusively locked */
227 lp->lpni_rtr_refcount--;
228 if (lp->lpni_rtr_refcount == 0) {
229 LASSERT(list_empty(&lp->lpni_routes));
231 if (lp->lpni_rcd != NULL) {
232 list_add(&lp->lpni_rcd->rcd_list,
233 &the_lnet.ln_rcd_deathrow);
237 list_del(&lp->lpni_rtr_list);
238 /* decref for the_lnet.ln_routers */
239 lnet_peer_ni_decref_locked(lp);
240 the_lnet.ln_routers_version++;
244 struct lnet_remotenet *
245 lnet_find_rnet_locked(__u32 net)
247 struct lnet_remotenet *rnet;
248 struct list_head *tmp;
249 struct list_head *rn_list;
251 LASSERT(the_lnet.ln_state == LNET_STATE_RUNNING);
253 rn_list = lnet_net2rnethash(net);
254 list_for_each(tmp, rn_list) {
255 rnet = list_entry(tmp, struct lnet_remotenet, lrn_list);
257 if (rnet->lrn_net == net)
263 static void lnet_shuffle_seed(void)
266 struct lnet_ni *ni = NULL;
271 /* Nodes with small feet have little entropy
272 * the NID for this node gives the most entropy in the low bits
274 while ((ni = lnet_get_next_ni_locked(NULL, ni)))
275 add_device_randomness(&ni->ni_nid, sizeof(ni->ni_nid));
281 /* NB expects LNET_LOCK held */
283 lnet_add_route_to_rnet(struct lnet_remotenet *rnet, struct lnet_route *route)
285 unsigned int len = 0;
286 unsigned int offset = 0;
291 list_for_each(e, &rnet->lrn_routes) {
295 /* len+1 positions to add a new entry, also prevents division by 0 */
296 offset = cfs_rand() % (len + 1);
297 list_for_each(e, &rnet->lrn_routes) {
302 list_add(&route->lr_list, e);
303 list_add(&route->lr_gwlist, &route->lr_gateway->lpni_routes);
305 the_lnet.ln_remote_nets_version++;
306 lnet_rtr_addref_locked(route->lr_gateway);
310 lnet_add_route(__u32 net, __u32 hops, lnet_nid_t gateway,
311 unsigned int priority)
314 struct lnet_remotenet *rnet;
315 struct lnet_remotenet *rnet2;
316 struct lnet_route *route;
318 struct lnet_peer_ni *lpni;
322 CDEBUG(D_NET, "Add route: net %s hops %d priority %u gw %s\n",
323 libcfs_net2str(net), hops, priority, libcfs_nid2str(gateway));
325 if (gateway == LNET_NID_ANY ||
326 LNET_NETTYP(LNET_NIDNET(gateway)) == LOLND ||
327 net == LNET_NIDNET(LNET_NID_ANY) ||
328 LNET_NETTYP(net) == LOLND ||
329 LNET_NIDNET(gateway) == net ||
330 (hops != LNET_UNDEFINED_HOPS && (hops < 1 || hops > 255)))
333 if (lnet_islocalnet(net)) /* it's a local network */
336 /* Assume net, route, all new */
337 LIBCFS_ALLOC(route, sizeof(*route));
338 LIBCFS_ALLOC(rnet, sizeof(*rnet));
339 if (route == NULL || rnet == NULL) {
340 CERROR("Out of memory creating route %s %d %s\n",
341 libcfs_net2str(net), hops, libcfs_nid2str(gateway));
343 LIBCFS_FREE(route, sizeof(*route));
345 LIBCFS_FREE(rnet, sizeof(*rnet));
349 INIT_LIST_HEAD(&rnet->lrn_routes);
351 route->lr_hops = hops;
353 route->lr_priority = priority;
355 lnet_net_lock(LNET_LOCK_EX);
357 lpni = lnet_nid2peerni_ex(gateway, LNET_LOCK_EX);
359 lnet_net_unlock(LNET_LOCK_EX);
361 LIBCFS_FREE(route, sizeof(*route));
362 LIBCFS_FREE(rnet, sizeof(*rnet));
365 if (rc == -EHOSTUNREACH) /* gateway is not on a local net. */
366 return rc; /* ignore the route entry */
367 CERROR("Error %d creating route %s %d %s\n", rc,
368 libcfs_net2str(net), hops,
369 libcfs_nid2str(gateway));
372 route->lr_gateway = lpni;
373 LASSERT(the_lnet.ln_state == LNET_STATE_RUNNING);
375 rnet2 = lnet_find_rnet_locked(net);
378 list_add_tail(&rnet->lrn_list, lnet_net2rnethash(net));
382 /* Search for a duplicate route (it's a NOOP if it is) */
384 list_for_each(e, &rnet2->lrn_routes) {
385 struct lnet_route *route2;
387 route2 = list_entry(e, struct lnet_route, lr_list);
388 if (route2->lr_gateway == route->lr_gateway) {
393 /* our lookups must be true */
394 LASSERT(route2->lr_gateway->lpni_nid != gateway);
398 lnet_peer_ni_addref_locked(route->lr_gateway); /* +1 for notify */
399 lnet_add_route_to_rnet(rnet2, route);
401 ni = lnet_get_next_ni_locked(route->lr_gateway->lpni_net, NULL);
402 lnet_net_unlock(LNET_LOCK_EX);
404 /* XXX Assume alive */
405 if (ni->ni_net->net_lnd->lnd_notify != NULL)
406 (ni->ni_net->net_lnd->lnd_notify)(ni, gateway, 1);
408 lnet_net_lock(LNET_LOCK_EX);
411 /* -1 for notify or !add_route */
412 lnet_peer_ni_decref_locked(route->lr_gateway);
413 lnet_net_unlock(LNET_LOCK_EX);
419 LIBCFS_FREE(route, sizeof(*route));
423 LIBCFS_FREE(rnet, sizeof(*rnet));
425 /* kick start the monitor thread to handle the added route */
426 wake_up(&the_lnet.ln_mt_waitq);
432 lnet_check_routes(void)
434 struct lnet_remotenet *rnet;
435 struct lnet_route *route;
436 struct lnet_route *route2;
437 struct list_head *e1;
438 struct list_head *e2;
440 struct list_head *rn_list;
443 cpt = lnet_net_lock_current();
445 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) {
446 rn_list = &the_lnet.ln_remote_nets_hash[i];
447 list_for_each(e1, rn_list) {
448 rnet = list_entry(e1, struct lnet_remotenet, lrn_list);
451 list_for_each(e2, &rnet->lrn_routes) {
456 route = list_entry(e2, struct lnet_route,
459 if (route2 == NULL) {
464 if (route->lr_gateway->lpni_net ==
465 route2->lr_gateway->lpni_net)
468 nid1 = route->lr_gateway->lpni_nid;
469 nid2 = route2->lr_gateway->lpni_nid;
472 lnet_net_unlock(cpt);
474 CERROR("Routes to %s via %s and %s not "
477 libcfs_nid2str(nid1),
478 libcfs_nid2str(nid2));
484 lnet_net_unlock(cpt);
489 lnet_del_route(__u32 net, lnet_nid_t gw_nid)
491 struct lnet_peer_ni *gateway;
492 struct lnet_remotenet *rnet;
493 struct lnet_route *route;
494 struct list_head *e1;
495 struct list_head *e2;
497 struct list_head *rn_list;
500 CDEBUG(D_NET, "Del route: net %s : gw %s\n",
501 libcfs_net2str(net), libcfs_nid2str(gw_nid));
503 /* NB Caller may specify either all routes via the given gateway
504 * or a specific route entry actual NIDs) */
506 lnet_net_lock(LNET_LOCK_EX);
507 if (net == LNET_NIDNET(LNET_NID_ANY))
508 rn_list = &the_lnet.ln_remote_nets_hash[0];
510 rn_list = lnet_net2rnethash(net);
513 list_for_each(e1, rn_list) {
514 rnet = list_entry(e1, struct lnet_remotenet, lrn_list);
516 if (!(net == LNET_NIDNET(LNET_NID_ANY) ||
517 net == rnet->lrn_net))
520 list_for_each(e2, &rnet->lrn_routes) {
521 route = list_entry(e2, struct lnet_route, lr_list);
523 gateway = route->lr_gateway;
524 if (!(gw_nid == LNET_NID_ANY ||
525 gw_nid == gateway->lpni_nid))
528 list_del(&route->lr_list);
529 list_del(&route->lr_gwlist);
530 the_lnet.ln_remote_nets_version++;
532 if (list_empty(&rnet->lrn_routes))
533 list_del(&rnet->lrn_list);
537 lnet_rtr_decref_locked(gateway);
538 lnet_peer_ni_decref_locked(gateway);
540 lnet_net_unlock(LNET_LOCK_EX);
542 LIBCFS_FREE(route, sizeof(*route));
545 LIBCFS_FREE(rnet, sizeof(*rnet));
548 lnet_net_lock(LNET_LOCK_EX);
553 if (net == LNET_NIDNET(LNET_NID_ANY) &&
554 ++idx < LNET_REMOTE_NETS_HASH_SIZE) {
555 rn_list = &the_lnet.ln_remote_nets_hash[idx];
558 lnet_net_unlock(LNET_LOCK_EX);
564 lnet_destroy_routes (void)
566 lnet_del_route(LNET_NIDNET(LNET_NID_ANY), LNET_NID_ANY);
569 int lnet_get_rtr_pool_cfg(int idx, struct lnet_ioctl_pool_cfg *pool_cfg)
571 int i, rc = -ENOENT, j;
573 if (the_lnet.ln_rtrpools == NULL)
576 for (i = 0; i < LNET_NRBPOOLS; i++) {
577 struct lnet_rtrbufpool *rbp;
579 lnet_net_lock(LNET_LOCK_EX);
580 cfs_percpt_for_each(rbp, j, the_lnet.ln_rtrpools) {
584 pool_cfg->pl_pools[i].pl_npages = rbp[i].rbp_npages;
585 pool_cfg->pl_pools[i].pl_nbuffers = rbp[i].rbp_nbuffers;
586 pool_cfg->pl_pools[i].pl_credits = rbp[i].rbp_credits;
587 pool_cfg->pl_pools[i].pl_mincredits = rbp[i].rbp_mincredits;
591 lnet_net_unlock(LNET_LOCK_EX);
594 lnet_net_lock(LNET_LOCK_EX);
595 pool_cfg->pl_routing = the_lnet.ln_routing;
596 lnet_net_unlock(LNET_LOCK_EX);
602 lnet_get_route(int idx, __u32 *net, __u32 *hops,
603 lnet_nid_t *gateway, __u32 *alive, __u32 *priority)
605 struct list_head *e1;
606 struct list_head *e2;
607 struct lnet_remotenet *rnet;
608 struct lnet_route *route;
611 struct list_head *rn_list;
613 cpt = lnet_net_lock_current();
615 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) {
616 rn_list = &the_lnet.ln_remote_nets_hash[i];
617 list_for_each(e1, rn_list) {
618 rnet = list_entry(e1, struct lnet_remotenet, lrn_list);
620 list_for_each(e2, &rnet->lrn_routes) {
621 route = list_entry(e2, struct lnet_route,
625 *net = rnet->lrn_net;
626 *hops = route->lr_hops;
627 *priority = route->lr_priority;
628 *gateway = route->lr_gateway->lpni_nid;
629 *alive = lnet_is_route_alive(route);
630 lnet_net_unlock(cpt);
637 lnet_net_unlock(cpt);
642 lnet_swap_pinginfo(struct lnet_ping_buffer *pbuf)
644 struct lnet_ni_status *stat;
648 __swab32s(&pbuf->pb_info.pi_magic);
649 __swab32s(&pbuf->pb_info.pi_features);
650 __swab32s(&pbuf->pb_info.pi_pid);
651 __swab32s(&pbuf->pb_info.pi_nnis);
652 nnis = pbuf->pb_info.pi_nnis;
653 if (nnis > pbuf->pb_nnis)
654 nnis = pbuf->pb_nnis;
655 for (i = 0; i < nnis; i++) {
656 stat = &pbuf->pb_info.pi_ni[i];
657 __swab64s(&stat->ns_nid);
658 __swab32s(&stat->ns_status);
664 * parse router-checker pinginfo, record number of down NIs for remote
665 * networks on that router.
668 lnet_parse_rc_info(struct lnet_rc_data *rcd)
670 struct lnet_ping_buffer *pbuf = rcd->rcd_pingbuffer;
671 struct lnet_peer_ni *gw = rcd->rcd_gateway;
672 struct lnet_route *rte;
675 if (!gw->lpni_alive || !pbuf)
679 * Protect gw->lpni_ping_feats. This can be set from
680 * lnet_notify_locked with different locks being held
682 spin_lock(&gw->lpni_lock);
684 if (pbuf->pb_info.pi_magic == __swab32(LNET_PROTO_PING_MAGIC))
685 lnet_swap_pinginfo(pbuf);
687 /* NB always racing with network! */
688 if (pbuf->pb_info.pi_magic != LNET_PROTO_PING_MAGIC) {
689 CDEBUG(D_NET, "%s: Unexpected magic %08x\n",
690 libcfs_nid2str(gw->lpni_nid), pbuf->pb_info.pi_magic);
691 gw->lpni_ping_feats = LNET_PING_FEAT_INVAL;
695 gw->lpni_ping_feats = pbuf->pb_info.pi_features;
697 /* Without NI status info there's nothing more to do. */
698 if ((gw->lpni_ping_feats & LNET_PING_FEAT_NI_STATUS) == 0)
701 /* Determine the number of NIs for which there is data. */
702 nnis = pbuf->pb_info.pi_nnis;
703 if (pbuf->pb_nnis < nnis) {
704 if (rcd->rcd_nnis < nnis)
705 rcd->rcd_nnis = nnis;
706 nnis = pbuf->pb_nnis;
709 list_for_each_entry(rte, &gw->lpni_routes, lr_gwlist) {
714 /* If routing disabled then the route is down. */
715 if ((gw->lpni_ping_feats & LNET_PING_FEAT_RTE_DISABLED) != 0) {
720 for (i = 0; i < nnis; i++) {
721 struct lnet_ni_status *stat = &pbuf->pb_info.pi_ni[i];
722 lnet_nid_t nid = stat->ns_nid;
724 if (nid == LNET_NID_ANY) {
725 CDEBUG(D_NET, "%s: unexpected LNET_NID_ANY\n",
726 libcfs_nid2str(gw->lpni_nid));
727 gw->lpni_ping_feats = LNET_PING_FEAT_INVAL;
731 if (LNET_NETTYP(LNET_NIDNET(nid)) == LOLND)
734 if (stat->ns_status == LNET_NI_STATUS_DOWN) {
739 if (stat->ns_status == LNET_NI_STATUS_UP) {
740 if (LNET_NIDNET(nid) == rte->lr_net) {
747 CDEBUG(D_NET, "%s: Unexpected status 0x%x\n",
748 libcfs_nid2str(gw->lpni_nid), stat->ns_status);
749 gw->lpni_ping_feats = LNET_PING_FEAT_INVAL;
753 if (up) { /* ignore downed NIs if NI for dest network is up */
757 /* if @down is zero and this route is single-hop, it means
758 * we can't find NI for target network */
759 if (down == 0 && rte->lr_hops == 1)
762 rte->lr_downis = down;
765 spin_unlock(&gw->lpni_lock);
769 lnet_router_checker_event(struct lnet_event *event)
771 struct lnet_rc_data *rcd = event->md.user_ptr;
772 struct lnet_peer_ni *lp;
774 LASSERT(rcd != NULL);
776 if (event->unlinked) {
777 LNetInvalidateMDHandle(&rcd->rcd_mdh);
781 LASSERT(event->type == LNET_EVENT_SEND ||
782 event->type == LNET_EVENT_REPLY);
784 lp = rcd->rcd_gateway;
787 /* NB: it's called with holding lnet_res_lock, we have a few
788 * places need to hold both locks at the same time, please take
789 * care of lock ordering */
790 lnet_net_lock(lp->lpni_cpt);
791 if (!lnet_isrouter(lp) || lp->lpni_rcd != rcd) {
792 /* ignore if no longer a router or rcd is replaced */
796 if (event->type == LNET_EVENT_SEND) {
797 lp->lpni_ping_notsent = 0;
798 if (event->status == 0)
802 /* LNET_EVENT_REPLY */
803 /* A successful REPLY means the router is up. If _any_ comms
804 * to the router fail I assume it's down (this will happen if
805 * we ping alive routers to try to detect router death before
806 * apps get burned). */
808 lnet_notify_locked(lp, 1, !event->status, ktime_get_seconds());
809 /* The router checker will wake up very shortly and do the
810 * actual notification.
811 * XXX If 'lp' stops being a router before then, it will still
812 * have the notification pending!!! */
814 if (avoid_asym_router_failure && event->status == 0)
815 lnet_parse_rc_info(rcd);
818 lnet_net_unlock(lp->lpni_cpt);
822 lnet_wait_known_routerstate(void)
824 struct lnet_peer_ni *rtr;
825 struct list_head *entry;
828 LASSERT(the_lnet.ln_mt_state == LNET_MT_STATE_RUNNING);
831 int cpt = lnet_net_lock_current();
834 list_for_each(entry, &the_lnet.ln_routers) {
835 rtr = list_entry(entry, struct lnet_peer_ni,
838 spin_lock(&rtr->lpni_lock);
840 if (rtr->lpni_alive_count == 0) {
842 spin_unlock(&rtr->lpni_lock);
845 spin_unlock(&rtr->lpni_lock);
848 lnet_net_unlock(cpt);
853 set_current_state(TASK_UNINTERRUPTIBLE);
854 schedule_timeout(cfs_time_seconds(1));
859 lnet_router_ni_update_locked(struct lnet_peer_ni *gw, __u32 net)
861 struct lnet_route *rte;
863 if ((gw->lpni_ping_feats & LNET_PING_FEAT_NI_STATUS) != 0) {
864 list_for_each_entry(rte, &gw->lpni_routes, lr_gwlist) {
865 if (rte->lr_net == net) {
874 lnet_update_ni_status_locked(void)
876 struct lnet_ni *ni = NULL;
880 LASSERT(the_lnet.ln_routing);
882 timeout = router_ping_timeout +
883 MAX(live_router_check_interval, dead_router_check_interval);
885 now = ktime_get_real_seconds();
886 while ((ni = lnet_get_next_ni_locked(NULL, ni))) {
887 if (ni->ni_net->net_lnd->lnd_type == LOLND)
890 if (now < ni->ni_last_alive + timeout)
894 /* re-check with lock */
895 if (now < ni->ni_last_alive + timeout) {
900 LASSERT(ni->ni_status != NULL);
902 if (ni->ni_status->ns_status != LNET_NI_STATUS_DOWN) {
903 CDEBUG(D_NET, "NI(%s:%lld) status changed to down\n",
904 libcfs_nid2str(ni->ni_nid), timeout);
905 /* NB: so far, this is the only place to set
906 * NI status to "down" */
907 ni->ni_status->ns_status = LNET_NI_STATUS_DOWN;
914 lnet_destroy_rc_data(struct lnet_rc_data *rcd)
916 LASSERT(list_empty(&rcd->rcd_list));
917 /* detached from network */
918 LASSERT(LNetMDHandleIsInvalid(rcd->rcd_mdh));
920 if (rcd->rcd_gateway != NULL) {
921 int cpt = rcd->rcd_gateway->lpni_cpt;
924 lnet_peer_ni_decref_locked(rcd->rcd_gateway);
925 lnet_net_unlock(cpt);
928 if (rcd->rcd_pingbuffer != NULL)
929 lnet_ping_buffer_decref(rcd->rcd_pingbuffer);
931 LIBCFS_FREE(rcd, sizeof(*rcd));
934 static struct lnet_rc_data *
935 lnet_update_rc_data_locked(struct lnet_peer_ni *gateway)
937 struct lnet_handle_md mdh;
938 struct lnet_rc_data *rcd;
939 struct lnet_ping_buffer *pbuf = NULL;
940 int nnis = LNET_INTERFACES_MIN;
944 rcd = gateway->lpni_rcd;
946 nnis = rcd->rcd_nnis;
948 LNetInvalidateMDHandle(&rcd->rcd_mdh);
949 pbuf = rcd->rcd_pingbuffer;
950 rcd->rcd_pingbuffer = NULL;
952 LNetInvalidateMDHandle(&mdh);
955 lnet_net_unlock(gateway->lpni_cpt);
959 lnet_ping_buffer_decref(pbuf);
961 LIBCFS_ALLOC(rcd, sizeof(*rcd));
965 LNetInvalidateMDHandle(&rcd->rcd_mdh);
966 INIT_LIST_HEAD(&rcd->rcd_list);
967 rcd->rcd_nnis = nnis;
970 pbuf = lnet_ping_buffer_alloc(nnis, GFP_NOFS);
974 for (i = 0; i < nnis; i++) {
975 pbuf->pb_info.pi_ni[i].ns_nid = LNET_NID_ANY;
976 pbuf->pb_info.pi_ni[i].ns_status = LNET_NI_STATUS_INVALID;
978 rcd->rcd_pingbuffer = pbuf;
980 LASSERT(!LNetEQHandleIsInvalid(the_lnet.ln_rc_eqh));
981 rc = LNetMDBind((struct lnet_md){.start = &pbuf->pb_info,
983 .length = LNET_PING_INFO_SIZE(nnis),
984 .threshold = LNET_MD_THRESH_INF,
985 .options = LNET_MD_TRUNCATE,
986 .eq_handle = the_lnet.ln_rc_eqh},
990 CERROR("Can't bind MD: %d\n", rc);
991 goto out_ping_buffer_decref;
995 lnet_net_lock(gateway->lpni_cpt);
996 /* Check if this is still a router. */
997 if (!lnet_isrouter(gateway))
999 /* Check if someone else installed router data. */
1000 if (gateway->lpni_rcd && gateway->lpni_rcd != rcd)
1003 /* Install and/or update the router data. */
1004 if (!gateway->lpni_rcd) {
1005 lnet_peer_ni_addref_locked(gateway);
1006 rcd->rcd_gateway = gateway;
1007 gateway->lpni_rcd = rcd;
1009 gateway->lpni_ping_notsent = 0;
1014 lnet_net_unlock(gateway->lpni_cpt);
1015 rc = LNetMDUnlink(mdh);
1017 out_ping_buffer_decref:
1018 lnet_ping_buffer_decref(pbuf);
1020 if (rcd && rcd != gateway->lpni_rcd)
1021 lnet_destroy_rc_data(rcd);
1022 lnet_net_lock(gateway->lpni_cpt);
1023 return gateway->lpni_rcd;
1027 lnet_router_check_interval(struct lnet_peer_ni *rtr)
1031 secs = rtr->lpni_alive ? live_router_check_interval :
1032 dead_router_check_interval;
1040 lnet_ping_router_locked(struct lnet_peer_ni *rtr)
1042 struct lnet_rc_data *rcd = NULL;
1043 time64_t now = ktime_get_seconds();
1047 lnet_peer_ni_addref_locked(rtr);
1049 if (rtr->lpni_ping_deadline != 0 && /* ping timed out? */
1050 now > rtr->lpni_ping_deadline)
1051 lnet_notify_locked(rtr, 1, 0, now);
1053 /* Run any outstanding notifications */
1054 ni = lnet_get_next_ni_locked(rtr->lpni_net, NULL);
1055 lnet_ni_notify_locked(ni, rtr);
1057 if (!lnet_isrouter(rtr) ||
1058 the_lnet.ln_mt_state != LNET_MT_STATE_RUNNING) {
1059 /* router table changed or router checker is shutting down */
1060 lnet_peer_ni_decref_locked(rtr);
1064 rcd = rtr->lpni_rcd;
1067 * The response to the router checker ping could've timed out and
1068 * the mdh might've been invalidated, so we need to update it
1071 if (!rcd || rcd->rcd_nnis > rcd->rcd_pingbuffer->pb_nnis ||
1072 LNetMDHandleIsInvalid(rcd->rcd_mdh))
1073 rcd = lnet_update_rc_data_locked(rtr);
1077 secs = lnet_router_check_interval(rtr);
1080 "rtr %s %lld: deadline %lld ping_notsent %d alive %d "
1081 "alive_count %d lpni_ping_timestamp %lld\n",
1082 libcfs_nid2str(rtr->lpni_nid), secs,
1083 rtr->lpni_ping_deadline, rtr->lpni_ping_notsent,
1084 rtr->lpni_alive, rtr->lpni_alive_count, rtr->lpni_ping_timestamp);
1086 if (secs != 0 && !rtr->lpni_ping_notsent &&
1087 now > rtr->lpni_ping_timestamp + secs) {
1089 struct lnet_process_id id;
1090 struct lnet_handle_md mdh;
1092 id.nid = rtr->lpni_nid;
1093 id.pid = LNET_PID_LUSTRE;
1094 CDEBUG(D_NET, "Check: %s\n", libcfs_id2str(id));
1096 rtr->lpni_ping_notsent = 1;
1097 rtr->lpni_ping_timestamp = now;
1101 if (rtr->lpni_ping_deadline == 0) {
1102 rtr->lpni_ping_deadline = ktime_get_seconds() +
1103 router_ping_timeout;
1106 lnet_net_unlock(rtr->lpni_cpt);
1108 rc = LNetGet(LNET_NID_ANY, mdh, id, LNET_RESERVED_PORTAL,
1109 LNET_PROTO_PING_MATCHBITS, 0, false);
1111 lnet_net_lock(rtr->lpni_cpt);
1113 rtr->lpni_ping_notsent = 0; /* no event pending */
1116 lnet_peer_ni_decref_locked(rtr);
1120 int lnet_router_pre_mt_start(void)
1124 if (check_routers_before_use &&
1125 dead_router_check_interval <= 0) {
1126 LCONSOLE_ERROR_MSG(0x10a, "'dead_router_check_interval' must be"
1127 " set if 'check_routers_before_use' is set"
1132 rc = LNetEQAlloc(0, lnet_router_checker_event, &the_lnet.ln_rc_eqh);
1134 CERROR("Can't allocate EQ(0): %d\n", rc);
1141 void lnet_router_post_mt_start(void)
1143 if (check_routers_before_use) {
1144 /* Note that a helpful side-effect of pinging all known routers
1145 * at startup is that it makes them drop stale connections they
1146 * may have to a previous instance of me. */
1147 lnet_wait_known_routerstate();
1152 lnet_router_cleanup(void)
1156 rc = LNetEQFree(the_lnet.ln_rc_eqh);
1162 lnet_prune_rc_data(int wait_unlink)
1164 struct lnet_rc_data *rcd;
1165 struct lnet_rc_data *tmp;
1166 struct lnet_peer_ni *lp;
1167 struct list_head head;
1170 if (likely(the_lnet.ln_mt_state == LNET_MT_STATE_RUNNING &&
1171 list_empty(&the_lnet.ln_rcd_deathrow) &&
1172 list_empty(&the_lnet.ln_rcd_zombie)))
1175 INIT_LIST_HEAD(&head);
1177 lnet_net_lock(LNET_LOCK_EX);
1179 if (the_lnet.ln_mt_state != LNET_MT_STATE_RUNNING) {
1180 /* router checker is stopping, prune all */
1181 list_for_each_entry(lp, &the_lnet.ln_routers,
1183 if (lp->lpni_rcd == NULL)
1186 LASSERT(list_empty(&lp->lpni_rcd->rcd_list));
1187 list_add(&lp->lpni_rcd->rcd_list,
1188 &the_lnet.ln_rcd_deathrow);
1189 lp->lpni_rcd = NULL;
1193 /* unlink all RCDs on deathrow list */
1194 list_splice_init(&the_lnet.ln_rcd_deathrow, &head);
1196 if (!list_empty(&head)) {
1197 lnet_net_unlock(LNET_LOCK_EX);
1199 list_for_each_entry(rcd, &head, rcd_list)
1200 LNetMDUnlink(rcd->rcd_mdh);
1202 lnet_net_lock(LNET_LOCK_EX);
1205 list_splice_init(&head, &the_lnet.ln_rcd_zombie);
1207 /* release all zombie RCDs */
1208 while (!list_empty(&the_lnet.ln_rcd_zombie)) {
1209 list_for_each_entry_safe(rcd, tmp, &the_lnet.ln_rcd_zombie,
1211 if (LNetMDHandleIsInvalid(rcd->rcd_mdh))
1212 list_move(&rcd->rcd_list, &head);
1215 wait_unlink = wait_unlink &&
1216 !list_empty(&the_lnet.ln_rcd_zombie);
1218 lnet_net_unlock(LNET_LOCK_EX);
1220 while (!list_empty(&head)) {
1221 rcd = list_entry(head.next,
1222 struct lnet_rc_data, rcd_list);
1223 list_del_init(&rcd->rcd_list);
1224 lnet_destroy_rc_data(rcd);
1231 CDEBUG(((i & (-i)) == i) ? D_WARNING : D_NET,
1232 "Waiting for rc buffers to unlink\n");
1233 set_current_state(TASK_UNINTERRUPTIBLE);
1234 schedule_timeout(cfs_time_seconds(1) / 4);
1236 lnet_net_lock(LNET_LOCK_EX);
1239 lnet_net_unlock(LNET_LOCK_EX);
1243 * This function is called from the monitor thread to check if there are
1244 * any active routers that need to be checked.
1247 lnet_router_checker_active(void)
1249 if (the_lnet.ln_mt_state != LNET_MT_STATE_RUNNING)
1252 /* Router Checker thread needs to run when routing is enabled in
1253 * order to call lnet_update_ni_status_locked() */
1254 if (the_lnet.ln_routing)
1257 /* if there are routers that need to be cleaned up then do so */
1258 if (!list_empty(&the_lnet.ln_rcd_deathrow) ||
1259 !list_empty(&the_lnet.ln_rcd_zombie))
1262 return !list_empty(&the_lnet.ln_routers) &&
1263 (live_router_check_interval > 0 ||
1264 dead_router_check_interval > 0);
1268 lnet_check_routers(void)
1270 struct lnet_peer_ni *rtr;
1271 struct list_head *entry;
1276 cpt = lnet_net_lock_current();
1278 version = the_lnet.ln_routers_version;
1280 list_for_each(entry, &the_lnet.ln_routers) {
1281 rtr = list_entry(entry, struct lnet_peer_ni,
1284 cpt2 = rtr->lpni_cpt;
1286 lnet_net_unlock(cpt);
1289 /* the routers list has changed */
1290 if (version != the_lnet.ln_routers_version)
1294 lnet_ping_router_locked(rtr);
1296 /* NB dropped lock */
1297 if (version != the_lnet.ln_routers_version) {
1298 /* the routers list has changed */
1303 if (the_lnet.ln_routing)
1304 lnet_update_ni_status_locked();
1306 lnet_net_unlock(cpt);
1308 lnet_prune_rc_data(0); /* don't wait for UNLINK */
1312 lnet_destroy_rtrbuf(struct lnet_rtrbuf *rb, int npages)
1314 int sz = offsetof(struct lnet_rtrbuf, rb_kiov[npages]);
1316 while (--npages >= 0)
1317 __free_page(rb->rb_kiov[npages].kiov_page);
1319 LIBCFS_FREE(rb, sz);
1322 static struct lnet_rtrbuf *
1323 lnet_new_rtrbuf(struct lnet_rtrbufpool *rbp, int cpt)
1325 int npages = rbp->rbp_npages;
1326 int sz = offsetof(struct lnet_rtrbuf, rb_kiov[npages]);
1328 struct lnet_rtrbuf *rb;
1331 LIBCFS_CPT_ALLOC(rb, lnet_cpt_table(), cpt, sz);
1337 for (i = 0; i < npages; i++) {
1338 page = cfs_page_cpt_alloc(lnet_cpt_table(), cpt,
1339 GFP_KERNEL | __GFP_ZERO);
1342 __free_page(rb->rb_kiov[i].kiov_page);
1344 LIBCFS_FREE(rb, sz);
1348 rb->rb_kiov[i].kiov_len = PAGE_SIZE;
1349 rb->rb_kiov[i].kiov_offset = 0;
1350 rb->rb_kiov[i].kiov_page = page;
1357 lnet_rtrpool_free_bufs(struct lnet_rtrbufpool *rbp, int cpt)
1359 int npages = rbp->rbp_npages;
1360 struct lnet_rtrbuf *rb;
1361 struct list_head tmp;
1363 if (rbp->rbp_nbuffers == 0) /* not initialized or already freed */
1366 INIT_LIST_HEAD(&tmp);
1369 list_splice_init(&rbp->rbp_msgs, &tmp);
1370 lnet_drop_routed_msgs_locked(&tmp, cpt);
1371 list_splice_init(&rbp->rbp_bufs, &tmp);
1372 rbp->rbp_req_nbuffers = 0;
1373 rbp->rbp_nbuffers = rbp->rbp_credits = 0;
1374 rbp->rbp_mincredits = 0;
1375 lnet_net_unlock(cpt);
1377 /* Free buffers on the free list. */
1378 while (!list_empty(&tmp)) {
1379 rb = list_entry(tmp.next, struct lnet_rtrbuf, rb_list);
1380 list_del(&rb->rb_list);
1381 lnet_destroy_rtrbuf(rb, npages);
1386 lnet_rtrpool_adjust_bufs(struct lnet_rtrbufpool *rbp, int nbufs, int cpt)
1388 struct list_head rb_list;
1389 struct lnet_rtrbuf *rb;
1391 int num_buffers = 0;
1393 int npages = rbp->rbp_npages;
1396 /* If we are called for less buffers than already in the pool, we
1397 * just lower the req_nbuffers number and excess buffers will be
1398 * thrown away as they are returned to the free list. Credits
1399 * then get adjusted as well.
1400 * If we already have enough buffers allocated to serve the
1401 * increase requested, then we can treat that the same way as we
1402 * do the decrease. */
1403 num_rb = nbufs - rbp->rbp_nbuffers;
1404 if (nbufs <= rbp->rbp_req_nbuffers || num_rb <= 0) {
1405 rbp->rbp_req_nbuffers = nbufs;
1406 lnet_net_unlock(cpt);
1409 /* store the older value of rbp_req_nbuffers and then set it to
1410 * the new request to prevent lnet_return_rx_credits_locked() from
1411 * freeing buffers that we need to keep around */
1412 old_req_nbufs = rbp->rbp_req_nbuffers;
1413 rbp->rbp_req_nbuffers = nbufs;
1414 lnet_net_unlock(cpt);
1416 INIT_LIST_HEAD(&rb_list);
1418 /* allocate the buffers on a local list first. If all buffers are
1419 * allocated successfully then join this list to the rbp buffer
1420 * list. If not then free all allocated buffers. */
1421 while (num_rb-- > 0) {
1422 rb = lnet_new_rtrbuf(rbp, cpt);
1424 CERROR("Failed to allocate %d route bufs of %d pages\n",
1428 rbp->rbp_req_nbuffers = old_req_nbufs;
1429 lnet_net_unlock(cpt);
1434 list_add(&rb->rb_list, &rb_list);
1440 list_splice_tail(&rb_list, &rbp->rbp_bufs);
1441 rbp->rbp_nbuffers += num_buffers;
1442 rbp->rbp_credits += num_buffers;
1443 rbp->rbp_mincredits = rbp->rbp_credits;
1444 /* We need to schedule blocked msg using the newly
1446 while (!list_empty(&rbp->rbp_bufs) &&
1447 !list_empty(&rbp->rbp_msgs))
1448 lnet_schedule_blocked_locked(rbp);
1450 lnet_net_unlock(cpt);
1455 while (!list_empty(&rb_list)) {
1456 rb = list_entry(rb_list.next, struct lnet_rtrbuf, rb_list);
1457 list_del(&rb->rb_list);
1458 lnet_destroy_rtrbuf(rb, npages);
1465 lnet_rtrpool_init(struct lnet_rtrbufpool *rbp, int npages)
1467 INIT_LIST_HEAD(&rbp->rbp_msgs);
1468 INIT_LIST_HEAD(&rbp->rbp_bufs);
1470 rbp->rbp_npages = npages;
1471 rbp->rbp_credits = 0;
1472 rbp->rbp_mincredits = 0;
1476 lnet_rtrpools_free(int keep_pools)
1478 struct lnet_rtrbufpool *rtrp;
1481 if (the_lnet.ln_rtrpools == NULL) /* uninitialized or freed */
1484 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1485 lnet_rtrpool_free_bufs(&rtrp[LNET_TINY_BUF_IDX], i);
1486 lnet_rtrpool_free_bufs(&rtrp[LNET_SMALL_BUF_IDX], i);
1487 lnet_rtrpool_free_bufs(&rtrp[LNET_LARGE_BUF_IDX], i);
1491 cfs_percpt_free(the_lnet.ln_rtrpools);
1492 the_lnet.ln_rtrpools = NULL;
1497 lnet_nrb_tiny_calculate(void)
1499 int nrbs = LNET_NRB_TINY;
1501 if (tiny_router_buffers < 0) {
1502 LCONSOLE_ERROR_MSG(0x10c,
1503 "tiny_router_buffers=%d invalid when "
1504 "routing enabled\n", tiny_router_buffers);
1508 if (tiny_router_buffers > 0)
1509 nrbs = tiny_router_buffers;
1511 nrbs /= LNET_CPT_NUMBER;
1512 return max(nrbs, LNET_NRB_TINY_MIN);
1516 lnet_nrb_small_calculate(void)
1518 int nrbs = LNET_NRB_SMALL;
1520 if (small_router_buffers < 0) {
1521 LCONSOLE_ERROR_MSG(0x10c,
1522 "small_router_buffers=%d invalid when "
1523 "routing enabled\n", small_router_buffers);
1527 if (small_router_buffers > 0)
1528 nrbs = small_router_buffers;
1530 nrbs /= LNET_CPT_NUMBER;
1531 return max(nrbs, LNET_NRB_SMALL_MIN);
1535 lnet_nrb_large_calculate(void)
1537 int nrbs = LNET_NRB_LARGE;
1539 if (large_router_buffers < 0) {
1540 LCONSOLE_ERROR_MSG(0x10c,
1541 "large_router_buffers=%d invalid when "
1542 "routing enabled\n", large_router_buffers);
1546 if (large_router_buffers > 0)
1547 nrbs = large_router_buffers;
1549 nrbs /= LNET_CPT_NUMBER;
1550 return max(nrbs, LNET_NRB_LARGE_MIN);
1554 lnet_rtrpools_alloc(int im_a_router)
1556 struct lnet_rtrbufpool *rtrp;
1563 if (!strcmp(forwarding, "")) {
1564 /* not set either way */
1567 } else if (!strcmp(forwarding, "disabled")) {
1568 /* explicitly disabled */
1570 } else if (!strcmp(forwarding, "enabled")) {
1571 /* explicitly enabled */
1573 LCONSOLE_ERROR_MSG(0x10b, "'forwarding' not set to either "
1574 "'enabled' or 'disabled'\n");
1578 nrb_tiny = lnet_nrb_tiny_calculate();
1582 nrb_small = lnet_nrb_small_calculate();
1586 nrb_large = lnet_nrb_large_calculate();
1590 the_lnet.ln_rtrpools = cfs_percpt_alloc(lnet_cpt_table(),
1592 sizeof(struct lnet_rtrbufpool));
1593 if (the_lnet.ln_rtrpools == NULL) {
1594 LCONSOLE_ERROR_MSG(0x10c,
1595 "Failed to initialize router buffe pool\n");
1599 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1600 lnet_rtrpool_init(&rtrp[LNET_TINY_BUF_IDX], 0);
1601 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_TINY_BUF_IDX],
1606 lnet_rtrpool_init(&rtrp[LNET_SMALL_BUF_IDX],
1607 LNET_NRB_SMALL_PAGES);
1608 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_SMALL_BUF_IDX],
1613 lnet_rtrpool_init(&rtrp[LNET_LARGE_BUF_IDX],
1614 LNET_NRB_LARGE_PAGES);
1615 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_LARGE_BUF_IDX],
1621 lnet_net_lock(LNET_LOCK_EX);
1622 the_lnet.ln_routing = 1;
1623 lnet_net_unlock(LNET_LOCK_EX);
1627 lnet_rtrpools_free(0);
1632 lnet_rtrpools_adjust_helper(int tiny, int small, int large)
1637 struct lnet_rtrbufpool *rtrp;
1639 /* If the provided values for each buffer pool are different than the
1640 * configured values, we need to take action. */
1642 tiny_router_buffers = tiny;
1643 nrb = lnet_nrb_tiny_calculate();
1644 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1645 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_TINY_BUF_IDX],
1652 small_router_buffers = small;
1653 nrb = lnet_nrb_small_calculate();
1654 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1655 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_SMALL_BUF_IDX],
1662 large_router_buffers = large;
1663 nrb = lnet_nrb_large_calculate();
1664 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1665 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_LARGE_BUF_IDX],
1676 lnet_rtrpools_adjust(int tiny, int small, int large)
1678 /* this function doesn't revert the changes if adding new buffers
1679 * failed. It's up to the user space caller to revert the
1682 if (!the_lnet.ln_routing)
1685 return lnet_rtrpools_adjust_helper(tiny, small, large);
1689 lnet_rtrpools_enable(void)
1693 if (the_lnet.ln_routing)
1696 if (the_lnet.ln_rtrpools == NULL)
1697 /* If routing is turned off, and we have never
1698 * initialized the pools before, just call the
1699 * standard buffer pool allocation routine as
1700 * if we are just configuring this for the first
1702 rc = lnet_rtrpools_alloc(1);
1704 rc = lnet_rtrpools_adjust_helper(0, 0, 0);
1708 lnet_net_lock(LNET_LOCK_EX);
1709 the_lnet.ln_routing = 1;
1711 the_lnet.ln_ping_target->pb_info.pi_features &=
1712 ~LNET_PING_FEAT_RTE_DISABLED;
1713 lnet_net_unlock(LNET_LOCK_EX);
1719 lnet_rtrpools_disable(void)
1721 if (!the_lnet.ln_routing)
1724 lnet_net_lock(LNET_LOCK_EX);
1725 the_lnet.ln_routing = 0;
1726 the_lnet.ln_ping_target->pb_info.pi_features |=
1727 LNET_PING_FEAT_RTE_DISABLED;
1729 tiny_router_buffers = 0;
1730 small_router_buffers = 0;
1731 large_router_buffers = 0;
1732 lnet_net_unlock(LNET_LOCK_EX);
1733 lnet_rtrpools_free(1);
1737 lnet_notify(struct lnet_ni *ni, lnet_nid_t nid, int alive, time64_t when)
1739 struct lnet_peer_ni *lp = NULL;
1740 time64_t now = ktime_get_seconds();
1741 int cpt = lnet_cpt_of_nid(nid, ni);
1743 LASSERT (!in_interrupt ());
1745 CDEBUG (D_NET, "%s notifying %s: %s\n",
1746 (ni == NULL) ? "userspace" : libcfs_nid2str(ni->ni_nid),
1747 libcfs_nid2str(nid),
1748 alive ? "up" : "down");
1751 LNET_NIDNET(ni->ni_nid) != LNET_NIDNET(nid)) {
1752 CWARN("Ignoring notification of %s %s by %s (different net)\n",
1753 libcfs_nid2str(nid), alive ? "birth" : "death",
1754 libcfs_nid2str(ni->ni_nid));
1758 /* can't do predictions... */
1760 CWARN("Ignoring prediction from %s of %s %s "
1761 "%lld seconds in the future\n",
1762 (ni == NULL) ? "userspace" : libcfs_nid2str(ni->ni_nid),
1763 libcfs_nid2str(nid), alive ? "up" : "down", when - now);
1767 if (ni != NULL && !alive && /* LND telling me she's down */
1768 !auto_down) { /* auto-down disabled */
1769 CDEBUG(D_NET, "Auto-down disabled\n");
1775 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
1776 lnet_net_unlock(cpt);
1780 lp = lnet_find_peer_ni_locked(nid);
1783 lnet_net_unlock(cpt);
1784 CDEBUG(D_NET, "%s not found\n", libcfs_nid2str(nid));
1789 * It is possible for this function to be called for the same peer
1790 * but with different NIs. We want to synchronize the notification
1791 * between the different calls. So we will use the lpni_cpt to
1792 * grab the net lock.
1794 if (lp->lpni_cpt != cpt) {
1795 lnet_net_unlock(cpt);
1800 /* We can't fully trust LND on reporting exact peer last_alive
1801 * if he notifies us about dead peer. For example ksocklnd can
1802 * call us with when == _time_when_the_node_was_booted_ if
1803 * no connections were successfully established */
1804 if (ni != NULL && !alive && when < lp->lpni_last_alive)
1805 when = lp->lpni_last_alive;
1807 lnet_notify_locked(lp, ni == NULL, alive, when);
1810 lnet_ni_notify_locked(ni, lp);
1812 lnet_peer_ni_decref_locked(lp);
1814 lnet_net_unlock(cpt);
1817 EXPORT_SYMBOL(lnet_notify);