2 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
4 * Copyright (c) 2011, 2014, Intel Corporation.
6 * This file is part of Portals
7 * http://sourceforge.net/projects/sandiaportals/
9 * Portals is free software; you can redistribute it and/or
10 * modify it under the terms of version 2 of the GNU General Public
11 * License as published by the Free Software Foundation.
13 * Portals is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Portals; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #define DEBUG_SUBSYSTEM S_LNET
25 #include <lnet/lib-lnet.h>
27 #define LNET_NRB_TINY_MIN 512 /* min value for each CPT */
28 #define LNET_NRB_TINY (LNET_NRB_TINY_MIN * 4)
29 #define LNET_NRB_SMALL_MIN 4096 /* min value for each CPT */
30 #define LNET_NRB_SMALL (LNET_NRB_SMALL_MIN * 4)
31 #define LNET_NRB_SMALL_PAGES 1
32 #define LNET_NRB_LARGE_MIN 256 /* min value for each CPT */
33 #define LNET_NRB_LARGE (LNET_NRB_LARGE_MIN * 4)
34 #define LNET_NRB_LARGE_PAGES ((LNET_MTU + PAGE_CACHE_SIZE - 1) >> \
37 static char *forwarding = "";
38 CFS_MODULE_PARM(forwarding, "s", charp, 0444,
39 "Explicitly enable/disable forwarding between networks");
41 static int tiny_router_buffers;
42 CFS_MODULE_PARM(tiny_router_buffers, "i", int, 0444,
43 "# of 0 payload messages to buffer in the router");
44 static int small_router_buffers;
45 CFS_MODULE_PARM(small_router_buffers, "i", int, 0444,
46 "# of small (1 page) messages to buffer in the router");
47 static int large_router_buffers;
48 CFS_MODULE_PARM(large_router_buffers, "i", int, 0444,
49 "# of large messages to buffer in the router");
50 static int peer_buffer_credits = 0;
51 CFS_MODULE_PARM(peer_buffer_credits, "i", int, 0444,
52 "# router buffer credits per peer");
54 static int auto_down = 1;
55 CFS_MODULE_PARM(auto_down, "i", int, 0444,
56 "Automatically mark peers down on comms error");
59 lnet_peer_buffer_credits(lnet_ni_t *ni)
61 /* NI option overrides LNet default */
62 if (ni->ni_peerrtrcredits > 0)
63 return ni->ni_peerrtrcredits;
64 if (peer_buffer_credits > 0)
65 return peer_buffer_credits;
67 /* As an approximation, allow this peer the same number of router
68 * buffers as it is allowed outstanding sends */
69 return ni->ni_peertxcredits;
73 static int lnet_router_checker(void *);
75 static int check_routers_before_use = 0;
76 CFS_MODULE_PARM(check_routers_before_use, "i", int, 0444,
77 "Assume routers are down and ping them before use");
79 int avoid_asym_router_failure = 1;
80 CFS_MODULE_PARM(avoid_asym_router_failure, "i", int, 0644,
81 "Avoid asymmetrical router failures (0 to disable)");
83 static int dead_router_check_interval = 60;
84 CFS_MODULE_PARM(dead_router_check_interval, "i", int, 0644,
85 "Seconds between dead router health checks (<= 0 to disable)");
87 static int live_router_check_interval = 60;
88 CFS_MODULE_PARM(live_router_check_interval, "i", int, 0644,
89 "Seconds between live router health checks (<= 0 to disable)");
91 static int router_ping_timeout = 50;
92 CFS_MODULE_PARM(router_ping_timeout, "i", int, 0644,
93 "Seconds to wait for the reply to a router health query");
96 lnet_peers_start_down(void)
98 return check_routers_before_use;
102 lnet_notify_locked(lnet_peer_t *lp, int notifylnd, int alive, cfs_time_t when)
104 if (cfs_time_before(when, lp->lp_timestamp)) { /* out of date information */
105 CDEBUG(D_NET, "Out of date\n");
109 lp->lp_timestamp = when; /* update timestamp */
110 lp->lp_ping_deadline = 0; /* disable ping timeout */
112 if (lp->lp_alive_count != 0 && /* got old news */
113 (!lp->lp_alive) == (!alive)) { /* new date for old news */
114 CDEBUG(D_NET, "Old news\n");
118 /* Flag that notification is outstanding */
120 lp->lp_alive_count++;
121 lp->lp_alive = !(!alive); /* 1 bit! */
123 lp->lp_notifylnd |= notifylnd;
125 lp->lp_ping_feats = LNET_PING_FEAT_INVAL; /* reset */
127 CDEBUG(D_NET, "set %s %d\n", libcfs_nid2str(lp->lp_nid), alive);
131 lnet_ni_notify_locked(lnet_ni_t *ni, lnet_peer_t *lp)
136 /* Notify only in 1 thread at any time to ensure ordered notification.
137 * NB individual events can be missed; the only guarantee is that you
138 * always get the most recent news */
140 if (lp->lp_notifying)
143 lp->lp_notifying = 1;
145 while (lp->lp_notify) {
146 alive = lp->lp_alive;
147 notifylnd = lp->lp_notifylnd;
149 lp->lp_notifylnd = 0;
152 if (notifylnd && ni->ni_lnd->lnd_notify != NULL) {
153 lnet_net_unlock(lp->lp_cpt);
155 /* A new notification could happen now; I'll handle it
156 * when control returns to me */
158 (ni->ni_lnd->lnd_notify)(ni, lp->lp_nid, alive);
160 lnet_net_lock(lp->lp_cpt);
164 lp->lp_notifying = 0;
169 lnet_rtr_addref_locked(lnet_peer_t *lp)
171 LASSERT(lp->lp_refcount > 0);
172 LASSERT(lp->lp_rtr_refcount >= 0);
174 /* lnet_net_lock must be exclusively locked */
175 lp->lp_rtr_refcount++;
176 if (lp->lp_rtr_refcount == 1) {
177 struct list_head *pos;
179 /* a simple insertion sort */
180 list_for_each_prev(pos, &the_lnet.ln_routers) {
181 lnet_peer_t *rtr = list_entry(pos, lnet_peer_t,
184 if (rtr->lp_nid < lp->lp_nid)
188 list_add(&lp->lp_rtr_list, pos);
189 /* addref for the_lnet.ln_routers */
190 lnet_peer_addref_locked(lp);
191 the_lnet.ln_routers_version++;
196 lnet_rtr_decref_locked(lnet_peer_t *lp)
198 LASSERT(lp->lp_refcount > 0);
199 LASSERT(lp->lp_rtr_refcount > 0);
201 /* lnet_net_lock must be exclusively locked */
202 lp->lp_rtr_refcount--;
203 if (lp->lp_rtr_refcount == 0) {
204 LASSERT(list_empty(&lp->lp_routes));
206 if (lp->lp_rcd != NULL) {
207 list_add(&lp->lp_rcd->rcd_list,
208 &the_lnet.ln_rcd_deathrow);
212 list_del(&lp->lp_rtr_list);
213 /* decref for the_lnet.ln_routers */
214 lnet_peer_decref_locked(lp);
215 the_lnet.ln_routers_version++;
220 lnet_find_net_locked (__u32 net)
222 lnet_remotenet_t *rnet;
223 struct list_head *tmp;
224 struct list_head *rn_list;
226 LASSERT(!the_lnet.ln_shutdown);
228 rn_list = lnet_net2rnethash(net);
229 list_for_each(tmp, rn_list) {
230 rnet = list_entry(tmp, lnet_remotenet_t, lrn_list);
232 if (rnet->lrn_net == net)
238 static void lnet_shuffle_seed(void)
245 struct list_head *tmp;
250 cfs_get_random_bytes(seed, sizeof(seed));
252 /* Nodes with small feet have little entropy
253 * the NID for this node gives the most entropy in the low bits */
254 list_for_each(tmp, &the_lnet.ln_nis) {
255 ni = list_entry(tmp, lnet_ni_t, ni_list);
256 lnd_type = LNET_NETTYP(LNET_NIDNET(ni->ni_nid));
258 if (lnd_type != LOLND)
259 seed[0] ^= (LNET_NIDADDR(ni->ni_nid) | lnd_type);
262 do_gettimeofday(&tv);
263 cfs_srand(tv.tv_sec ^ seed[0], tv.tv_usec ^ seed[1]);
268 /* NB expects LNET_LOCK held */
270 lnet_add_route_to_rnet(lnet_remotenet_t *rnet, lnet_route_t *route)
272 unsigned int len = 0;
273 unsigned int offset = 0;
278 list_for_each(e, &rnet->lrn_routes) {
282 /* len+1 positions to add a new entry, also prevents division by 0 */
283 offset = cfs_rand() % (len + 1);
284 list_for_each(e, &rnet->lrn_routes) {
289 list_add(&route->lr_list, e);
290 list_add(&route->lr_gwlist, &route->lr_gateway->lp_routes);
292 the_lnet.ln_remote_nets_version++;
293 lnet_rtr_addref_locked(route->lr_gateway);
297 lnet_add_route(__u32 net, unsigned int hops, lnet_nid_t gateway,
298 unsigned int priority)
301 lnet_remotenet_t *rnet;
302 lnet_remotenet_t *rnet2;
308 CDEBUG(D_NET, "Add route: net %s hops %u priority %u gw %s\n",
309 libcfs_net2str(net), hops, priority, libcfs_nid2str(gateway));
311 if (gateway == LNET_NID_ANY ||
312 LNET_NETTYP(LNET_NIDNET(gateway)) == LOLND ||
313 net == LNET_NIDNET(LNET_NID_ANY) ||
314 LNET_NETTYP(net) == LOLND ||
315 LNET_NIDNET(gateway) == net ||
316 hops < 1 || hops > 255)
319 if (lnet_islocalnet(net)) /* it's a local network */
322 /* Assume net, route, all new */
323 LIBCFS_ALLOC(route, sizeof(*route));
324 LIBCFS_ALLOC(rnet, sizeof(*rnet));
325 if (route == NULL || rnet == NULL) {
326 CERROR("Out of memory creating route %s %d %s\n",
327 libcfs_net2str(net), hops, libcfs_nid2str(gateway));
329 LIBCFS_FREE(route, sizeof(*route));
331 LIBCFS_FREE(rnet, sizeof(*rnet));
335 INIT_LIST_HEAD(&rnet->lrn_routes);
337 route->lr_hops = hops;
339 route->lr_priority = priority;
341 lnet_net_lock(LNET_LOCK_EX);
343 rc = lnet_nid2peer_locked(&route->lr_gateway, gateway, LNET_LOCK_EX);
345 lnet_net_unlock(LNET_LOCK_EX);
347 LIBCFS_FREE(route, sizeof(*route));
348 LIBCFS_FREE(rnet, sizeof(*rnet));
350 if (rc == -EHOSTUNREACH) /* gateway is not on a local net. */
351 return rc; /* ignore the route entry */
352 CERROR("Error %d creating route %s %d %s\n", rc,
353 libcfs_net2str(net), hops,
354 libcfs_nid2str(gateway));
358 LASSERT(!the_lnet.ln_shutdown);
360 rnet2 = lnet_find_net_locked(net);
363 list_add_tail(&rnet->lrn_list, lnet_net2rnethash(net));
367 /* Search for a duplicate route (it's a NOOP if it is) */
369 list_for_each(e, &rnet2->lrn_routes) {
370 lnet_route_t *route2 = list_entry(e, lnet_route_t, lr_list);
372 if (route2->lr_gateway == route->lr_gateway) {
377 /* our lookups must be true */
378 LASSERT(route2->lr_gateway->lp_nid != gateway);
382 lnet_peer_addref_locked(route->lr_gateway); /* +1 for notify */
383 lnet_add_route_to_rnet(rnet2, route);
385 ni = route->lr_gateway->lp_ni;
386 lnet_net_unlock(LNET_LOCK_EX);
388 /* XXX Assume alive */
389 if (ni->ni_lnd->lnd_notify != NULL)
390 (ni->ni_lnd->lnd_notify)(ni, gateway, 1);
392 lnet_net_lock(LNET_LOCK_EX);
395 /* -1 for notify or !add_route */
396 lnet_peer_decref_locked(route->lr_gateway);
397 lnet_net_unlock(LNET_LOCK_EX);
403 LIBCFS_FREE(route, sizeof(*route));
407 LIBCFS_FREE(rnet, sizeof(*rnet));
409 /* indicate to startup the router checker if configured */
410 wake_up(&the_lnet.ln_rc_waitq);
416 lnet_check_routes(void)
418 lnet_remotenet_t *rnet;
420 lnet_route_t *route2;
421 struct list_head *e1;
422 struct list_head *e2;
424 struct list_head *rn_list;
427 cpt = lnet_net_lock_current();
429 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) {
430 rn_list = &the_lnet.ln_remote_nets_hash[i];
431 list_for_each(e1, rn_list) {
432 rnet = list_entry(e1, lnet_remotenet_t, lrn_list);
435 list_for_each(e2, &rnet->lrn_routes) {
440 route = list_entry(e2, lnet_route_t,
443 if (route2 == NULL) {
448 if (route->lr_gateway->lp_ni ==
449 route2->lr_gateway->lp_ni)
452 nid1 = route->lr_gateway->lp_nid;
453 nid2 = route2->lr_gateway->lp_nid;
456 lnet_net_unlock(cpt);
458 CERROR("Routes to %s via %s and %s not "
461 libcfs_nid2str(nid1),
462 libcfs_nid2str(nid2));
468 lnet_net_unlock(cpt);
473 lnet_del_route(__u32 net, lnet_nid_t gw_nid)
475 struct lnet_peer *gateway;
476 lnet_remotenet_t *rnet;
478 struct list_head *e1;
479 struct list_head *e2;
481 struct list_head *rn_list;
484 CDEBUG(D_NET, "Del route: net %s : gw %s\n",
485 libcfs_net2str(net), libcfs_nid2str(gw_nid));
487 /* NB Caller may specify either all routes via the given gateway
488 * or a specific route entry actual NIDs) */
490 lnet_net_lock(LNET_LOCK_EX);
491 if (net == LNET_NIDNET(LNET_NID_ANY))
492 rn_list = &the_lnet.ln_remote_nets_hash[0];
494 rn_list = lnet_net2rnethash(net);
497 list_for_each(e1, rn_list) {
498 rnet = list_entry(e1, lnet_remotenet_t, lrn_list);
500 if (!(net == LNET_NIDNET(LNET_NID_ANY) ||
501 net == rnet->lrn_net))
504 list_for_each(e2, &rnet->lrn_routes) {
505 route = list_entry(e2, lnet_route_t, lr_list);
507 gateway = route->lr_gateway;
508 if (!(gw_nid == LNET_NID_ANY ||
509 gw_nid == gateway->lp_nid))
512 list_del(&route->lr_list);
513 list_del(&route->lr_gwlist);
514 the_lnet.ln_remote_nets_version++;
516 if (list_empty(&rnet->lrn_routes))
517 list_del(&rnet->lrn_list);
521 lnet_rtr_decref_locked(gateway);
522 lnet_peer_decref_locked(gateway);
524 lnet_net_unlock(LNET_LOCK_EX);
526 LIBCFS_FREE(route, sizeof(*route));
529 LIBCFS_FREE(rnet, sizeof(*rnet));
532 lnet_net_lock(LNET_LOCK_EX);
537 if (net == LNET_NIDNET(LNET_NID_ANY) &&
538 ++idx < LNET_REMOTE_NETS_HASH_SIZE) {
539 rn_list = &the_lnet.ln_remote_nets_hash[idx];
542 lnet_net_unlock(LNET_LOCK_EX);
548 lnet_destroy_routes (void)
550 lnet_del_route(LNET_NIDNET(LNET_NID_ANY), LNET_NID_ANY);
553 int lnet_get_rtr_pool_cfg(int idx, struct lnet_ioctl_pool_cfg *pool_cfg)
555 int i, rc = -ENOENT, lidx, j;
557 if (the_lnet.ln_rtrpools == NULL)
560 for (i = 0; i < LNET_NRBPOOLS; i++) {
561 lnet_rtrbufpool_t *rbp;
563 lnet_net_lock(LNET_LOCK_EX);
565 cfs_percpt_for_each(rbp, j, the_lnet.ln_rtrpools) {
568 pool_cfg->pl_pools[i].pl_npages =
570 pool_cfg->pl_pools[i].pl_nbuffers =
572 pool_cfg->pl_pools[i].pl_credits =
574 pool_cfg->pl_pools[i].pl_mincredits =
575 rbp[i].rbp_mincredits;
579 lnet_net_unlock(LNET_LOCK_EX);
582 lnet_net_lock(LNET_LOCK_EX);
583 pool_cfg->pl_routing = the_lnet.ln_routing;
584 lnet_net_unlock(LNET_LOCK_EX);
590 lnet_get_route(int idx, __u32 *net, __u32 *hops,
591 lnet_nid_t *gateway, __u32 *alive, __u32 *priority)
593 struct list_head *e1;
594 struct list_head *e2;
595 lnet_remotenet_t *rnet;
599 struct list_head *rn_list;
601 cpt = lnet_net_lock_current();
603 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) {
604 rn_list = &the_lnet.ln_remote_nets_hash[i];
605 list_for_each(e1, rn_list) {
606 rnet = list_entry(e1, lnet_remotenet_t, lrn_list);
608 list_for_each(e2, &rnet->lrn_routes) {
609 route = list_entry(e2, lnet_route_t,
613 *net = rnet->lrn_net;
614 *hops = route->lr_hops;
615 *priority = route->lr_priority;
616 *gateway = route->lr_gateway->lp_nid;
618 route->lr_gateway->lp_alive &&
620 lnet_net_unlock(cpt);
627 lnet_net_unlock(cpt);
632 lnet_swap_pinginfo(lnet_ping_info_t *info)
635 lnet_ni_status_t *stat;
637 __swab32s(&info->pi_magic);
638 __swab32s(&info->pi_features);
639 __swab32s(&info->pi_pid);
640 __swab32s(&info->pi_nnis);
641 for (i = 0; i < info->pi_nnis && i < LNET_MAX_RTR_NIS; i++) {
642 stat = &info->pi_ni[i];
643 __swab64s(&stat->ns_nid);
644 __swab32s(&stat->ns_status);
650 * parse router-checker pinginfo, record number of down NIs for remote
651 * networks on that router.
654 lnet_parse_rc_info(lnet_rc_data_t *rcd)
656 lnet_ping_info_t *info = rcd->rcd_pinginfo;
657 struct lnet_peer *gw = rcd->rcd_gateway;
663 if (info->pi_magic == __swab32(LNET_PROTO_PING_MAGIC))
664 lnet_swap_pinginfo(info);
666 /* NB always racing with network! */
667 if (info->pi_magic != LNET_PROTO_PING_MAGIC) {
668 CDEBUG(D_NET, "%s: Unexpected magic %08x\n",
669 libcfs_nid2str(gw->lp_nid), info->pi_magic);
670 gw->lp_ping_feats = LNET_PING_FEAT_INVAL;
674 gw->lp_ping_feats = info->pi_features;
675 if ((gw->lp_ping_feats & LNET_PING_FEAT_MASK) == 0) {
676 CDEBUG(D_NET, "%s: Unexpected features 0x%x\n",
677 libcfs_nid2str(gw->lp_nid), gw->lp_ping_feats);
678 return; /* nothing I can understand */
681 if ((gw->lp_ping_feats & LNET_PING_FEAT_NI_STATUS) == 0)
682 return; /* can't carry NI status info */
684 list_for_each_entry(rte, &gw->lp_routes, lr_gwlist) {
689 if ((gw->lp_ping_feats & LNET_PING_FEAT_RTE_DISABLED) != 0) {
694 for (i = 0; i < info->pi_nnis && i < LNET_MAX_RTR_NIS; i++) {
695 lnet_ni_status_t *stat = &info->pi_ni[i];
696 lnet_nid_t nid = stat->ns_nid;
698 if (nid == LNET_NID_ANY) {
699 CDEBUG(D_NET, "%s: unexpected LNET_NID_ANY\n",
700 libcfs_nid2str(gw->lp_nid));
701 gw->lp_ping_feats = LNET_PING_FEAT_INVAL;
705 if (LNET_NETTYP(LNET_NIDNET(nid)) == LOLND)
708 if (stat->ns_status == LNET_NI_STATUS_DOWN) {
713 if (stat->ns_status == LNET_NI_STATUS_UP) {
714 if (LNET_NIDNET(nid) == rte->lr_net) {
721 CDEBUG(D_NET, "%s: Unexpected status 0x%x\n",
722 libcfs_nid2str(gw->lp_nid), stat->ns_status);
723 gw->lp_ping_feats = LNET_PING_FEAT_INVAL;
727 if (up) { /* ignore downed NIs if NI for dest network is up */
731 /* if @down is zero and this route is single-hop, it means
732 * we can't find NI for target network */
733 if (down == 0 && rte->lr_hops == 1)
736 rte->lr_downis = down;
741 lnet_router_checker_event(lnet_event_t *event)
743 lnet_rc_data_t *rcd = event->md.user_ptr;
744 struct lnet_peer *lp;
746 LASSERT(rcd != NULL);
748 if (event->unlinked) {
749 LNetInvalidateHandle(&rcd->rcd_mdh);
753 LASSERT(event->type == LNET_EVENT_SEND ||
754 event->type == LNET_EVENT_REPLY);
756 lp = rcd->rcd_gateway;
759 /* NB: it's called with holding lnet_res_lock, we have a few
760 * places need to hold both locks at the same time, please take
761 * care of lock ordering */
762 lnet_net_lock(lp->lp_cpt);
763 if (!lnet_isrouter(lp) || lp->lp_rcd != rcd) {
764 /* ignore if no longer a router or rcd is replaced */
768 if (event->type == LNET_EVENT_SEND) {
769 lp->lp_ping_notsent = 0;
770 if (event->status == 0)
774 /* LNET_EVENT_REPLY */
775 /* A successful REPLY means the router is up. If _any_ comms
776 * to the router fail I assume it's down (this will happen if
777 * we ping alive routers to try to detect router death before
778 * apps get burned). */
780 lnet_notify_locked(lp, 1, (event->status == 0), cfs_time_current());
781 /* The router checker will wake up very shortly and do the
782 * actual notification.
783 * XXX If 'lp' stops being a router before then, it will still
784 * have the notification pending!!! */
786 if (avoid_asym_router_failure && event->status == 0)
787 lnet_parse_rc_info(rcd);
790 lnet_net_unlock(lp->lp_cpt);
794 lnet_wait_known_routerstate(void)
797 struct list_head *entry;
800 LASSERT(the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING);
803 int cpt = lnet_net_lock_current();
806 list_for_each(entry, &the_lnet.ln_routers) {
807 rtr = list_entry(entry, lnet_peer_t, lp_rtr_list);
809 if (rtr->lp_alive_count == 0) {
815 lnet_net_unlock(cpt);
820 cfs_pause(cfs_time_seconds(1));
825 lnet_router_ni_update_locked(lnet_peer_t *gw, __u32 net)
829 if ((gw->lp_ping_feats & LNET_PING_FEAT_NI_STATUS) != 0) {
830 list_for_each_entry(rte, &gw->lp_routes, lr_gwlist) {
831 if (rte->lr_net == net) {
840 lnet_update_ni_status_locked(void)
846 LASSERT(the_lnet.ln_routing);
848 timeout = router_ping_timeout +
849 MAX(live_router_check_interval, dead_router_check_interval);
851 now = cfs_time_current_sec();
852 list_for_each_entry(ni, &the_lnet.ln_nis, ni_list) {
853 if (ni->ni_lnd->lnd_type == LOLND)
856 if (now < ni->ni_last_alive + timeout)
860 /* re-check with lock */
861 if (now < ni->ni_last_alive + timeout) {
866 LASSERT(ni->ni_status != NULL);
868 if (ni->ni_status->ns_status != LNET_NI_STATUS_DOWN) {
869 CDEBUG(D_NET, "NI(%s:%d) status changed to down\n",
870 libcfs_nid2str(ni->ni_nid), timeout);
871 /* NB: so far, this is the only place to set
872 * NI status to "down" */
873 ni->ni_status->ns_status = LNET_NI_STATUS_DOWN;
880 lnet_destroy_rc_data(lnet_rc_data_t *rcd)
882 LASSERT(list_empty(&rcd->rcd_list));
883 /* detached from network */
884 LASSERT(LNetHandleIsInvalid(rcd->rcd_mdh));
886 if (rcd->rcd_gateway != NULL) {
887 int cpt = rcd->rcd_gateway->lp_cpt;
890 lnet_peer_decref_locked(rcd->rcd_gateway);
891 lnet_net_unlock(cpt);
894 if (rcd->rcd_pinginfo != NULL)
895 LIBCFS_FREE(rcd->rcd_pinginfo, LNET_PINGINFO_SIZE);
897 LIBCFS_FREE(rcd, sizeof(*rcd));
900 static lnet_rc_data_t *
901 lnet_create_rc_data_locked(lnet_peer_t *gateway)
903 lnet_rc_data_t *rcd = NULL;
904 lnet_ping_info_t *pi;
908 lnet_net_unlock(gateway->lp_cpt);
910 LIBCFS_ALLOC(rcd, sizeof(*rcd));
914 LNetInvalidateHandle(&rcd->rcd_mdh);
915 INIT_LIST_HEAD(&rcd->rcd_list);
917 LIBCFS_ALLOC(pi, LNET_PINGINFO_SIZE);
921 for (i = 0; i < LNET_MAX_RTR_NIS; i++) {
922 pi->pi_ni[i].ns_nid = LNET_NID_ANY;
923 pi->pi_ni[i].ns_status = LNET_NI_STATUS_INVALID;
925 rcd->rcd_pinginfo = pi;
927 LASSERT (!LNetHandleIsInvalid(the_lnet.ln_rc_eqh));
928 rc = LNetMDBind((lnet_md_t){.start = pi,
930 .length = LNET_PINGINFO_SIZE,
931 .threshold = LNET_MD_THRESH_INF,
932 .options = LNET_MD_TRUNCATE,
933 .eq_handle = the_lnet.ln_rc_eqh},
937 CERROR("Can't bind MD: %d\n", rc);
942 lnet_net_lock(gateway->lp_cpt);
943 /* router table changed or someone has created rcd for this gateway */
944 if (!lnet_isrouter(gateway) || gateway->lp_rcd != NULL) {
945 lnet_net_unlock(gateway->lp_cpt);
949 lnet_peer_addref_locked(gateway);
950 rcd->rcd_gateway = gateway;
951 gateway->lp_rcd = rcd;
952 gateway->lp_ping_notsent = 0;
958 if (!LNetHandleIsInvalid(rcd->rcd_mdh)) {
959 rc = LNetMDUnlink(rcd->rcd_mdh);
962 lnet_destroy_rc_data(rcd);
965 lnet_net_lock(gateway->lp_cpt);
966 return gateway->lp_rcd;
970 lnet_router_check_interval (lnet_peer_t *rtr)
974 secs = rtr->lp_alive ? live_router_check_interval :
975 dead_router_check_interval;
983 lnet_ping_router_locked (lnet_peer_t *rtr)
985 lnet_rc_data_t *rcd = NULL;
986 cfs_time_t now = cfs_time_current();
989 lnet_peer_addref_locked(rtr);
991 if (rtr->lp_ping_deadline != 0 && /* ping timed out? */
992 cfs_time_after(now, rtr->lp_ping_deadline))
993 lnet_notify_locked(rtr, 1, 0, now);
995 /* Run any outstanding notifications */
996 lnet_ni_notify_locked(rtr->lp_ni, rtr);
998 if (!lnet_isrouter(rtr) ||
999 the_lnet.ln_rc_state != LNET_RC_STATE_RUNNING) {
1000 /* router table changed or router checker is shutting down */
1001 lnet_peer_decref_locked(rtr);
1005 rcd = rtr->lp_rcd != NULL ?
1006 rtr->lp_rcd : lnet_create_rc_data_locked(rtr);
1011 secs = lnet_router_check_interval(rtr);
1014 "rtr %s %d: deadline %lu ping_notsent %d alive %d "
1015 "alive_count %d lp_ping_timestamp %lu\n",
1016 libcfs_nid2str(rtr->lp_nid), secs,
1017 rtr->lp_ping_deadline, rtr->lp_ping_notsent,
1018 rtr->lp_alive, rtr->lp_alive_count, rtr->lp_ping_timestamp);
1020 if (secs != 0 && !rtr->lp_ping_notsent &&
1021 cfs_time_after(now, cfs_time_add(rtr->lp_ping_timestamp,
1022 cfs_time_seconds(secs)))) {
1024 lnet_process_id_t id;
1025 lnet_handle_md_t mdh;
1027 id.nid = rtr->lp_nid;
1028 id.pid = LNET_PID_LUSTRE;
1029 CDEBUG(D_NET, "Check: %s\n", libcfs_id2str(id));
1031 rtr->lp_ping_notsent = 1;
1032 rtr->lp_ping_timestamp = now;
1036 if (rtr->lp_ping_deadline == 0) {
1037 rtr->lp_ping_deadline =
1038 cfs_time_shift(router_ping_timeout);
1041 lnet_net_unlock(rtr->lp_cpt);
1043 rc = LNetGet(LNET_NID_ANY, mdh, id, LNET_RESERVED_PORTAL,
1044 LNET_PROTO_PING_MATCHBITS, 0);
1046 lnet_net_lock(rtr->lp_cpt);
1048 rtr->lp_ping_notsent = 0; /* no event pending */
1051 lnet_peer_decref_locked(rtr);
1056 lnet_router_checker_start(void)
1060 struct task_struct *task;
1062 LASSERT(the_lnet.ln_rc_state == LNET_RC_STATE_SHUTDOWN);
1064 if (check_routers_before_use &&
1065 dead_router_check_interval <= 0) {
1066 LCONSOLE_ERROR_MSG(0x10a, "'dead_router_check_interval' must be"
1067 " set if 'check_routers_before_use' is set"
1072 sema_init(&the_lnet.ln_rc_signal, 0);
1074 rc = LNetEQAlloc(0, lnet_router_checker_event, &the_lnet.ln_rc_eqh);
1076 CERROR("Can't allocate EQ(%d): %d\n", eqsz, rc);
1080 the_lnet.ln_rc_state = LNET_RC_STATE_RUNNING;
1081 task = kthread_run(lnet_router_checker, NULL, "router_checker");
1084 CERROR("Can't start router checker thread: %d\n", rc);
1085 /* block until event callback signals exit */
1086 down(&the_lnet.ln_rc_signal);
1087 rc = LNetEQFree(the_lnet.ln_rc_eqh);
1089 the_lnet.ln_rc_state = LNET_RC_STATE_SHUTDOWN;
1093 if (check_routers_before_use) {
1094 /* Note that a helpful side-effect of pinging all known routers
1095 * at startup is that it makes them drop stale connections they
1096 * may have to a previous instance of me. */
1097 lnet_wait_known_routerstate();
1104 lnet_router_checker_stop (void)
1108 if (the_lnet.ln_rc_state == LNET_RC_STATE_SHUTDOWN)
1111 LASSERT (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING);
1112 the_lnet.ln_rc_state = LNET_RC_STATE_STOPPING;
1113 /* wakeup the RC thread if it's sleeping */
1114 wake_up(&the_lnet.ln_rc_waitq);
1116 /* block until event callback signals exit */
1117 down(&the_lnet.ln_rc_signal);
1118 LASSERT(the_lnet.ln_rc_state == LNET_RC_STATE_SHUTDOWN);
1120 rc = LNetEQFree(the_lnet.ln_rc_eqh);
1126 lnet_prune_rc_data(int wait_unlink)
1128 lnet_rc_data_t *rcd;
1129 lnet_rc_data_t *tmp;
1131 struct list_head head;
1134 if (likely(the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING &&
1135 list_empty(&the_lnet.ln_rcd_deathrow) &&
1136 list_empty(&the_lnet.ln_rcd_zombie)))
1139 INIT_LIST_HEAD(&head);
1141 lnet_net_lock(LNET_LOCK_EX);
1143 if (the_lnet.ln_rc_state != LNET_RC_STATE_RUNNING) {
1144 /* router checker is stopping, prune all */
1145 list_for_each_entry(lp, &the_lnet.ln_routers,
1147 if (lp->lp_rcd == NULL)
1150 LASSERT(list_empty(&lp->lp_rcd->rcd_list));
1151 list_add(&lp->lp_rcd->rcd_list,
1152 &the_lnet.ln_rcd_deathrow);
1157 /* unlink all RCDs on deathrow list */
1158 list_splice_init(&the_lnet.ln_rcd_deathrow, &head);
1160 if (!list_empty(&head)) {
1161 lnet_net_unlock(LNET_LOCK_EX);
1163 list_for_each_entry(rcd, &head, rcd_list)
1164 LNetMDUnlink(rcd->rcd_mdh);
1166 lnet_net_lock(LNET_LOCK_EX);
1169 list_splice_init(&head, &the_lnet.ln_rcd_zombie);
1171 /* release all zombie RCDs */
1172 while (!list_empty(&the_lnet.ln_rcd_zombie)) {
1173 list_for_each_entry_safe(rcd, tmp, &the_lnet.ln_rcd_zombie,
1175 if (LNetHandleIsInvalid(rcd->rcd_mdh))
1176 list_move(&rcd->rcd_list, &head);
1179 wait_unlink = wait_unlink &&
1180 !list_empty(&the_lnet.ln_rcd_zombie);
1182 lnet_net_unlock(LNET_LOCK_EX);
1184 while (!list_empty(&head)) {
1185 rcd = list_entry(head.next,
1186 lnet_rc_data_t, rcd_list);
1187 list_del_init(&rcd->rcd_list);
1188 lnet_destroy_rc_data(rcd);
1195 CDEBUG(((i & (-i)) == i) ? D_WARNING : D_NET,
1196 "Waiting for rc buffers to unlink\n");
1197 cfs_pause(cfs_time_seconds(1) / 4);
1199 lnet_net_lock(LNET_LOCK_EX);
1202 lnet_net_unlock(LNET_LOCK_EX);
1206 * This function is called to check if the RC should block indefinitely.
1207 * It's called from lnet_router_checker() as well as being passed to
1208 * wait_event_interruptible() to avoid the lost wake_up problem.
1210 * When it's called from wait_event_interruptible() it is necessary to
1211 * also not sleep if the rc state is not running to avoid a deadlock
1212 * when the system is shutting down
1215 lnet_router_checker_active(void)
1217 if (the_lnet.ln_rc_state != LNET_RC_STATE_RUNNING)
1220 /* Router Checker thread needs to run when routing is enabled in
1221 * order to call lnet_update_ni_status_locked() */
1222 if (the_lnet.ln_routing)
1225 return !list_empty(&the_lnet.ln_routers) &&
1226 (live_router_check_interval > 0 ||
1227 dead_router_check_interval > 0);
1231 lnet_router_checker(void *arg)
1234 struct list_head *entry;
1236 cfs_block_allsigs();
1238 LASSERT (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING);
1240 while (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING) {
1245 cpt = lnet_net_lock_current();
1247 version = the_lnet.ln_routers_version;
1249 list_for_each(entry, &the_lnet.ln_routers) {
1250 rtr = list_entry(entry, lnet_peer_t, lp_rtr_list);
1252 cpt2 = lnet_cpt_of_nid_locked(rtr->lp_nid);
1254 lnet_net_unlock(cpt);
1257 /* the routers list has changed */
1258 if (version != the_lnet.ln_routers_version)
1262 lnet_ping_router_locked(rtr);
1264 /* NB dropped lock */
1265 if (version != the_lnet.ln_routers_version) {
1266 /* the routers list has changed */
1271 if (the_lnet.ln_routing)
1272 lnet_update_ni_status_locked();
1274 lnet_net_unlock(cpt);
1276 lnet_prune_rc_data(0); /* don't wait for UNLINK */
1278 /* Call cfs_pause() here always adds 1 to load average
1279 * because kernel counts # active tasks as nr_running
1280 * + nr_uninterruptible. */
1281 /* if there are any routes then wakeup every second. If
1282 * there are no routes then sleep indefinitely until woken
1283 * up by a user adding a route */
1284 if (!lnet_router_checker_active())
1285 wait_event_interruptible(the_lnet.ln_rc_waitq,
1286 lnet_router_checker_active());
1288 wait_event_interruptible_timeout(the_lnet.ln_rc_waitq,
1290 cfs_time_seconds(1));
1293 LASSERT(the_lnet.ln_rc_state == LNET_RC_STATE_STOPPING);
1295 lnet_prune_rc_data(1); /* wait for UNLINK */
1297 the_lnet.ln_rc_state = LNET_RC_STATE_SHUTDOWN;
1298 up(&the_lnet.ln_rc_signal);
1299 /* The unlink event callback will signal final completion */
1304 lnet_destroy_rtrbuf(lnet_rtrbuf_t *rb, int npages)
1306 int sz = offsetof(lnet_rtrbuf_t, rb_kiov[npages]);
1308 while (--npages >= 0)
1309 __free_page(rb->rb_kiov[npages].kiov_page);
1311 LIBCFS_FREE(rb, sz);
1314 static lnet_rtrbuf_t *
1315 lnet_new_rtrbuf(lnet_rtrbufpool_t *rbp, int cpt)
1317 int npages = rbp->rbp_npages;
1318 int sz = offsetof(lnet_rtrbuf_t, rb_kiov[npages]);
1323 LIBCFS_CPT_ALLOC(rb, lnet_cpt_table(), cpt, sz);
1329 for (i = 0; i < npages; i++) {
1330 page = cfs_page_cpt_alloc(lnet_cpt_table(), cpt,
1331 __GFP_ZERO | GFP_IOFS);
1334 __free_page(rb->rb_kiov[i].kiov_page);
1336 LIBCFS_FREE(rb, sz);
1340 rb->rb_kiov[i].kiov_len = PAGE_CACHE_SIZE;
1341 rb->rb_kiov[i].kiov_offset = 0;
1342 rb->rb_kiov[i].kiov_page = page;
1349 lnet_rtrpool_free_bufs(lnet_rtrbufpool_t *rbp, int cpt)
1351 int npages = rbp->rbp_npages;
1353 struct list_head tmp;
1355 if (rbp->rbp_nbuffers == 0) /* not initialized or already freed */
1358 INIT_LIST_HEAD(&tmp);
1361 lnet_drop_routed_msgs_locked(&rbp->rbp_msgs, cpt);
1362 list_splice_init(&rbp->rbp_bufs, &tmp);
1363 rbp->rbp_nbuffers = rbp->rbp_credits = 0;
1364 rbp->rbp_mincredits = 0;
1365 lnet_net_unlock(cpt);
1367 /* Free buffers on the free list. */
1368 while (!list_empty(&tmp)) {
1369 rb = list_entry(tmp.next, lnet_rtrbuf_t, rb_list);
1370 list_del(&rb->rb_list);
1371 lnet_destroy_rtrbuf(rb, npages);
1376 lnet_rtrpool_adjust_bufs(lnet_rtrbufpool_t *rbp, int nbufs, int cpt)
1378 struct list_head rb_list;
1381 int num_buffers = 0;
1382 int npages = rbp->rbp_npages;
1384 /* If we are called for less buffers than already in the pool, we
1385 * just lower the nbuffers number and excess buffers will be
1386 * thrown away as they are returned to the free list. Credits
1387 * then get adjusted as well. */
1388 if (nbufs <= rbp->rbp_nbuffers) {
1390 rbp->rbp_nbuffers = nbufs;
1391 lnet_net_unlock(cpt);
1395 INIT_LIST_HEAD(&rb_list);
1397 /* allocate the buffers on a local list first. If all buffers are
1398 * allocated successfully then join this list to the rbp buffer
1399 * list. If not then free all allocated buffers. */
1400 num_rb = rbp->rbp_nbuffers;
1402 while (num_rb < nbufs) {
1403 rb = lnet_new_rtrbuf(rbp, cpt);
1405 CERROR("Failed to allocate %d route bufs of %d pages\n",
1410 list_add(&rb->rb_list, &rb_list);
1417 list_splice_tail(&rb_list, &rbp->rbp_bufs);
1418 rbp->rbp_nbuffers += num_buffers;
1419 rbp->rbp_credits += num_buffers;
1420 rbp->rbp_mincredits = rbp->rbp_credits;
1421 /* We need to schedule blocked msg using the newly
1423 while (!list_empty(&rbp->rbp_bufs) &&
1424 !list_empty(&rbp->rbp_msgs))
1425 lnet_schedule_blocked_locked(rbp);
1427 lnet_net_unlock(cpt);
1432 while (!list_empty(&rb_list)) {
1433 rb = list_entry(rb_list.next, lnet_rtrbuf_t, rb_list);
1434 list_del(&rb->rb_list);
1435 lnet_destroy_rtrbuf(rb, npages);
1442 lnet_rtrpool_init(lnet_rtrbufpool_t *rbp, int npages)
1444 INIT_LIST_HEAD(&rbp->rbp_msgs);
1445 INIT_LIST_HEAD(&rbp->rbp_bufs);
1447 rbp->rbp_npages = npages;
1448 rbp->rbp_credits = 0;
1449 rbp->rbp_mincredits = 0;
1453 lnet_rtrpools_free(int keep_pools)
1455 lnet_rtrbufpool_t *rtrp;
1458 if (the_lnet.ln_rtrpools == NULL) /* uninitialized or freed */
1461 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1462 lnet_rtrpool_free_bufs(&rtrp[LNET_TINY_BUF_IDX], i);
1463 lnet_rtrpool_free_bufs(&rtrp[LNET_SMALL_BUF_IDX], i);
1464 lnet_rtrpool_free_bufs(&rtrp[LNET_LARGE_BUF_IDX], i);
1468 cfs_percpt_free(the_lnet.ln_rtrpools);
1469 the_lnet.ln_rtrpools = NULL;
1474 lnet_nrb_tiny_calculate(void)
1476 int nrbs = LNET_NRB_TINY;
1478 if (tiny_router_buffers < 0) {
1479 LCONSOLE_ERROR_MSG(0x10c,
1480 "tiny_router_buffers=%d invalid when "
1481 "routing enabled\n", tiny_router_buffers);
1485 if (tiny_router_buffers > 0)
1486 nrbs = tiny_router_buffers;
1488 nrbs /= LNET_CPT_NUMBER;
1489 return max(nrbs, LNET_NRB_TINY_MIN);
1493 lnet_nrb_small_calculate(void)
1495 int nrbs = LNET_NRB_SMALL;
1497 if (small_router_buffers < 0) {
1498 LCONSOLE_ERROR_MSG(0x10c,
1499 "small_router_buffers=%d invalid when "
1500 "routing enabled\n", small_router_buffers);
1504 if (small_router_buffers > 0)
1505 nrbs = small_router_buffers;
1507 nrbs /= LNET_CPT_NUMBER;
1508 return max(nrbs, LNET_NRB_SMALL_MIN);
1512 lnet_nrb_large_calculate(void)
1514 int nrbs = LNET_NRB_LARGE;
1516 if (large_router_buffers < 0) {
1517 LCONSOLE_ERROR_MSG(0x10c,
1518 "large_router_buffers=%d invalid when "
1519 "routing enabled\n", large_router_buffers);
1523 if (large_router_buffers > 0)
1524 nrbs = large_router_buffers;
1526 nrbs /= LNET_CPT_NUMBER;
1527 return max(nrbs, LNET_NRB_LARGE_MIN);
1531 lnet_rtrpools_alloc(int im_a_router)
1533 lnet_rtrbufpool_t *rtrp;
1540 if (!strcmp(forwarding, "")) {
1541 /* not set either way */
1544 } else if (!strcmp(forwarding, "disabled")) {
1545 /* explicitly disabled */
1547 } else if (!strcmp(forwarding, "enabled")) {
1548 /* explicitly enabled */
1550 LCONSOLE_ERROR_MSG(0x10b, "'forwarding' not set to either "
1551 "'enabled' or 'disabled'\n");
1555 nrb_tiny = lnet_nrb_tiny_calculate();
1559 nrb_small = lnet_nrb_small_calculate();
1563 nrb_large = lnet_nrb_large_calculate();
1567 the_lnet.ln_rtrpools = cfs_percpt_alloc(lnet_cpt_table(),
1569 sizeof(lnet_rtrbufpool_t));
1570 if (the_lnet.ln_rtrpools == NULL) {
1571 LCONSOLE_ERROR_MSG(0x10c,
1572 "Failed to initialize router buffe pool\n");
1576 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1577 lnet_rtrpool_init(&rtrp[LNET_TINY_BUF_IDX], 0);
1578 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_TINY_BUF_IDX],
1583 lnet_rtrpool_init(&rtrp[LNET_SMALL_BUF_IDX],
1584 LNET_NRB_SMALL_PAGES);
1585 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_SMALL_BUF_IDX],
1590 lnet_rtrpool_init(&rtrp[LNET_LARGE_BUF_IDX],
1591 LNET_NRB_LARGE_PAGES);
1592 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_LARGE_BUF_IDX],
1598 lnet_net_lock(LNET_LOCK_EX);
1599 the_lnet.ln_routing = 1;
1600 lnet_net_unlock(LNET_LOCK_EX);
1604 lnet_rtrpools_free(0);
1609 lnet_rtrpools_adjust_helper(int tiny, int small, int large)
1614 lnet_rtrbufpool_t *rtrp;
1616 /* If the provided values for each buffer pool are different than the
1617 * configured values, we need to take action. */
1619 tiny_router_buffers = tiny;
1620 nrb = lnet_nrb_tiny_calculate();
1621 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1622 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_TINY_BUF_IDX],
1629 small_router_buffers = small;
1630 nrb = lnet_nrb_small_calculate();
1631 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1632 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_SMALL_BUF_IDX],
1639 large_router_buffers = large;
1640 nrb = lnet_nrb_large_calculate();
1641 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1642 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_LARGE_BUF_IDX],
1653 lnet_rtrpools_adjust(int tiny, int small, int large)
1655 /* this function doesn't revert the changes if adding new buffers
1656 * failed. It's up to the user space caller to revert the
1659 if (!the_lnet.ln_routing)
1662 return lnet_rtrpools_adjust_helper(tiny, small, large);
1666 lnet_rtrpools_enable(void)
1670 if (the_lnet.ln_routing)
1673 if (the_lnet.ln_rtrpools == NULL)
1674 /* If routing is turned off, and we have never
1675 * initialized the pools before, just call the
1676 * standard buffer pool allocation routine as
1677 * if we are just configuring this for the first
1679 return lnet_rtrpools_alloc(1);
1681 rc = lnet_rtrpools_adjust_helper(0, 0, 0);
1685 lnet_net_lock(LNET_LOCK_EX);
1686 the_lnet.ln_routing = 1;
1688 the_lnet.ln_ping_info->pi_features &= ~LNET_PING_FEAT_RTE_DISABLED;
1689 lnet_net_unlock(LNET_LOCK_EX);
1695 lnet_rtrpools_disable(void)
1697 if (!the_lnet.ln_routing)
1700 lnet_net_lock(LNET_LOCK_EX);
1701 the_lnet.ln_routing = 0;
1702 the_lnet.ln_ping_info->pi_features |= LNET_PING_FEAT_RTE_DISABLED;
1704 tiny_router_buffers = 0;
1705 small_router_buffers = 0;
1706 large_router_buffers = 0;
1707 lnet_net_unlock(LNET_LOCK_EX);
1708 lnet_rtrpools_free(1);
1712 lnet_notify(lnet_ni_t *ni, lnet_nid_t nid, int alive, cfs_time_t when)
1714 struct lnet_peer *lp = NULL;
1715 cfs_time_t now = cfs_time_current();
1716 int cpt = lnet_cpt_of_nid(nid);
1718 LASSERT (!in_interrupt ());
1720 CDEBUG (D_NET, "%s notifying %s: %s\n",
1721 (ni == NULL) ? "userspace" : libcfs_nid2str(ni->ni_nid),
1722 libcfs_nid2str(nid),
1723 alive ? "up" : "down");
1726 LNET_NIDNET(ni->ni_nid) != LNET_NIDNET(nid)) {
1727 CWARN ("Ignoring notification of %s %s by %s (different net)\n",
1728 libcfs_nid2str(nid), alive ? "birth" : "death",
1729 libcfs_nid2str(ni->ni_nid));
1733 /* can't do predictions... */
1734 if (cfs_time_after(when, now)) {
1735 CWARN ("Ignoring prediction from %s of %s %s "
1736 "%ld seconds in the future\n",
1737 (ni == NULL) ? "userspace" : libcfs_nid2str(ni->ni_nid),
1738 libcfs_nid2str(nid), alive ? "up" : "down",
1739 cfs_duration_sec(cfs_time_sub(when, now)));
1743 if (ni != NULL && !alive && /* LND telling me she's down */
1744 !auto_down) { /* auto-down disabled */
1745 CDEBUG(D_NET, "Auto-down disabled\n");
1751 if (the_lnet.ln_shutdown) {
1752 lnet_net_unlock(cpt);
1756 lp = lnet_find_peer_locked(the_lnet.ln_peer_tables[cpt], nid);
1759 lnet_net_unlock(cpt);
1760 CDEBUG(D_NET, "%s not found\n", libcfs_nid2str(nid));
1764 /* We can't fully trust LND on reporting exact peer last_alive
1765 * if he notifies us about dead peer. For example ksocklnd can
1766 * call us with when == _time_when_the_node_was_booted_ if
1767 * no connections were successfully established */
1768 if (ni != NULL && !alive && when < lp->lp_last_alive)
1769 when = lp->lp_last_alive;
1771 lnet_notify_locked(lp, ni == NULL, alive, when);
1774 lnet_ni_notify_locked(ni, lp);
1776 lnet_peer_decref_locked(lp);
1778 lnet_net_unlock(cpt);
1781 EXPORT_SYMBOL(lnet_notify);