Whamcloud - gitweb
b=16150
[fs/lustre-release.git] / lnet / lnet / router.c
index df1bfc8..7530fca 100644 (file)
@@ -1,7 +1,7 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- * Copyright (C) 2002 Cluster File Systems, Inc.
+ * Copyright  2008 Sun Microsystems, Inc. All rights reserved
  *
  *   This file is part of Portals
  *   http://sourceforge.net/projects/sandiaportals/
@@ -94,14 +94,14 @@ lnet_notify_locked(lnet_peer_t *lp, int notifylnd, int alive, time_t when)
 }
 
 void
-lnet_do_notify (lnet_peer_t *lp) 
+lnet_do_notify (lnet_peer_t *lp)
 {
         lnet_ni_t *ni = lp->lp_ni;
         int        alive;
         int        notifylnd;
-        
+
         LNET_LOCK();
-                
+
         /* Notify only in 1 thread at any time to ensure ordered notification.
          * NB individual events can be missed; the only guarantee is that you
          * always get the most recent news */
@@ -112,7 +112,7 @@ lnet_do_notify (lnet_peer_t *lp)
         }
 
         lp->lp_notifying = 1;
-        
+
         while (lp->lp_notify) {
                 alive     = lp->lp_alive;
                 notifylnd = lp->lp_notifylnd;
@@ -173,7 +173,7 @@ lnet_notify (lnet_ni_t *ni, lnet_nid_t nid, int alive, time_t when)
                 CDEBUG(D_NET, "Auto-down disabled\n");
                 return 0;
         }
-        
+
         LNET_LOCK();
 
         lp = lnet_find_peer_locked(nid);
@@ -187,9 +187,9 @@ lnet_notify (lnet_ni_t *ni, lnet_nid_t nid, int alive, time_t when)
         lnet_notify_locked(lp, ni == NULL, alive, when);
 
         LNET_UNLOCK();
-        
+
         lnet_do_notify(lp);
-        
+
         LNET_LOCK();
 
         lnet_peer_decref_locked(lp);
@@ -271,11 +271,11 @@ int
 lnet_add_route (__u32 net, unsigned int hops, lnet_nid_t gateway)
 {
         struct list_head     zombies;
-       struct list_head    *e;
-       lnet_remotenet_t    *rnet;
-       lnet_remotenet_t    *rnet2;
-       lnet_route_t        *route;
-       lnet_route_t        *route2;
+        struct list_head    *e;
+        lnet_remotenet_t    *rnet;
+        lnet_remotenet_t    *rnet2;
+        lnet_route_t        *route;
+        lnet_route_t        *route2;
         lnet_ni_t           *ni;
         int                  add_route;
         int                  rc;
@@ -307,7 +307,7 @@ lnet_add_route (__u32 net, unsigned int hops, lnet_nid_t gateway)
                 return -ENOMEM;
         }
 
-        INIT_LIST_HEAD(&rnet->lrn_routes);
+        CFS_INIT_LIST_HEAD(&rnet->lrn_routes);
         rnet->lrn_net = net;
         rnet->lrn_hops = hops;
 
@@ -363,11 +363,11 @@ lnet_add_route (__u32 net, unsigned int hops, lnet_nid_t gateway)
                         LASSERT (route2->lr_gateway->lp_nid != gateway);
                 }
         }
-        
+
         if (add_route) {
                 ni = route->lr_gateway->lp_ni;
                 lnet_ni_addref_locked(ni);
-                
+
                 LASSERT (rc == 0);
                 list_add_tail(&route->lr_list, &rnet2->lrn_routes);
                 the_lnet.ln_remote_nets_version++;
@@ -393,8 +393,9 @@ lnet_add_route (__u32 net, unsigned int hops, lnet_nid_t gateway)
         while (!list_empty(&zombies)) {
                 route = list_entry(zombies.next, lnet_route_t, lr_list);
                 list_del(&route->lr_list);
-                
+
                 LNET_LOCK();
+                lnet_rtr_decref_locked(route->lr_gateway);
                 lnet_peer_decref_locked(route->lr_gateway);
                 LNET_UNLOCK();
                 LIBCFS_FREE(route, sizeof(*route));
@@ -426,7 +427,7 @@ lnet_check_routes (void)
                         else if (route->lr_gateway->lp_ni !=
                                  route2->lr_gateway->lp_ni) {
                                 LNET_UNLOCK();
-                                
+
                                 CERROR("Routes to %s via %s and %s not supported\n",
                                        libcfs_net2str(rnet->lrn_net),
                                        libcfs_nid2str(route->lr_gateway->lp_nid),
@@ -435,7 +436,7 @@ lnet_check_routes (void)
                         }
                 }
         }
-        
+
         LNET_UNLOCK();
         return 0;
 }
