Whamcloud - gitweb
LU-56 lnet: cleanup for rtrpool and LNet counter
[fs/lustre-release.git] / lnet / lnet / router_proc.c
index b7365f2..60e0dda 100644 (file)
@@ -1,8 +1,8 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  *
+ * Copyright (c) 2011, Whamcloud, Inc.
+ *
  *   This file is part of Portals
  *   http://sourceforge.net/projects/sandiaportals/
  *
@@ -97,10 +97,8 @@ static int __proc_lnet_stats(void *data, int write,
         const int        tmpsiz = 256; /* 7 %u and 4 LPU64 */
 
         if (write) {
-                LNET_LOCK();
-                memset(&the_lnet.ln_counters, 0, sizeof(the_lnet.ln_counters));
-                LNET_UNLOCK();
-                return 0;
+               lnet_counters_reset();
+               return 0;
         }
 
         /* read */
@@ -115,9 +113,7 @@ static int __proc_lnet_stats(void *data, int write,
                 return -ENOMEM;
         }
 
-        LNET_LOCK();
-        *ctrs = the_lnet.ln_counters;
-        LNET_UNLOCK();
+       lnet_counters_get(ctrs);
 
         len = snprintf(tmpstr, tmpsiz,
                        "%u %u %u %u %u %u %u "LPU64" "LPU64" "
@@ -331,8 +327,20 @@ int LL_PROC_PROTO(proc_lnet_routers)
                         int pingsent  = !peer->lp_ping_notsent;
                         int last_ping = cfs_duration_sec(cfs_time_sub(now,
                                                      peer->lp_ping_timestamp));
-                        int down_ni   = lnet_router_down_ni(peer,
-                                                    LNET_NIDNET(LNET_NID_ANY));
+                       int down_ni   = 0;
+                       lnet_route_t *rtr;
+
+                       if (peer->lp_ping_version == LNET_PROTO_PING_VERSION) {
+                               cfs_list_for_each_entry(rtr, &peer->lp_routes,
+                                                       lr_gwlist) {
+                                       /* downis on any route should be the
+                                        * number of downis on the gateway */
+                                       if (rtr->lr_downis != 0) {
+                                               down_ni = rtr->lr_downis;
+                                               break;
+                                       }
+                               }
+                       }
 
                         if (deadline == 0)
                                 s += snprintf(s, tmpstr + tmpsiz - s,
@@ -378,6 +386,7 @@ int LL_PROC_PROTO(proc_lnet_routers)
 
 int LL_PROC_PROTO(proc_lnet_peers)
 {
+       struct lnet_peer_table  *ptable = the_lnet.ln_peer_table;
         int        rc = 0;
         char      *tmpstr;
         char      *s;
@@ -414,7 +423,7 @@ int LL_PROC_PROTO(proc_lnet_peers)
                 LASSERT (tmpstr + tmpsiz - s > 0);
 
                 LNET_LOCK();
-                ver = (unsigned int)the_lnet.ln_peertable_version;
+               ver = (unsigned int)ptable->pt_version;
                 LNET_UNLOCK();
                 *ppos = LNET_PHASH_POS_MAKE(ver, idx, num);
 
@@ -426,7 +435,7 @@ int LL_PROC_PROTO(proc_lnet_peers)
 
                 LNET_LOCK();
 
-                if (ver != LNET_VERSION_VALID_MASK(the_lnet.ln_peertable_version)) {
+               if (ver != LNET_VERSION_VALID_MASK(ptable->pt_version)) {
                         LNET_UNLOCK();
                         LIBCFS_FREE(tmpstr, tmpsiz);
                         return -ESTALE;
@@ -434,9 +443,9 @@ int LL_PROC_PROTO(proc_lnet_peers)
 
                 while (idx < LNET_PEER_HASHSIZE) {
                         if (p == NULL)
-                                p = the_lnet.ln_peer_hash[idx].next;
+                               p = ptable->pt_hash[idx].next;
 
-                        while (p != &the_lnet.ln_peer_hash[idx]) {
+                       while (p != &ptable->pt_hash[idx]) {
                                 lnet_peer_t *lp = cfs_list_entry(p, lnet_peer_t,
                                                                  lp_hashlist);
                                 if (skip == 0) {
@@ -445,8 +454,8 @@ int LL_PROC_PROTO(proc_lnet_peers)
                                         /* minor optimization: start from idx+1
                                          * on next iteration if we've just
                                          * drained lp_hashlist */
-                                        if (lp->lp_hashlist.next ==
-                                            &the_lnet.ln_peer_hash[idx]) {
+                                       if (lp->lp_hashlist.next ==
+                                           &ptable->pt_hash[idx]) {
                                                 num = 1;
                                                 idx++;
                                         } else {
@@ -553,6 +562,9 @@ static int __proc_lnet_buffers(void *data, int write,
                       "pages", "count", "credits", "min");
         LASSERT (tmpstr + tmpsiz - s > 0);
 
+       if (the_lnet.ln_rtrpools == NULL)
+               goto out; /* I'm not a router */
+
         LNET_LOCK();
 
         for (idx = 0; idx < LNET_NRBPOOLS; idx++) {
@@ -571,6 +583,7 @@ static int __proc_lnet_buffers(void *data, int write,
 
         LNET_UNLOCK();
 
+ out:
         len = s - tmpstr;
 
         if (pos >= min_t(int, len, strlen(tmpstr)))