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
24 #include <lnet/lib-lnet.h>
26 #define LNET_NRB_TINY_MIN 512 /* min value for each CPT */
27 #define LNET_NRB_TINY (LNET_NRB_TINY_MIN * 4)
28 #define LNET_NRB_SMALL_MIN 4096 /* min value for each CPT */
29 #define LNET_NRB_SMALL (LNET_NRB_SMALL_MIN * 4)
30 #define LNET_NRB_SMALL_PAGES 1
31 #define LNET_NRB_LARGE_MIN 256 /* min value for each CPT */
32 #define LNET_NRB_LARGE (LNET_NRB_LARGE_MIN * 4)
33 #define LNET_NRB_LARGE_PAGES ((LNET_MTU + PAGE_SIZE - 1) >> \
36 static char *forwarding = "";
37 module_param(forwarding, charp, 0444);
38 MODULE_PARM_DESC(forwarding, "Explicitly enable/disable forwarding between networks");
40 static int tiny_router_buffers;
41 module_param(tiny_router_buffers, int, 0444);
42 MODULE_PARM_DESC(tiny_router_buffers, "# of 0 payload messages to buffer in the router");
43 static int small_router_buffers;
44 module_param(small_router_buffers, int, 0444);
45 MODULE_PARM_DESC(small_router_buffers, "# of small (1 page) messages to buffer in the router");
46 static int large_router_buffers;
47 module_param(large_router_buffers, int, 0444);
48 MODULE_PARM_DESC(large_router_buffers, "# of large messages to buffer in the router");
49 static int peer_buffer_credits;
50 module_param(peer_buffer_credits, int, 0444);
51 MODULE_PARM_DESC(peer_buffer_credits, "# router buffer credits per peer");
53 static int auto_down = 1;
54 module_param(auto_down, int, 0444);
55 MODULE_PARM_DESC(auto_down, "Automatically mark peers down on comms error");
58 lnet_peer_buffer_credits(struct lnet_net *net)
60 /* NI option overrides LNet default */
61 if (net->net_tunables.lct_peer_rtr_credits > 0)
62 return net->net_tunables.lct_peer_rtr_credits;
63 if (peer_buffer_credits > 0)
64 return peer_buffer_credits;
66 /* As an approximation, allow this peer the same number of router
67 * buffers as it is allowed outstanding sends */
68 return net->net_tunables.lct_peer_tx_credits;
71 static int check_routers_before_use;
72 module_param(check_routers_before_use, int, 0444);
73 MODULE_PARM_DESC(check_routers_before_use, "Assume routers are down and ping them before use");
75 int avoid_asym_router_failure = 1;
76 module_param(avoid_asym_router_failure, int, 0644);
77 MODULE_PARM_DESC(avoid_asym_router_failure, "Avoid asymmetrical router failures (0 to disable)");
79 static int dead_router_check_interval = 60;
80 module_param(dead_router_check_interval, int, 0644);
81 MODULE_PARM_DESC(dead_router_check_interval, "Seconds between dead router health checks (<= 0 to disable)");
83 static int live_router_check_interval = 60;
84 module_param(live_router_check_interval, int, 0644);
85 MODULE_PARM_DESC(live_router_check_interval, "Seconds between live router health checks (<= 0 to disable)");
87 static int router_ping_timeout = 50;
88 module_param(router_ping_timeout, int, 0644);
89 MODULE_PARM_DESC(router_ping_timeout, "Seconds to wait for the reply to a router health query");
92 lnet_peers_start_down(void)
94 return check_routers_before_use;
98 lnet_notify_locked(struct lnet_peer_ni *lp, int notifylnd, int alive,
101 if (lp->lpni_timestamp > when) { /* out of date information */
102 CDEBUG(D_NET, "Out of date\n");
107 * This function can be called with different cpt locks being
108 * held. lpni_alive_count modification needs to be properly protected.
109 * Significant reads to lpni_alive_count are also protected with
112 spin_lock(&lp->lpni_lock);
114 lp->lpni_timestamp = when; /* update timestamp */
115 lp->lpni_ping_deadline = 0; /* disable ping timeout */
117 if (lp->lpni_alive_count != 0 && /* got old news */
118 (!lp->lpni_alive) == (!alive)) { /* new date for old news */
119 spin_unlock(&lp->lpni_lock);
120 CDEBUG(D_NET, "Old news\n");
124 /* Flag that notification is outstanding */
126 lp->lpni_alive_count++;
127 lp->lpni_alive = (alive) ? 1 : 0;
129 lp->lpni_notifylnd = notifylnd;
131 lp->lpni_ping_feats = LNET_PING_FEAT_INVAL; /* reset */
133 spin_unlock(&lp->lpni_lock);
135 CDEBUG(D_NET, "set %s %d\n", libcfs_nid2str(lp->lpni_nid), alive);
139 * This function will always be called with lp->lpni_cpt lock held.
142 lnet_ni_notify_locked(struct lnet_ni *ni, struct lnet_peer_ni *lp)
147 /* Notify only in 1 thread at any time to ensure ordered notification.
148 * NB individual events can be missed; the only guarantee is that you
149 * always get the most recent news */
151 spin_lock(&lp->lpni_lock);
153 if (lp->lpni_notifying || ni == NULL) {
154 spin_unlock(&lp->lpni_lock);
158 lp->lpni_notifying = 1;
161 * lp->lpni_notify needs to be protected because it can be set in
162 * lnet_notify_locked().
164 while (lp->lpni_notify) {
165 alive = lp->lpni_alive;
166 notifylnd = lp->lpni_notifylnd;
168 lp->lpni_notifylnd = 0;
171 if (notifylnd && ni->ni_net->net_lnd->lnd_notify != NULL) {
172 spin_unlock(&lp->lpni_lock);
173 lnet_net_unlock(lp->lpni_cpt);
175 /* A new notification could happen now; I'll handle it
176 * when control returns to me */
178 (ni->ni_net->net_lnd->lnd_notify)(ni, lp->lpni_nid,
181 lnet_net_lock(lp->lpni_cpt);
182 spin_lock(&lp->lpni_lock);
186 lp->lpni_notifying = 0;
187 spin_unlock(&lp->lpni_lock);
191 lnet_rtr_addref_locked(struct lnet_peer_ni *lp)
193 LASSERT(atomic_read(&lp->lpni_refcount) > 0);
194 LASSERT(lp->lpni_rtr_refcount >= 0);
196 /* lnet_net_lock must be exclusively locked */
197 lp->lpni_rtr_refcount++;
198 if (lp->lpni_rtr_refcount == 1) {
199 struct list_head *pos;
201 /* a simple insertion sort */
202 list_for_each_prev(pos, &the_lnet.ln_routers) {
203 struct lnet_peer_ni *rtr;
205 rtr = list_entry(pos, struct lnet_peer_ni,
207 if (rtr->lpni_nid < lp->lpni_nid)
211 list_add(&lp->lpni_rtr_list, pos);
212 /* addref for the_lnet.ln_routers */
213 lnet_peer_ni_addref_locked(lp);
214 the_lnet.ln_routers_version++;
219 lnet_rtr_decref_locked(struct lnet_peer_ni *lp)
221 LASSERT(atomic_read(&lp->lpni_refcount) > 0);
222 LASSERT(lp->lpni_rtr_refcount > 0);
224 /* lnet_net_lock must be exclusively locked */
225 lp->lpni_rtr_refcount--;
226 if (lp->lpni_rtr_refcount == 0) {
227 LASSERT(list_empty(&lp->lpni_routes));
229 if (lp->lpni_rcd != NULL) {
230 list_add(&lp->lpni_rcd->rcd_list,
231 &the_lnet.ln_rcd_deathrow);
235 list_del(&lp->lpni_rtr_list);
236 /* decref for the_lnet.ln_routers */
237 lnet_peer_ni_decref_locked(lp);
238 the_lnet.ln_routers_version++;
242 struct lnet_remotenet *
243 lnet_find_rnet_locked(__u32 net)
245 struct lnet_remotenet *rnet;
246 struct list_head *tmp;
247 struct list_head *rn_list;
249 LASSERT(the_lnet.ln_state == LNET_STATE_RUNNING);
251 rn_list = lnet_net2rnethash(net);
252 list_for_each(tmp, rn_list) {
253 rnet = list_entry(tmp, struct lnet_remotenet, lrn_list);
255 if (rnet->lrn_net == net)
261 static void lnet_shuffle_seed(void)
266 struct timespec64 ts;
267 struct lnet_ni *ni = NULL;
272 cfs_get_random_bytes(seed, sizeof(seed));
274 /* Nodes with small feet have little entropy
275 * the NID for this node gives the most entropy in the low bits */
276 while ((ni = lnet_get_next_ni_locked(NULL, ni))) {
277 lnd_type = LNET_NETTYP(LNET_NIDNET(ni->ni_nid));
279 if (lnd_type != LOLND)
280 seed[0] ^= (LNET_NIDADDR(ni->ni_nid) | lnd_type);
284 cfs_srand(ts.tv_sec ^ seed[0], ts.tv_nsec ^ seed[1]);
289 /* NB expects LNET_LOCK held */
291 lnet_add_route_to_rnet(struct lnet_remotenet *rnet, struct lnet_route *route)
293 unsigned int len = 0;
294 unsigned int offset = 0;
299 list_for_each(e, &rnet->lrn_routes) {
303 /* len+1 positions to add a new entry, also prevents division by 0 */
304 offset = cfs_rand() % (len + 1);
305 list_for_each(e, &rnet->lrn_routes) {
310 list_add(&route->lr_list, e);
311 list_add(&route->lr_gwlist, &route->lr_gateway->lpni_routes);
313 the_lnet.ln_remote_nets_version++;
314 lnet_rtr_addref_locked(route->lr_gateway);
318 lnet_add_route(__u32 net, __u32 hops, lnet_nid_t gateway,
319 unsigned int priority)
322 struct lnet_remotenet *rnet;
323 struct lnet_remotenet *rnet2;
324 struct lnet_route *route;
326 struct lnet_peer_ni *lpni;
330 CDEBUG(D_NET, "Add route: net %s hops %d priority %u gw %s\n",
331 libcfs_net2str(net), hops, priority, libcfs_nid2str(gateway));
333 if (gateway == LNET_NID_ANY ||
334 LNET_NETTYP(LNET_NIDNET(gateway)) == LOLND ||
335 net == LNET_NIDNET(LNET_NID_ANY) ||
336 LNET_NETTYP(net) == LOLND ||
337 LNET_NIDNET(gateway) == net ||
338 (hops != LNET_UNDEFINED_HOPS && (hops < 1 || hops > 255)))
341 if (lnet_islocalnet(net)) /* it's a local network */
344 if (!lnet_islocalnet(LNET_NIDNET(gateway))) {
345 CERROR("Cannot add route with gateway %s. There is no local interface configured on LNet %s\n",
346 libcfs_nid2str(gateway),
347 libcfs_net2str(LNET_NIDNET(gateway)));
348 return -EHOSTUNREACH;
351 /* Assume net, route, all new */
352 LIBCFS_ALLOC(route, sizeof(*route));
353 LIBCFS_ALLOC(rnet, sizeof(*rnet));
354 if (route == NULL || rnet == NULL) {
355 CERROR("Out of memory creating route %s %d %s\n",
356 libcfs_net2str(net), hops, libcfs_nid2str(gateway));
358 LIBCFS_FREE(route, sizeof(*route));
360 LIBCFS_FREE(rnet, sizeof(*rnet));
364 INIT_LIST_HEAD(&rnet->lrn_routes);
366 route->lr_hops = hops;
368 route->lr_priority = priority;
370 lnet_net_lock(LNET_LOCK_EX);
372 lpni = lnet_nid2peerni_ex(gateway, LNET_LOCK_EX);
374 lnet_net_unlock(LNET_LOCK_EX);
376 LIBCFS_FREE(route, sizeof(*route));
377 LIBCFS_FREE(rnet, sizeof(*rnet));
380 if (rc == -EHOSTUNREACH) /* gateway is not on a local net. */
381 return rc; /* ignore the route entry */
382 CERROR("Error %d creating route %s %d %s\n", rc,
383 libcfs_net2str(net), hops,
384 libcfs_nid2str(gateway));
387 route->lr_gateway = lpni;
388 LASSERT(the_lnet.ln_state == LNET_STATE_RUNNING);
390 rnet2 = lnet_find_rnet_locked(net);
393 list_add_tail(&rnet->lrn_list, lnet_net2rnethash(net));
397 /* Search for a duplicate route (it's a NOOP if it is) */
399 list_for_each(e, &rnet2->lrn_routes) {
400 struct lnet_route *route2;
402 route2 = list_entry(e, struct lnet_route, lr_list);
403 if (route2->lr_gateway == route->lr_gateway) {
408 /* our lookups must be true */
409 LASSERT(route2->lr_gateway->lpni_nid != gateway);
413 lnet_peer_ni_addref_locked(route->lr_gateway); /* +1 for notify */
414 lnet_add_route_to_rnet(rnet2, route);
416 ni = lnet_get_next_ni_locked(route->lr_gateway->lpni_net, NULL);
417 lnet_net_unlock(LNET_LOCK_EX);
419 /* XXX Assume alive */
420 if (ni->ni_net->net_lnd->lnd_notify != NULL)
421 (ni->ni_net->net_lnd->lnd_notify)(ni, gateway, 1);
423 lnet_net_lock(LNET_LOCK_EX);
426 /* -1 for notify or !add_route */
427 lnet_peer_ni_decref_locked(route->lr_gateway);
428 lnet_net_unlock(LNET_LOCK_EX);
434 LIBCFS_FREE(route, sizeof(*route));
438 LIBCFS_FREE(rnet, sizeof(*rnet));
440 /* kick start the monitor thread to handle the added route */
441 wake_up(&the_lnet.ln_mt_waitq);
447 lnet_check_routes(void)
449 struct lnet_remotenet *rnet;
450 struct lnet_route *route;
451 struct lnet_route *route2;
452 struct list_head *e1;
453 struct list_head *e2;
455 struct list_head *rn_list;
458 cpt = lnet_net_lock_current();
460 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) {
461 rn_list = &the_lnet.ln_remote_nets_hash[i];
462 list_for_each(e1, rn_list) {
463 rnet = list_entry(e1, struct lnet_remotenet, lrn_list);
466 list_for_each(e2, &rnet->lrn_routes) {
471 route = list_entry(e2, struct lnet_route,
474 if (route2 == NULL) {
479 if (route->lr_gateway->lpni_net ==
480 route2->lr_gateway->lpni_net)
483 nid1 = route->lr_gateway->lpni_nid;
484 nid2 = route2->lr_gateway->lpni_nid;
487 lnet_net_unlock(cpt);
489 CERROR("Routes to %s via %s and %s not "
492 libcfs_nid2str(nid1),
493 libcfs_nid2str(nid2));
499 lnet_net_unlock(cpt);
504 lnet_del_route(__u32 net, lnet_nid_t gw_nid)
506 struct lnet_peer_ni *gateway;
507 struct lnet_remotenet *rnet;
508 struct lnet_route *route;
509 struct list_head *e1;
510 struct list_head *e2;
512 struct list_head *rn_list;
515 CDEBUG(D_NET, "Del route: net %s : gw %s\n",
516 libcfs_net2str(net), libcfs_nid2str(gw_nid));
518 /* NB Caller may specify either all routes via the given gateway
519 * or a specific route entry actual NIDs) */
521 lnet_net_lock(LNET_LOCK_EX);
522 if (net == LNET_NIDNET(LNET_NID_ANY))
523 rn_list = &the_lnet.ln_remote_nets_hash[0];
525 rn_list = lnet_net2rnethash(net);
528 list_for_each(e1, rn_list) {
529 rnet = list_entry(e1, struct lnet_remotenet, lrn_list);
531 if (!(net == LNET_NIDNET(LNET_NID_ANY) ||
532 net == rnet->lrn_net))
535 list_for_each(e2, &rnet->lrn_routes) {
536 route = list_entry(e2, struct lnet_route, lr_list);
538 gateway = route->lr_gateway;
539 if (!(gw_nid == LNET_NID_ANY ||
540 gw_nid == gateway->lpni_nid))
543 list_del(&route->lr_list);
544 list_del(&route->lr_gwlist);
545 the_lnet.ln_remote_nets_version++;
547 if (list_empty(&rnet->lrn_routes))
548 list_del(&rnet->lrn_list);
552 lnet_rtr_decref_locked(gateway);
553 lnet_peer_ni_decref_locked(gateway);
555 lnet_net_unlock(LNET_LOCK_EX);
557 LIBCFS_FREE(route, sizeof(*route));
560 LIBCFS_FREE(rnet, sizeof(*rnet));
563 lnet_net_lock(LNET_LOCK_EX);
568 if (net == LNET_NIDNET(LNET_NID_ANY) &&
569 ++idx < LNET_REMOTE_NETS_HASH_SIZE) {
570 rn_list = &the_lnet.ln_remote_nets_hash[idx];
573 lnet_net_unlock(LNET_LOCK_EX);
579 lnet_destroy_routes (void)
581 lnet_del_route(LNET_NIDNET(LNET_NID_ANY), LNET_NID_ANY);
584 int lnet_get_rtr_pool_cfg(int cpt, struct lnet_ioctl_pool_cfg *pool_cfg)
586 struct lnet_rtrbufpool *rbp;
587 int i, rc = -ENOENT, j;
589 if (the_lnet.ln_rtrpools == NULL)
593 cfs_percpt_for_each(rbp, i, the_lnet.ln_rtrpools) {
598 for (j = 0; j < LNET_NRBPOOLS; j++) {
599 pool_cfg->pl_pools[j].pl_npages = rbp[j].rbp_npages;
600 pool_cfg->pl_pools[j].pl_nbuffers = rbp[j].rbp_nbuffers;
601 pool_cfg->pl_pools[j].pl_credits = rbp[j].rbp_credits;
602 pool_cfg->pl_pools[j].pl_mincredits = rbp[j].rbp_mincredits;
609 lnet_net_lock(LNET_LOCK_EX);
610 pool_cfg->pl_routing = the_lnet.ln_routing;
611 lnet_net_unlock(LNET_LOCK_EX);
617 lnet_get_route(int idx, __u32 *net, __u32 *hops,
618 lnet_nid_t *gateway, __u32 *alive, __u32 *priority)
620 struct list_head *e1;
621 struct list_head *e2;
622 struct lnet_remotenet *rnet;
623 struct lnet_route *route;
626 struct list_head *rn_list;
628 cpt = lnet_net_lock_current();
630 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) {
631 rn_list = &the_lnet.ln_remote_nets_hash[i];
632 list_for_each(e1, rn_list) {
633 rnet = list_entry(e1, struct lnet_remotenet, lrn_list);
635 list_for_each(e2, &rnet->lrn_routes) {
636 route = list_entry(e2, struct lnet_route,
640 *net = rnet->lrn_net;
641 *hops = route->lr_hops;
642 *priority = route->lr_priority;
643 *gateway = route->lr_gateway->lpni_nid;
644 *alive = lnet_is_route_alive(route);
645 lnet_net_unlock(cpt);
652 lnet_net_unlock(cpt);
657 lnet_swap_pinginfo(struct lnet_ping_buffer *pbuf)
659 struct lnet_ni_status *stat;
663 __swab32s(&pbuf->pb_info.pi_magic);
664 __swab32s(&pbuf->pb_info.pi_features);
665 __swab32s(&pbuf->pb_info.pi_pid);
666 __swab32s(&pbuf->pb_info.pi_nnis);
667 nnis = pbuf->pb_info.pi_nnis;
668 if (nnis > pbuf->pb_nnis)
669 nnis = pbuf->pb_nnis;
670 for (i = 0; i < nnis; i++) {
671 stat = &pbuf->pb_info.pi_ni[i];
672 __swab64s(&stat->ns_nid);
673 __swab32s(&stat->ns_status);
679 * parse router-checker pinginfo, record number of down NIs for remote
680 * networks on that router.
683 lnet_parse_rc_info(struct lnet_rc_data *rcd)
685 struct lnet_ping_buffer *pbuf = rcd->rcd_pingbuffer;
686 struct lnet_peer_ni *gw = rcd->rcd_gateway;
687 struct lnet_route *rte;
690 if (!gw->lpni_alive || !pbuf)
694 * Protect gw->lpni_ping_feats. This can be set from
695 * lnet_notify_locked with different locks being held
697 spin_lock(&gw->lpni_lock);
699 if (pbuf->pb_info.pi_magic == __swab32(LNET_PROTO_PING_MAGIC))
700 lnet_swap_pinginfo(pbuf);
702 /* NB always racing with network! */
703 if (pbuf->pb_info.pi_magic != LNET_PROTO_PING_MAGIC) {
704 CDEBUG(D_NET, "%s: Unexpected magic %08x\n",
705 libcfs_nid2str(gw->lpni_nid), pbuf->pb_info.pi_magic);
706 gw->lpni_ping_feats = LNET_PING_FEAT_INVAL;
710 gw->lpni_ping_feats = pbuf->pb_info.pi_features;
712 /* Without NI status info there's nothing more to do. */
713 if ((gw->lpni_ping_feats & LNET_PING_FEAT_NI_STATUS) == 0)
716 /* Determine the number of NIs for which there is data. */
717 nnis = pbuf->pb_info.pi_nnis;
718 if (pbuf->pb_nnis < nnis) {
719 if (rcd->rcd_nnis < nnis)
720 rcd->rcd_nnis = nnis;
721 nnis = pbuf->pb_nnis;
724 list_for_each_entry(rte, &gw->lpni_routes, lr_gwlist) {
729 /* If routing disabled then the route is down. */
730 if ((gw->lpni_ping_feats & LNET_PING_FEAT_RTE_DISABLED) != 0) {
735 for (i = 0; i < nnis; i++) {
736 struct lnet_ni_status *stat = &pbuf->pb_info.pi_ni[i];
737 lnet_nid_t nid = stat->ns_nid;
739 if (nid == LNET_NID_ANY) {
740 CDEBUG(D_NET, "%s: unexpected LNET_NID_ANY\n",
741 libcfs_nid2str(gw->lpni_nid));
742 gw->lpni_ping_feats = LNET_PING_FEAT_INVAL;
746 if (LNET_NETTYP(LNET_NIDNET(nid)) == LOLND)
749 if (stat->ns_status == LNET_NI_STATUS_DOWN) {
754 if (stat->ns_status == LNET_NI_STATUS_UP) {
755 if (LNET_NIDNET(nid) == rte->lr_net) {
762 CDEBUG(D_NET, "%s: Unexpected status 0x%x\n",
763 libcfs_nid2str(gw->lpni_nid), stat->ns_status);
764 gw->lpni_ping_feats = LNET_PING_FEAT_INVAL;
768 if (up) { /* ignore downed NIs if NI for dest network is up */
772 /* if @down is zero and this route is single-hop, it means
773 * we can't find NI for target network */
774 if (down == 0 && rte->lr_hops == 1)
777 rte->lr_downis = down;
780 spin_unlock(&gw->lpni_lock);
784 lnet_router_checker_event(struct lnet_event *event)
786 struct lnet_rc_data *rcd = event->md.user_ptr;
787 struct lnet_peer_ni *lp;
789 LASSERT(rcd != NULL);
791 if (event->unlinked) {
792 LNetInvalidateMDHandle(&rcd->rcd_mdh);
796 LASSERT(event->type == LNET_EVENT_SEND ||
797 event->type == LNET_EVENT_REPLY);
799 lp = rcd->rcd_gateway;
802 /* NB: it's called with holding lnet_res_lock, we have a few
803 * places need to hold both locks at the same time, please take
804 * care of lock ordering */
805 lnet_net_lock(lp->lpni_cpt);
806 if (!lnet_isrouter(lp) || lp->lpni_rcd != rcd) {
807 /* ignore if no longer a router or rcd is replaced */
811 if (event->type == LNET_EVENT_SEND) {
812 lp->lpni_ping_notsent = 0;
813 if (event->status == 0)
817 /* LNET_EVENT_REPLY */
818 /* A successful REPLY means the router is up. If _any_ comms
819 * to the router fail I assume it's down (this will happen if
820 * we ping alive routers to try to detect router death before
821 * apps get burned). */
823 lnet_notify_locked(lp, 1, !event->status, ktime_get_seconds());
824 /* The router checker will wake up very shortly and do the
825 * actual notification.
826 * XXX If 'lp' stops being a router before then, it will still
827 * have the notification pending!!! */
829 if (avoid_asym_router_failure && event->status == 0)
830 lnet_parse_rc_info(rcd);
833 lnet_net_unlock(lp->lpni_cpt);
837 lnet_wait_known_routerstate(void)
839 struct lnet_peer_ni *rtr;
840 struct list_head *entry;
843 LASSERT(the_lnet.ln_mt_state == LNET_MT_STATE_RUNNING);
846 int cpt = lnet_net_lock_current();
849 list_for_each(entry, &the_lnet.ln_routers) {
850 rtr = list_entry(entry, struct lnet_peer_ni,
853 spin_lock(&rtr->lpni_lock);
855 if (rtr->lpni_alive_count == 0) {
857 spin_unlock(&rtr->lpni_lock);
860 spin_unlock(&rtr->lpni_lock);
863 lnet_net_unlock(cpt);
868 set_current_state(TASK_UNINTERRUPTIBLE);
869 schedule_timeout(cfs_time_seconds(1));
874 lnet_router_ni_update_locked(struct lnet_peer_ni *gw, __u32 net)
876 struct lnet_route *rte;
878 if ((gw->lpni_ping_feats & LNET_PING_FEAT_NI_STATUS) != 0) {
879 list_for_each_entry(rte, &gw->lpni_routes, lr_gwlist) {
880 if (rte->lr_net == net) {
889 lnet_update_ni_status_locked(void)
891 struct lnet_ni *ni = NULL;
895 LASSERT(the_lnet.ln_routing);
897 timeout = router_ping_timeout +
898 MAX(live_router_check_interval, dead_router_check_interval);
900 now = ktime_get_real_seconds();
901 while ((ni = lnet_get_next_ni_locked(NULL, ni))) {
902 if (ni->ni_net->net_lnd->lnd_type == LOLND)
905 if (now < ni->ni_last_alive + timeout)
909 /* re-check with lock */
910 if (now < ni->ni_last_alive + timeout) {
915 LASSERT(ni->ni_status != NULL);
917 if (ni->ni_status->ns_status != LNET_NI_STATUS_DOWN) {
918 CDEBUG(D_NET, "NI(%s:%lld) status changed to down\n",
919 libcfs_nid2str(ni->ni_nid), timeout);
920 /* NB: so far, this is the only place to set
921 * NI status to "down" */
922 ni->ni_status->ns_status = LNET_NI_STATUS_DOWN;
929 lnet_destroy_rc_data(struct lnet_rc_data *rcd)
931 LASSERT(list_empty(&rcd->rcd_list));
932 /* detached from network */
933 LASSERT(LNetMDHandleIsInvalid(rcd->rcd_mdh));
935 if (rcd->rcd_gateway != NULL) {
936 int cpt = rcd->rcd_gateway->lpni_cpt;
939 lnet_peer_ni_decref_locked(rcd->rcd_gateway);
940 lnet_net_unlock(cpt);
943 if (rcd->rcd_pingbuffer != NULL)
944 lnet_ping_buffer_decref(rcd->rcd_pingbuffer);
946 LIBCFS_FREE(rcd, sizeof(*rcd));
949 static struct lnet_rc_data *
950 lnet_update_rc_data_locked(struct lnet_peer_ni *gateway)
952 struct lnet_handle_md mdh;
953 struct lnet_rc_data *rcd;
954 struct lnet_ping_buffer *pbuf = NULL;
955 int nnis = LNET_INTERFACES_MIN;
959 rcd = gateway->lpni_rcd;
961 nnis = rcd->rcd_nnis;
963 LNetInvalidateMDHandle(&rcd->rcd_mdh);
964 pbuf = rcd->rcd_pingbuffer;
965 rcd->rcd_pingbuffer = NULL;
967 LNetInvalidateMDHandle(&mdh);
970 lnet_net_unlock(gateway->lpni_cpt);
974 lnet_ping_buffer_decref(pbuf);
976 LIBCFS_ALLOC(rcd, sizeof(*rcd));
980 LNetInvalidateMDHandle(&rcd->rcd_mdh);
981 INIT_LIST_HEAD(&rcd->rcd_list);
982 rcd->rcd_nnis = nnis;
985 pbuf = lnet_ping_buffer_alloc(nnis, GFP_NOFS);
989 for (i = 0; i < nnis; i++) {
990 pbuf->pb_info.pi_ni[i].ns_nid = LNET_NID_ANY;
991 pbuf->pb_info.pi_ni[i].ns_status = LNET_NI_STATUS_INVALID;
993 rcd->rcd_pingbuffer = pbuf;
995 LASSERT(!LNetEQHandleIsInvalid(the_lnet.ln_rc_eqh));
996 rc = LNetMDBind((struct lnet_md){.start = &pbuf->pb_info,
998 .length = LNET_PING_INFO_SIZE(nnis),
999 .threshold = LNET_MD_THRESH_INF,
1000 .options = LNET_MD_TRUNCATE,
1001 .eq_handle = the_lnet.ln_rc_eqh},
1005 CERROR("Can't bind MD: %d\n", rc);
1006 goto out_ping_buffer_decref;
1010 lnet_net_lock(gateway->lpni_cpt);
1011 /* Check if this is still a router. */
1012 if (!lnet_isrouter(gateway))
1014 /* Check if someone else installed router data. */
1015 if (gateway->lpni_rcd && gateway->lpni_rcd != rcd)
1018 /* Install and/or update the router data. */
1019 if (!gateway->lpni_rcd) {
1020 lnet_peer_ni_addref_locked(gateway);
1021 rcd->rcd_gateway = gateway;
1022 gateway->lpni_rcd = rcd;
1024 gateway->lpni_ping_notsent = 0;
1029 lnet_net_unlock(gateway->lpni_cpt);
1030 rc = LNetMDUnlink(mdh);
1032 out_ping_buffer_decref:
1033 lnet_ping_buffer_decref(pbuf);
1035 if (rcd && rcd != gateway->lpni_rcd)
1036 lnet_destroy_rc_data(rcd);
1037 lnet_net_lock(gateway->lpni_cpt);
1038 return gateway->lpni_rcd;
1042 lnet_router_check_interval(struct lnet_peer_ni *rtr)
1046 secs = rtr->lpni_alive ? live_router_check_interval :
1047 dead_router_check_interval;
1055 lnet_ping_router_locked(struct lnet_peer_ni *rtr)
1057 struct lnet_rc_data *rcd = NULL;
1058 time64_t now = ktime_get_seconds();
1062 lnet_peer_ni_addref_locked(rtr);
1064 if (rtr->lpni_ping_deadline != 0 && /* ping timed out? */
1065 now > rtr->lpni_ping_deadline)
1066 lnet_notify_locked(rtr, 1, 0, now);
1068 /* Run any outstanding notifications */
1069 ni = lnet_get_next_ni_locked(rtr->lpni_net, NULL);
1070 lnet_ni_notify_locked(ni, rtr);
1072 if (!lnet_isrouter(rtr) ||
1073 the_lnet.ln_mt_state != LNET_MT_STATE_RUNNING) {
1074 /* router table changed or router checker is shutting down */
1075 lnet_peer_ni_decref_locked(rtr);
1079 rcd = rtr->lpni_rcd;
1082 * The response to the router checker ping could've timed out and
1083 * the mdh might've been invalidated, so we need to update it
1086 if (!rcd || rcd->rcd_nnis > rcd->rcd_pingbuffer->pb_nnis ||
1087 LNetMDHandleIsInvalid(rcd->rcd_mdh))
1088 rcd = lnet_update_rc_data_locked(rtr);
1092 secs = lnet_router_check_interval(rtr);
1095 "rtr %s %lld: deadline %lld ping_notsent %d alive %d "
1096 "alive_count %d lpni_ping_timestamp %lld\n",
1097 libcfs_nid2str(rtr->lpni_nid), secs,
1098 rtr->lpni_ping_deadline, rtr->lpni_ping_notsent,
1099 rtr->lpni_alive, rtr->lpni_alive_count, rtr->lpni_ping_timestamp);
1101 if (secs != 0 && !rtr->lpni_ping_notsent &&
1102 now > rtr->lpni_ping_timestamp + secs) {
1104 struct lnet_process_id id;
1105 struct lnet_handle_md mdh;
1107 id.nid = rtr->lpni_nid;
1108 id.pid = LNET_PID_LUSTRE;
1109 CDEBUG(D_NET, "Check: %s\n", libcfs_id2str(id));
1111 rtr->lpni_ping_notsent = 1;
1112 rtr->lpni_ping_timestamp = now;
1116 if (rtr->lpni_ping_deadline == 0) {
1117 rtr->lpni_ping_deadline = ktime_get_seconds() +
1118 router_ping_timeout;
1121 lnet_net_unlock(rtr->lpni_cpt);
1123 rc = LNetGet(LNET_NID_ANY, mdh, id, LNET_RESERVED_PORTAL,
1124 LNET_PROTO_PING_MATCHBITS, 0, false);
1126 lnet_net_lock(rtr->lpni_cpt);
1128 rtr->lpni_ping_notsent = 0; /* no event pending */
1131 lnet_peer_ni_decref_locked(rtr);
1135 int lnet_router_pre_mt_start(void)
1139 if (check_routers_before_use &&
1140 dead_router_check_interval <= 0) {
1141 LCONSOLE_ERROR_MSG(0x10a, "'dead_router_check_interval' must be"
1142 " set if 'check_routers_before_use' is set"
1147 rc = LNetEQAlloc(0, lnet_router_checker_event, &the_lnet.ln_rc_eqh);
1149 CERROR("Can't allocate EQ(0): %d\n", rc);
1156 void lnet_router_post_mt_start(void)
1158 if (check_routers_before_use) {
1159 /* Note that a helpful side-effect of pinging all known routers
1160 * at startup is that it makes them drop stale connections they
1161 * may have to a previous instance of me. */
1162 lnet_wait_known_routerstate();
1167 lnet_router_cleanup(void)
1171 rc = LNetEQFree(the_lnet.ln_rc_eqh);
1177 lnet_prune_rc_data(int wait_unlink)
1179 struct lnet_rc_data *rcd;
1180 struct lnet_rc_data *tmp;
1181 struct lnet_peer_ni *lp;
1182 struct list_head head;
1185 if (likely(the_lnet.ln_mt_state == LNET_MT_STATE_RUNNING &&
1186 list_empty(&the_lnet.ln_rcd_deathrow) &&
1187 list_empty(&the_lnet.ln_rcd_zombie)))
1190 INIT_LIST_HEAD(&head);
1192 lnet_net_lock(LNET_LOCK_EX);
1194 if (the_lnet.ln_mt_state != LNET_MT_STATE_RUNNING) {
1195 /* router checker is stopping, prune all */
1196 list_for_each_entry(lp, &the_lnet.ln_routers,
1198 if (lp->lpni_rcd == NULL)
1201 LASSERT(list_empty(&lp->lpni_rcd->rcd_list));
1202 list_add(&lp->lpni_rcd->rcd_list,
1203 &the_lnet.ln_rcd_deathrow);
1204 lp->lpni_rcd = NULL;
1208 /* unlink all RCDs on deathrow list */
1209 list_splice_init(&the_lnet.ln_rcd_deathrow, &head);
1211 if (!list_empty(&head)) {
1212 lnet_net_unlock(LNET_LOCK_EX);
1214 list_for_each_entry(rcd, &head, rcd_list)
1215 LNetMDUnlink(rcd->rcd_mdh);
1217 lnet_net_lock(LNET_LOCK_EX);
1220 list_splice_init(&head, &the_lnet.ln_rcd_zombie);
1222 /* release all zombie RCDs */
1223 while (!list_empty(&the_lnet.ln_rcd_zombie)) {
1224 list_for_each_entry_safe(rcd, tmp, &the_lnet.ln_rcd_zombie,
1226 if (LNetMDHandleIsInvalid(rcd->rcd_mdh))
1227 list_move(&rcd->rcd_list, &head);
1230 wait_unlink = wait_unlink &&
1231 !list_empty(&the_lnet.ln_rcd_zombie);
1233 lnet_net_unlock(LNET_LOCK_EX);
1235 while (!list_empty(&head)) {
1236 rcd = list_entry(head.next,
1237 struct lnet_rc_data, rcd_list);
1238 list_del_init(&rcd->rcd_list);
1239 lnet_destroy_rc_data(rcd);
1246 CDEBUG(((i & (-i)) == i) ? D_WARNING : D_NET,
1247 "Waiting for rc buffers to unlink\n");
1248 set_current_state(TASK_UNINTERRUPTIBLE);
1249 schedule_timeout(cfs_time_seconds(1) / 4);
1251 lnet_net_lock(LNET_LOCK_EX);
1254 lnet_net_unlock(LNET_LOCK_EX);
1258 * This function is called from the monitor thread to check if there are
1259 * any active routers that need to be checked.
1262 lnet_router_checker_active(void)
1264 if (the_lnet.ln_mt_state != LNET_MT_STATE_RUNNING)
1267 /* Router Checker thread needs to run when routing is enabled in
1268 * order to call lnet_update_ni_status_locked() */
1269 if (the_lnet.ln_routing)
1272 /* if there are routers that need to be cleaned up then do so */
1273 if (!list_empty(&the_lnet.ln_rcd_deathrow) ||
1274 !list_empty(&the_lnet.ln_rcd_zombie))
1277 return !list_empty(&the_lnet.ln_routers) &&
1278 (live_router_check_interval > 0 ||
1279 dead_router_check_interval > 0);
1283 lnet_check_routers(void)
1285 struct lnet_peer_ni *rtr;
1286 struct list_head *entry;
1291 cpt = lnet_net_lock_current();
1293 version = the_lnet.ln_routers_version;
1295 list_for_each(entry, &the_lnet.ln_routers) {
1296 rtr = list_entry(entry, struct lnet_peer_ni,
1299 cpt2 = rtr->lpni_cpt;
1301 lnet_net_unlock(cpt);
1304 /* the routers list has changed */
1305 if (version != the_lnet.ln_routers_version)
1309 lnet_ping_router_locked(rtr);
1311 /* NB dropped lock */
1312 if (version != the_lnet.ln_routers_version) {
1313 /* the routers list has changed */
1318 if (the_lnet.ln_routing)
1319 lnet_update_ni_status_locked();
1321 lnet_net_unlock(cpt);
1323 lnet_prune_rc_data(0); /* don't wait for UNLINK */
1327 lnet_destroy_rtrbuf(struct lnet_rtrbuf *rb, int npages)
1329 int sz = offsetof(struct lnet_rtrbuf, rb_kiov[npages]);
1331 while (--npages >= 0)
1332 __free_page(rb->rb_kiov[npages].kiov_page);
1334 LIBCFS_FREE(rb, sz);
1337 static struct lnet_rtrbuf *
1338 lnet_new_rtrbuf(struct lnet_rtrbufpool *rbp, int cpt)
1340 int npages = rbp->rbp_npages;
1341 int sz = offsetof(struct lnet_rtrbuf, rb_kiov[npages]);
1343 struct lnet_rtrbuf *rb;
1346 LIBCFS_CPT_ALLOC(rb, lnet_cpt_table(), cpt, sz);
1352 for (i = 0; i < npages; i++) {
1353 page = cfs_page_cpt_alloc(lnet_cpt_table(), cpt,
1354 GFP_KERNEL | __GFP_ZERO);
1357 __free_page(rb->rb_kiov[i].kiov_page);
1359 LIBCFS_FREE(rb, sz);
1363 rb->rb_kiov[i].kiov_len = PAGE_SIZE;
1364 rb->rb_kiov[i].kiov_offset = 0;
1365 rb->rb_kiov[i].kiov_page = page;
1372 lnet_rtrpool_free_bufs(struct lnet_rtrbufpool *rbp, int cpt)
1374 int npages = rbp->rbp_npages;
1375 struct lnet_rtrbuf *rb;
1376 struct list_head tmp;
1378 if (rbp->rbp_nbuffers == 0) /* not initialized or already freed */
1381 INIT_LIST_HEAD(&tmp);
1384 list_splice_init(&rbp->rbp_msgs, &tmp);
1385 lnet_drop_routed_msgs_locked(&tmp, cpt);
1386 list_splice_init(&rbp->rbp_bufs, &tmp);
1387 rbp->rbp_req_nbuffers = 0;
1388 rbp->rbp_nbuffers = rbp->rbp_credits = 0;
1389 rbp->rbp_mincredits = 0;
1390 lnet_net_unlock(cpt);
1392 /* Free buffers on the free list. */
1393 while (!list_empty(&tmp)) {
1394 rb = list_entry(tmp.next, struct lnet_rtrbuf, rb_list);
1395 list_del(&rb->rb_list);
1396 lnet_destroy_rtrbuf(rb, npages);
1401 lnet_rtrpool_adjust_bufs(struct lnet_rtrbufpool *rbp, int nbufs, int cpt)
1403 struct list_head rb_list;
1404 struct lnet_rtrbuf *rb;
1406 int num_buffers = 0;
1408 int npages = rbp->rbp_npages;
1411 /* If we are called for less buffers than already in the pool, we
1412 * just lower the req_nbuffers number and excess buffers will be
1413 * thrown away as they are returned to the free list. Credits
1414 * then get adjusted as well.
1415 * If we already have enough buffers allocated to serve the
1416 * increase requested, then we can treat that the same way as we
1417 * do the decrease. */
1418 num_rb = nbufs - rbp->rbp_nbuffers;
1419 if (nbufs <= rbp->rbp_req_nbuffers || num_rb <= 0) {
1420 rbp->rbp_req_nbuffers = nbufs;
1421 lnet_net_unlock(cpt);
1424 /* store the older value of rbp_req_nbuffers and then set it to
1425 * the new request to prevent lnet_return_rx_credits_locked() from
1426 * freeing buffers that we need to keep around */
1427 old_req_nbufs = rbp->rbp_req_nbuffers;
1428 rbp->rbp_req_nbuffers = nbufs;
1429 lnet_net_unlock(cpt);
1431 INIT_LIST_HEAD(&rb_list);
1433 /* allocate the buffers on a local list first. If all buffers are
1434 * allocated successfully then join this list to the rbp buffer
1435 * list. If not then free all allocated buffers. */
1436 while (num_rb-- > 0) {
1437 rb = lnet_new_rtrbuf(rbp, cpt);
1439 CERROR("Failed to allocate %d route bufs of %d pages\n",
1443 rbp->rbp_req_nbuffers = old_req_nbufs;
1444 lnet_net_unlock(cpt);
1449 list_add(&rb->rb_list, &rb_list);
1455 list_splice_tail(&rb_list, &rbp->rbp_bufs);
1456 rbp->rbp_nbuffers += num_buffers;
1457 rbp->rbp_credits += num_buffers;
1458 rbp->rbp_mincredits = rbp->rbp_credits;
1459 /* We need to schedule blocked msg using the newly
1461 while (!list_empty(&rbp->rbp_bufs) &&
1462 !list_empty(&rbp->rbp_msgs))
1463 lnet_schedule_blocked_locked(rbp);
1465 lnet_net_unlock(cpt);
1470 while (!list_empty(&rb_list)) {
1471 rb = list_entry(rb_list.next, struct lnet_rtrbuf, rb_list);
1472 list_del(&rb->rb_list);
1473 lnet_destroy_rtrbuf(rb, npages);
1480 lnet_rtrpool_init(struct lnet_rtrbufpool *rbp, int npages)
1482 INIT_LIST_HEAD(&rbp->rbp_msgs);
1483 INIT_LIST_HEAD(&rbp->rbp_bufs);
1485 rbp->rbp_npages = npages;
1486 rbp->rbp_credits = 0;
1487 rbp->rbp_mincredits = 0;
1491 lnet_rtrpools_free(int keep_pools)
1493 struct lnet_rtrbufpool *rtrp;
1496 if (the_lnet.ln_rtrpools == NULL) /* uninitialized or freed */
1499 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1500 lnet_rtrpool_free_bufs(&rtrp[LNET_TINY_BUF_IDX], i);
1501 lnet_rtrpool_free_bufs(&rtrp[LNET_SMALL_BUF_IDX], i);
1502 lnet_rtrpool_free_bufs(&rtrp[LNET_LARGE_BUF_IDX], i);
1506 cfs_percpt_free(the_lnet.ln_rtrpools);
1507 the_lnet.ln_rtrpools = NULL;
1512 lnet_nrb_tiny_calculate(void)
1514 int nrbs = LNET_NRB_TINY;
1516 if (tiny_router_buffers < 0) {
1517 LCONSOLE_ERROR_MSG(0x10c,
1518 "tiny_router_buffers=%d invalid when "
1519 "routing enabled\n", tiny_router_buffers);
1523 if (tiny_router_buffers > 0)
1524 nrbs = tiny_router_buffers;
1526 nrbs /= LNET_CPT_NUMBER;
1527 return max(nrbs, LNET_NRB_TINY_MIN);
1531 lnet_nrb_small_calculate(void)
1533 int nrbs = LNET_NRB_SMALL;
1535 if (small_router_buffers < 0) {
1536 LCONSOLE_ERROR_MSG(0x10c,
1537 "small_router_buffers=%d invalid when "
1538 "routing enabled\n", small_router_buffers);
1542 if (small_router_buffers > 0)
1543 nrbs = small_router_buffers;
1545 nrbs /= LNET_CPT_NUMBER;
1546 return max(nrbs, LNET_NRB_SMALL_MIN);
1550 lnet_nrb_large_calculate(void)
1552 int nrbs = LNET_NRB_LARGE;
1554 if (large_router_buffers < 0) {
1555 LCONSOLE_ERROR_MSG(0x10c,
1556 "large_router_buffers=%d invalid when "
1557 "routing enabled\n", large_router_buffers);
1561 if (large_router_buffers > 0)
1562 nrbs = large_router_buffers;
1564 nrbs /= LNET_CPT_NUMBER;
1565 return max(nrbs, LNET_NRB_LARGE_MIN);
1569 lnet_rtrpools_alloc(int im_a_router)
1571 struct lnet_rtrbufpool *rtrp;
1578 if (!strcmp(forwarding, "")) {
1579 /* not set either way */
1582 } else if (!strcmp(forwarding, "disabled")) {
1583 /* explicitly disabled */
1585 } else if (!strcmp(forwarding, "enabled")) {
1586 /* explicitly enabled */
1588 LCONSOLE_ERROR_MSG(0x10b, "'forwarding' not set to either "
1589 "'enabled' or 'disabled'\n");
1593 nrb_tiny = lnet_nrb_tiny_calculate();
1597 nrb_small = lnet_nrb_small_calculate();
1601 nrb_large = lnet_nrb_large_calculate();
1605 the_lnet.ln_rtrpools = cfs_percpt_alloc(lnet_cpt_table(),
1607 sizeof(struct lnet_rtrbufpool));
1608 if (the_lnet.ln_rtrpools == NULL) {
1609 LCONSOLE_ERROR_MSG(0x10c,
1610 "Failed to initialize router buffe pool\n");
1614 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1615 lnet_rtrpool_init(&rtrp[LNET_TINY_BUF_IDX], 0);
1616 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_TINY_BUF_IDX],
1621 lnet_rtrpool_init(&rtrp[LNET_SMALL_BUF_IDX],
1622 LNET_NRB_SMALL_PAGES);
1623 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_SMALL_BUF_IDX],
1628 lnet_rtrpool_init(&rtrp[LNET_LARGE_BUF_IDX],
1629 LNET_NRB_LARGE_PAGES);
1630 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_LARGE_BUF_IDX],
1636 lnet_net_lock(LNET_LOCK_EX);
1637 the_lnet.ln_routing = 1;
1638 lnet_net_unlock(LNET_LOCK_EX);
1642 lnet_rtrpools_free(0);
1647 lnet_rtrpools_adjust_helper(int tiny, int small, int large)
1652 struct lnet_rtrbufpool *rtrp;
1654 /* If the provided values for each buffer pool are different than the
1655 * configured values, we need to take action. */
1657 tiny_router_buffers = tiny;
1658 nrb = lnet_nrb_tiny_calculate();
1659 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1660 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_TINY_BUF_IDX],
1667 small_router_buffers = small;
1668 nrb = lnet_nrb_small_calculate();
1669 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1670 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_SMALL_BUF_IDX],
1677 large_router_buffers = large;
1678 nrb = lnet_nrb_large_calculate();
1679 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1680 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_LARGE_BUF_IDX],
1691 lnet_rtrpools_adjust(int tiny, int small, int large)
1693 /* this function doesn't revert the changes if adding new buffers
1694 * failed. It's up to the user space caller to revert the
1697 if (!the_lnet.ln_routing)
1700 return lnet_rtrpools_adjust_helper(tiny, small, large);
1704 lnet_rtrpools_enable(void)
1708 if (the_lnet.ln_routing)
1711 if (the_lnet.ln_rtrpools == NULL)
1712 /* If routing is turned off, and we have never
1713 * initialized the pools before, just call the
1714 * standard buffer pool allocation routine as
1715 * if we are just configuring this for the first
1717 rc = lnet_rtrpools_alloc(1);
1719 rc = lnet_rtrpools_adjust_helper(0, 0, 0);
1723 lnet_net_lock(LNET_LOCK_EX);
1724 the_lnet.ln_routing = 1;
1726 the_lnet.ln_ping_target->pb_info.pi_features &=
1727 ~LNET_PING_FEAT_RTE_DISABLED;
1728 lnet_net_unlock(LNET_LOCK_EX);
1734 lnet_rtrpools_disable(void)
1736 if (!the_lnet.ln_routing)
1739 lnet_net_lock(LNET_LOCK_EX);
1740 the_lnet.ln_routing = 0;
1741 the_lnet.ln_ping_target->pb_info.pi_features |=
1742 LNET_PING_FEAT_RTE_DISABLED;
1744 tiny_router_buffers = 0;
1745 small_router_buffers = 0;
1746 large_router_buffers = 0;
1747 lnet_net_unlock(LNET_LOCK_EX);
1748 lnet_rtrpools_free(1);
1752 lnet_notify(struct lnet_ni *ni, lnet_nid_t nid, int alive, time64_t when)
1754 struct lnet_peer_ni *lp = NULL;
1755 time64_t now = ktime_get_seconds();
1756 int cpt = lnet_cpt_of_nid(nid, ni);
1758 LASSERT (!in_interrupt ());
1760 CDEBUG (D_NET, "%s notifying %s: %s\n",
1761 (ni == NULL) ? "userspace" : libcfs_nid2str(ni->ni_nid),
1762 libcfs_nid2str(nid),
1763 alive ? "up" : "down");
1766 LNET_NIDNET(ni->ni_nid) != LNET_NIDNET(nid)) {
1767 CWARN("Ignoring notification of %s %s by %s (different net)\n",
1768 libcfs_nid2str(nid), alive ? "birth" : "death",
1769 libcfs_nid2str(ni->ni_nid));
1773 /* can't do predictions... */
1775 CWARN("Ignoring prediction from %s of %s %s "
1776 "%lld seconds in the future\n",
1777 (ni == NULL) ? "userspace" : libcfs_nid2str(ni->ni_nid),
1778 libcfs_nid2str(nid), alive ? "up" : "down", when - now);
1782 if (ni != NULL && !alive && /* LND telling me she's down */
1783 !auto_down) { /* auto-down disabled */
1784 CDEBUG(D_NET, "Auto-down disabled\n");
1790 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
1791 lnet_net_unlock(cpt);
1795 lp = lnet_find_peer_ni_locked(nid);
1798 lnet_net_unlock(cpt);
1799 CDEBUG(D_NET, "%s not found\n", libcfs_nid2str(nid));
1804 * It is possible for this function to be called for the same peer
1805 * but with different NIs. We want to synchronize the notification
1806 * between the different calls. So we will use the lpni_cpt to
1807 * grab the net lock.
1809 if (lp->lpni_cpt != cpt) {
1810 lnet_net_unlock(cpt);
1815 /* We can't fully trust LND on reporting exact peer last_alive
1816 * if he notifies us about dead peer. For example ksocklnd can
1817 * call us with when == _time_when_the_node_was_booted_ if
1818 * no connections were successfully established */
1819 if (ni != NULL && !alive && when < lp->lpni_last_alive)
1820 when = lp->lpni_last_alive;
1822 lnet_notify_locked(lp, ni == NULL, alive, when);
1825 lnet_ni_notify_locked(ni, lp);
1827 lnet_peer_ni_decref_locked(lp);
1829 lnet_net_unlock(cpt);
1832 EXPORT_SYMBOL(lnet_notify);