@@ -508,8 +509,8 @@ int
 lnet_get_route (int idx, __u32 *net, __u32 *hops,
                lnet_nid_t *gateway, __u32 *alive)
 {
-       struct list_head    *e1;
-       struct list_head    *e2;
+        struct list_head    *e1;
+        struct list_head    *e2;
         lnet_remotenet_t    *rnet;
         lnet_route_t        *route;
 
@@ -550,14 +551,14 @@ lnet_router_checker_event (lnet_event_t *event)
                 /* The router checker thread has unlinked the rc_md
                  * and exited. */
                 LASSERT (the_lnet.ln_rc_state == LNET_RC_STATE_UNLINKING);
-                the_lnet.ln_rc_state = LNET_RC_STATE_UNLINKED; 
-                mutex_up(&the_lnet.ln_rc_signal); 
+                the_lnet.ln_rc_state = LNET_RC_STATE_UNLINKED;
+                mutex_up(&the_lnet.ln_rc_signal);
                 return;
         }
 
-        LASSERT (event->type == LNET_EVENT_SEND || 
+        LASSERT (event->type == LNET_EVENT_SEND ||
                  event->type == LNET_EVENT_REPLY);
-        
+
         nid = (event->type == LNET_EVENT_SEND) ?
               event->target.nid : event->initiator.nid;
 
@@ -574,7 +575,7 @@ lnet_router_checker_event (lnet_event_t *event)
         if (lnet_isrouter(lp) &&                /* ignore if no longer a router */
             (event->status != 0 ||
              event->type == LNET_EVENT_REPLY)) {
-                
+
                 /* A successful REPLY means the router is up.  If _any_ comms
                  * to the router fail I assume it's down (this will happen if
                  * we ping alive routers to try to detect router death before
@@ -605,25 +606,29 @@ lnet_router_checker(void *arg)
         int                  rc;
         lnet_handle_md_t     mdh;
         lnet_peer_t         *rtr;
+        lnet_md_t            md = {0};
         struct list_head    *entry;
         time_t               now;
         lnet_process_id_t    rtr_id;
         int                  secs;
 
-       cfs_daemonize("router_checker");
-       cfs_block_allsigs();
+        cfs_daemonize("router_checker");
+        cfs_block_allsigs();
 
         rtr_id.pid = LUSTRE_SRV_LNET_PID;
 
         LASSERT (the_lnet.ln_rc_state == LNET_RC_STATE_SHUTDOWN);
 
-        rc = LNetMDBind((lnet_md_t){.start     = &pinginfo,
-                                    .length    = sizeof(pinginfo),
-                                    .threshold = LNET_MD_THRESH_INF,
-                                    .options   = LNET_MD_TRUNCATE,
-                                    .eq_handle = the_lnet.ln_rc_eqh},
-                        LNET_UNLINK,
-                        &mdh);
+        /* initialize md content */
+        md.start     = &pinginfo;
+        md.length    = sizeof(pinginfo);
+        md.threshold = LNET_MD_THRESH_INF;
+        md.max_size  = 0;
+        md.options   = LNET_MD_TRUNCATE,
+        md.user_ptr  = NULL;
+        md.eq_handle = the_lnet.ln_rc_eqh;
+
+        rc = LNetMDBind(md, LNET_UNLINK, &mdh);
 
         if (rc < 0) {
                 CERROR("Can't bind MD: %d\n", rc);
@@ -637,7 +642,7 @@ lnet_router_checker(void *arg)
         the_lnet.ln_rc_state = LNET_RC_STATE_RUNNING;
         mutex_up(&the_lnet.ln_rc_signal);       /* let my parent go */
 
-       while (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING) {
+        while (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING) {
                 __u64 version;
 
                 LNET_LOCK();
@@ -667,7 +672,7 @@ rescan:
                         }
                         if (secs <= 0)
                                 secs = 0;
-                        
+
                         if (secs != 0 &&
                             !rtr->lp_ping_notsent &&
                             now > rtr->lp_ping_timestamp + secs) {
@@ -689,7 +694,7 @@ rescan:
                                         LNET_RESERVED_PORTAL,
                                         LNET_PROTO_PING_MATCHBITS, 0);
                         }
-                        
+
                         LNET_LOCK();
                         lnet_peer_decref_locked(rtr);
 
@@ -704,20 +709,18 @@ rescan:
                 /* Call cfs_pause() here always adds 1 to load average 
                  * because kernel counts # active tasks as nr_running 
                  * + nr_uninterruptible. */
-                set_current_state(CFS_TASK_INTERRUPTIBLE);
                 cfs_schedule_timeout(CFS_TASK_INTERRUPTIBLE,
                                      cfs_time_seconds(1));
-       }
+        }
 
         LASSERT (the_lnet.ln_rc_state == LNET_RC_STATE_STOPTHREAD);
         the_lnet.ln_rc_state = LNET_RC_STATE_UNLINKING;
-        
+
         rc = LNetMDUnlink(mdh);
         LASSERT (rc == 0);
 
         /* The unlink event callback will signal final completion */
-
-       return 0;
+        return 0;
 }
 
 
