1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
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 #if defined(__KERNEL__) && defined(LNET_ROUTER)
29 static char *forwarding = "";
30 CFS_MODULE_PARM(forwarding, "s", charp, 0444,
31 "Explicitly enable/disable forwarding between networks");
33 static int tiny_router_buffers = 1024;
34 CFS_MODULE_PARM(tiny_router_buffers, "i", int, 0444,
35 "# of 0 payload messages to buffer in the router");
36 static int small_router_buffers = 8192;
37 CFS_MODULE_PARM(small_router_buffers, "i", int, 0444,
38 "# of small (1 page) messages to buffer in the router");
39 static int large_router_buffers = 512;
40 CFS_MODULE_PARM(large_router_buffers, "i", int, 0444,
41 "# of large messages to buffer in the router");
43 static int auto_down = 1;
44 CFS_MODULE_PARM(auto_down, "i", int, 0444,
45 "Automatically mark peers down on comms error");
47 static int check_routers_before_use = 0;
48 CFS_MODULE_PARM(check_routers_before_use, "i", int, 0444,
49 "Assume routers are down and ping them before use");
51 static int dead_router_check_interval = 0;
52 CFS_MODULE_PARM(dead_router_check_interval, "i", int, 0444,
53 "Seconds between dead router health checks (<= 0 to disable)");
55 static int live_router_check_interval = 0;
56 CFS_MODULE_PARM(live_router_check_interval, "i", int, 0444,
57 "Seconds between live router health checks (<= 0 to disable)");
59 static int router_ping_timeout = 50;
60 CFS_MODULE_PARM(router_ping_timeout, "i", int, 0444,
61 "Seconds to wait for the reply to a router health query");
64 lnet_peers_start_down(void)
66 return check_routers_before_use;
70 lnet_notify_locked(lnet_peer_t *lp, int notifylnd, int alive, time_t when)
72 if (when < lp->lp_timestamp) { /* out of date information */
73 CDEBUG(D_NET, "Out of date\n");
77 lp->lp_timestamp = when; /* update timestamp */
78 lp->lp_ping_deadline = 0; /* disable ping timeout */
80 if (lp->lp_alive_count != 0 && /* got old news */
81 (!lp->lp_alive) == (!alive)) { /* new date for old news */
82 CDEBUG(D_NET, "Old news\n");
86 /* Flag that notification is outstanding */
89 lp->lp_alive = !(!alive); /* 1 bit! */
91 lp->lp_notifylnd |= notifylnd;
93 CDEBUG(D_NET, "set %s %d\n", libcfs_nid2str(lp->lp_nid), alive);
97 lnet_do_notify (lnet_peer_t *lp)
99 lnet_ni_t *ni = lp->lp_ni;
105 /* Notify only in 1 thread at any time to ensure ordered notification.
106 * NB individual events can be missed; the only guarantee is that you
107 * always get the most recent news */
109 if (lp->lp_notifying) {
114 lp->lp_notifying = 1;
116 while (lp->lp_notify) {
117 alive = lp->lp_alive;
118 notifylnd = lp->lp_notifylnd;
120 lp->lp_notifylnd = 0;
123 if (notifylnd && ni->ni_lnd->lnd_notify != NULL) {
126 /* A new notification could happen now; I'll handle it
127 * when control returns to me */
129 (ni->ni_lnd->lnd_notify)(ni, lp->lp_nid, alive);
135 lp->lp_notifying = 0;
141 lnet_notify (lnet_ni_t *ni, lnet_nid_t nid, int alive, time_t when)
143 lnet_peer_t *lp = NULL;
144 time_t now = cfs_time_current_sec();
146 LASSERT (!in_interrupt ());
148 CDEBUG (D_NET, "%s notifying %s: %s\n",
149 (ni == NULL) ? "userspace" : libcfs_nid2str(ni->ni_nid),
151 alive ? "up" : "down");
154 LNET_NIDNET(ni->ni_nid) != LNET_NIDNET(nid)) {
155 CWARN ("Ignoring notification of %s %s by %s (different net)\n",
156 libcfs_nid2str(nid), alive ? "birth" : "death",
157 libcfs_nid2str(ni->ni_nid));
161 /* can't do predictions... */
163 CWARN ("Ignoring prediction from %s of %s %s "
164 "%ld seconds in the future\n",
165 (ni == NULL) ? "userspace" : libcfs_nid2str(ni->ni_nid),
166 libcfs_nid2str(nid), alive ? "up" : "down",
171 if (ni != NULL && !alive && /* LND telling me she's down */
172 !auto_down) { /* auto-down disabled */
173 CDEBUG(D_NET, "Auto-down disabled\n");
179 lp = lnet_find_peer_locked(nid);
183 CDEBUG(D_NET, "%s not found\n", libcfs_nid2str(nid));
187 /* We can't fully trust LND on reporting exact peer last_alive
188 * if he notifies us about dead peer. For example ksocklnd can
189 * call us with when == _time_when_the_node_was_booted_ if
190 * no connections were successfully established */
191 if (ni != NULL && !alive && when < lp->lp_last_alive)
192 when = lp->lp_last_alive;
194 lnet_notify_locked(lp, ni == NULL, alive, when);
202 lnet_peer_decref_locked(lp);
207 EXPORT_SYMBOL(lnet_notify);
212 lnet_notify (lnet_ni_t *ni, lnet_nid_t nid, int alive, time_t when)
218 lnet_notify_locked (lnet_peer_t *lp, int notifylnd, int alive, time_t when)
226 lnet_rtr_addref_locked(lnet_peer_t *lp)
228 LASSERT (lp->lp_refcount > 0);
229 LASSERT (lp->lp_rtr_refcount >= 0);
231 lp->lp_rtr_refcount++;
232 if (lp->lp_rtr_refcount == 1) {
233 struct list_head *pos;
235 /* a simple insertion sort */
236 list_for_each_prev(pos, &the_lnet.ln_routers) {
237 lnet_peer_t *rtr = list_entry(pos, lnet_peer_t,
240 if (rtr->lp_nid < lp->lp_nid)
244 list_add(&lp->lp_rtr_list, pos);
245 /* addref for the_lnet.ln_routers */
246 lnet_peer_addref_locked(lp);
247 the_lnet.ln_routers_version++;
252 lnet_rtr_decref_locked(lnet_peer_t *lp)
254 LASSERT (lp->lp_refcount > 0);
255 LASSERT (lp->lp_rtr_refcount > 0);
257 lp->lp_rtr_refcount--;
258 if (lp->lp_rtr_refcount == 0) {
259 list_del(&lp->lp_rtr_list);
260 /* decref for the_lnet.ln_routers */
261 lnet_peer_decref_locked(lp);
262 the_lnet.ln_routers_version++;
267 lnet_find_net_locked (__u32 net)
269 lnet_remotenet_t *rnet;
270 struct list_head *tmp;
272 LASSERT (!the_lnet.ln_shutdown);
274 list_for_each (tmp, &the_lnet.ln_remote_nets) {
275 rnet = list_entry(tmp, lnet_remotenet_t, lrn_list);
277 if (rnet->lrn_net == net)
284 lnet_add_route (__u32 net, unsigned int hops, lnet_nid_t gateway)
286 struct list_head zombies;
288 lnet_remotenet_t *rnet;
289 lnet_remotenet_t *rnet2;
291 lnet_route_t *route2;
296 CDEBUG(D_NET, "Add route: net %s hops %u gw %s\n",
297 libcfs_net2str(net), hops, libcfs_nid2str(gateway));
299 if (gateway == LNET_NID_ANY ||
300 LNET_NETTYP(LNET_NIDNET(gateway)) == LOLND ||
301 net == LNET_NIDNET(LNET_NID_ANY) ||
302 LNET_NETTYP(net) == LOLND ||
303 LNET_NIDNET(gateway) == net ||
304 hops < 1 || hops > 255)
307 if (lnet_islocalnet(net)) /* it's a local network */
308 return 0; /* ignore the route entry */
310 /* Assume net, route, all new */
311 LIBCFS_ALLOC(route, sizeof(*route));
312 LIBCFS_ALLOC(rnet, sizeof(*rnet));
313 if (route == NULL || rnet == NULL) {
314 CERROR("Out of memory creating route %s %d %s\n",
315 libcfs_net2str(net), hops, libcfs_nid2str(gateway));
317 LIBCFS_FREE(route, sizeof(*route));
319 LIBCFS_FREE(rnet, sizeof(*rnet));
323 CFS_INIT_LIST_HEAD(&rnet->lrn_routes);
325 rnet->lrn_hops = hops;
329 rc = lnet_nid2peer_locked(&route->lr_gateway, gateway);
333 LIBCFS_FREE(route, sizeof(*route));
334 LIBCFS_FREE(rnet, sizeof(*rnet));
336 if (rc == -EHOSTUNREACH) /* gateway is not on a local net */
337 return 0; /* ignore the route entry */
339 CERROR("Error %d creating route %s %d %s\n", rc,
340 libcfs_net2str(net), hops, libcfs_nid2str(gateway));
344 LASSERT (!the_lnet.ln_shutdown);
345 CFS_INIT_LIST_HEAD(&zombies);
347 rnet2 = lnet_find_net_locked(net);
350 list_add_tail(&rnet->lrn_list, &the_lnet.ln_remote_nets);
354 if (hops > rnet2->lrn_hops) {
355 /* New route is longer; ignore it */
357 } else if (hops < rnet2->lrn_hops) {
358 /* new route supercedes all currently known routes to this
360 list_add(&zombies, &rnet2->lrn_routes);
361 list_del_init(&rnet2->lrn_routes);
365 /* New route has the same hopcount as existing routes; search
366 * for a duplicate route (it's a NOOP if it is) */
367 list_for_each (e, &rnet2->lrn_routes) {
368 route2 = list_entry(e, lnet_route_t, lr_list);
370 if (route2->lr_gateway == route->lr_gateway) {
375 /* our loopups must be true */
376 LASSERT (route2->lr_gateway->lp_nid != gateway);
381 ni = route->lr_gateway->lp_ni;
382 lnet_ni_addref_locked(ni);
385 list_add_tail(&route->lr_list, &rnet2->lrn_routes);
386 the_lnet.ln_remote_nets_version++;
388 lnet_rtr_addref_locked(route->lr_gateway);
392 /* XXX Assume alive */
393 if (ni->ni_lnd->lnd_notify != NULL)
394 (ni->ni_lnd->lnd_notify)(ni, gateway, 1);
398 lnet_peer_decref_locked(route->lr_gateway);
400 LIBCFS_FREE(route, sizeof(*route));
404 LIBCFS_FREE(rnet, sizeof(*rnet));
406 while (!list_empty(&zombies)) {
407 route = list_entry(zombies.next, lnet_route_t, lr_list);
408 list_del(&route->lr_list);
411 lnet_rtr_decref_locked(route->lr_gateway);
412 lnet_peer_decref_locked(route->lr_gateway);
414 LIBCFS_FREE(route, sizeof(*route));
421 lnet_check_routes (void)
423 lnet_remotenet_t *rnet;
425 lnet_route_t *route2;
426 struct list_head *e1;
427 struct list_head *e2;
431 list_for_each (e1, &the_lnet.ln_remote_nets) {
432 rnet = list_entry(e1, lnet_remotenet_t, lrn_list);
435 list_for_each (e2, &rnet->lrn_routes) {
436 route = list_entry(e2, lnet_route_t, lr_list);
440 else if (route->lr_gateway->lp_ni !=
441 route2->lr_gateway->lp_ni) {
444 CERROR("Routes to %s via %s and %s not supported\n",
445 libcfs_net2str(rnet->lrn_net),
446 libcfs_nid2str(route->lr_gateway->lp_nid),
447 libcfs_nid2str(route2->lr_gateway->lp_nid));
458 lnet_del_route (__u32 net, lnet_nid_t gw_nid)
460 lnet_remotenet_t *rnet;
462 struct list_head *e1;
463 struct list_head *e2;
466 CDEBUG(D_NET, "Del route: net %s : gw %s\n",
467 libcfs_net2str(net), libcfs_nid2str(gw_nid));
469 /* NB Caller may specify either all routes via the given gateway
470 * or a specific route entry actual NIDs) */
475 list_for_each (e1, &the_lnet.ln_remote_nets) {
476 rnet = list_entry(e1, lnet_remotenet_t, lrn_list);
478 if (!(net == LNET_NIDNET(LNET_NID_ANY) ||
479 net == rnet->lrn_net))
482 list_for_each (e2, &rnet->lrn_routes) {
483 route = list_entry(e2, lnet_route_t, lr_list);
485 if (!(gw_nid == LNET_NID_ANY ||
486 gw_nid == route->lr_gateway->lp_nid))
489 list_del(&route->lr_list);
490 the_lnet.ln_remote_nets_version++;
492 if (list_empty(&rnet->lrn_routes))
493 list_del(&rnet->lrn_list);
497 lnet_rtr_decref_locked(route->lr_gateway);
498 lnet_peer_decref_locked(route->lr_gateway);
501 LIBCFS_FREE(route, sizeof (*route));
504 LIBCFS_FREE(rnet, sizeof(*rnet));
516 lnet_destroy_routes (void)
518 lnet_del_route(LNET_NIDNET(LNET_NID_ANY), LNET_NID_ANY);
522 lnet_get_route (int idx, __u32 *net, __u32 *hops,
523 lnet_nid_t *gateway, __u32 *alive)
525 struct list_head *e1;
526 struct list_head *e2;
527 lnet_remotenet_t *rnet;
532 list_for_each (e1, &the_lnet.ln_remote_nets) {
533 rnet = list_entry(e1, lnet_remotenet_t, lrn_list);
535 list_for_each (e2, &rnet->lrn_routes) {
536 route = list_entry(e2, lnet_route_t, lr_list);
539 *net = rnet->lrn_net;
540 *hops = rnet->lrn_hops;
541 *gateway = route->lr_gateway->lp_nid;
542 *alive = route->lr_gateway->lp_alive;
553 #if defined(__KERNEL__) && defined(LNET_ROUTER)
555 lnet_router_checker_event (lnet_event_t *event)
557 /* CAVEAT EMPTOR: I'm called with LNET_LOCKed and I'm not allowed to
558 * drop it (that's how come I see _every_ event, even ones that would
563 if (event->unlinked) {
564 /* The router checker thread has unlinked the rc_md
566 LASSERT (the_lnet.ln_rc_state == LNET_RC_STATE_UNLINKING);
567 the_lnet.ln_rc_state = LNET_RC_STATE_UNLINKED;
568 mutex_up(&the_lnet.ln_rc_signal);
572 LASSERT (event->type == LNET_EVENT_SEND ||
573 event->type == LNET_EVENT_REPLY);
575 nid = (event->type == LNET_EVENT_SEND) ?
576 event->target.nid : event->initiator.nid;
578 lp = lnet_find_peer_locked(nid);
580 /* router may have been removed */
581 CDEBUG(D_NET, "Router %s not found\n", libcfs_nid2str(nid));
585 if (event->type == LNET_EVENT_SEND) /* re-enable another ping */
586 lp->lp_ping_notsent = 0;
588 if (lnet_isrouter(lp) && /* ignore if no longer a router */
589 (event->status != 0 ||
590 event->type == LNET_EVENT_REPLY)) {
592 /* A successful REPLY means the router is up. If _any_ comms
593 * to the router fail I assume it's down (this will happen if
594 * we ping alive routers to try to detect router death before
595 * apps get burned). */
597 lnet_notify_locked(lp, 1, (event->status == 0),
598 cfs_time_current_sec());
600 /* The router checker will wake up very shortly and do the
601 * actual notification.
602 * XXX If 'lp' stops being a router before then, it will still
603 * have the notification pending!!! */
606 /* This decref will NOT drop LNET_LOCK (it had to have 1 ref when it
607 * was in the peer table and I've not dropped the lock, so no-one else
608 * can have reduced the refcount) */
609 LASSERT(lp->lp_refcount > 1);
611 lnet_peer_decref_locked(lp);
615 lnet_router_checker(void *arg)
617 static lnet_ping_info_t pinginfo;
620 lnet_handle_md_t mdh;
623 struct list_head *entry;
625 lnet_process_id_t rtr_id;
628 cfs_daemonize("router_checker");
631 rtr_id.pid = LUSTRE_SRV_LNET_PID;
633 LASSERT (the_lnet.ln_rc_state == LNET_RC_STATE_SHUTDOWN);
635 /* initialize md content */
636 md.start = &pinginfo;
637 md.length = sizeof(pinginfo);
638 md.threshold = LNET_MD_THRESH_INF;
640 md.options = LNET_MD_TRUNCATE,
642 md.eq_handle = the_lnet.ln_rc_eqh;
644 rc = LNetMDBind(md, LNET_UNLINK, &mdh);
647 CERROR("Can't bind MD: %d\n", rc);
648 the_lnet.ln_rc_state = rc;
649 mutex_up(&the_lnet.ln_rc_signal);
655 the_lnet.ln_rc_state = LNET_RC_STATE_RUNNING;
656 mutex_up(&the_lnet.ln_rc_signal); /* let my parent go */
658 while (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING) {
663 version = the_lnet.ln_routers_version;
665 list_for_each (entry, &the_lnet.ln_routers) {
666 rtr = list_entry(entry, lnet_peer_t, lp_rtr_list);
668 lnet_peer_addref_locked(rtr);
670 now = cfs_time_current_sec();
672 if (rtr->lp_ping_deadline != 0 && /* ping timed out? */
673 now > rtr->lp_ping_deadline)
674 lnet_notify_locked(rtr, 1, 0, now);
678 /* Run any outstanding notificiations */
682 secs = live_router_check_interval;
684 secs = dead_router_check_interval;
690 !rtr->lp_ping_notsent &&
691 now > rtr->lp_ping_timestamp + secs) {
692 CDEBUG(D_NET, "Check: %s\n",
693 libcfs_nid2str(rtr->lp_nid));
696 rtr_id.nid = rtr->lp_nid;
697 rtr->lp_ping_notsent = 1;
698 rtr->lp_ping_timestamp = now;
700 if (rtr->lp_ping_deadline == 0)
701 rtr->lp_ping_deadline =
702 now + router_ping_timeout;
706 LNetGet(LNET_NID_ANY, mdh, rtr_id,
707 LNET_RESERVED_PORTAL,
708 LNET_PROTO_PING_MATCHBITS, 0);
712 lnet_peer_decref_locked(rtr);
714 if (version != the_lnet.ln_routers_version) {
715 /* the routers list has changed */
722 /* Call cfs_pause() here always adds 1 to load average
723 * because kernel counts # active tasks as nr_running
724 * + nr_uninterruptible. */
725 cfs_schedule_timeout(CFS_TASK_INTERRUPTIBLE,
726 cfs_time_seconds(1));
729 LASSERT (the_lnet.ln_rc_state == LNET_RC_STATE_STOPTHREAD);
730 the_lnet.ln_rc_state = LNET_RC_STATE_UNLINKING;
732 rc = LNetMDUnlink(mdh);
735 /* The unlink event callback will signal final completion */
741 lnet_wait_known_routerstate(void)
744 struct list_head *entry;
751 list_for_each (entry, &the_lnet.ln_routers) {
752 rtr = list_entry(entry, lnet_peer_t, lp_rtr_list);
754 if (rtr->lp_alive_count == 0) {
765 cfs_pause(cfs_time_seconds(1));
770 lnet_router_checker_stop(void)
774 LASSERT (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING ||
775 the_lnet.ln_rc_state == LNET_RC_STATE_SHUTDOWN);
777 if (the_lnet.ln_rc_state == LNET_RC_STATE_SHUTDOWN)
780 the_lnet.ln_rc_state = LNET_RC_STATE_STOPTHREAD;
781 /* block until event callback signals exit */
782 mutex_down(&the_lnet.ln_rc_signal);
784 LASSERT (the_lnet.ln_rc_state == LNET_RC_STATE_UNLINKED);
786 rc = LNetEQFree(the_lnet.ln_rc_eqh);
789 the_lnet.ln_rc_state = LNET_RC_STATE_SHUTDOWN;
793 lnet_router_checker_start(void)
797 LASSERT (the_lnet.ln_rc_state == LNET_RC_STATE_SHUTDOWN);
799 if (check_routers_before_use &&
800 dead_router_check_interval <= 0) {
801 LCONSOLE_ERROR_MSG(0x10a, "'dead_router_check_interval' must be"
802 " set if 'check_routers_before_use' is set"
807 if (live_router_check_interval <= 0 &&
808 dead_router_check_interval <= 0)
811 init_mutex_locked(&the_lnet.ln_rc_signal);
813 /* EQ size doesn't matter; the callback is guaranteed to get every
815 rc = LNetEQAlloc(1, lnet_router_checker_event,
816 &the_lnet.ln_rc_eqh);
818 CERROR("Can't allocate EQ: %d\n", rc);
822 rc = (int)cfs_kernel_thread(lnet_router_checker, NULL, 0);
824 CERROR("Can't start router checker thread: %d\n", rc);
828 mutex_down(&the_lnet.ln_rc_signal); /* wait for checker to startup */
830 rc = the_lnet.ln_rc_state;
832 the_lnet.ln_rc_state = LNET_RC_STATE_SHUTDOWN;
836 LASSERT (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING);
838 if (check_routers_before_use) {
839 /* Note that a helpful side-effect of pinging all known routers
840 * at startup is that it makes them drop stale connections they
841 * may have to a previous instance of me. */
842 lnet_wait_known_routerstate();
848 rc = LNetEQFree(the_lnet.ln_rc_eqh);
854 lnet_destroy_rtrbuf(lnet_rtrbuf_t *rb, int npages)
856 int sz = offsetof(lnet_rtrbuf_t, rb_kiov[npages]);
858 while (--npages >= 0)
859 cfs_free_page(rb->rb_kiov[npages].kiov_page);
865 lnet_new_rtrbuf(lnet_rtrbufpool_t *rbp)
867 int npages = rbp->rbp_npages;
868 int sz = offsetof(lnet_rtrbuf_t, rb_kiov[npages]);
873 LIBCFS_ALLOC(rb, sz);
879 for (i = 0; i < npages; i++) {
880 page = cfs_alloc_page(CFS_ALLOC_ZERO | CFS_ALLOC_STD);
883 cfs_free_page(rb->rb_kiov[i].kiov_page);
889 rb->rb_kiov[i].kiov_len = CFS_PAGE_SIZE;
890 rb->rb_kiov[i].kiov_offset = 0;
891 rb->rb_kiov[i].kiov_page = page;
898 lnet_rtrpool_free_bufs(lnet_rtrbufpool_t *rbp)
900 int npages = rbp->rbp_npages;
904 LASSERT (list_empty(&rbp->rbp_msgs));
905 LASSERT (rbp->rbp_credits == rbp->rbp_nbuffers);
907 while (!list_empty(&rbp->rbp_bufs)) {
908 LASSERT (rbp->rbp_credits > 0);
910 rb = list_entry(rbp->rbp_bufs.next,
911 lnet_rtrbuf_t, rb_list);
912 list_del(&rb->rb_list);
913 lnet_destroy_rtrbuf(rb, npages);
917 LASSERT (rbp->rbp_nbuffers == nbuffers);
918 LASSERT (rbp->rbp_credits == nbuffers);
920 rbp->rbp_nbuffers = rbp->rbp_credits = 0;
924 lnet_rtrpool_alloc_bufs(lnet_rtrbufpool_t *rbp, int nbufs)
929 if (rbp->rbp_nbuffers != 0) {
930 LASSERT (rbp->rbp_nbuffers == nbufs);
934 for (i = 0; i < nbufs; i++) {
935 rb = lnet_new_rtrbuf(rbp);
938 CERROR("Failed to allocate %d router bufs of %d pages\n",
939 nbufs, rbp->rbp_npages);
945 rbp->rbp_mincredits++;
946 list_add(&rb->rb_list, &rbp->rbp_bufs);
948 /* No allocation "under fire" */
949 /* Otherwise we'd need code to schedule blocked msgs etc */
950 LASSERT (!the_lnet.ln_routing);
953 LASSERT (rbp->rbp_credits == nbufs);
958 lnet_rtrpool_init(lnet_rtrbufpool_t *rbp, int npages)
960 CFS_INIT_LIST_HEAD(&rbp->rbp_msgs);
961 CFS_INIT_LIST_HEAD(&rbp->rbp_bufs);
963 rbp->rbp_npages = npages;
964 rbp->rbp_credits = 0;
965 rbp->rbp_mincredits = 0;
969 lnet_free_rtrpools(void)
971 lnet_rtrpool_free_bufs(&the_lnet.ln_rtrpools[0]);
972 lnet_rtrpool_free_bufs(&the_lnet.ln_rtrpools[1]);
973 lnet_rtrpool_free_bufs(&the_lnet.ln_rtrpools[2]);
977 lnet_init_rtrpools(void)
980 int large_pages = (LNET_MTU + CFS_PAGE_SIZE - 1) >> CFS_PAGE_SHIFT;
982 lnet_rtrpool_init(&the_lnet.ln_rtrpools[0], 0);
983 lnet_rtrpool_init(&the_lnet.ln_rtrpools[1], small_pages);
984 lnet_rtrpool_init(&the_lnet.ln_rtrpools[2], large_pages);
989 lnet_alloc_rtrpools(int im_a_router)
993 if (!strcmp(forwarding, "")) {
994 /* not set either way */
997 } else if (!strcmp(forwarding, "disabled")) {
998 /* explicitly disabled */
1000 } else if (!strcmp(forwarding, "enabled")) {
1001 /* explicitly enabled */
1003 LCONSOLE_ERROR_MSG(0x10b, "'forwarding' not set to either "
1004 "'enabled' or 'disabled'\n");
1008 if (tiny_router_buffers <= 0) {
1009 LCONSOLE_ERROR_MSG(0x10c, "tiny_router_buffers=%d invalid when "
1010 "routing enabled\n", tiny_router_buffers);
1015 rc = lnet_rtrpool_alloc_bufs(&the_lnet.ln_rtrpools[0],
1016 tiny_router_buffers);
1020 if (small_router_buffers <= 0) {
1021 LCONSOLE_ERROR_MSG(0x10d, "small_router_buffers=%d invalid when"
1022 " routing enabled\n", small_router_buffers);
1027 rc = lnet_rtrpool_alloc_bufs(&the_lnet.ln_rtrpools[1],
1028 small_router_buffers);
1032 if (large_router_buffers <= 0) {
1033 LCONSOLE_ERROR_MSG(0x10e, "large_router_buffers=%d invalid when"
1034 " routing enabled\n", large_router_buffers);
1039 rc = lnet_rtrpool_alloc_bufs(&the_lnet.ln_rtrpools[2],
1040 large_router_buffers);
1045 the_lnet.ln_routing = 1;
1051 lnet_free_rtrpools();
1058 lnet_peers_start_down(void)
1064 lnet_router_checker_stop(void)
1070 lnet_router_checker_start(void)
1076 lnet_free_rtrpools (void)
1081 lnet_init_rtrpools (void)
1086 lnet_alloc_rtrpools (int im_a_arouter)