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 Lustre, https://wiki.hpdd.intel.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_CACHE_SIZE - 1) >> \
36 static char *forwarding = "";
37 CFS_MODULE_PARM(forwarding, "s", charp, 0444,
38 "Explicitly enable/disable forwarding between networks");
40 static int tiny_router_buffers;
41 CFS_MODULE_PARM(tiny_router_buffers, "i", int, 0444,
42 "# of 0 payload messages to buffer in the router");
43 static int small_router_buffers;
44 CFS_MODULE_PARM(small_router_buffers, "i", int, 0444,
45 "# of small (1 page) messages to buffer in the router");
46 static int large_router_buffers;
47 CFS_MODULE_PARM(large_router_buffers, "i", int, 0444,
48 "# of large messages to buffer in the router");
49 static int peer_buffer_credits = 0;
50 CFS_MODULE_PARM(peer_buffer_credits, "i", int, 0444,
51 "# router buffer credits per peer");
53 static int auto_down = 1;
54 CFS_MODULE_PARM(auto_down, "i", int, 0444,
55 "Automatically mark peers down on comms error");
58 lnet_peer_buffer_credits(lnet_ni_t *ni)
60 /* NI option overrides LNet default */
61 if (ni->ni_peerrtrcredits > 0)
62 return ni->ni_peerrtrcredits;
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 ni->ni_peertxcredits;
72 static int lnet_router_checker(void *);
74 static int check_routers_before_use = 0;
75 CFS_MODULE_PARM(check_routers_before_use, "i", int, 0444,
76 "Assume routers are down and ping them before use");
78 int avoid_asym_router_failure = 1;
79 CFS_MODULE_PARM(avoid_asym_router_failure, "i", int, 0644,
80 "Avoid asymmetrical router failures (0 to disable)");
82 static int dead_router_check_interval = 60;
83 CFS_MODULE_PARM(dead_router_check_interval, "i", int, 0644,
84 "Seconds between dead router health checks (<= 0 to disable)");
86 static int live_router_check_interval = 60;
87 CFS_MODULE_PARM(live_router_check_interval, "i", int, 0644,
88 "Seconds between live router health checks (<= 0 to disable)");
90 static int router_ping_timeout = 50;
91 CFS_MODULE_PARM(router_ping_timeout, "i", int, 0644,
92 "Seconds to wait for the reply to a router health query");
95 lnet_peers_start_down(void)
97 return check_routers_before_use;
101 lnet_notify_locked(lnet_peer_t *lp, int notifylnd, int alive, cfs_time_t when)
103 if (cfs_time_before(when, lp->lp_timestamp)) { /* out of date information */
104 CDEBUG(D_NET, "Out of date\n");
108 lp->lp_timestamp = when; /* update timestamp */
109 lp->lp_ping_deadline = 0; /* disable ping timeout */
111 if (lp->lp_alive_count != 0 && /* got old news */
112 (!lp->lp_alive) == (!alive)) { /* new date for old news */
113 CDEBUG(D_NET, "Old news\n");
117 /* Flag that notification is outstanding */
119 lp->lp_alive_count++;
120 lp->lp_alive = !(!alive); /* 1 bit! */
122 lp->lp_notifylnd |= notifylnd;
124 lp->lp_ping_feats = LNET_PING_FEAT_INVAL; /* reset */
126 CDEBUG(D_NET, "set %s %d\n", libcfs_nid2str(lp->lp_nid), alive);
130 lnet_ni_notify_locked(lnet_ni_t *ni, lnet_peer_t *lp)
135 /* Notify only in 1 thread at any time to ensure ordered notification.
136 * NB individual events can be missed; the only guarantee is that you
137 * always get the most recent news */
139 if (lp->lp_notifying)
142 lp->lp_notifying = 1;
144 while (lp->lp_notify) {
145 alive = lp->lp_alive;
146 notifylnd = lp->lp_notifylnd;
148 lp->lp_notifylnd = 0;
151 if (notifylnd && ni->ni_lnd->lnd_notify != NULL) {
152 lnet_net_unlock(lp->lp_cpt);
154 /* A new notification could happen now; I'll handle it
155 * when control returns to me */
157 (ni->ni_lnd->lnd_notify)(ni, lp->lp_nid, alive);
159 lnet_net_lock(lp->lp_cpt);
163 lp->lp_notifying = 0;
168 lnet_rtr_addref_locked(lnet_peer_t *lp)
170 LASSERT(lp->lp_refcount > 0);
171 LASSERT(lp->lp_rtr_refcount >= 0);
173 /* lnet_net_lock must be exclusively locked */
174 lp->lp_rtr_refcount++;
175 if (lp->lp_rtr_refcount == 1) {
176 struct list_head *pos;
178 /* a simple insertion sort */
179 list_for_each_prev(pos, &the_lnet.ln_routers) {
180 lnet_peer_t *rtr = list_entry(pos, lnet_peer_t,
183 if (rtr->lp_nid < lp->lp_nid)
187 list_add(&lp->lp_rtr_list, pos);
188 /* addref for the_lnet.ln_routers */
189 lnet_peer_addref_locked(lp);
190 the_lnet.ln_routers_version++;
195 lnet_rtr_decref_locked(lnet_peer_t *lp)
197 LASSERT(lp->lp_refcount > 0);
198 LASSERT(lp->lp_rtr_refcount > 0);
200 /* lnet_net_lock must be exclusively locked */
201 lp->lp_rtr_refcount--;
202 if (lp->lp_rtr_refcount == 0) {
203 LASSERT(list_empty(&lp->lp_routes));
205 if (lp->lp_rcd != NULL) {
206 list_add(&lp->lp_rcd->rcd_list,
207 &the_lnet.ln_rcd_deathrow);
211 list_del(&lp->lp_rtr_list);
212 /* decref for the_lnet.ln_routers */
213 lnet_peer_decref_locked(lp);
214 the_lnet.ln_routers_version++;
219 lnet_find_net_locked (__u32 net)
221 lnet_remotenet_t *rnet;
222 struct list_head *tmp;
223 struct list_head *rn_list;
225 LASSERT(!the_lnet.ln_shutdown);
227 rn_list = lnet_net2rnethash(net);
228 list_for_each(tmp, rn_list) {
229 rnet = list_entry(tmp, lnet_remotenet_t, lrn_list);
231 if (rnet->lrn_net == net)
237 static void lnet_shuffle_seed(void)
244 struct list_head *tmp;
249 cfs_get_random_bytes(seed, sizeof(seed));
251 /* Nodes with small feet have little entropy
252 * the NID for this node gives the most entropy in the low bits */
253 list_for_each(tmp, &the_lnet.ln_nis) {
254 ni = list_entry(tmp, lnet_ni_t, ni_list);
255 lnd_type = LNET_NETTYP(LNET_NIDNET(ni->ni_nid));
257 if (lnd_type != LOLND)
258 seed[0] ^= (LNET_NIDADDR(ni->ni_nid) | lnd_type);
261 do_gettimeofday(&tv);
262 cfs_srand(tv.tv_sec ^ seed[0], tv.tv_usec ^ seed[1]);
267 /* NB expects LNET_LOCK held */
269 lnet_add_route_to_rnet(lnet_remotenet_t *rnet, lnet_route_t *route)
271 unsigned int len = 0;
272 unsigned int offset = 0;
277 list_for_each(e, &rnet->lrn_routes) {
281 /* len+1 positions to add a new entry, also prevents division by 0 */
282 offset = cfs_rand() % (len + 1);
283 list_for_each(e, &rnet->lrn_routes) {
288 list_add(&route->lr_list, e);
289 list_add(&route->lr_gwlist, &route->lr_gateway->lp_routes);
291 the_lnet.ln_remote_nets_version++;
292 lnet_rtr_addref_locked(route->lr_gateway);
296 lnet_add_route(__u32 net, unsigned int hops, lnet_nid_t gateway,
297 unsigned int priority)
300 lnet_remotenet_t *rnet;
301 lnet_remotenet_t *rnet2;
307 CDEBUG(D_NET, "Add route: net %s hops %u priority %u gw %s\n",
308 libcfs_net2str(net), hops, priority, libcfs_nid2str(gateway));
310 if (gateway == LNET_NID_ANY ||
311 LNET_NETTYP(LNET_NIDNET(gateway)) == LOLND ||
312 net == LNET_NIDNET(LNET_NID_ANY) ||
313 LNET_NETTYP(net) == LOLND ||
314 LNET_NIDNET(gateway) == net ||
315 hops < 1 || hops > 255)
318 if (lnet_islocalnet(net)) /* it's a local network */
321 /* Assume net, route, all new */
322 LIBCFS_ALLOC(route, sizeof(*route));
323 LIBCFS_ALLOC(rnet, sizeof(*rnet));
324 if (route == NULL || rnet == NULL) {
325 CERROR("Out of memory creating route %s %d %s\n",
326 libcfs_net2str(net), hops, libcfs_nid2str(gateway));
328 LIBCFS_FREE(route, sizeof(*route));
330 LIBCFS_FREE(rnet, sizeof(*rnet));
334 INIT_LIST_HEAD(&rnet->lrn_routes);
336 route->lr_hops = hops;
338 route->lr_priority = priority;
340 lnet_net_lock(LNET_LOCK_EX);
342 rc = lnet_nid2peer_locked(&route->lr_gateway, gateway, LNET_LOCK_EX);
344 lnet_net_unlock(LNET_LOCK_EX);
346 LIBCFS_FREE(route, sizeof(*route));
347 LIBCFS_FREE(rnet, sizeof(*rnet));
349 if (rc == -EHOSTUNREACH) /* gateway is not on a local net. */
350 return rc; /* ignore the route entry */
351 CERROR("Error %d creating route %s %d %s\n", rc,
352 libcfs_net2str(net), hops,
353 libcfs_nid2str(gateway));
357 LASSERT(!the_lnet.ln_shutdown);
359 rnet2 = lnet_find_net_locked(net);
362 list_add_tail(&rnet->lrn_list, lnet_net2rnethash(net));
366 /* Search for a duplicate route (it's a NOOP if it is) */
368 list_for_each(e, &rnet2->lrn_routes) {
369 lnet_route_t *route2 = list_entry(e, lnet_route_t, lr_list);
371 if (route2->lr_gateway == route->lr_gateway) {
376 /* our lookups must be true */
377 LASSERT(route2->lr_gateway->lp_nid != gateway);
381 lnet_peer_addref_locked(route->lr_gateway); /* +1 for notify */
382 lnet_add_route_to_rnet(rnet2, route);
384 ni = route->lr_gateway->lp_ni;
385 lnet_net_unlock(LNET_LOCK_EX);
387 /* XXX Assume alive */
388 if (ni->ni_lnd->lnd_notify != NULL)
389 (ni->ni_lnd->lnd_notify)(ni, gateway, 1);
391 lnet_net_lock(LNET_LOCK_EX);
394 /* -1 for notify or !add_route */
395 lnet_peer_decref_locked(route->lr_gateway);
396 lnet_net_unlock(LNET_LOCK_EX);
402 LIBCFS_FREE(route, sizeof(*route));
406 LIBCFS_FREE(rnet, sizeof(*rnet));
408 /* indicate to startup the router checker if configured */
409 wake_up(&the_lnet.ln_rc_waitq);
415 lnet_check_routes(void)
417 lnet_remotenet_t *rnet;
419 lnet_route_t *route2;
420 struct list_head *e1;
421 struct list_head *e2;
423 struct list_head *rn_list;
426 cpt = lnet_net_lock_current();
428 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) {
429 rn_list = &the_lnet.ln_remote_nets_hash[i];
430 list_for_each(e1, rn_list) {
431 rnet = list_entry(e1, lnet_remotenet_t, lrn_list);
434 list_for_each(e2, &rnet->lrn_routes) {
439 route = list_entry(e2, lnet_route_t,
442 if (route2 == NULL) {
447 if (route->lr_gateway->lp_ni ==
448 route2->lr_gateway->lp_ni)
451 nid1 = route->lr_gateway->lp_nid;
452 nid2 = route2->lr_gateway->lp_nid;
455 lnet_net_unlock(cpt);
457 CERROR("Routes to %s via %s and %s not "
460 libcfs_nid2str(nid1),
461 libcfs_nid2str(nid2));
467 lnet_net_unlock(cpt);
472 lnet_del_route(__u32 net, lnet_nid_t gw_nid)
474 struct lnet_peer *gateway;
475 lnet_remotenet_t *rnet;
477 struct list_head *e1;
478 struct list_head *e2;
480 struct list_head *rn_list;
483 CDEBUG(D_NET, "Del route: net %s : gw %s\n",
484 libcfs_net2str(net), libcfs_nid2str(gw_nid));
486 /* NB Caller may specify either all routes via the given gateway
487 * or a specific route entry actual NIDs) */
489 lnet_net_lock(LNET_LOCK_EX);
490 if (net == LNET_NIDNET(LNET_NID_ANY))
491 rn_list = &the_lnet.ln_remote_nets_hash[0];
493 rn_list = lnet_net2rnethash(net);
496 list_for_each(e1, rn_list) {
497 rnet = list_entry(e1, lnet_remotenet_t, lrn_list);
499 if (!(net == LNET_NIDNET(LNET_NID_ANY) ||
500 net == rnet->lrn_net))
503 list_for_each(e2, &rnet->lrn_routes) {
504 route = list_entry(e2, lnet_route_t, lr_list);
506 gateway = route->lr_gateway;
507 if (!(gw_nid == LNET_NID_ANY ||
508 gw_nid == gateway->lp_nid))
511 list_del(&route->lr_list);
512 list_del(&route->lr_gwlist);
513 the_lnet.ln_remote_nets_version++;
515 if (list_empty(&rnet->lrn_routes))
516 list_del(&rnet->lrn_list);
520 lnet_rtr_decref_locked(gateway);
521 lnet_peer_decref_locked(gateway);
523 lnet_net_unlock(LNET_LOCK_EX);
525 LIBCFS_FREE(route, sizeof(*route));
528 LIBCFS_FREE(rnet, sizeof(*rnet));
531 lnet_net_lock(LNET_LOCK_EX);
536 if (net == LNET_NIDNET(LNET_NID_ANY) &&
537 ++idx < LNET_REMOTE_NETS_HASH_SIZE) {
538 rn_list = &the_lnet.ln_remote_nets_hash[idx];
541 lnet_net_unlock(LNET_LOCK_EX);
547 lnet_destroy_routes (void)
549 lnet_del_route(LNET_NIDNET(LNET_NID_ANY), LNET_NID_ANY);
552 int lnet_get_rtr_pool_cfg(int idx, struct lnet_ioctl_pool_cfg *pool_cfg)
554 int i, rc = -ENOENT, lidx, j;
556 if (the_lnet.ln_rtrpools == NULL)
559 for (i = 0; i < LNET_NRBPOOLS; i++) {
560 lnet_rtrbufpool_t *rbp;
562 lnet_net_lock(LNET_LOCK_EX);
564 cfs_percpt_for_each(rbp, j, the_lnet.ln_rtrpools) {
567 pool_cfg->pl_pools[i].pl_npages =
569 pool_cfg->pl_pools[i].pl_nbuffers =
571 pool_cfg->pl_pools[i].pl_credits =
573 pool_cfg->pl_pools[i].pl_mincredits =
574 rbp[i].rbp_mincredits;
578 lnet_net_unlock(LNET_LOCK_EX);
581 lnet_net_lock(LNET_LOCK_EX);
582 pool_cfg->pl_routing = the_lnet.ln_routing;
583 lnet_net_unlock(LNET_LOCK_EX);
589 lnet_get_route(int idx, __u32 *net, __u32 *hops,
590 lnet_nid_t *gateway, __u32 *alive, __u32 *priority)
592 struct list_head *e1;
593 struct list_head *e2;
594 lnet_remotenet_t *rnet;
598 struct list_head *rn_list;
600 cpt = lnet_net_lock_current();
602 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) {
603 rn_list = &the_lnet.ln_remote_nets_hash[i];
604 list_for_each(e1, rn_list) {
605 rnet = list_entry(e1, lnet_remotenet_t, lrn_list);
607 list_for_each(e2, &rnet->lrn_routes) {
608 route = list_entry(e2, lnet_route_t,
612 *net = rnet->lrn_net;
613 *hops = route->lr_hops;
614 *priority = route->lr_priority;
615 *gateway = route->lr_gateway->lp_nid;
617 route->lr_gateway->lp_alive &&
619 lnet_net_unlock(cpt);
626 lnet_net_unlock(cpt);
631 lnet_swap_pinginfo(lnet_ping_info_t *info)
634 lnet_ni_status_t *stat;
636 __swab32s(&info->pi_magic);
637 __swab32s(&info->pi_features);
638 __swab32s(&info->pi_pid);
639 __swab32s(&info->pi_nnis);
640 for (i = 0; i < info->pi_nnis && i < LNET_MAX_RTR_NIS; i++) {
641 stat = &info->pi_ni[i];
642 __swab64s(&stat->ns_nid);
643 __swab32s(&stat->ns_status);
649 * parse router-checker pinginfo, record number of down NIs for remote
650 * networks on that router.
653 lnet_parse_rc_info(lnet_rc_data_t *rcd)
655 lnet_ping_info_t *info = rcd->rcd_pinginfo;
656 struct lnet_peer *gw = rcd->rcd_gateway;
662 if (info->pi_magic == __swab32(LNET_PROTO_PING_MAGIC))
663 lnet_swap_pinginfo(info);
665 /* NB always racing with network! */
666 if (info->pi_magic != LNET_PROTO_PING_MAGIC) {
667 CDEBUG(D_NET, "%s: Unexpected magic %08x\n",
668 libcfs_nid2str(gw->lp_nid), info->pi_magic);
669 gw->lp_ping_feats = LNET_PING_FEAT_INVAL;
673 gw->lp_ping_feats = info->pi_features;
674 if ((gw->lp_ping_feats & LNET_PING_FEAT_MASK) == 0) {
675 CDEBUG(D_NET, "%s: Unexpected features 0x%x\n",
676 libcfs_nid2str(gw->lp_nid), gw->lp_ping_feats);
677 return; /* nothing I can understand */
680 if ((gw->lp_ping_feats & LNET_PING_FEAT_NI_STATUS) == 0)
681 return; /* can't carry NI status info */
683 list_for_each_entry(rte, &gw->lp_routes, lr_gwlist) {
688 if ((gw->lp_ping_feats & LNET_PING_FEAT_RTE_DISABLED) != 0) {
693 for (i = 0; i < info->pi_nnis && i < LNET_MAX_RTR_NIS; i++) {
694 lnet_ni_status_t *stat = &info->pi_ni[i];
695 lnet_nid_t nid = stat->ns_nid;
697 if (nid == LNET_NID_ANY) {
698 CDEBUG(D_NET, "%s: unexpected LNET_NID_ANY\n",
699 libcfs_nid2str(gw->lp_nid));
700 gw->lp_ping_feats = LNET_PING_FEAT_INVAL;
704 if (LNET_NETTYP(LNET_NIDNET(nid)) == LOLND)
707 if (stat->ns_status == LNET_NI_STATUS_DOWN) {
712 if (stat->ns_status == LNET_NI_STATUS_UP) {
713 if (LNET_NIDNET(nid) == rte->lr_net) {
720 CDEBUG(D_NET, "%s: Unexpected status 0x%x\n",
721 libcfs_nid2str(gw->lp_nid), stat->ns_status);
722 gw->lp_ping_feats = LNET_PING_FEAT_INVAL;
726 if (up) { /* ignore downed NIs if NI for dest network is up */
730 /* if @down is zero and this route is single-hop, it means
731 * we can't find NI for target network */
732 if (down == 0 && rte->lr_hops == 1)
735 rte->lr_downis = down;
740 lnet_router_checker_event(lnet_event_t *event)
742 lnet_rc_data_t *rcd = event->md.user_ptr;
743 struct lnet_peer *lp;
745 LASSERT(rcd != NULL);
747 if (event->unlinked) {
748 LNetInvalidateHandle(&rcd->rcd_mdh);
752 LASSERT(event->type == LNET_EVENT_SEND ||
753 event->type == LNET_EVENT_REPLY);
755 lp = rcd->rcd_gateway;
758 /* NB: it's called with holding lnet_res_lock, we have a few
759 * places need to hold both locks at the same time, please take
760 * care of lock ordering */
761 lnet_net_lock(lp->lp_cpt);
762 if (!lnet_isrouter(lp) || lp->lp_rcd != rcd) {
763 /* ignore if no longer a router or rcd is replaced */
767 if (event->type == LNET_EVENT_SEND) {
768 lp->lp_ping_notsent = 0;
769 if (event->status == 0)
773 /* LNET_EVENT_REPLY */
774 /* A successful REPLY means the router is up. If _any_ comms
775 * to the router fail I assume it's down (this will happen if
776 * we ping alive routers to try to detect router death before
777 * apps get burned). */
779 lnet_notify_locked(lp, 1, (event->status == 0), cfs_time_current());
780 /* The router checker will wake up very shortly and do the
781 * actual notification.
782 * XXX If 'lp' stops being a router before then, it will still
783 * have the notification pending!!! */
785 if (avoid_asym_router_failure && event->status == 0)
786 lnet_parse_rc_info(rcd);
789 lnet_net_unlock(lp->lp_cpt);
793 lnet_wait_known_routerstate(void)
796 struct list_head *entry;
799 LASSERT(the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING);
802 int cpt = lnet_net_lock_current();
805 list_for_each(entry, &the_lnet.ln_routers) {
806 rtr = list_entry(entry, lnet_peer_t, lp_rtr_list);
808 if (rtr->lp_alive_count == 0) {
814 lnet_net_unlock(cpt);
819 set_current_state(TASK_UNINTERRUPTIBLE);
820 schedule_timeout(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 set_current_state(TASK_UNINTERRUPTIBLE);
1198 schedule_timeout(cfs_time_seconds(1) / 4);
1200 lnet_net_lock(LNET_LOCK_EX);
1203 lnet_net_unlock(LNET_LOCK_EX);
1207 * This function is called to check if the RC should block indefinitely.
1208 * It's called from lnet_router_checker() as well as being passed to
1209 * wait_event_interruptible() to avoid the lost wake_up problem.
1211 * When it's called from wait_event_interruptible() it is necessary to
1212 * also not sleep if the rc state is not running to avoid a deadlock
1213 * when the system is shutting down
1216 lnet_router_checker_active(void)
1218 if (the_lnet.ln_rc_state != LNET_RC_STATE_RUNNING)
1221 /* Router Checker thread needs to run when routing is enabled in
1222 * order to call lnet_update_ni_status_locked() */
1223 if (the_lnet.ln_routing)
1226 return !list_empty(&the_lnet.ln_routers) &&
1227 (live_router_check_interval > 0 ||
1228 dead_router_check_interval > 0);
1232 lnet_router_checker(void *arg)
1235 struct list_head *entry;
1237 cfs_block_allsigs();
1239 LASSERT (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING);
1241 while (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING) {
1246 cpt = lnet_net_lock_current();
1248 version = the_lnet.ln_routers_version;
1250 list_for_each(entry, &the_lnet.ln_routers) {
1251 rtr = list_entry(entry, lnet_peer_t, lp_rtr_list);
1253 cpt2 = lnet_cpt_of_nid_locked(rtr->lp_nid);
1255 lnet_net_unlock(cpt);
1258 /* the routers list has changed */
1259 if (version != the_lnet.ln_routers_version)
1263 lnet_ping_router_locked(rtr);
1265 /* NB dropped lock */
1266 if (version != the_lnet.ln_routers_version) {
1267 /* the routers list has changed */
1272 if (the_lnet.ln_routing)
1273 lnet_update_ni_status_locked();
1275 lnet_net_unlock(cpt);
1277 lnet_prune_rc_data(0); /* don't wait for UNLINK */
1279 /* Call schedule_timeout() here always adds 1 to load average
1280 * because kernel counts # active tasks as nr_running
1281 * + nr_uninterruptible. */
1282 /* if there are any routes then wakeup every second. If
1283 * there are no routes then sleep indefinitely until woken
1284 * up by a user adding a route */
1285 if (!lnet_router_checker_active())
1286 wait_event_interruptible(the_lnet.ln_rc_waitq,
1287 lnet_router_checker_active());
1289 wait_event_interruptible_timeout(the_lnet.ln_rc_waitq,
1291 cfs_time_seconds(1));
1294 LASSERT(the_lnet.ln_rc_state == LNET_RC_STATE_STOPPING);
1296 lnet_prune_rc_data(1); /* wait for UNLINK */
1298 the_lnet.ln_rc_state = LNET_RC_STATE_SHUTDOWN;
1299 up(&the_lnet.ln_rc_signal);
1300 /* The unlink event callback will signal final completion */
1305 lnet_destroy_rtrbuf(lnet_rtrbuf_t *rb, int npages)
1307 int sz = offsetof(lnet_rtrbuf_t, rb_kiov[npages]);
1309 while (--npages >= 0)
1310 __free_page(rb->rb_kiov[npages].kiov_page);
1312 LIBCFS_FREE(rb, sz);
1315 static lnet_rtrbuf_t *
1316 lnet_new_rtrbuf(lnet_rtrbufpool_t *rbp, int cpt)
1318 int npages = rbp->rbp_npages;
1319 int sz = offsetof(lnet_rtrbuf_t, rb_kiov[npages]);
1324 LIBCFS_CPT_ALLOC(rb, lnet_cpt_table(), cpt, sz);
1330 for (i = 0; i < npages; i++) {
1331 page = cfs_page_cpt_alloc(lnet_cpt_table(), cpt,
1332 __GFP_ZERO | GFP_IOFS);
1335 __free_page(rb->rb_kiov[i].kiov_page);
1337 LIBCFS_FREE(rb, sz);
1341 rb->rb_kiov[i].kiov_len = PAGE_CACHE_SIZE;
1342 rb->rb_kiov[i].kiov_offset = 0;
1343 rb->rb_kiov[i].kiov_page = page;
1350 lnet_rtrpool_free_bufs(lnet_rtrbufpool_t *rbp, int cpt)
1352 int npages = rbp->rbp_npages;
1354 struct list_head tmp;
1356 if (rbp->rbp_nbuffers == 0) /* not initialized or already freed */
1359 INIT_LIST_HEAD(&tmp);
1362 lnet_drop_routed_msgs_locked(&rbp->rbp_msgs, cpt);
1363 list_splice_init(&rbp->rbp_bufs, &tmp);
1364 rbp->rbp_nbuffers = rbp->rbp_credits = 0;
1365 rbp->rbp_mincredits = 0;
1366 lnet_net_unlock(cpt);
1368 /* Free buffers on the free list. */
1369 while (!list_empty(&tmp)) {
1370 rb = list_entry(tmp.next, lnet_rtrbuf_t, rb_list);
1371 list_del(&rb->rb_list);
1372 lnet_destroy_rtrbuf(rb, npages);
1377 lnet_rtrpool_adjust_bufs(lnet_rtrbufpool_t *rbp, int nbufs, int cpt)
1379 struct list_head rb_list;
1382 int num_buffers = 0;
1383 int npages = rbp->rbp_npages;
1385 /* If we are called for less buffers than already in the pool, we
1386 * just lower the nbuffers number and excess buffers will be
1387 * thrown away as they are returned to the free list. Credits
1388 * then get adjusted as well. */
1389 if (nbufs <= rbp->rbp_nbuffers) {
1391 rbp->rbp_nbuffers = nbufs;
1392 lnet_net_unlock(cpt);
1396 INIT_LIST_HEAD(&rb_list);
1398 /* allocate the buffers on a local list first. If all buffers are
1399 * allocated successfully then join this list to the rbp buffer
1400 * list. If not then free all allocated buffers. */
1401 num_rb = rbp->rbp_nbuffers;
1403 while (num_rb < nbufs) {
1404 rb = lnet_new_rtrbuf(rbp, cpt);
1406 CERROR("Failed to allocate %d route bufs of %d pages\n",
1411 list_add(&rb->rb_list, &rb_list);
1418 list_splice_tail(&rb_list, &rbp->rbp_bufs);
1419 rbp->rbp_nbuffers += num_buffers;
1420 rbp->rbp_credits += num_buffers;
1421 rbp->rbp_mincredits = rbp->rbp_credits;
1422 /* We need to schedule blocked msg using the newly
1424 while (!list_empty(&rbp->rbp_bufs) &&
1425 !list_empty(&rbp->rbp_msgs))
1426 lnet_schedule_blocked_locked(rbp);
1428 lnet_net_unlock(cpt);
1433 while (!list_empty(&rb_list)) {
1434 rb = list_entry(rb_list.next, lnet_rtrbuf_t, rb_list);
1435 list_del(&rb->rb_list);
1436 lnet_destroy_rtrbuf(rb, npages);
1443 lnet_rtrpool_init(lnet_rtrbufpool_t *rbp, int npages)
1445 INIT_LIST_HEAD(&rbp->rbp_msgs);
1446 INIT_LIST_HEAD(&rbp->rbp_bufs);
1448 rbp->rbp_npages = npages;
1449 rbp->rbp_credits = 0;
1450 rbp->rbp_mincredits = 0;
1454 lnet_rtrpools_free(int keep_pools)
1456 lnet_rtrbufpool_t *rtrp;
1459 if (the_lnet.ln_rtrpools == NULL) /* uninitialized or freed */
1462 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1463 lnet_rtrpool_free_bufs(&rtrp[LNET_TINY_BUF_IDX], i);
1464 lnet_rtrpool_free_bufs(&rtrp[LNET_SMALL_BUF_IDX], i);
1465 lnet_rtrpool_free_bufs(&rtrp[LNET_LARGE_BUF_IDX], i);
1469 cfs_percpt_free(the_lnet.ln_rtrpools);
1470 the_lnet.ln_rtrpools = NULL;
1475 lnet_nrb_tiny_calculate(void)
1477 int nrbs = LNET_NRB_TINY;
1479 if (tiny_router_buffers < 0) {
1480 LCONSOLE_ERROR_MSG(0x10c,
1481 "tiny_router_buffers=%d invalid when "
1482 "routing enabled\n", tiny_router_buffers);
1486 if (tiny_router_buffers > 0)
1487 nrbs = tiny_router_buffers;
1489 nrbs /= LNET_CPT_NUMBER;
1490 return max(nrbs, LNET_NRB_TINY_MIN);
1494 lnet_nrb_small_calculate(void)
1496 int nrbs = LNET_NRB_SMALL;
1498 if (small_router_buffers < 0) {
1499 LCONSOLE_ERROR_MSG(0x10c,
1500 "small_router_buffers=%d invalid when "
1501 "routing enabled\n", small_router_buffers);
1505 if (small_router_buffers > 0)
1506 nrbs = small_router_buffers;
1508 nrbs /= LNET_CPT_NUMBER;
1509 return max(nrbs, LNET_NRB_SMALL_MIN);
1513 lnet_nrb_large_calculate(void)
1515 int nrbs = LNET_NRB_LARGE;
1517 if (large_router_buffers < 0) {
1518 LCONSOLE_ERROR_MSG(0x10c,
1519 "large_router_buffers=%d invalid when "
1520 "routing enabled\n", large_router_buffers);
1524 if (large_router_buffers > 0)
1525 nrbs = large_router_buffers;
1527 nrbs /= LNET_CPT_NUMBER;
1528 return max(nrbs, LNET_NRB_LARGE_MIN);
1532 lnet_rtrpools_alloc(int im_a_router)
1534 lnet_rtrbufpool_t *rtrp;
1541 if (!strcmp(forwarding, "")) {
1542 /* not set either way */
1545 } else if (!strcmp(forwarding, "disabled")) {
1546 /* explicitly disabled */
1548 } else if (!strcmp(forwarding, "enabled")) {
1549 /* explicitly enabled */
1551 LCONSOLE_ERROR_MSG(0x10b, "'forwarding' not set to either "
1552 "'enabled' or 'disabled'\n");
1556 nrb_tiny = lnet_nrb_tiny_calculate();
1560 nrb_small = lnet_nrb_small_calculate();
1564 nrb_large = lnet_nrb_large_calculate();
1568 the_lnet.ln_rtrpools = cfs_percpt_alloc(lnet_cpt_table(),
1570 sizeof(lnet_rtrbufpool_t));
1571 if (the_lnet.ln_rtrpools == NULL) {
1572 LCONSOLE_ERROR_MSG(0x10c,
1573 "Failed to initialize router buffe pool\n");
1577 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1578 lnet_rtrpool_init(&rtrp[LNET_TINY_BUF_IDX], 0);
1579 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_TINY_BUF_IDX],
1584 lnet_rtrpool_init(&rtrp[LNET_SMALL_BUF_IDX],
1585 LNET_NRB_SMALL_PAGES);
1586 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_SMALL_BUF_IDX],
1591 lnet_rtrpool_init(&rtrp[LNET_LARGE_BUF_IDX],
1592 LNET_NRB_LARGE_PAGES);
1593 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_LARGE_BUF_IDX],
1599 lnet_net_lock(LNET_LOCK_EX);
1600 the_lnet.ln_routing = 1;
1601 lnet_net_unlock(LNET_LOCK_EX);
1605 lnet_rtrpools_free(0);
1610 lnet_rtrpools_adjust_helper(int tiny, int small, int large)
1615 lnet_rtrbufpool_t *rtrp;
1617 /* If the provided values for each buffer pool are different than the
1618 * configured values, we need to take action. */
1620 tiny_router_buffers = tiny;
1621 nrb = lnet_nrb_tiny_calculate();
1622 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1623 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_TINY_BUF_IDX],
1630 small_router_buffers = small;
1631 nrb = lnet_nrb_small_calculate();
1632 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1633 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_SMALL_BUF_IDX],
1640 large_router_buffers = large;
1641 nrb = lnet_nrb_large_calculate();
1642 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1643 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_LARGE_BUF_IDX],
1654 lnet_rtrpools_adjust(int tiny, int small, int large)
1656 /* this function doesn't revert the changes if adding new buffers
1657 * failed. It's up to the user space caller to revert the
1660 if (!the_lnet.ln_routing)
1663 return lnet_rtrpools_adjust_helper(tiny, small, large);
1667 lnet_rtrpools_enable(void)
1671 if (the_lnet.ln_routing)
1674 if (the_lnet.ln_rtrpools == NULL)
1675 /* If routing is turned off, and we have never
1676 * initialized the pools before, just call the
1677 * standard buffer pool allocation routine as
1678 * if we are just configuring this for the first
1680 return lnet_rtrpools_alloc(1);
1682 rc = lnet_rtrpools_adjust_helper(0, 0, 0);
1686 lnet_net_lock(LNET_LOCK_EX);
1687 the_lnet.ln_routing = 1;
1689 the_lnet.ln_ping_info->pi_features &= ~LNET_PING_FEAT_RTE_DISABLED;
1690 lnet_net_unlock(LNET_LOCK_EX);
1696 lnet_rtrpools_disable(void)
1698 if (!the_lnet.ln_routing)
1701 lnet_net_lock(LNET_LOCK_EX);
1702 the_lnet.ln_routing = 0;
1703 the_lnet.ln_ping_info->pi_features |= LNET_PING_FEAT_RTE_DISABLED;
1705 tiny_router_buffers = 0;
1706 small_router_buffers = 0;
1707 large_router_buffers = 0;
1708 lnet_net_unlock(LNET_LOCK_EX);
1709 lnet_rtrpools_free(1);
1713 lnet_notify(lnet_ni_t *ni, lnet_nid_t nid, int alive, cfs_time_t when)
1715 struct lnet_peer *lp = NULL;
1716 cfs_time_t now = cfs_time_current();
1717 int cpt = lnet_cpt_of_nid(nid);
1719 LASSERT (!in_interrupt ());
1721 CDEBUG (D_NET, "%s notifying %s: %s\n",
1722 (ni == NULL) ? "userspace" : libcfs_nid2str(ni->ni_nid),
1723 libcfs_nid2str(nid),
1724 alive ? "up" : "down");
1727 LNET_NIDNET(ni->ni_nid) != LNET_NIDNET(nid)) {
1728 CWARN ("Ignoring notification of %s %s by %s (different net)\n",
1729 libcfs_nid2str(nid), alive ? "birth" : "death",
1730 libcfs_nid2str(ni->ni_nid));
1734 /* can't do predictions... */
1735 if (cfs_time_after(when, now)) {
1736 CWARN ("Ignoring prediction from %s of %s %s "
1737 "%ld seconds in the future\n",
1738 (ni == NULL) ? "userspace" : libcfs_nid2str(ni->ni_nid),
1739 libcfs_nid2str(nid), alive ? "up" : "down",
1740 cfs_duration_sec(cfs_time_sub(when, now)));
1744 if (ni != NULL && !alive && /* LND telling me she's down */
1745 !auto_down) { /* auto-down disabled */
1746 CDEBUG(D_NET, "Auto-down disabled\n");
1752 if (the_lnet.ln_shutdown) {
1753 lnet_net_unlock(cpt);
1757 lp = lnet_find_peer_locked(the_lnet.ln_peer_tables[cpt], nid);
1760 lnet_net_unlock(cpt);
1761 CDEBUG(D_NET, "%s not found\n", libcfs_nid2str(nid));
1765 /* We can't fully trust LND on reporting exact peer last_alive
1766 * if he notifies us about dead peer. For example ksocklnd can
1767 * call us with when == _time_when_the_node_was_booted_ if
1768 * no connections were successfully established */
1769 if (ni != NULL && !alive && when < lp->lp_last_alive)
1770 when = lp->lp_last_alive;
1772 lnet_notify_locked(lp, ni == NULL, alive, when);
1775 lnet_ni_notify_locked(ni, lp);
1777 lnet_peer_decref_locked(lp);
1779 lnet_net_unlock(cpt);
1782 EXPORT_SYMBOL(lnet_notify);