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_del_route(__u32 net, lnet_nid_t gw_nid)
434 struct lnet_peer_ni *gateway;
435 struct lnet_remotenet *rnet;
436 struct lnet_route *route;
437 struct list_head *e1;
438 struct list_head *e2;
440 struct list_head *rn_list;
443 CDEBUG(D_NET, "Del route: net %s : gw %s\n",
444 libcfs_net2str(net), libcfs_nid2str(gw_nid));
446 /* NB Caller may specify either all routes via the given gateway
447 * or a specific route entry actual NIDs) */
449 lnet_net_lock(LNET_LOCK_EX);
450 if (net == LNET_NIDNET(LNET_NID_ANY))
451 rn_list = &the_lnet.ln_remote_nets_hash[0];
453 rn_list = lnet_net2rnethash(net);
456 list_for_each(e1, rn_list) {
457 rnet = list_entry(e1, struct lnet_remotenet, lrn_list);
459 if (!(net == LNET_NIDNET(LNET_NID_ANY) ||
460 net == rnet->lrn_net))
463 list_for_each(e2, &rnet->lrn_routes) {
464 route = list_entry(e2, struct lnet_route, lr_list);
466 gateway = route->lr_gateway;
467 if (!(gw_nid == LNET_NID_ANY ||
468 gw_nid == gateway->lpni_nid))
471 list_del(&route->lr_list);
472 list_del(&route->lr_gwlist);
473 the_lnet.ln_remote_nets_version++;
475 if (list_empty(&rnet->lrn_routes))
476 list_del(&rnet->lrn_list);
480 lnet_rtr_decref_locked(gateway);
481 lnet_peer_ni_decref_locked(gateway);
483 lnet_net_unlock(LNET_LOCK_EX);
485 LIBCFS_FREE(route, sizeof(*route));
488 LIBCFS_FREE(rnet, sizeof(*rnet));
491 lnet_net_lock(LNET_LOCK_EX);
496 if (net == LNET_NIDNET(LNET_NID_ANY) &&
497 ++idx < LNET_REMOTE_NETS_HASH_SIZE) {
498 rn_list = &the_lnet.ln_remote_nets_hash[idx];
501 lnet_net_unlock(LNET_LOCK_EX);
507 lnet_destroy_routes (void)
509 lnet_del_route(LNET_NIDNET(LNET_NID_ANY), LNET_NID_ANY);
512 int lnet_get_rtr_pool_cfg(int cpt, struct lnet_ioctl_pool_cfg *pool_cfg)
514 struct lnet_rtrbufpool *rbp;
515 int i, rc = -ENOENT, j;
517 if (the_lnet.ln_rtrpools == NULL)
521 cfs_percpt_for_each(rbp, i, the_lnet.ln_rtrpools) {
526 for (j = 0; j < LNET_NRBPOOLS; j++) {
527 pool_cfg->pl_pools[j].pl_npages = rbp[j].rbp_npages;
528 pool_cfg->pl_pools[j].pl_nbuffers = rbp[j].rbp_nbuffers;
529 pool_cfg->pl_pools[j].pl_credits = rbp[j].rbp_credits;
530 pool_cfg->pl_pools[j].pl_mincredits = rbp[j].rbp_mincredits;
537 lnet_net_lock(LNET_LOCK_EX);
538 pool_cfg->pl_routing = the_lnet.ln_routing;
539 lnet_net_unlock(LNET_LOCK_EX);
545 lnet_get_route(int idx, __u32 *net, __u32 *hops,
546 lnet_nid_t *gateway, __u32 *alive, __u32 *priority)
548 struct list_head *e1;
549 struct list_head *e2;
550 struct lnet_remotenet *rnet;
551 struct lnet_route *route;
554 struct list_head *rn_list;
556 cpt = lnet_net_lock_current();
558 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) {
559 rn_list = &the_lnet.ln_remote_nets_hash[i];
560 list_for_each(e1, rn_list) {
561 rnet = list_entry(e1, struct lnet_remotenet, lrn_list);
563 list_for_each(e2, &rnet->lrn_routes) {
564 route = list_entry(e2, struct lnet_route,
568 *net = rnet->lrn_net;
569 *hops = route->lr_hops;
570 *priority = route->lr_priority;
571 *gateway = route->lr_gateway->lpni_nid;
572 *alive = lnet_is_route_alive(route);
573 lnet_net_unlock(cpt);
580 lnet_net_unlock(cpt);
585 lnet_swap_pinginfo(struct lnet_ping_buffer *pbuf)
587 struct lnet_ni_status *stat;
591 __swab32s(&pbuf->pb_info.pi_magic);
592 __swab32s(&pbuf->pb_info.pi_features);
593 __swab32s(&pbuf->pb_info.pi_pid);
594 __swab32s(&pbuf->pb_info.pi_nnis);
595 nnis = pbuf->pb_info.pi_nnis;
596 if (nnis > pbuf->pb_nnis)
597 nnis = pbuf->pb_nnis;
598 for (i = 0; i < nnis; i++) {
599 stat = &pbuf->pb_info.pi_ni[i];
600 __swab64s(&stat->ns_nid);
601 __swab32s(&stat->ns_status);
607 * parse router-checker pinginfo, record number of down NIs for remote
608 * networks on that router.
611 lnet_parse_rc_info(struct lnet_rc_data *rcd)
613 struct lnet_ping_buffer *pbuf = rcd->rcd_pingbuffer;
614 struct lnet_peer_ni *gw = rcd->rcd_gateway;
615 struct lnet_route *rte;
618 if (!gw->lpni_alive || !pbuf)
622 * Protect gw->lpni_ping_feats. This can be set from
623 * lnet_notify_locked with different locks being held
625 spin_lock(&gw->lpni_lock);
627 if (pbuf->pb_info.pi_magic == __swab32(LNET_PROTO_PING_MAGIC))
628 lnet_swap_pinginfo(pbuf);
630 /* NB always racing with network! */
631 if (pbuf->pb_info.pi_magic != LNET_PROTO_PING_MAGIC) {
632 CDEBUG(D_NET, "%s: Unexpected magic %08x\n",
633 libcfs_nid2str(gw->lpni_nid), pbuf->pb_info.pi_magic);
634 gw->lpni_ping_feats = LNET_PING_FEAT_INVAL;
638 gw->lpni_ping_feats = pbuf->pb_info.pi_features;
640 /* Without NI status info there's nothing more to do. */
641 if ((gw->lpni_ping_feats & LNET_PING_FEAT_NI_STATUS) == 0)
644 /* Determine the number of NIs for which there is data. */
645 nnis = pbuf->pb_info.pi_nnis;
646 if (pbuf->pb_nnis < nnis) {
647 if (rcd->rcd_nnis < nnis)
648 rcd->rcd_nnis = nnis;
649 nnis = pbuf->pb_nnis;
652 list_for_each_entry(rte, &gw->lpni_routes, lr_gwlist) {
657 /* If routing disabled then the route is down. */
658 if ((gw->lpni_ping_feats & LNET_PING_FEAT_RTE_DISABLED) != 0) {
663 for (i = 0; i < nnis; i++) {
664 struct lnet_ni_status *stat = &pbuf->pb_info.pi_ni[i];
665 lnet_nid_t nid = stat->ns_nid;
667 if (nid == LNET_NID_ANY) {
668 CDEBUG(D_NET, "%s: unexpected LNET_NID_ANY\n",
669 libcfs_nid2str(gw->lpni_nid));
670 gw->lpni_ping_feats = LNET_PING_FEAT_INVAL;
674 if (LNET_NETTYP(LNET_NIDNET(nid)) == LOLND)
677 if (stat->ns_status == LNET_NI_STATUS_DOWN) {
682 if (stat->ns_status == LNET_NI_STATUS_UP) {
683 if (LNET_NIDNET(nid) == rte->lr_net) {
690 CDEBUG(D_NET, "%s: Unexpected status 0x%x\n",
691 libcfs_nid2str(gw->lpni_nid), stat->ns_status);
692 gw->lpni_ping_feats = LNET_PING_FEAT_INVAL;
696 if (up) { /* ignore downed NIs if NI for dest network is up */
700 /* if @down is zero and this route is single-hop, it means
701 * we can't find NI for target network */
702 if (down == 0 && rte->lr_hops == 1)
705 rte->lr_downis = down;
708 spin_unlock(&gw->lpni_lock);
712 lnet_router_checker_event(struct lnet_event *event)
714 struct lnet_rc_data *rcd = event->md.user_ptr;
715 struct lnet_peer_ni *lp;
717 LASSERT(rcd != NULL);
719 if (event->unlinked) {
720 LNetInvalidateMDHandle(&rcd->rcd_mdh);
724 LASSERT(event->type == LNET_EVENT_SEND ||
725 event->type == LNET_EVENT_REPLY);
727 lp = rcd->rcd_gateway;
730 /* NB: it's called with holding lnet_res_lock, we have a few
731 * places need to hold both locks at the same time, please take
732 * care of lock ordering */
733 lnet_net_lock(lp->lpni_cpt);
734 if (!lnet_isrouter(lp) || lp->lpni_rcd != rcd) {
735 /* ignore if no longer a router or rcd is replaced */
739 if (event->type == LNET_EVENT_SEND) {
740 lp->lpni_ping_notsent = 0;
741 if (event->status == 0)
745 /* LNET_EVENT_REPLY */
746 /* A successful REPLY means the router is up. If _any_ comms
747 * to the router fail I assume it's down (this will happen if
748 * we ping alive routers to try to detect router death before
749 * apps get burned). */
751 lnet_notify_locked(lp, 1, !event->status, ktime_get_seconds());
752 /* The router checker will wake up very shortly and do the
753 * actual notification.
754 * XXX If 'lp' stops being a router before then, it will still
755 * have the notification pending!!! */
757 if (avoid_asym_router_failure && event->status == 0)
758 lnet_parse_rc_info(rcd);
761 lnet_net_unlock(lp->lpni_cpt);
765 lnet_wait_known_routerstate(void)
767 struct lnet_peer_ni *rtr;
768 struct list_head *entry;
771 LASSERT(the_lnet.ln_mt_state == LNET_MT_STATE_RUNNING);
774 int cpt = lnet_net_lock_current();
777 list_for_each(entry, &the_lnet.ln_routers) {
778 rtr = list_entry(entry, struct lnet_peer_ni,
781 spin_lock(&rtr->lpni_lock);
783 if (rtr->lpni_alive_count == 0) {
785 spin_unlock(&rtr->lpni_lock);
788 spin_unlock(&rtr->lpni_lock);
791 lnet_net_unlock(cpt);
796 set_current_state(TASK_UNINTERRUPTIBLE);
797 schedule_timeout(cfs_time_seconds(1));
802 lnet_router_ni_update_locked(struct lnet_peer_ni *gw, __u32 net)
804 struct lnet_route *rte;
806 if ((gw->lpni_ping_feats & LNET_PING_FEAT_NI_STATUS) != 0) {
807 list_for_each_entry(rte, &gw->lpni_routes, lr_gwlist) {
808 if (rte->lr_net == net) {
817 lnet_update_ni_status_locked(void)
819 struct lnet_ni *ni = NULL;
823 LASSERT(the_lnet.ln_routing);
825 timeout = router_ping_timeout +
826 MAX(live_router_check_interval, dead_router_check_interval);
828 now = ktime_get_real_seconds();
829 while ((ni = lnet_get_next_ni_locked(NULL, ni))) {
830 if (ni->ni_net->net_lnd->lnd_type == LOLND)
833 if (now < ni->ni_last_alive + timeout)
837 /* re-check with lock */
838 if (now < ni->ni_last_alive + timeout) {
843 LASSERT(ni->ni_status != NULL);
845 if (ni->ni_status->ns_status != LNET_NI_STATUS_DOWN) {
846 CDEBUG(D_NET, "NI(%s:%lld) status changed to down\n",
847 libcfs_nid2str(ni->ni_nid), timeout);
848 /* NB: so far, this is the only place to set
849 * NI status to "down" */
850 ni->ni_status->ns_status = LNET_NI_STATUS_DOWN;
857 lnet_destroy_rc_data(struct lnet_rc_data *rcd)
859 LASSERT(list_empty(&rcd->rcd_list));
860 /* detached from network */
861 LASSERT(LNetMDHandleIsInvalid(rcd->rcd_mdh));
863 if (rcd->rcd_gateway != NULL) {
864 int cpt = rcd->rcd_gateway->lpni_cpt;
867 lnet_peer_ni_decref_locked(rcd->rcd_gateway);
868 lnet_net_unlock(cpt);
871 if (rcd->rcd_pingbuffer != NULL)
872 lnet_ping_buffer_decref(rcd->rcd_pingbuffer);
874 LIBCFS_FREE(rcd, sizeof(*rcd));
877 static struct lnet_rc_data *
878 lnet_update_rc_data_locked(struct lnet_peer_ni *gateway)
880 struct lnet_handle_md mdh;
881 struct lnet_rc_data *rcd;
882 struct lnet_ping_buffer *pbuf = NULL;
883 int nnis = LNET_INTERFACES_MIN;
887 rcd = gateway->lpni_rcd;
889 nnis = rcd->rcd_nnis;
891 LNetInvalidateMDHandle(&rcd->rcd_mdh);
892 pbuf = rcd->rcd_pingbuffer;
893 rcd->rcd_pingbuffer = NULL;
895 LNetInvalidateMDHandle(&mdh);
898 lnet_net_unlock(gateway->lpni_cpt);
902 lnet_ping_buffer_decref(pbuf);
904 LIBCFS_ALLOC(rcd, sizeof(*rcd));
908 LNetInvalidateMDHandle(&rcd->rcd_mdh);
909 INIT_LIST_HEAD(&rcd->rcd_list);
910 rcd->rcd_nnis = nnis;
913 pbuf = lnet_ping_buffer_alloc(nnis, GFP_NOFS);
917 for (i = 0; i < nnis; i++) {
918 pbuf->pb_info.pi_ni[i].ns_nid = LNET_NID_ANY;
919 pbuf->pb_info.pi_ni[i].ns_status = LNET_NI_STATUS_INVALID;
921 rcd->rcd_pingbuffer = pbuf;
923 LASSERT(!LNetEQHandleIsInvalid(the_lnet.ln_rc_eqh));
924 rc = LNetMDBind((struct lnet_md){.start = &pbuf->pb_info,
926 .length = LNET_PING_INFO_SIZE(nnis),
927 .threshold = LNET_MD_THRESH_INF,
928 .options = LNET_MD_TRUNCATE,
929 .eq_handle = the_lnet.ln_rc_eqh},
933 CERROR("Can't bind MD: %d\n", rc);
934 goto out_ping_buffer_decref;
938 lnet_net_lock(gateway->lpni_cpt);
939 /* Check if this is still a router. */
940 if (!lnet_isrouter(gateway))
942 /* Check if someone else installed router data. */
943 if (gateway->lpni_rcd && gateway->lpni_rcd != rcd)
946 /* Install and/or update the router data. */
947 if (!gateway->lpni_rcd) {
948 lnet_peer_ni_addref_locked(gateway);
949 rcd->rcd_gateway = gateway;
950 gateway->lpni_rcd = rcd;
952 gateway->lpni_ping_notsent = 0;
957 lnet_net_unlock(gateway->lpni_cpt);
958 rc = LNetMDUnlink(mdh);
960 out_ping_buffer_decref:
961 lnet_ping_buffer_decref(pbuf);
963 if (rcd && rcd != gateway->lpni_rcd)
964 lnet_destroy_rc_data(rcd);
965 lnet_net_lock(gateway->lpni_cpt);
966 return gateway->lpni_rcd;
970 lnet_router_check_interval(struct lnet_peer_ni *rtr)
974 secs = rtr->lpni_alive ? live_router_check_interval :
975 dead_router_check_interval;
983 lnet_ping_router_locked(struct lnet_peer_ni *rtr)
985 struct lnet_rc_data *rcd = NULL;
986 time64_t now = ktime_get_seconds();
990 lnet_peer_ni_addref_locked(rtr);
992 if (rtr->lpni_ping_deadline != 0 && /* ping timed out? */
993 now > rtr->lpni_ping_deadline)
994 lnet_notify_locked(rtr, 1, 0, now);
996 /* Run any outstanding notifications */
997 ni = lnet_get_next_ni_locked(rtr->lpni_net, NULL);
998 lnet_ni_notify_locked(ni, rtr);
1000 if (!lnet_isrouter(rtr) ||
1001 the_lnet.ln_mt_state != LNET_MT_STATE_RUNNING) {
1002 /* router table changed or router checker is shutting down */
1003 lnet_peer_ni_decref_locked(rtr);
1007 rcd = rtr->lpni_rcd;
1010 * The response to the router checker ping could've timed out and
1011 * the mdh might've been invalidated, so we need to update it
1014 if (!rcd || rcd->rcd_nnis > rcd->rcd_pingbuffer->pb_nnis ||
1015 LNetMDHandleIsInvalid(rcd->rcd_mdh))
1016 rcd = lnet_update_rc_data_locked(rtr);
1020 secs = lnet_router_check_interval(rtr);
1023 "rtr %s %lld: deadline %lld ping_notsent %d alive %d "
1024 "alive_count %d lpni_ping_timestamp %lld\n",
1025 libcfs_nid2str(rtr->lpni_nid), secs,
1026 rtr->lpni_ping_deadline, rtr->lpni_ping_notsent,
1027 rtr->lpni_alive, rtr->lpni_alive_count, rtr->lpni_ping_timestamp);
1029 if (secs != 0 && !rtr->lpni_ping_notsent &&
1030 now > rtr->lpni_ping_timestamp + secs) {
1032 struct lnet_process_id id;
1033 struct lnet_handle_md mdh;
1035 id.nid = rtr->lpni_nid;
1036 id.pid = LNET_PID_LUSTRE;
1037 CDEBUG(D_NET, "Check: %s\n", libcfs_id2str(id));
1039 rtr->lpni_ping_notsent = 1;
1040 rtr->lpni_ping_timestamp = now;
1044 if (rtr->lpni_ping_deadline == 0) {
1045 rtr->lpni_ping_deadline = ktime_get_seconds() +
1046 router_ping_timeout;
1049 lnet_net_unlock(rtr->lpni_cpt);
1051 rc = LNetGet(LNET_NID_ANY, mdh, id, LNET_RESERVED_PORTAL,
1052 LNET_PROTO_PING_MATCHBITS, 0, false);
1054 lnet_net_lock(rtr->lpni_cpt);
1056 rtr->lpni_ping_notsent = 0; /* no event pending */
1059 lnet_peer_ni_decref_locked(rtr);
1063 int lnet_router_pre_mt_start(void)
1067 if (check_routers_before_use &&
1068 dead_router_check_interval <= 0) {
1069 LCONSOLE_ERROR_MSG(0x10a, "'dead_router_check_interval' must be"
1070 " set if 'check_routers_before_use' is set"
1075 rc = LNetEQAlloc(0, lnet_router_checker_event, &the_lnet.ln_rc_eqh);
1077 CERROR("Can't allocate EQ(0): %d\n", rc);
1084 void lnet_router_post_mt_start(void)
1086 if (check_routers_before_use) {
1087 /* Note that a helpful side-effect of pinging all known routers
1088 * at startup is that it makes them drop stale connections they
1089 * may have to a previous instance of me. */
1090 lnet_wait_known_routerstate();
1095 lnet_router_cleanup(void)
1099 rc = LNetEQFree(the_lnet.ln_rc_eqh);
1105 lnet_prune_rc_data(int wait_unlink)
1107 struct lnet_rc_data *rcd;
1108 struct lnet_rc_data *tmp;
1109 struct lnet_peer_ni *lp;
1110 struct list_head head;
1113 if (likely(the_lnet.ln_mt_state == LNET_MT_STATE_RUNNING &&
1114 list_empty(&the_lnet.ln_rcd_deathrow) &&
1115 list_empty(&the_lnet.ln_rcd_zombie)))
1118 INIT_LIST_HEAD(&head);
1120 lnet_net_lock(LNET_LOCK_EX);
1122 if (the_lnet.ln_mt_state != LNET_MT_STATE_RUNNING) {
1123 /* router checker is stopping, prune all */
1124 list_for_each_entry(lp, &the_lnet.ln_routers,
1126 if (lp->lpni_rcd == NULL)
1129 LASSERT(list_empty(&lp->lpni_rcd->rcd_list));
1130 list_add(&lp->lpni_rcd->rcd_list,
1131 &the_lnet.ln_rcd_deathrow);
1132 lp->lpni_rcd = NULL;
1136 /* unlink all RCDs on deathrow list */
1137 list_splice_init(&the_lnet.ln_rcd_deathrow, &head);
1139 if (!list_empty(&head)) {
1140 lnet_net_unlock(LNET_LOCK_EX);
1142 list_for_each_entry(rcd, &head, rcd_list)
1143 LNetMDUnlink(rcd->rcd_mdh);
1145 lnet_net_lock(LNET_LOCK_EX);
1148 list_splice_init(&head, &the_lnet.ln_rcd_zombie);
1150 /* release all zombie RCDs */
1151 while (!list_empty(&the_lnet.ln_rcd_zombie)) {
1152 list_for_each_entry_safe(rcd, tmp, &the_lnet.ln_rcd_zombie,
1154 if (LNetMDHandleIsInvalid(rcd->rcd_mdh))
1155 list_move(&rcd->rcd_list, &head);
1158 wait_unlink = wait_unlink &&
1159 !list_empty(&the_lnet.ln_rcd_zombie);
1161 lnet_net_unlock(LNET_LOCK_EX);
1163 while (!list_empty(&head)) {
1164 rcd = list_entry(head.next,
1165 struct lnet_rc_data, rcd_list);
1166 list_del_init(&rcd->rcd_list);
1167 lnet_destroy_rc_data(rcd);
1174 CDEBUG(((i & (-i)) == i) ? D_WARNING : D_NET,
1175 "Waiting for rc buffers to unlink\n");
1176 set_current_state(TASK_UNINTERRUPTIBLE);
1177 schedule_timeout(cfs_time_seconds(1) / 4);
1179 lnet_net_lock(LNET_LOCK_EX);
1182 lnet_net_unlock(LNET_LOCK_EX);
1186 * This function is called from the monitor thread to check if there are
1187 * any active routers that need to be checked.
1190 lnet_router_checker_active(void)
1192 if (the_lnet.ln_mt_state != LNET_MT_STATE_RUNNING)
1195 /* Router Checker thread needs to run when routing is enabled in
1196 * order to call lnet_update_ni_status_locked() */
1197 if (the_lnet.ln_routing)
1200 /* if there are routers that need to be cleaned up then do so */
1201 if (!list_empty(&the_lnet.ln_rcd_deathrow) ||
1202 !list_empty(&the_lnet.ln_rcd_zombie))
1205 return !list_empty(&the_lnet.ln_routers) &&
1206 (live_router_check_interval > 0 ||
1207 dead_router_check_interval > 0);
1211 lnet_check_routers(void)
1213 struct lnet_peer_ni *rtr;
1214 struct list_head *entry;
1219 cpt = lnet_net_lock_current();
1221 version = the_lnet.ln_routers_version;
1223 list_for_each(entry, &the_lnet.ln_routers) {
1224 rtr = list_entry(entry, struct lnet_peer_ni,
1227 cpt2 = rtr->lpni_cpt;
1229 lnet_net_unlock(cpt);
1232 /* the routers list has changed */
1233 if (version != the_lnet.ln_routers_version)
1237 lnet_ping_router_locked(rtr);
1239 /* NB dropped lock */
1240 if (version != the_lnet.ln_routers_version) {
1241 /* the routers list has changed */
1246 if (the_lnet.ln_routing)
1247 lnet_update_ni_status_locked();
1249 lnet_net_unlock(cpt);
1251 lnet_prune_rc_data(0); /* don't wait for UNLINK */
1255 lnet_destroy_rtrbuf(struct lnet_rtrbuf *rb, int npages)
1257 int sz = offsetof(struct lnet_rtrbuf, rb_kiov[npages]);
1259 while (--npages >= 0)
1260 __free_page(rb->rb_kiov[npages].kiov_page);
1262 LIBCFS_FREE(rb, sz);
1265 static struct lnet_rtrbuf *
1266 lnet_new_rtrbuf(struct lnet_rtrbufpool *rbp, int cpt)
1268 int npages = rbp->rbp_npages;
1269 int sz = offsetof(struct lnet_rtrbuf, rb_kiov[npages]);
1271 struct lnet_rtrbuf *rb;
1274 LIBCFS_CPT_ALLOC(rb, lnet_cpt_table(), cpt, sz);
1280 for (i = 0; i < npages; i++) {
1281 page = cfs_page_cpt_alloc(lnet_cpt_table(), cpt,
1282 GFP_KERNEL | __GFP_ZERO);
1285 __free_page(rb->rb_kiov[i].kiov_page);
1287 LIBCFS_FREE(rb, sz);
1291 rb->rb_kiov[i].kiov_len = PAGE_SIZE;
1292 rb->rb_kiov[i].kiov_offset = 0;
1293 rb->rb_kiov[i].kiov_page = page;
1300 lnet_rtrpool_free_bufs(struct lnet_rtrbufpool *rbp, int cpt)
1302 int npages = rbp->rbp_npages;
1303 struct lnet_rtrbuf *rb;
1304 struct list_head tmp;
1306 if (rbp->rbp_nbuffers == 0) /* not initialized or already freed */
1309 INIT_LIST_HEAD(&tmp);
1312 list_splice_init(&rbp->rbp_msgs, &tmp);
1313 lnet_drop_routed_msgs_locked(&tmp, cpt);
1314 list_splice_init(&rbp->rbp_bufs, &tmp);
1315 rbp->rbp_req_nbuffers = 0;
1316 rbp->rbp_nbuffers = rbp->rbp_credits = 0;
1317 rbp->rbp_mincredits = 0;
1318 lnet_net_unlock(cpt);
1320 /* Free buffers on the free list. */
1321 while (!list_empty(&tmp)) {
1322 rb = list_entry(tmp.next, struct lnet_rtrbuf, rb_list);
1323 list_del(&rb->rb_list);
1324 lnet_destroy_rtrbuf(rb, npages);
1329 lnet_rtrpool_adjust_bufs(struct lnet_rtrbufpool *rbp, int nbufs, int cpt)
1331 struct list_head rb_list;
1332 struct lnet_rtrbuf *rb;
1334 int num_buffers = 0;
1336 int npages = rbp->rbp_npages;
1339 /* If we are called for less buffers than already in the pool, we
1340 * just lower the req_nbuffers number and excess buffers will be
1341 * thrown away as they are returned to the free list. Credits
1342 * then get adjusted as well.
1343 * If we already have enough buffers allocated to serve the
1344 * increase requested, then we can treat that the same way as we
1345 * do the decrease. */
1346 num_rb = nbufs - rbp->rbp_nbuffers;
1347 if (nbufs <= rbp->rbp_req_nbuffers || num_rb <= 0) {
1348 rbp->rbp_req_nbuffers = nbufs;
1349 lnet_net_unlock(cpt);
1352 /* store the older value of rbp_req_nbuffers and then set it to
1353 * the new request to prevent lnet_return_rx_credits_locked() from
1354 * freeing buffers that we need to keep around */
1355 old_req_nbufs = rbp->rbp_req_nbuffers;
1356 rbp->rbp_req_nbuffers = nbufs;
1357 lnet_net_unlock(cpt);
1359 INIT_LIST_HEAD(&rb_list);
1361 /* allocate the buffers on a local list first. If all buffers are
1362 * allocated successfully then join this list to the rbp buffer
1363 * list. If not then free all allocated buffers. */
1364 while (num_rb-- > 0) {
1365 rb = lnet_new_rtrbuf(rbp, cpt);
1367 CERROR("Failed to allocate %d route bufs of %d pages\n",
1371 rbp->rbp_req_nbuffers = old_req_nbufs;
1372 lnet_net_unlock(cpt);
1377 list_add(&rb->rb_list, &rb_list);
1383 list_splice_tail(&rb_list, &rbp->rbp_bufs);
1384 rbp->rbp_nbuffers += num_buffers;
1385 rbp->rbp_credits += num_buffers;
1386 rbp->rbp_mincredits = rbp->rbp_credits;
1387 /* We need to schedule blocked msg using the newly
1389 while (!list_empty(&rbp->rbp_bufs) &&
1390 !list_empty(&rbp->rbp_msgs))
1391 lnet_schedule_blocked_locked(rbp);
1393 lnet_net_unlock(cpt);
1398 while (!list_empty(&rb_list)) {
1399 rb = list_entry(rb_list.next, struct lnet_rtrbuf, rb_list);
1400 list_del(&rb->rb_list);
1401 lnet_destroy_rtrbuf(rb, npages);
1408 lnet_rtrpool_init(struct lnet_rtrbufpool *rbp, int npages)
1410 INIT_LIST_HEAD(&rbp->rbp_msgs);
1411 INIT_LIST_HEAD(&rbp->rbp_bufs);
1413 rbp->rbp_npages = npages;
1414 rbp->rbp_credits = 0;
1415 rbp->rbp_mincredits = 0;
1419 lnet_rtrpools_free(int keep_pools)
1421 struct lnet_rtrbufpool *rtrp;
1424 if (the_lnet.ln_rtrpools == NULL) /* uninitialized or freed */
1427 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1428 lnet_rtrpool_free_bufs(&rtrp[LNET_TINY_BUF_IDX], i);
1429 lnet_rtrpool_free_bufs(&rtrp[LNET_SMALL_BUF_IDX], i);
1430 lnet_rtrpool_free_bufs(&rtrp[LNET_LARGE_BUF_IDX], i);
1434 cfs_percpt_free(the_lnet.ln_rtrpools);
1435 the_lnet.ln_rtrpools = NULL;
1440 lnet_nrb_tiny_calculate(void)
1442 int nrbs = LNET_NRB_TINY;
1444 if (tiny_router_buffers < 0) {
1445 LCONSOLE_ERROR_MSG(0x10c,
1446 "tiny_router_buffers=%d invalid when "
1447 "routing enabled\n", tiny_router_buffers);
1451 if (tiny_router_buffers > 0)
1452 nrbs = tiny_router_buffers;
1454 nrbs /= LNET_CPT_NUMBER;
1455 return max(nrbs, LNET_NRB_TINY_MIN);
1459 lnet_nrb_small_calculate(void)
1461 int nrbs = LNET_NRB_SMALL;
1463 if (small_router_buffers < 0) {
1464 LCONSOLE_ERROR_MSG(0x10c,
1465 "small_router_buffers=%d invalid when "
1466 "routing enabled\n", small_router_buffers);
1470 if (small_router_buffers > 0)
1471 nrbs = small_router_buffers;
1473 nrbs /= LNET_CPT_NUMBER;
1474 return max(nrbs, LNET_NRB_SMALL_MIN);
1478 lnet_nrb_large_calculate(void)
1480 int nrbs = LNET_NRB_LARGE;
1482 if (large_router_buffers < 0) {
1483 LCONSOLE_ERROR_MSG(0x10c,
1484 "large_router_buffers=%d invalid when "
1485 "routing enabled\n", large_router_buffers);
1489 if (large_router_buffers > 0)
1490 nrbs = large_router_buffers;
1492 nrbs /= LNET_CPT_NUMBER;
1493 return max(nrbs, LNET_NRB_LARGE_MIN);
1497 lnet_rtrpools_alloc(int im_a_router)
1499 struct lnet_rtrbufpool *rtrp;
1506 if (!strcmp(forwarding, "")) {
1507 /* not set either way */
1510 } else if (!strcmp(forwarding, "disabled")) {
1511 /* explicitly disabled */
1513 } else if (!strcmp(forwarding, "enabled")) {
1514 /* explicitly enabled */
1516 LCONSOLE_ERROR_MSG(0x10b, "'forwarding' not set to either "
1517 "'enabled' or 'disabled'\n");
1521 nrb_tiny = lnet_nrb_tiny_calculate();
1525 nrb_small = lnet_nrb_small_calculate();
1529 nrb_large = lnet_nrb_large_calculate();
1533 the_lnet.ln_rtrpools = cfs_percpt_alloc(lnet_cpt_table(),
1535 sizeof(struct lnet_rtrbufpool));
1536 if (the_lnet.ln_rtrpools == NULL) {
1537 LCONSOLE_ERROR_MSG(0x10c,
1538 "Failed to initialize router buffe pool\n");
1542 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1543 lnet_rtrpool_init(&rtrp[LNET_TINY_BUF_IDX], 0);
1544 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_TINY_BUF_IDX],
1549 lnet_rtrpool_init(&rtrp[LNET_SMALL_BUF_IDX],
1550 LNET_NRB_SMALL_PAGES);
1551 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_SMALL_BUF_IDX],
1556 lnet_rtrpool_init(&rtrp[LNET_LARGE_BUF_IDX],
1557 LNET_NRB_LARGE_PAGES);
1558 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_LARGE_BUF_IDX],
1564 lnet_net_lock(LNET_LOCK_EX);
1565 the_lnet.ln_routing = 1;
1566 lnet_net_unlock(LNET_LOCK_EX);
1570 lnet_rtrpools_free(0);
1575 lnet_rtrpools_adjust_helper(int tiny, int small, int large)
1580 struct lnet_rtrbufpool *rtrp;
1582 /* If the provided values for each buffer pool are different than the
1583 * configured values, we need to take action. */
1585 tiny_router_buffers = tiny;
1586 nrb = lnet_nrb_tiny_calculate();
1587 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1588 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_TINY_BUF_IDX],
1595 small_router_buffers = small;
1596 nrb = lnet_nrb_small_calculate();
1597 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1598 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_SMALL_BUF_IDX],
1605 large_router_buffers = large;
1606 nrb = lnet_nrb_large_calculate();
1607 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1608 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_LARGE_BUF_IDX],
1619 lnet_rtrpools_adjust(int tiny, int small, int large)
1621 /* this function doesn't revert the changes if adding new buffers
1622 * failed. It's up to the user space caller to revert the
1625 if (!the_lnet.ln_routing)
1628 return lnet_rtrpools_adjust_helper(tiny, small, large);
1632 lnet_rtrpools_enable(void)
1636 if (the_lnet.ln_routing)
1639 if (the_lnet.ln_rtrpools == NULL)
1640 /* If routing is turned off, and we have never
1641 * initialized the pools before, just call the
1642 * standard buffer pool allocation routine as
1643 * if we are just configuring this for the first
1645 rc = lnet_rtrpools_alloc(1);
1647 rc = lnet_rtrpools_adjust_helper(0, 0, 0);
1651 lnet_net_lock(LNET_LOCK_EX);
1652 the_lnet.ln_routing = 1;
1654 the_lnet.ln_ping_target->pb_info.pi_features &=
1655 ~LNET_PING_FEAT_RTE_DISABLED;
1656 lnet_net_unlock(LNET_LOCK_EX);
1662 lnet_rtrpools_disable(void)
1664 if (!the_lnet.ln_routing)
1667 lnet_net_lock(LNET_LOCK_EX);
1668 the_lnet.ln_routing = 0;
1669 the_lnet.ln_ping_target->pb_info.pi_features |=
1670 LNET_PING_FEAT_RTE_DISABLED;
1672 tiny_router_buffers = 0;
1673 small_router_buffers = 0;
1674 large_router_buffers = 0;
1675 lnet_net_unlock(LNET_LOCK_EX);
1676 lnet_rtrpools_free(1);
1680 lnet_notify(struct lnet_ni *ni, lnet_nid_t nid, int alive, time64_t when)
1682 struct lnet_peer_ni *lp = NULL;
1683 time64_t now = ktime_get_seconds();
1684 int cpt = lnet_cpt_of_nid(nid, ni);
1686 LASSERT (!in_interrupt ());
1688 CDEBUG (D_NET, "%s notifying %s: %s\n",
1689 (ni == NULL) ? "userspace" : libcfs_nid2str(ni->ni_nid),
1690 libcfs_nid2str(nid),
1691 alive ? "up" : "down");
1694 LNET_NIDNET(ni->ni_nid) != LNET_NIDNET(nid)) {
1695 CWARN("Ignoring notification of %s %s by %s (different net)\n",
1696 libcfs_nid2str(nid), alive ? "birth" : "death",
1697 libcfs_nid2str(ni->ni_nid));
1701 /* can't do predictions... */
1703 CWARN("Ignoring prediction from %s of %s %s "
1704 "%lld seconds in the future\n",
1705 (ni == NULL) ? "userspace" : libcfs_nid2str(ni->ni_nid),
1706 libcfs_nid2str(nid), alive ? "up" : "down", when - now);
1710 if (ni != NULL && !alive && /* LND telling me she's down */
1711 !auto_down) { /* auto-down disabled */
1712 CDEBUG(D_NET, "Auto-down disabled\n");
1718 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
1719 lnet_net_unlock(cpt);
1723 lp = lnet_find_peer_ni_locked(nid);
1726 lnet_net_unlock(cpt);
1727 CDEBUG(D_NET, "%s not found\n", libcfs_nid2str(nid));
1732 * It is possible for this function to be called for the same peer
1733 * but with different NIs. We want to synchronize the notification
1734 * between the different calls. So we will use the lpni_cpt to
1735 * grab the net lock.
1737 if (lp->lpni_cpt != cpt) {
1738 lnet_net_unlock(cpt);
1743 /* We can't fully trust LND on reporting exact peer last_alive
1744 * if he notifies us about dead peer. For example ksocklnd can
1745 * call us with when == _time_when_the_node_was_booted_ if
1746 * no connections were successfully established */
1747 if (ni != NULL && !alive && when < lp->lpni_last_alive)
1748 when = lp->lpni_last_alive;
1750 lnet_notify_locked(lp, ni == NULL, alive, when);
1753 lnet_ni_notify_locked(ni, lp);
1755 lnet_peer_ni_decref_locked(lp);
1757 lnet_net_unlock(cpt);
1760 EXPORT_SYMBOL(lnet_notify);