@@ -730,11 +733,11 @@ lnet_wait_known_routerstate(void)
 
         for (;;) {
                 LNET_LOCK();
-                
+
                 all_known = 1;
                 list_for_each (entry, &the_lnet.ln_routers) {
                         rtr = list_entry(entry, lnet_peer_t, lp_rtr_list);
-                
+
                         if (rtr->lp_alive_count == 0) {
                                 all_known = 0;
                                 break;
@@ -762,14 +765,14 @@ lnet_router_checker_stop(void)
                 return;
 
         the_lnet.ln_rc_state = LNET_RC_STATE_STOPTHREAD;
-       /* block until event callback signals exit */
-       mutex_down(&the_lnet.ln_rc_signal);
+        /* block until event callback signals exit */
+        mutex_down(&the_lnet.ln_rc_signal);
 
         LASSERT (the_lnet.ln_rc_state == LNET_RC_STATE_UNLINKED);
 
         rc = LNetEQFree(the_lnet.ln_rc_eqh);
         LASSERT (rc == 0);
-        
+
         the_lnet.ln_rc_state = LNET_RC_STATE_SHUTDOWN;
 }
 
@@ -787,12 +790,12 @@ lnet_router_checker_start(void)
                                    "\n");
                 return -EINVAL;
         }
-        
+
         if (live_router_check_interval <= 0 &&
             dead_router_check_interval <= 0)
                 return 0;
 
-       init_mutex_locked(&the_lnet.ln_rc_signal);
+        init_mutex_locked(&the_lnet.ln_rc_signal);
 
         /* EQ size doesn't matter; the callback is guaranteed to get every
          * event */
@@ -803,20 +806,20 @@ lnet_router_checker_start(void)
                 return -ENOMEM;
         }
 
-       rc = (int)cfs_kernel_thread(lnet_router_checker, NULL, 0);
-       if (rc < 0) {
-               CERROR("Can't start router checker thread: %d\n", rc);
+        rc = (int)cfs_kernel_thread(lnet_router_checker, NULL, 0);
+        if (rc < 0) {
+                CERROR("Can't start router checker thread: %d\n", rc);
                 goto failed;
-       }
+        }
 
-       mutex_down(&the_lnet.ln_rc_signal);     /* wait for checker to startup */
+        mutex_down(&the_lnet.ln_rc_signal);     /* wait for checker to startup */
 
         rc = the_lnet.ln_rc_state;
         if (rc < 0) {
                 the_lnet.ln_rc_state = LNET_RC_STATE_SHUTDOWN;
                 goto failed;
         }
-        
+
         LASSERT (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING);
 
         if (check_routers_before_use) {
@@ -825,9 +828,9 @@ lnet_router_checker_start(void)
                  * may have to a previous instance of me. */
                 lnet_wait_known_routerstate();
         }
-        
+
         return 0;
-        
+
  failed:
         rc = LNetEQFree(the_lnet.ln_rc_eqh);
         LASSERT (rc == 0);
@@ -914,7 +917,7 @@ lnet_rtrpool_alloc_bufs(lnet_rtrbufpool_t *rbp, int nbufs)
                 LASSERT (rbp->rbp_nbuffers == nbufs);
                 return 0;
         }
-        
+
         for (i = 0; i < nbufs; i++) {
                 rb = lnet_new_rtrbuf(rbp);
 
@@ -973,7 +976,7 @@ int
 lnet_alloc_rtrpools(int im_a_router)
 {
         int       rc;
-        
+
         if (!strcmp(forwarding, "")) {
                 /* not set either way */
                 if (!im_a_router)
@@ -988,7 +991,7 @@ lnet_alloc_rtrpools(int im_a_router)
                                    "'enabled' or 'disabled'\n");
                 return -EINVAL;
         }
-        
+
         if (tiny_router_buffers <= 0) {
                 LCONSOLE_ERROR_MSG(0x10c, "tiny_router_buffers=%d invalid when "
                                    "routing enabled\n", tiny_router_buffers);
@@ -1028,7 +1031,7 @@ lnet_alloc_rtrpools(int im_a_router)
         LNET_LOCK();
         the_lnet.ln_routing = 1;
         LNET_UNLOCK();
-        
+
         return 0;
 
  failed: